Skip to content

Commit

Permalink
JNG-5899 save state
Browse files Browse the repository at this point in the history
  • Loading branch information
noherczeg committed Sep 3, 2024
1 parent efaa575 commit 898626d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,6 @@ export function LazyTable<T extends GridValidRowModel, TStored extends T, S exte
disabled: () => false,
action: async (rowData: TStored) => {
setRowModesModel({ ...rowModesModel, [rowData.__identifier!]: { mode: GridRowModes.View } });
/*try {
const validationResult = await applyRowEdit!(rowData);
} catch(e) {
console.error(e);
}*/
},
},
{
Expand Down Expand Up @@ -588,12 +583,19 @@ export function LazyTable<T extends GridValidRowModel, TStored extends T, S exte
}

const processRowUpdate = useCallback(async (newRow: GridRowModel) => {
await applyRowEdit!(newRow as TStored);
// we need to reject with the identifier in order for MUI to be able to detect which row should be kept in edit mode
return Promise.reject(new Error(newRow.__identifier));
try {
await applyRowEdit!(newRow as TStored);
// https://mui.com/x/react-data-grid/editing/#server-side-persistence
// "Please note that the processRowUpdate must return the row object to update the Data Grid internal state."
return newRow;
} catch(error) {
// we need to reject with the identifier in order for MUI to be able to detect which row should be kept in edit mode
return Promise.reject(new Error(newRow.__identifier));
}
}, [applyRowEdit]);

const handleProcessRowUpdateError = useCallback((error: Error) => {
// the message is expected to be the row identifier
setRowModesModel({ ...rowModesModel, [error.message]: { mode: GridRowModes.Edit } });
}, []);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ type: '{{ columnType column }}',
editable: true,
renderEditCell: (props: GridRenderEditCellParams) => {
let error: string | undefined;
if (rowValidation.has(props.row.__identifier)) {
if (props.row && rowValidation.has(props.row.__identifier)) {
const errors = rowValidation.get(props.row.__identifier);
error = errors?.get('{{ column.attributeType.name }}');
}
Expand Down
12 changes: 8 additions & 4 deletions judo-ui-react/src/main/resources/actor/src/pages/index.tsx.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,15 @@ export default function {{ pageName page }}() {
{{# each page.container.tables as |table| }}
{{# if table.isInlineEditable }}
const apply{{ firstToUpper table.relationName }}RowEdit = async (rowData: {{ classDataName (getReferenceClassType table) 'Stored' }}): Promise<any> => {
setIsLoading(true);
alert(JSON.stringify(rowData, null, 2));
setTimeout(() => {
try {
setIsLoading(true);
await {{ getServiceImplForPage page }}.update{{ firstToUpper table.relationName }}({{# unless page.dataElement.isAccess }}{ __signedIdentifier: signedIdentifier } as any, {{/ unless }}rowData);
await refresh();
} catch(error) {
return Promise.reject(error);
} finally {
setIsLoading(false);
}, 500);
}
};
{{/ if }}
{{/ each }}
Expand Down

0 comments on commit 898626d

Please sign in to comment.