From c74384fa9629db5f94fca7423efb099183a1d4b9 Mon Sep 17 00:00:00 2001 From: Boris Date: Tue, 14 May 2024 11:36:17 +0800 Subject: [PATCH] fix: useFields in share page (#605) --- .../view/ShareTablePermissionProvider.tsx | 35 +++++++++++++++++++ .../app/blocks/share/view/ShareViewPage.tsx | 5 ++- 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 apps/nextjs-app/src/features/app/blocks/share/view/ShareTablePermissionProvider.tsx diff --git a/apps/nextjs-app/src/features/app/blocks/share/view/ShareTablePermissionProvider.tsx b/apps/nextjs-app/src/features/app/blocks/share/view/ShareTablePermissionProvider.tsx new file mode 100644 index 000000000..8c96cb379 --- /dev/null +++ b/apps/nextjs-app/src/features/app/blocks/share/view/ShareTablePermissionProvider.tsx @@ -0,0 +1,35 @@ +import { + TablePermissionContext, + TablePermissionContextDefaultValue, +} from '@teable/sdk/context/table-permission'; +import { useFields } from '@teable/sdk/hooks'; +import { map } from 'lodash'; +import { useMemo } from 'react'; + +export const ShareTablePermissionProvider = ({ children }: { children: React.ReactNode }) => { + const fields = useFields({ withHidden: true, withDenied: true }); + const fieldIds = map(fields, 'id'); + + const value = useMemo(() => { + return { + ...TablePermissionContextDefaultValue, + field: { + create: false, + fields: fieldIds.reduce( + (acc, fieldId) => { + acc[fieldId] = { + 'field|read': true, + }; + return acc; + }, + {} as Record> + ), + }, + }; + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [JSON.stringify(fieldIds)]); + + return ( + {children} + ); +}; diff --git a/apps/nextjs-app/src/features/app/blocks/share/view/ShareViewPage.tsx b/apps/nextjs-app/src/features/app/blocks/share/view/ShareViewPage.tsx index f4d1fdc5d..84bcf4406 100644 --- a/apps/nextjs-app/src/features/app/blocks/share/view/ShareViewPage.tsx +++ b/apps/nextjs-app/src/features/app/blocks/share/view/ShareViewPage.tsx @@ -14,6 +14,7 @@ import { useTranslation } from 'react-i18next'; import { useSdkLocale } from '@/features/app/hooks/useSdkLocale'; import { AppLayout } from '@/features/app/layouts'; import { addQueryParamsToWebSocketUrl } from '@/features/app/utils/socket-url'; +import { ShareTablePermissionProvider } from './ShareTablePermissionProvider'; import { ShareView } from './ShareView'; import { ShareViewPageContext } from './ShareViewPageContext'; import { ViewProxy } from './ViewProxy'; @@ -60,7 +61,9 @@ export const ShareViewPage = (props: IShareViewPageProps) => { - + + +