Skip to content

Commit

Permalink
Fix properties custom cell editor (#2161)
Browse files Browse the repository at this point in the history
Signed-off-by: achour94 <[email protected]>
  • Loading branch information
achour94 authored Jul 10, 2024
1 parent 410a5db commit 9e50c72
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 54 deletions.
49 changes: 0 additions & 49 deletions src/components/spreadsheet/utils/config-tables.js
Original file line number Diff line number Diff line change
Expand Up @@ -473,13 +473,6 @@ export const TABLES_DEFINITIONS = {
return params;
},
cellEditor: SitePropertiesEditor,
cellEditorParams: (params) => {
return {
gridApi: params.api,
colDef: params.colDef,
rowData: params.data,
};
},
cellEditorPopup: true,
...defaultTextFilterConfig,
},
Expand Down Expand Up @@ -649,13 +642,6 @@ export const TABLES_DEFINITIONS = {
return params;
},
cellEditor: SitePropertiesEditor,
cellEditorParams: (params) => {
return {
gridApi: params.api,
colDef: params.colDef,
rowData: params.data,
};
},
cellEditorPopup: true,
...defaultTextFilterConfig,
},
Expand Down Expand Up @@ -1571,13 +1557,6 @@ export const TABLES_DEFINITIONS = {
return params;
},
cellEditor: SitePropertiesEditor,
cellEditorParams: (params) => {
return {
gridApi: params.api,
colDef: params.colDef,
rowData: params.data,
};
},
cellEditorPopup: true,
...defaultTextFilterConfig,
},
Expand Down Expand Up @@ -2649,13 +2628,6 @@ export const TABLES_DEFINITIONS = {
return params;
},
cellEditor: SitePropertiesEditor,
cellEditorParams: (params) => {
return {
gridApi: params.api,
colDef: params.colDef,
rowData: params.data,
};
},
cellEditorPopup: true,
...defaultTextFilterConfig,
},
Expand Down Expand Up @@ -2800,13 +2772,6 @@ export const TABLES_DEFINITIONS = {
return params;
},
cellEditor: SitePropertiesEditor,
cellEditorParams: (params) => {
return {
gridApi: params.api,
colDef: params.colDef,
rowData: params.data,
};
},
cellEditorPopup: true,
...defaultTextFilterConfig,
},
Expand Down Expand Up @@ -3021,13 +2986,6 @@ export const TABLES_DEFINITIONS = {
return params;
},
cellEditor: SitePropertiesEditor,
cellEditorParams: (params) => {
return {
gridApi: params.api,
colDef: params.colDef,
rowData: params.data,
};
},
cellEditorPopup: true,
...defaultTextFilterConfig,
},
Expand Down Expand Up @@ -3367,13 +3325,6 @@ export const TABLES_DEFINITIONS = {
return params;
},
cellEditor: SitePropertiesEditor,
cellEditorParams: (params) => {
return {
gridApi: params.api,
colDef: params.colDef,
rowData: params.data,
};
},
cellEditorPopup: true,
...defaultTextFilterConfig,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
forwardRef,
useImperativeHandle,
useMemo,
useEffect,
} from 'react';
import { FormattedMessage, useIntl } from 'react-intl';

Expand All @@ -32,6 +33,7 @@ import {
} from '@mui/material';
import { SelectOptionsDialog } from 'utils/dialogs';
import yup from 'components/utils/yup-config';
import { ICellEditorParams } from 'ag-grid-community';

const validationSchema = yup
.array()
Expand Down Expand Up @@ -65,15 +67,17 @@ function initializeLocalRowData(rowData: any) {
}

export const SitePropertiesEditor = forwardRef(
({ colDef, gridApi, rowData }: any, ref) => {
({ colDef, data, stopEditing }: ICellEditorParams, ref) => {
const theme = useTheme();
const [error, setError] = useState('');
const intl = useIntl();
const [open, setOpen] = useState(true);
const [cancel, setCancel] = useState(false);
const [localRowData, setRowData] = useState(() =>
initializeLocalRowData(rowData)
initializeLocalRowData(data)
);

// Documented in https://www.ag-grid.com/archive/31.2.0/react-data-grid/component-cell-editor-imperative-react/
useImperativeHandle(
ref,
() => {
Expand All @@ -84,11 +88,20 @@ export const SitePropertiesEditor = forwardRef(
getField: () => {
return colDef.field;
},
isCancelAfterEnd: () => {
return cancel;
},
};
},
[colDef.field, localRowData]
[colDef.field, localRowData, cancel]
);

useEffect(() => {
if (cancel) {
stopEditing();
}
}, [cancel, stopEditing]);

const handleRemoveRow = useCallback(
(index: number) => {
const newData = [...localRowData];
Expand Down Expand Up @@ -125,7 +138,7 @@ export const SitePropertiesEditor = forwardRef(
if (!hasError) {
setError('');
setOpen(false);
gridApi.stopEditing();
stopEditing();
}

return !hasError;
Expand All @@ -145,7 +158,7 @@ export const SitePropertiesEditor = forwardRef(

const handleCancelPopupSelectEditSiteProperties = () => {
setOpen(false);
gridApi.stopEditing();
setCancel(true);
};

return (
Expand Down

0 comments on commit 9e50c72

Please sign in to comment.