From e36b79c9401fbf40e12fef0378a1d56fa133747d Mon Sep 17 00:00:00 2001 From: Nazar Gargol Date: Fri, 3 Jul 2020 16:54:21 +1200 Subject: [PATCH] Added field mapping column to members importer gird no issue - Adds UI to map imported csv fields to ones accepted by Ghost API - Includes automatic mapping detection for emails and stripe_customer_ids --- .../gh-members-import-mapping-input.hbs | 13 +++ .../gh-members-import-mapping-input.js | 29 ++++++ .../components/gh-members-import-table.hbs | 14 +-- .../app/components/gh-members-import-table.js | 21 +++- .../app/components/modal-import-members.hbs | 12 ++- .../app/components/modal-import-members.js | 96 +++++++++++++++++++ .../gh-members-import-table-test.js | 38 +++++--- 7 files changed, 199 insertions(+), 24 deletions(-) create mode 100644 ghost/admin/app/components/gh-members-import-mapping-input.hbs create mode 100644 ghost/admin/app/components/gh-members-import-mapping-input.js diff --git a/ghost/admin/app/components/gh-members-import-mapping-input.hbs b/ghost/admin/app/components/gh-members-import-mapping-input.hbs new file mode 100644 index 0000000000..64b134493a --- /dev/null +++ b/ghost/admin/app/components/gh-members-import-mapping-input.hbs @@ -0,0 +1,13 @@ + + + {{svg-jar "arrow-down-small"}} + \ No newline at end of file diff --git a/ghost/admin/app/components/gh-members-import-mapping-input.js b/ghost/admin/app/components/gh-members-import-mapping-input.js new file mode 100644 index 0000000000..a7c29ed698 --- /dev/null +++ b/ghost/admin/app/components/gh-members-import-mapping-input.js @@ -0,0 +1,29 @@ +import Component from '@glimmer/component'; +import {action} from '@ember/object'; +import {tracked} from '@glimmer/tracking'; + +const FIELD_MAPPINGS = [ + {label: 'email', value: 'email'}, + {label: 'name', value: 'name'}, + {label: 'note', value: 'note'}, + {label: 'subscribed_to_emails', value: 'subscribed_to_emails'}, + {label: 'stripe_customer_id', value: 'stripe_customer_id'}, + {label: 'complimentary_plan', value: 'complimentary_plan'}, + {label: 'labels', value: 'labels'}, + {label: 'created_at', value: 'created_at'} +]; + +export default class extends Component { + @tracked availableFields = FIELD_MAPPINGS; + + get mapTo() { + return this.args.mapTo; + } + + @action + updateMapping(newMapTo) { + if (this.args.updateMapping) { + this.args.updateMapping(this.args.mapFrom, newMapTo); + } + } +} diff --git a/ghost/admin/app/components/gh-members-import-table.hbs b/ghost/admin/app/components/gh-members-import-table.hbs index 8a8bbd0748..e62186fe97 100644 --- a/ghost/admin/app/components/gh-members-import-table.hbs +++ b/ghost/admin/app/components/gh-members-import-table.hbs @@ -1,26 +1,28 @@ - + + - {{#each-in currentlyDisplayedData as |key value|}} + {{#each currentlyDisplayedData as |row|}} - - + + + {{else}} - {{/each-in}} + {{/each}}
HeaderField Import as...
{{key}}{{value}}{{row.key}}{{row.value}}
No data
\ No newline at end of file diff --git a/ghost/admin/app/components/gh-members-import-table.js b/ghost/admin/app/components/gh-members-import-table.js index fa73a6ed50..350f034d46 100644 --- a/ghost/admin/app/components/gh-members-import-table.js +++ b/ghost/admin/app/components/gh-members-import-table.js @@ -6,11 +6,26 @@ export default class GhMembersImportTable extends Component { @tracked dataPreviewIndex = 0; get currentlyDisplayedData() { - if (this.args && this.args.importData) { - return this.args.importData[this.dataPreviewIndex]; + let rows = []; + + if (this.args && this.args.importData && this.args.mapping && this.args.mapping.mapping) { + let currentRecord = this.args.importData[this.dataPreviewIndex]; + + for (const [key, value] of Object.entries(currentRecord)) { + rows.push({ + key: key, + value: value, + mapTo: this.args.mapping.get(key) + }); + } } - return {}; + return rows; + } + + @action + updateMapping(mapFrom, mapTo) { + this.args.updateMapping(mapFrom, mapTo); } @action diff --git a/ghost/admin/app/components/modal-import-members.hbs b/ghost/admin/app/components/modal-import-members.hbs index 64305f7547..7165f2702a 100644 --- a/ghost/admin/app/components/modal-import-members.hbs +++ b/ghost/admin/app/components/modal-import-members.hbs @@ -12,12 +12,12 @@ {{#if this.importResponse}}