Skip to content

Commit

Permalink
bugfix: useObject original default params reinstated
Browse files Browse the repository at this point in the history
- some typing for files changed
KBDEV-1095
  • Loading branch information
kttkjl committed May 1, 2024
1 parent 499a726 commit 8240a31
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
8 changes: 2 additions & 6 deletions src/components/RecordFormDialog/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const RecordFormDialog = (props: RecordFormDialogProps) => {
onClose,
onError,
onSubmit,
title,
title = '',
variant,
value,
...rest
Expand Down Expand Up @@ -70,6 +70,7 @@ const RecordFormDialog = (props: RecordFormDialogProps) => {
modelName={modelName}
onError={onError}
onSubmit={onSubmit}
title={title}
value={value}
variant={variant}
/>
Expand All @@ -78,9 +79,4 @@ const RecordFormDialog = (props: RecordFormDialogProps) => {
);
};

RecordFormDialog.defaultProps = {
isOpen: false,
title: '',
};

export default RecordFormDialog;
8 changes: 4 additions & 4 deletions src/components/hooks/useObject.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ function useObject<T extends object>(initialValue: T): {
setContent({ type: 'update', payload: { name, value } });
}, [setContent]);

const update = useCallback((newContent: Partial<T>) => {
const update = useCallback((newContent: Partial<T> = {} as T) => {
setContent({ type: 'bulk-update', payload: newContent });
}, [setContent]);

const replace = useCallback((newContent: T) => {
const replace = useCallback((newContent: T = {} as T) => {
setContent({ type: 'replace', payload: newContent });
}, [setContent]);

Expand All @@ -55,8 +55,8 @@ function useObject<T extends object>(initialValue: T): {
}, [content, setContent]);

useDeepCompareEffect(() => {
replace(initialValue);
}, [initialValue]);
replace(initialValue || {});
}, [initialValue || {}]);

return {
content,
Expand Down
8 changes: 5 additions & 3 deletions src/views/AdminView/components/AdminTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ import {
} from '@material-ui/core';
import AddIcon from '@material-ui/icons/Add';
import EditIcon from '@material-ui/icons/Edit';
import { ColDef } from 'ag-grid-community';
import { AgGridReact } from 'ag-grid-react';
import React, {
useCallback,
useState,
} from 'react';

import RecordFormDialog from '@/components/RecordFormDialog';
import { GeneralRecordType } from '@/components/types';
import { FORM_VARIANT } from '@/components/util';

interface AdminTableProps {
Expand All @@ -31,7 +33,7 @@ interface AdminTableProps {
* Component for managing AdminView User form state.
*/
const AdminTable = ({ onChange, records = [], variant = 'User' }: AdminTableProps) => {
const [recordOpen, setRecordOpen] = useState(null);
const [recordOpen, setRecordOpen] = useState<GeneralRecordType | null>();
const [dialogOpen, setDialogOpen] = useState(false);

const handleOpenEditDialog = (record) => {
Expand Down Expand Up @@ -60,7 +62,7 @@ const AdminTable = ({ onChange, records = [], variant = 'User' }: AdminTableProp
onChange();
}, [onChange]);

const colDefs = [
const colDefs: ColDef[] = [
{
headerName: 'record ID',
field: '@rid',
Expand Down Expand Up @@ -93,7 +95,7 @@ const AdminTable = ({ onChange, records = [], variant = 'User' }: AdminTableProp
flex: true,
valueGetter: ({ data: { groups } }) => groups?.map((group) => group.name).join(', ') ?? '',
},
]);
] as ColDef[]);
}
colDefs.push(...[
{
Expand Down

0 comments on commit 8240a31

Please sign in to comment.