Skip to content

Commit

Permalink
updated handleUpdateConfiguration
Browse files Browse the repository at this point in the history
  • Loading branch information
NyashaMuusha committed Jul 2, 2024
1 parent 1b5832d commit 26abc8f
Showing 1 changed file with 10 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ interface GoldenRecordListsProps {
const GoldenRecordLists: FC<GoldenRecordListsProps> = ({ goldenRecordList }) => {
const [rows, setRows] = useState<RowData[]>([]);
const [rowModesModel, setRowModesModel] = useState<GridRowModesModel>({});
const [configuration, setConfiguration] = useState<Configuration>();
const [, setConfiguration] = useState<Configuration>();

useEffect(() => {
if (goldenRecordList) {
Expand All @@ -56,23 +56,6 @@ const GoldenRecordLists: FC<GoldenRecordListsProps> = ({ goldenRecordList }) =>
}
}, [goldenRecordList]);

useEffect(() => {
if (configuration) {
const rowsWithIds = configuration.additionalNodes.flatMap((node, nodeIndex) => {
return node.fields.map((field, fieldIndex) => ({
id: `${node.name}_${nodeIndex}_${fieldIndex}`,
nodeName: node.name,
fieldName: field.fieldName,
fieldType: field.fieldType,
csvCol: field.source?.csvCol ?? 0,
nodeIndex,
fieldIndex,
}));
});
setRows(rowsWithIds);
}
}, [configuration]);

const handleEditClick = (id: GridRowId) => () => {
setRowModesModel((prevModel) => ({ ...prevModel, [id]: { mode: GridRowModes.Edit } }));
};
Expand All @@ -85,14 +68,15 @@ const GoldenRecordLists: FC<GoldenRecordListsProps> = ({ goldenRecordList }) =>
};

const handleUpdateConfiguration = (updatedRow: RowData, rowIndex: number) => {
setConfiguration(previousConfiguration => {
if (!previousConfiguration) return previousConfiguration
const updatedConfiguration = getUpdatedConfiguration(updatedRow, rowIndex, previousConfiguration);
localStorage.setItem('configuration', JSON.stringify(updatedConfiguration));
return updatedConfiguration;
});
};

const storedConfiguration = localStorage.getItem('configuration');
const currentConfiguration = storedConfiguration ? JSON.parse(storedConfiguration) : {};
const updatedConfiguration = getUpdatedConfiguration(updatedRow, rowIndex, currentConfiguration);
localStorage.setItem(
'configuration',
JSON.stringify(updatedConfiguration)
)
setConfiguration(updatedConfiguration);
}
const getUpdatedConfiguration = (updatedRow: RowData, fieldIndex: number, currentConfig: Configuration): Configuration => {
const nodeIndex = updatedRow.nodeIndex;
const fieldName = toSnakeCase(updatedRow.fieldName);
Expand Down

0 comments on commit 26abc8f

Please sign in to comment.