mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 21:05:19 +00:00
fix(core): workspace feature should be workspace specific (#5677)
fix TOV-429
This commit is contained in:
@@ -5,25 +5,25 @@ import {
|
||||
enabledFeaturesQuery,
|
||||
setWorkspaceExperimentalFeatureMutation,
|
||||
} from '@affine/graphql';
|
||||
import { useAtomValue } from 'jotai';
|
||||
import type { WorkspaceMetadata } from '@affine/workspace/metadata';
|
||||
|
||||
import { waitForCurrentWorkspaceAtom } from '../modules/workspace';
|
||||
import { useAsyncCallback } from './affine-async-hooks';
|
||||
import { useMutateQueryResource, useMutation } from './use-mutation';
|
||||
import { useQueryImmutable } from './use-query';
|
||||
|
||||
const emptyFeatures: FeatureType[] = [];
|
||||
|
||||
export const useWorkspaceAvailableFeatures = () => {
|
||||
const currentWorkspace = useAtomValue(waitForCurrentWorkspaceAtom);
|
||||
export const useWorkspaceAvailableFeatures = (
|
||||
workspaceMetadata: WorkspaceMetadata
|
||||
) => {
|
||||
const isCloudWorkspace =
|
||||
currentWorkspace.flavour === WorkspaceFlavour.AFFINE_CLOUD;
|
||||
workspaceMetadata.flavour === WorkspaceFlavour.AFFINE_CLOUD;
|
||||
const { data } = useQueryImmutable(
|
||||
isCloudWorkspace
|
||||
? {
|
||||
query: availableFeaturesQuery,
|
||||
variables: {
|
||||
id: currentWorkspace.id,
|
||||
id: workspaceMetadata.id,
|
||||
},
|
||||
}
|
||||
: undefined
|
||||
@@ -31,16 +31,17 @@ export const useWorkspaceAvailableFeatures = () => {
|
||||
return data?.workspace.availableFeatures ?? emptyFeatures;
|
||||
};
|
||||
|
||||
export const useWorkspaceEnabledFeatures = () => {
|
||||
const currentWorkspace = useAtomValue(waitForCurrentWorkspaceAtom);
|
||||
export const useWorkspaceEnabledFeatures = (
|
||||
workspaceMetadata: WorkspaceMetadata
|
||||
) => {
|
||||
const isCloudWorkspace =
|
||||
currentWorkspace.flavour === WorkspaceFlavour.AFFINE_CLOUD;
|
||||
workspaceMetadata.flavour === WorkspaceFlavour.AFFINE_CLOUD;
|
||||
const { data } = useQueryImmutable(
|
||||
isCloudWorkspace
|
||||
? {
|
||||
query: enabledFeaturesQuery,
|
||||
variables: {
|
||||
id: currentWorkspace.id,
|
||||
id: workspaceMetadata.id,
|
||||
},
|
||||
}
|
||||
: undefined
|
||||
@@ -48,8 +49,9 @@ export const useWorkspaceEnabledFeatures = () => {
|
||||
return data?.workspace.features ?? emptyFeatures;
|
||||
};
|
||||
|
||||
export const useSetWorkspaceFeature = () => {
|
||||
const currentWorkspace = useAtomValue(waitForCurrentWorkspaceAtom);
|
||||
export const useSetWorkspaceFeature = (
|
||||
workspaceMetadata: WorkspaceMetadata
|
||||
) => {
|
||||
const { trigger, isMutating } = useMutation({
|
||||
mutation: setWorkspaceExperimentalFeatureMutation,
|
||||
});
|
||||
@@ -59,15 +61,15 @@ export const useSetWorkspaceFeature = () => {
|
||||
trigger: useAsyncCallback(
|
||||
async (feature: FeatureType, enable: boolean) => {
|
||||
await trigger({
|
||||
workspaceId: currentWorkspace.id,
|
||||
workspaceId: workspaceMetadata.id,
|
||||
feature,
|
||||
enable,
|
||||
});
|
||||
await revalidate(enabledFeaturesQuery, vars => {
|
||||
return vars.id === currentWorkspace.id;
|
||||
return vars.id === workspaceMetadata.id;
|
||||
});
|
||||
},
|
||||
[currentWorkspace.id, revalidate, trigger]
|
||||
[workspaceMetadata.id, revalidate, trigger]
|
||||
),
|
||||
isMutating,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user