Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | 66x 66x 66x 66x 66x 66x | import { RecordProps, Store, TableMetaProps } from "@props/RecordProps"; import { isObjectType } from "@utils/ColumnsUtils"; import { transformRecord } from "@kernel/DisplayComponentsMapping"; export enum ArrayColumnOperationsTypeEnum { ADD = "ADD", REMOVE = "REMOVE", EDIT = "EDIT", NOT_CHANGE = "NOT_CHANGE", } export interface ArrayColumnOption { operations: Record<ArrayColumnOperationsTypeEnum, number[]>; ownerColumnName?: string; } export const convertValueToForm = (record: RecordProps, columnsRecord: Record<string, TableMetaProps>): Store => { const val: Store = {}; if (!columnsRecord) { return val; } Object.keys(columnsRecord).forEach((key) => { const column = columnsRecord[key]; if (column && isObjectType(column.type)) { val[key] = record[key]?.id; } else { val[key] = record[key]; } }); return val; }; export const mergeChangedValues = (record: RecordProps, changedValues: Store): RecordProps => { const newRecord: RecordProps = { ...record }; Object.keys(changedValues).forEach(key => { newRecord[key] = changedValues[key]; }); return newRecord; }; export const convertValueFromForm = (prev: RecordProps, store: Store, columnsRecord: Record<string, TableMetaProps>): RecordProps => { const val: RecordProps = { ...prev }; if (!columnsRecord) { return val; } Object.keys(columnsRecord).forEach((key) => { const column = columnsRecord[key]; if (column && column.display) { if (isObjectType(column.type)) { if (store[key]) { val[key] = { id: store[key], }; } else { val[key] = undefined; } } else { val[key] = store[key]; } } }); return val; }; export const convertRecordToStore = (record: RecordProps, columnsRecord: Record<string, TableMetaProps>): RecordProps => { const convertedData = transformRecord(Object.values(columnsRecord), record); const res: RecordProps = { } as RecordProps; // filter out the columns that are not in the columnsRecord Object.keys(columnsRecord).forEach((key) => { res[key] = convertedData[key]; }); return res; }; export const markRecordEdited = (arrayColumnOption: ArrayColumnOption, record: RecordProps): void => { // added row if (record.id < 0) { return; } arrayColumnOption.operations[ArrayColumnOperationsTypeEnum.NOT_CHANGE] = arrayColumnOption.operations[ArrayColumnOperationsTypeEnum.NOT_CHANGE].filter(value => value !== record.id); arrayColumnOption.operations[ArrayColumnOperationsTypeEnum.EDIT] = arrayColumnOption.operations[ArrayColumnOperationsTypeEnum.EDIT].filter(value => value !== record.id); }; export const markRecordRemoved = (arrayColumnOption: ArrayColumnOption, record: RecordProps): void => { // remove row if (record.id < 0) { arrayColumnOption.operations[ArrayColumnOperationsTypeEnum.NOT_CHANGE] = arrayColumnOption.operations[ArrayColumnOperationsTypeEnum.NOT_CHANGE].filter(value => value !== record.id); return; } arrayColumnOption.operations[ArrayColumnOperationsTypeEnum.NOT_CHANGE] = arrayColumnOption.operations[ArrayColumnOperationsTypeEnum.NOT_CHANGE].filter(value => value !== record.id); arrayColumnOption.operations[ArrayColumnOperationsTypeEnum.EDIT] = arrayColumnOption.operations[ArrayColumnOperationsTypeEnum.EDIT].filter(value => value !== record.id); if (!arrayColumnOption.operations[ArrayColumnOperationsTypeEnum.REMOVE].find(value => value === record.id)) { arrayColumnOption.operations[ArrayColumnOperationsTypeEnum.REMOVE].push(record.id); } }; |