From 938423ec546306342c0048778f06252a91c024e4 Mon Sep 17 00:00:00 2001 From: Erik Magnusson <32518962+ejkkan@users.noreply.github.com> Date: Fri, 24 Feb 2023 14:19:08 +0100 Subject: [PATCH] console: add create "delete" permissions PR-URL: https://github.com/hasura/graphql-engine-mono/pull/8071 GitOrigin-RevId: efb545e134908b61eef71f79a477061753a4bb1c --- .../PermissionsForm/PermissionsForm.tsx | 27 ++-- .../Permissions/PermissionsForm/api/api.ts | 13 +- .../api/createSelectArgs.test.ts | 126 +++++++++--------- .../Permissions/PermissionsForm/api/utils.ts | 63 ++++++--- .../useFormData/createDefaultValues/utils.ts | 2 +- .../hooks/submitHooks/useDeletePermission.tsx | 2 +- .../hooks/submitHooks/useSubmitForm.tsx | 2 +- .../hooks/useScrollIntoView.tsx | 40 ++++++ .../mocks/createPermissionsData.mock.ts | 122 +++++++++++++++++ .../PermissionsTab/PermissionsTab.stories.tsx | 2 - .../PermissionsTable/PermissionsTable.tsx | 3 +- 11 files changed, 294 insertions(+), 108 deletions(-) create mode 100644 frontend/libs/console/legacy-ce/src/lib/features/Permissions/PermissionsForm/hooks/useScrollIntoView.tsx create mode 100644 frontend/libs/console/legacy-ce/src/lib/features/Permissions/PermissionsForm/mocks/createPermissionsData.mock.ts diff --git a/frontend/libs/console/legacy-ce/src/lib/features/Permissions/PermissionsForm/PermissionsForm.tsx b/frontend/libs/console/legacy-ce/src/lib/features/Permissions/PermissionsForm/PermissionsForm.tsx index 03d06dcd46a..1d77e0babdc 100644 --- a/frontend/libs/console/legacy-ce/src/lib/features/Permissions/PermissionsForm/PermissionsForm.tsx +++ b/frontend/libs/console/legacy-ce/src/lib/features/Permissions/PermissionsForm/PermissionsForm.tsx @@ -1,4 +1,4 @@ -import React, { useEffect } from 'react'; +import React, { useEffect, useRef } from 'react'; import { useConsoleForm } from '../../../new-components/Form'; import { Button } from '../../../new-components/Button'; import { IndicatorCard } from '../../../new-components/IndicatorCard'; @@ -21,11 +21,11 @@ import { RowPermissionsSectionWrapper, } from './components'; -import { ReturnValue, useFormData, useUpdatePermissions } from './hooks'; +import { useFormData, useUpdatePermissions } from './hooks'; import ColumnRootFieldPermissions from './components/RootFieldPermissions/RootFieldPermissions'; import { useListAllTableColumns } from '../../Data'; import { useMetadataSource } from '../../MetadataAPI'; -import { omit } from 'lodash'; +import useScrollIntoView from './hooks/useScrollIntoView'; export interface ComponentProps { dataSourceName: string; @@ -37,17 +37,6 @@ export interface ComponentProps { data: ReturnType['data']; } -const getCanSave = ( - defaultValues: ReturnValue['defaultValues'], - newValues: Record -) => { - const cloneWithoutClonePermissions = omit(newValues, 'clonePermissions'); - return ( - JSON.stringify(cloneWithoutClonePermissions) === - JSON.stringify(defaultValues) - ); -}; - const Component = (props: ComponentProps) => { const { dataSourceName, @@ -58,6 +47,8 @@ const Component = (props: ComponentProps) => { handleClose, data, } = props; + const permissionSectionRef = useRef(null); + useScrollIntoView(permissionSectionRef, [roleName], { behavior: 'smooth' }); const { data: metadataTables } = useMetadata( MetadataSelector.getTables(dataSourceName) @@ -199,7 +190,12 @@ const Component = (props: ComponentProps) => { tables={tables} roles={roles} /> -
+ +