Skip to content

Commit

Permalink
fix #168
Browse files Browse the repository at this point in the history
  • Loading branch information
AhmedElywa committed Feb 3, 2021
1 parent 8a06518 commit 5463d55
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
7 changes: 6 additions & 1 deletion packages/admin/src/PrismaTable/EditRecord.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const EditRecord: React.FC<EditRecordProps> = ({
push,
pagesPath,
onCancelUpdate,
actions,
} = useContext(TableContext);
const modelObject = models.find((item) => item.id === model);
const [getRecord, { data, loading, error }] = useLazyQuery(
Expand All @@ -61,7 +62,11 @@ const EditRecord: React.FC<EditRecordProps> = ({
(field) => field.kind === 'object' && field.list && field.read,
);

if (!loading && data && !data[`findUnique${model}`] && modelObject)
if (
(!loading && data && !data[`findUnique${model}`] && modelObject) ||
(modelObject && !modelObject.update && !actions && !view) ||
(actions && !actions.includes('update') && !view)
)
push(pagesPath + model);

const onUpdateCancel =
Expand Down
17 changes: 12 additions & 5 deletions packages/admin/src/PrismaTable/Table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export const Table: React.FC<TableProps> = ({
paginationOptions,
tableColumns,
onSelect,
actions: userActions,
} = useContext(TableContext);
const model = models.find((item) => item.id === modelName);
const columnList = columns(model, tableColumns);
Expand Down Expand Up @@ -140,11 +141,17 @@ export const Table: React.FC<TableProps> = ({
};
}, [columnList]);

const actions = {
create: model?.create,
update: model?.update,
delete: model?.delete,
};
const actions = userActions
? {
create: userActions.includes('create'),
update: userActions.includes('update'),
delete: userActions.includes('delete'),
}
: {
create: model?.create,
update: model?.update,
delete: model?.delete,
};

const isSelect = onSelect && !inEdit;

Expand Down
1 change: 1 addition & 0 deletions packages/admin/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ interface RequireContextProps {
}

interface SameProps {
actions?: ('create' | 'update' | 'delete')[];
useSet?: boolean;
tableColumns?: GetColumnsPartial;
formInputs?: Partial<FormInputs>;
Expand Down

0 comments on commit 5463d55

Please sign in to comment.