Skip to content

Commit

Permalink
fix: useFields in share page (#605)
Browse files Browse the repository at this point in the history
  • Loading branch information
boris-w committed May 14, 2024
1 parent b32d7cc commit c74384f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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<string, Record<string, boolean>>
),
},
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [JSON.stringify(fieldIds)]);

return (
<TablePermissionContext.Provider value={value}>{children}</TablePermissionContext.Provider>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -60,7 +61,9 @@ export const ShareViewPage = (props: IShareViewPageProps) => {
<ViewProvider serverData={[view]}>
<ViewProxy serverData={[view]}>
<FieldProvider serverSideData={fields}>
<ShareView />
<ShareTablePermissionProvider>
<ShareView />
</ShareTablePermissionProvider>
</FieldProvider>
</ViewProxy>
</ViewProvider>
Expand Down

0 comments on commit c74384f

Please sign in to comment.