paljs / prisma-tools

Prisma tools to help you generate CRUD system for GraphQL servers
https://paljs.com
MIT License
683 stars 54 forks source link

'adminSettings.json' problems #168

Closed gtolarc closed 3 years ago

gtolarc commented 3 years ago

Setting management using the'adminSettings.json' file is not flexible. It is not possible to restrict actions (create/update/delete) according to each user's permission or support i18n of field titles. Can you guys think about this and improve it?

AhmedElywa commented 3 years ago

Hi @gtolarc, It's an interesting idea we can give you a react component props say permissions It takes an array of strings, create/update/delete. It will force what is in adminSettings.json. What do you think?

gtolarc commented 3 years ago

If you can receive one prop(I think the name updateModel would be good.) of the following shape in PrismaTable, it seems that we can solve both the permission and i18n problem at the same time.

{
    actions: ['create', 'update', 'delete'],
    titles: {
        id: '번호', // This part can be replaced by using a library like react-i18next.
        name: '이름',
        createdAt: '생성일',
    },
}
AhmedElywa commented 3 years ago

Please, I need to focus on one issue. Can we solve permissions here and open a new issue for other issues

gtolarc commented 3 years ago

Got it. I think your solution is fine. It seems to be a simple way to allow the client to determine actions.

AhmedElywa commented 3 years ago

you can now pass actions props to the PrismaAdmin component from version 2.12.0

import { PrismaTable } from '@paljs/admin';

const Table: React.FC<{ model: string }> = ({ model }) => {
  const router = useRouter();
  return <PrismaTable model={model} push={router.push} query={router.query} actions={['update']} />;
};

export default Table;