|
|
|
@ -72,6 +72,8 @@ export default class ExcelTemplateAdapter extends TemplateGenerator {
|
|
|
|
|
parse() { |
|
|
|
|
const tableNamePrefixRef: Record<string, any> = {} |
|
|
|
|
|
|
|
|
|
const maxSelectOptionsAllowed = 100 |
|
|
|
|
|
|
|
|
|
for (let i = 0; i < this.wb.SheetNames.length; i++) { |
|
|
|
|
const columnNamePrefixRef: Record<string, any> = { id: 0 } |
|
|
|
|
const sheet: any = this.wb.SheetNames[i] |
|
|
|
@ -151,9 +153,6 @@ export default class ExcelTemplateAdapter extends TemplateGenerator {
|
|
|
|
|
if (checkboxType.length === 1) { |
|
|
|
|
column.uidt = UITypes.Checkbox |
|
|
|
|
} else { |
|
|
|
|
// todo: optimize
|
|
|
|
|
// check column is multi or single select by comparing unique values
|
|
|
|
|
// todo:
|
|
|
|
|
if (vals.some((v: any) => v && v.toString().includes(','))) { |
|
|
|
|
let flattenedVals = vals.flatMap((v: any) => |
|
|
|
|
v |
|
|
|
@ -163,29 +162,43 @@ export default class ExcelTemplateAdapter extends TemplateGenerator {
|
|
|
|
|
.split(/\s*,\s*/) |
|
|
|
|
: [], |
|
|
|
|
) |
|
|
|
|
const uniqueVals = (flattenedVals = flattenedVals.filter( |
|
|
|
|
(v: any, i: any, arr: any) => i === arr.findIndex((v1: any) => v.toLowerCase() === v1.toLowerCase()), |
|
|
|
|
)) |
|
|
|
|
// assume the column type is multiple select if there are repeated values
|
|
|
|
|
if (flattenedVals.length > uniqueVals.length && uniqueVals.length <= Math.ceil(flattenedVals.length / 2)) { |
|
|
|
|
column.uidt = UITypes.MultiSelect |
|
|
|
|
|
|
|
|
|
// TODO: handle case sensitive case
|
|
|
|
|
const uniqueVals = [...new Set(flattenedVals.map((v: any) => v.toString().trim().toLowerCase()))] |
|
|
|
|
|
|
|
|
|
if (uniqueVals.length > maxSelectOptionsAllowed) { |
|
|
|
|
// too many options are detected, convert the column to SingleLineText instead
|
|
|
|
|
column.uidt = UITypes.SingleLineText |
|
|
|
|
// _disableSelect is used to disable the <a-select-option/> in TemplateEditor
|
|
|
|
|
column._disableSelect = true |
|
|
|
|
} else { |
|
|
|
|
// assume the column type is multiple select if there are repeated values
|
|
|
|
|
if (flattenedVals.length > uniqueVals.length && uniqueVals.length <= Math.ceil(flattenedVals.length / 2)) { |
|
|
|
|
column.uidt = UITypes.MultiSelect |
|
|
|
|
} |
|
|
|
|
// set dtxp here so that users can have the options even they switch the type from other types to MultiSelect
|
|
|
|
|
// once it's set, dtxp needs to be reset if the final column type is not MultiSelect
|
|
|
|
|
column.dtxp = `'${uniqueVals.join("','")}'` |
|
|
|
|
} |
|
|
|
|
// set dtxp here so that users can have the options even they switch the type from other types to MultiSelect
|
|
|
|
|
// once it's set, dtxp needs to be reset if the final column type is not MultiSelect
|
|
|
|
|
column.dtxp = `'${uniqueVals.join("','")}'` |
|
|
|
|
} else { |
|
|
|
|
// assume the column type is single select if there are repeated values
|
|
|
|
|
// once it's set, dtxp needs to be reset if the final column type is not Single Select
|
|
|
|
|
const uniqueVals = vals |
|
|
|
|
.map((v: any) => v.toString().trim()) |
|
|
|
|
.filter((v: any, i: any, arr: any) => i === arr.findIndex((v1: any) => v.toLowerCase() === v1.toLowerCase())) |
|
|
|
|
|
|
|
|
|
if (vals.length > uniqueVals.length && uniqueVals.length <= Math.ceil(vals.length / 2)) { |
|
|
|
|
column.uidt = UITypes.SingleSelect |
|
|
|
|
// TODO: handle case sensitive case
|
|
|
|
|
const uniqueVals = [...new Set(vals.map((v: any) => v.toString().trim().toLowerCase()))] |
|
|
|
|
|
|
|
|
|
if (uniqueVals.length > maxSelectOptionsAllowed) { |
|
|
|
|
// too many options are detected, convert the column to SingleLineText instead
|
|
|
|
|
column.uidt = UITypes.SingleLineText |
|
|
|
|
// _disableSelect is used to disable the <a-select-option/> in TemplateEditor
|
|
|
|
|
column._disableSelect = true |
|
|
|
|
} else { |
|
|
|
|
// assume the column type is single select if there are repeated values
|
|
|
|
|
// once it's set, dtxp needs to be reset if the final column type is not Single Select
|
|
|
|
|
if (vals.length > uniqueVals.length && uniqueVals.length <= Math.ceil(vals.length / 2)) { |
|
|
|
|
column.uidt = UITypes.SingleSelect |
|
|
|
|
} |
|
|
|
|
// set dtxp here so that users can have the options even they switch the type from other types to SingleSelect
|
|
|
|
|
// once it's set, dtxp needs to be reset if the final column type is not SingleSelect
|
|
|
|
|
column.dtxp = `'${uniqueVals.join("','")}'` |
|
|
|
|
} |
|
|
|
|
// set dtxp here so that users can have the options even they switch the type from other types to SingleSelect
|
|
|
|
|
// once it's set, dtxp needs to be reset if the final column type is not SingleSelect
|
|
|
|
|
column.dtxp = `'${uniqueVals.join("','")}'` |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|