Improve Jotai work (#18205)
This commit is contained in:
+5
-4
@@ -7,7 +7,6 @@ import { contextStoreTargetedRecordsRuleComponentState } from '@/context-store/s
|
||||
import { type ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
|
||||
import { recordStoreFamilyState } from '@/object-record/record-store/states/recordStoreFamilyState';
|
||||
import { useSnackBar } from '@/ui/feedback/snack-bar-manager/hooks/useSnackBar';
|
||||
import { jotaiStore } from '@/ui/utilities/state/jotai/jotaiStore';
|
||||
import { useRecordIndexIdFromCurrentContextStore } from '@/object-record/record-index/hooks/useRecordIndexIdFromCurrentContextStore';
|
||||
import { useRecoilComponentValueV2 } from '@/ui/utilities/state/jotai/hooks/useRecoilComponentValueV2';
|
||||
import { useActiveWorkflowVersionsWithManualTrigger } from '@/workflow/hooks/useActiveWorkflowVersionsWithManualTrigger';
|
||||
@@ -20,6 +19,7 @@ import { useCallback } from 'react';
|
||||
import { QUERY_MAX_RECORDS } from 'twenty-shared/constants';
|
||||
import { capitalize, isDefined } from 'twenty-shared/utils';
|
||||
import { useIcons } from 'twenty-ui/display';
|
||||
import { useStore } from 'jotai';
|
||||
|
||||
export const useRunWorkflowRecordActions = ({
|
||||
objectMetadataItem,
|
||||
@@ -28,6 +28,7 @@ export const useRunWorkflowRecordActions = ({
|
||||
objectMetadataItem: ObjectMetadataItem;
|
||||
skip?: boolean;
|
||||
}) => {
|
||||
const store = useStore();
|
||||
const { getIcon } = useIcons();
|
||||
const { enqueueWarningSnackBar } = useSnackBar();
|
||||
const { recordIndexId } = useRecordIndexIdFromCurrentContextStore();
|
||||
@@ -88,7 +89,7 @@ export const useRunWorkflowRecordActions = ({
|
||||
const objectNamePlural = objectMetadataItem.namePlural;
|
||||
const selectedRecords = limitedSelectedRecordIds
|
||||
.map((recordId) =>
|
||||
jotaiStore.get(recordStoreFamilyState.atomFamily(recordId)),
|
||||
store.get(recordStoreFamilyState.atomFamily(recordId)),
|
||||
)
|
||||
.filter(isDefined);
|
||||
|
||||
@@ -101,7 +102,7 @@ export const useRunWorkflowRecordActions = ({
|
||||
});
|
||||
} else {
|
||||
for (const selectedRecordId of limitedSelectedRecordIds) {
|
||||
const selectedRecord = jotaiStore.get(
|
||||
const selectedRecord = store.get(
|
||||
recordStoreFamilyState.atomFamily(selectedRecordId),
|
||||
);
|
||||
|
||||
@@ -117,7 +118,7 @@ export const useRunWorkflowRecordActions = ({
|
||||
}
|
||||
}
|
||||
},
|
||||
[runWorkflowVersion, objectMetadataItem, enqueueWarningSnackBar],
|
||||
[runWorkflowVersion, objectMetadataItem, enqueueWarningSnackBar, store],
|
||||
);
|
||||
|
||||
return activeWorkflowVersions
|
||||
|
||||
-4
@@ -1,13 +1,9 @@
|
||||
import { contextStoreTargetedRecordsRuleComponentState } from '@/context-store/states/contextStoreTargetedRecordsRuleComponentState';
|
||||
import { useRecordIndexIdFromCurrentContextStore } from '@/object-record/record-index/hooks/useRecordIndexIdFromCurrentContextStore';
|
||||
import { useRecoilComponentValueV2 } from '@/ui/utilities/state/jotai/hooks/useRecoilComponentValueV2';
|
||||
|
||||
export const useSelectedRecordIdOrThrow = () => {
|
||||
const { recordIndexId } = useRecordIndexIdFromCurrentContextStore();
|
||||
|
||||
const contextStoreTargetedRecordsRule = useRecoilComponentValueV2(
|
||||
contextStoreTargetedRecordsRuleComponentState,
|
||||
recordIndexId,
|
||||
);
|
||||
|
||||
if (
|
||||
|
||||
-4
@@ -1,13 +1,9 @@
|
||||
import { contextStoreTargetedRecordsRuleComponentState } from '@/context-store/states/contextStoreTargetedRecordsRuleComponentState';
|
||||
import { useRecordIndexIdFromCurrentContextStore } from '@/object-record/record-index/hooks/useRecordIndexIdFromCurrentContextStore';
|
||||
import { useRecoilComponentValueV2 } from '@/ui/utilities/state/jotai/hooks/useRecoilComponentValueV2';
|
||||
|
||||
export const useSelectedRecordIds = () => {
|
||||
const { recordIndexId } = useRecordIndexIdFromCurrentContextStore();
|
||||
|
||||
const contextStoreTargetedRecordsRule = useRecoilComponentValueV2(
|
||||
contextStoreTargetedRecordsRuleComponentState,
|
||||
recordIndexId,
|
||||
);
|
||||
|
||||
if (
|
||||
|
||||
+3
-2
@@ -4,10 +4,11 @@ import { useGetUpdatableWorkflowVersionOrThrow } from '@/workflow/hooks/useGetUp
|
||||
import { getWorkflowVisualizerComponentInstanceId } from '@/workflow/utils/getWorkflowVisualizerComponentInstanceId';
|
||||
import { workflowDiagramComponentState } from '@/workflow/workflow-diagram/states/workflowDiagramComponentState';
|
||||
import { useTidyUpWorkflowVersion } from '@/workflow/workflow-version/hooks/useTidyUpWorkflowVersion';
|
||||
import { jotaiStore } from '@/ui/utilities/state/jotai/jotaiStore';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
import { useStore } from 'jotai';
|
||||
|
||||
export const TidyUpWorkflowSingleRecordAction = () => {
|
||||
const store = useStore();
|
||||
const recordId = useSelectedRecordIdOrThrow();
|
||||
const { tidyUpWorkflowVersion } = useTidyUpWorkflowVersion();
|
||||
const instanceId = getWorkflowVisualizerComponentInstanceId({
|
||||
@@ -20,7 +21,7 @@ export const TidyUpWorkflowSingleRecordAction = () => {
|
||||
const workflowDiagramAtom = workflowDiagramComponentState.atomFamily({
|
||||
instanceId,
|
||||
});
|
||||
const workflowDiagram = jotaiStore.get(workflowDiagramAtom);
|
||||
const workflowDiagram = store.get(workflowDiagramAtom);
|
||||
|
||||
if (!isDefined(workflowDiagram)) {
|
||||
return;
|
||||
|
||||
+6
-5
@@ -21,17 +21,18 @@ import { useRecoilComponentSelectorValueV2 } from '@/ui/utilities/state/jotai/ho
|
||||
import { useRecoilComponentValueV2 } from '@/ui/utilities/state/jotai/hooks/useRecoilComponentValueV2';
|
||||
import { useFamilyRecoilValueV2 } from '@/ui/utilities/state/jotai/hooks/useFamilyRecoilValueV2';
|
||||
import { useRecoilValueV2 } from '@/ui/utilities/state/jotai/hooks/useRecoilValueV2';
|
||||
import { jotaiStore } from '@/ui/utilities/state/jotai/jotaiStore';
|
||||
import { useIsFeatureEnabled } from '@/workspace/hooks/useIsFeatureEnabled';
|
||||
import { useCallback, useContext, useMemo } from 'react';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
import { FeatureFlagKey } from '~/generated-metadata/graphql';
|
||||
import { useStore } from 'jotai';
|
||||
|
||||
export const useShouldActionBeRegisteredParams = ({
|
||||
objectMetadataItem,
|
||||
}: {
|
||||
objectMetadataItem?: ObjectMetadataItem;
|
||||
}): ShouldBeRegisteredFunctionParams => {
|
||||
const store = useStore();
|
||||
const { sortedFavorites: favorites } = useFavorites();
|
||||
const { navigationMenuItems } = usePrefetchedNavigationMenuItemsData();
|
||||
const isNavigationMenuItemEditingEnabled = useIsFeatureEnabled(
|
||||
@@ -119,24 +120,24 @@ export const useShouldActionBeRegisteredParams = ({
|
||||
|
||||
const getObjectReadPermission = useCallback(
|
||||
(objectMetadataNameSingular: string) => {
|
||||
return jotaiStore.get(
|
||||
return store.get(
|
||||
objectPermissionsFamilySelector.selectorFamily({
|
||||
objectNameSingular: objectMetadataNameSingular,
|
||||
}),
|
||||
).canRead;
|
||||
},
|
||||
[],
|
||||
[store],
|
||||
);
|
||||
|
||||
const getObjectWritePermission = useCallback(
|
||||
(objectMetadataNameSingular: string) => {
|
||||
return jotaiStore.get(
|
||||
return store.get(
|
||||
objectPermissionsFamilySelector.selectorFamily({
|
||||
objectNameSingular: objectMetadataNameSingular,
|
||||
}),
|
||||
).canUpdate;
|
||||
},
|
||||
[],
|
||||
[store],
|
||||
);
|
||||
|
||||
const forceRegisteredActionsByKey = useRecoilValueV2(
|
||||
|
||||
Reference in New Issue
Block a user