-
Notifications
You must be signed in to change notification settings - Fork 0
Import export fix #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,6 +48,36 @@ export default class ImportExport extends AdminForthPlugin { | |
| // Needed if plugin can have multiple instances on one resource | ||
| return `${this.pluginInstanceId}`; | ||
| } | ||
| fixArrayFields(row: any) { | ||
| this.resourceConfig.columns.forEach((col) => { | ||
| if (col.isArray?.enabled) { | ||
| const val = row[col.name]; | ||
|
|
||
| if (typeof val === 'string') { | ||
| if (!val.trim()) { | ||
| row[col.name] = []; | ||
| } else { | ||
| let useCommaParsing = false; | ||
|
|
||
| if (val.trim().startsWith('[') && val.trim().endsWith(']')) { | ||
| try { row[col.name] = JSON.parse(val); } | ||
| catch (e) { useCommaParsing = true; } | ||
| } else { | ||
| useCommaParsing = true; | ||
| } | ||
|
|
||
| if (useCommaParsing) { | ||
| row[col.name] = val.split(',').map(s => s.trim()); | ||
| } | ||
| } | ||
| } else if (typeof val === 'number') { | ||
| row[col.name] = [val.toString()]; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. are u sure this is possible? if you will try to add console.log, can you make it executing and show screenshot here.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lets research why wand whether it is needed |
||
| } else if (val === null || val === undefined) { | ||
| row[col.name] = []; | ||
| } | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| setupEndpoints(server: IHttpServer) { | ||
| server.endpoint({ | ||
|
|
@@ -128,6 +158,7 @@ export default class ImportExport extends AdminForthPlugin { | |
| let updatedCount = 0; | ||
|
|
||
| await Promise.all(rows.map(async (row) => { | ||
| this.fixArrayFields(row); | ||
| try { | ||
| if (primaryKeyColumn && row[primaryKeyColumn.name]) { | ||
| const existingRecord = await this.adminforth.resource(this.resourceConfig.resourceId) | ||
|
|
@@ -186,7 +217,10 @@ export default class ImportExport extends AdminForthPlugin { | |
|
|
||
| let importedCount = 0; | ||
|
|
||
|
|
||
| await Promise.all(rows.map(async (row) => { | ||
| this.fixArrayFields(row); | ||
|
|
||
| try { | ||
| if (primaryKeyColumn && row[primaryKeyColumn.name]) { | ||
| const existingRecord = await this.adminforth.resource(this.resourceConfig.resourceId) | ||
|
|
||

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets fix DRY on this line
Instead we can use boolean like
let useCommaParsing = false;
and set it to true