|
|
|
@ -40,6 +40,7 @@ export const isCheckboxType: any = (values: [], col = null) => {
|
|
|
|
|
} |
|
|
|
|
return options |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export const getCheckboxValue = (value: number) => { |
|
|
|
|
return value && aggBooleanOptions[value] |
|
|
|
|
} |
|
|
|
@ -51,6 +52,7 @@ export const isMultiLineTextType = (values: [], col = null) => {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export const extractMultiOrSingleSelectProps = (colData: []) => { |
|
|
|
|
const maxSelectOptionsAllowed = 64 |
|
|
|
|
const colProps: any = {} |
|
|
|
|
if (colData.some((v: any) => v && (v || '').toString().includes(','))) { |
|
|
|
|
let flattenedVals = colData.flatMap((v: any) => |
|
|
|
@ -64,20 +66,40 @@ export const extractMultiOrSingleSelectProps = (colData: []) => {
|
|
|
|
|
const uniqueVals = (flattenedVals = flattenedVals.filter( |
|
|
|
|
(v, i, arr) => i === arr.findIndex((v1) => v.toLowerCase() === v1.toLowerCase()), |
|
|
|
|
)) |
|
|
|
|
if (flattenedVals.length > uniqueVals.length && uniqueVals.length <= Math.ceil(flattenedVals.length / 2)) { |
|
|
|
|
colProps.uidt = UITypes.MultiSelect |
|
|
|
|
if (uniqueVals.length > maxSelectOptionsAllowed) { |
|
|
|
|
// too many options are detected, convert the column to SingleLineText instead
|
|
|
|
|
colProps.uidt = UITypes.SingleLineText |
|
|
|
|
// _disableSelect is used to disable the <a-select-option/> in TemplateEditor
|
|
|
|
|
colProps._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)) { |
|
|
|
|
colProps.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
|
|
|
|
|
colProps.dtxp = `'${uniqueVals.join("','")}'` |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
const uniqueVals = colData |
|
|
|
|
.map((v: any) => (v || '').toString().trim()) |
|
|
|
|
.filter((v, i, arr) => i === arr.findIndex((v1) => v.toLowerCase() === v1.toLowerCase())) |
|
|
|
|
if (colData.length > uniqueVals.length && uniqueVals.length <= Math.ceil(colData.length / 2)) { |
|
|
|
|
colProps.uidt = UITypes.SingleSelect |
|
|
|
|
const uniqueVals = [...new Set(colData.map((v: any) => v.toString().trim().toLowerCase()))] |
|
|
|
|
|
|
|
|
|
if (uniqueVals.length > maxSelectOptionsAllowed) { |
|
|
|
|
// too many options are detected, convert the column to SingleLineText instead
|
|
|
|
|
colProps.uidt = UITypes.SingleLineText |
|
|
|
|
// _disableSelect is used to disable the <a-select-option/> in TemplateEditor
|
|
|
|
|
colProps._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 (colData.length > uniqueVals.length && uniqueVals.length <= Math.ceil(colData.length / 2)) { |
|
|
|
|
colProps.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
|
|
|
|
|
colProps.dtxp = `'${uniqueVals.join("','")}'` |
|
|
|
|
} |
|
|
|
|
return colProps |
|
|
|
|
} |
|
|
|
|
return colProps |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export const isDecimalType = (colData: []) => |
|
|
|
@ -89,7 +111,39 @@ export const isEmailType = (colData: []) =>
|
|
|
|
|
!colData.some((v: any) => { |
|
|
|
|
return v && !isEmail(v) |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
export const isUrlType = (colData: []) => |
|
|
|
|
!colData.some((v: any) => { |
|
|
|
|
return v && !isValidURL(v) |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
export const getColumnUIDTAndMetas = (colData: [], defaultType: string) => { |
|
|
|
|
const colProps = { uidt: defaultType } |
|
|
|
|
|
|
|
|
|
if (colProps.uidt === UITypes.SingleLineText) { |
|
|
|
|
// check for long text
|
|
|
|
|
if (isMultiLineTextType(colData)) { |
|
|
|
|
colProps.uidt = UITypes.LongText |
|
|
|
|
} |
|
|
|
|
if (isEmailType(colData)) { |
|
|
|
|
colProps.uidt = UITypes.Email |
|
|
|
|
} |
|
|
|
|
if (isUrlType(colData)) { |
|
|
|
|
colProps.uidt = UITypes.URL |
|
|
|
|
} else { |
|
|
|
|
const checkboxType = isCheckboxType(colData) |
|
|
|
|
if (checkboxType.length === 1) { |
|
|
|
|
colProps.uidt = UITypes.Checkbox |
|
|
|
|
} else { |
|
|
|
|
Object.assign(colProps, extractMultiOrSingleSelectProps(colData)) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} else if (colProps.uidt === UITypes.Number) { |
|
|
|
|
if (isDecimalType(colData)) { |
|
|
|
|
colProps.uidt = UITypes.Decimal |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// TODO: currency
|
|
|
|
|
// TODO: date / datetime
|
|
|
|
|
return colProps |
|
|
|
|
} |
|
|
|
|