From dd3f5553ab2ab9c6ea5b39937aa2f882089ee710 Mon Sep 17 00:00:00 2001 From: Sidney Alcantara Date: Fri, 18 Nov 2022 18:36:41 +1100 Subject: [PATCH] fix Rating cells not saving to db & add warning in comments --- src/components/Table/TableCell/withRenderTableCell.tsx | 8 ++++---- src/components/fields/Rating/EditorCell.tsx | 6 +++++- src/components/fields/types.ts | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/components/Table/TableCell/withRenderTableCell.tsx b/src/components/Table/TableCell/withRenderTableCell.tsx index 0d215b19..60935e07 100644 --- a/src/components/Table/TableCell/withRenderTableCell.tsx +++ b/src/components/Table/TableCell/withRenderTableCell.tsx @@ -67,12 +67,12 @@ export interface IRenderedTableCellProps * * - `EditorCell` should use the `value` and `onChange` props for the * rendered inputs. Avoid creating another local state here. - * - `onSubmit` is available if `saveOnUnmount` does not work or if you want - * to submit to the db before unmount. - * - ✨ You can reuse your `SideDrawerField` as they take the same props. It - * should probably be displayed in a popover. * - You can pass `null` to `withRenderTableCell()` to always display the * `DisplayCell`. + * - ⚠️ If it’s displayed inline, you must call `onSubmit` to save the value + * to the database, because it never unmounts. + * - ✨ You can reuse your `SideDrawerField` as they take the same props. It + * should probably be displayed in a popover. * - ⚠️ Make sure to use the `tabIndex` prop for buttons, text fields, and * other interactive elements. * - {@link IEditorCellProps} diff --git a/src/components/fields/Rating/EditorCell.tsx b/src/components/fields/Rating/EditorCell.tsx index 4d3c0c23..89a48f2d 100644 --- a/src/components/fields/Rating/EditorCell.tsx +++ b/src/components/fields/Rating/EditorCell.tsx @@ -4,6 +4,7 @@ import DisplayCell from "./DisplayCell"; export default function Rating({ onChange, + onSubmit, tabIndex, ...props }: IEditorCellProps) { @@ -20,7 +21,10 @@ export default function Rating({ onChange(newValue)} + onChange={(_, newValue) => { + onChange(newValue); + onSubmit(); + }} ref={ref} /> ); diff --git a/src/components/fields/types.ts b/src/components/fields/types.ts index 50a05f8a..63374d81 100644 --- a/src/components/fields/types.ts +++ b/src/components/fields/types.ts @@ -1,5 +1,5 @@ import { FieldType } from "@src/constants/fields"; -import type { IRenderedTableCellProps } from "@src/components/Table/TableCell/withRenderTableCell"; +import { IRenderedTableCellProps } from "@src/components/Table/TableCell/withRenderTableCell"; import type { PopoverProps } from "@mui/material"; import type { ColumnConfig,