Migrate more to Jotai (#17968)
As per title --------- Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
This commit is contained in:
+4
-4
@@ -8,10 +8,10 @@ import { selectedItemIdComponentState } from '@/ui/layout/selectable-list/states
|
||||
import { useRecoilComponentValue } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentValue';
|
||||
import { useDeleteStep } from '@/workflow/workflow-steps/hooks/useDeleteStep';
|
||||
import { useDuplicateStep } from '@/workflow/workflow-steps/hooks/useDuplicateStep';
|
||||
import { workflowAiAgentActionAgentState } from '@/workflow/workflow-steps/workflow-actions/ai-agent-action/states/workflowAiAgentActionAgentState';
|
||||
import { useRecoilValueV2 } from '@/ui/utilities/state/jotai/hooks/useRecoilValueV2';
|
||||
import { workflowAiAgentActionAgentStateV2 } from '@/workflow/workflow-steps/workflow-actions/ai-agent-action/states/workflowAiAgentActionAgentStateV2';
|
||||
import { useLingui } from '@lingui/react/macro';
|
||||
import { useId } from 'react';
|
||||
import { useRecoilValue } from 'recoil';
|
||||
import { SettingsPath } from 'twenty-shared/types';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
import { TRIGGER_STEP_ID } from 'twenty-shared/workflow';
|
||||
@@ -44,8 +44,8 @@ export const WorkflowStepFooter = ({
|
||||
} = useWorkflowCommandMenu();
|
||||
const { deleteStep } = useDeleteStep();
|
||||
const navigateSettings = useNavigateSettings();
|
||||
const workflowAiAgentActionAgent = useRecoilValue(
|
||||
workflowAiAgentActionAgentState,
|
||||
const workflowAiAgentActionAgent = useRecoilValueV2(
|
||||
workflowAiAgentActionAgentStateV2,
|
||||
);
|
||||
const shouldPinDeleteButton =
|
||||
!isDefined(additionalActions) || additionalActions.length === 0;
|
||||
|
||||
+9
-8
@@ -3,13 +3,14 @@ import { useActionRolePermissionFlagConfig } from '@/settings/roles/role-permiss
|
||||
import { TextInput } from '@/ui/input/components/TextInput';
|
||||
import { type WorkflowAiAgentAction } from '@/workflow/types/Workflow';
|
||||
import { useWorkflowAiAgentPermissionActions } from '@/workflow/workflow-steps/workflow-actions/ai-agent-action/hooks/useWorkflowAiAgentPermissionActions';
|
||||
import { workflowAiAgentActionAgentState } from '@/workflow/workflow-steps/workflow-actions/ai-agent-action/states/workflowAiAgentActionAgentState';
|
||||
import { workflowAiAgentPermissionsIsAddingPermissionState } from '@/workflow/workflow-steps/workflow-actions/ai-agent-action/states/workflowAiAgentPermissionsIsAddingPermissionState';
|
||||
import { workflowAiAgentPermissionsSelectedObjectIdState } from '@/workflow/workflow-steps/workflow-actions/ai-agent-action/states/workflowAiAgentPermissionsSelectedObjectIdState';
|
||||
import { useRecoilStateV2 } from '@/ui/utilities/state/jotai/hooks/useRecoilStateV2';
|
||||
import { useRecoilValueV2 } from '@/ui/utilities/state/jotai/hooks/useRecoilValueV2';
|
||||
import { workflowAiAgentActionAgentStateV2 } from '@/workflow/workflow-steps/workflow-actions/ai-agent-action/states/workflowAiAgentActionAgentStateV2';
|
||||
import { workflowAiAgentPermissionsIsAddingPermissionStateV2 } from '@/workflow/workflow-steps/workflow-actions/ai-agent-action/states/workflowAiAgentPermissionsIsAddingPermissionStateV2';
|
||||
import { workflowAiAgentPermissionsSelectedObjectIdStateV2 } from '@/workflow/workflow-steps/workflow-actions/ai-agent-action/states/workflowAiAgentPermissionsSelectedObjectIdStateV2';
|
||||
import styled from '@emotion/styled';
|
||||
import { t } from '@lingui/core/macro';
|
||||
import { useState } from 'react';
|
||||
import { useRecoilState, useRecoilValue } from 'recoil';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
import { IconChevronLeft } from 'twenty-ui/display';
|
||||
import { IconButton } from 'twenty-ui/input';
|
||||
@@ -74,18 +75,18 @@ export const WorkflowAiAgentPermissionsTab = ({
|
||||
isAgentLoading,
|
||||
refetchAgent,
|
||||
}: WorkflowAiAgentPermissionsTabProps) => {
|
||||
const workflowAiAgentActionAgent = useRecoilValue(
|
||||
workflowAiAgentActionAgentState,
|
||||
const workflowAiAgentActionAgent = useRecoilValueV2(
|
||||
workflowAiAgentActionAgentStateV2,
|
||||
);
|
||||
|
||||
const [
|
||||
workflowAiAgentPermissionsSelectedObjectId,
|
||||
setWorkflowAiAgentPermissionsSelectedObjectId,
|
||||
] = useRecoilState(workflowAiAgentPermissionsSelectedObjectIdState);
|
||||
] = useRecoilStateV2(workflowAiAgentPermissionsSelectedObjectIdStateV2);
|
||||
const [
|
||||
workflowAiAgentPermissionsIsAddingPermission,
|
||||
setWorkflowAiAgentPermissionsIsAddingPermission,
|
||||
] = useRecoilState(workflowAiAgentPermissionsIsAddingPermissionState);
|
||||
] = useRecoilStateV2(workflowAiAgentPermissionsIsAddingPermissionStateV2);
|
||||
|
||||
const { alphaSortedActiveNonSystemObjectMetadataItems: objectMetadataItems } =
|
||||
useFilteredObjectMetadataItems();
|
||||
|
||||
+4
-4
@@ -1,9 +1,9 @@
|
||||
import { FormTextFieldInput } from '@/object-record/record-field/ui/form-types/components/FormTextFieldInput';
|
||||
import { Select } from '@/ui/input/components/Select';
|
||||
import { workflowAiAgentActionAgentState } from '@/workflow/workflow-steps/workflow-actions/ai-agent-action/states/workflowAiAgentActionAgentState';
|
||||
import { useRecoilValueV2 } from '@/ui/utilities/state/jotai/hooks/useRecoilValueV2';
|
||||
import { workflowAiAgentActionAgentStateV2 } from '@/workflow/workflow-steps/workflow-actions/ai-agent-action/states/workflowAiAgentActionAgentStateV2';
|
||||
import { WorkflowVariablePicker } from '@/workflow/workflow-variables/components/WorkflowVariablePicker';
|
||||
import { t } from '@lingui/core/macro';
|
||||
import { useRecoilValue } from 'recoil';
|
||||
import {
|
||||
type AgentResponseSchema,
|
||||
type ModelConfiguration,
|
||||
@@ -32,8 +32,8 @@ export const WorkflowAiAgentPromptTab = ({
|
||||
onModelConfigurationChange,
|
||||
onResponseFormatChange,
|
||||
}: WorkflowAiAgentPromptTabProps) => {
|
||||
const workflowAiAgentActionAgent = useRecoilValue(
|
||||
workflowAiAgentActionAgentState,
|
||||
const workflowAiAgentActionAgent = useRecoilValueV2(
|
||||
workflowAiAgentActionAgentStateV2,
|
||||
);
|
||||
return (
|
||||
<>
|
||||
|
||||
+5
-5
@@ -12,11 +12,11 @@ import { useUpdateWorkflowVersionStep } from '@/workflow/workflow-steps/hooks/us
|
||||
import { WorkflowAiAgentPermissionsTab } from '@/workflow/workflow-steps/workflow-actions/ai-agent-action/components/WorkflowAiAgentPermissionsTab';
|
||||
import { WORKFLOW_AI_AGENT_TABS } from '@/workflow/workflow-steps/workflow-actions/ai-agent-action/constants/WorkflowAiAgentTabs';
|
||||
import { useResetWorkflowAiAgentPermissionsStateOnCommandMenuClose } from '@/workflow/workflow-steps/workflow-actions/ai-agent-action/hooks/useResetWorkflowAiAgentPermissionsStateOnCommandMenuClose';
|
||||
import { workflowAiAgentActionAgentState } from '@/workflow/workflow-steps/workflow-actions/ai-agent-action/states/workflowAiAgentActionAgentState';
|
||||
import { workflowAiAgentPermissionsIsAddingPermissionState } from '@/workflow/workflow-steps/workflow-actions/ai-agent-action/states/workflowAiAgentPermissionsIsAddingPermissionState';
|
||||
import { useRecoilStateV2 } from '@/ui/utilities/state/jotai/hooks/useRecoilStateV2';
|
||||
import { workflowAiAgentActionAgentStateV2 } from '@/workflow/workflow-steps/workflow-actions/ai-agent-action/states/workflowAiAgentActionAgentStateV2';
|
||||
import { workflowAiAgentPermissionsIsAddingPermissionStateV2 } from '@/workflow/workflow-steps/workflow-actions/ai-agent-action/states/workflowAiAgentPermissionsIsAddingPermissionStateV2';
|
||||
import styled from '@emotion/styled';
|
||||
import { useLingui } from '@lingui/react/macro';
|
||||
import { useRecoilState } from 'recoil';
|
||||
import {
|
||||
type AgentResponseSchema,
|
||||
type ModelConfiguration,
|
||||
@@ -66,7 +66,7 @@ export const WorkflowEditActionAiAgent = ({
|
||||
const componentInstanceId = `${WORKFLOW_AI_AGENT_TAB_LIST_COMPONENT_ID}-${action.id}`;
|
||||
const agentId = action.settings.input.agentId;
|
||||
const [workflowAiAgentActionAgent, setWorkflowAiAgentActionAgent] =
|
||||
useRecoilState(workflowAiAgentActionAgentState);
|
||||
useRecoilStateV2(workflowAiAgentActionAgentStateV2);
|
||||
const { loading: agentLoading, refetch: refetchAgent } = useFindOneAgentQuery(
|
||||
{
|
||||
variables: { id: agentId || '' },
|
||||
@@ -217,7 +217,7 @@ export const WorkflowEditActionAiAgent = ({
|
||||
const [
|
||||
workflowAiAgentPermissionsIsAddingPermission,
|
||||
setWorkflowAiAgentPermissionsIsAddingPermission,
|
||||
] = useRecoilState(workflowAiAgentPermissionsIsAddingPermissionState);
|
||||
] = useRecoilStateV2(workflowAiAgentPermissionsIsAddingPermissionStateV2);
|
||||
|
||||
const role = rolesData?.getRoles.find(
|
||||
(item) => item.id === workflowAiAgentActionAgent?.roleId,
|
||||
|
||||
+11
-11
@@ -1,22 +1,22 @@
|
||||
import { useListenToSidePanelClosing } from '@/ui/layout/right-drawer/hooks/useListenToSidePanelClosing';
|
||||
import { workflowAiAgentActionAgentState } from '@/workflow/workflow-steps/workflow-actions/ai-agent-action/states/workflowAiAgentActionAgentState';
|
||||
import { workflowAiAgentPermissionsIsAddingPermissionState } from '@/workflow/workflow-steps/workflow-actions/ai-agent-action/states/workflowAiAgentPermissionsIsAddingPermissionState';
|
||||
import { workflowAiAgentPermissionsSelectedObjectIdState } from '@/workflow/workflow-steps/workflow-actions/ai-agent-action/states/workflowAiAgentPermissionsSelectedObjectIdState';
|
||||
import { useResetRecoilState, useSetRecoilState } from 'recoil';
|
||||
import { useSetRecoilStateV2 } from '@/ui/utilities/state/jotai/hooks/useSetRecoilStateV2';
|
||||
import { workflowAiAgentActionAgentStateV2 } from '@/workflow/workflow-steps/workflow-actions/ai-agent-action/states/workflowAiAgentActionAgentStateV2';
|
||||
import { workflowAiAgentPermissionsIsAddingPermissionStateV2 } from '@/workflow/workflow-steps/workflow-actions/ai-agent-action/states/workflowAiAgentPermissionsIsAddingPermissionStateV2';
|
||||
import { workflowAiAgentPermissionsSelectedObjectIdStateV2 } from '@/workflow/workflow-steps/workflow-actions/ai-agent-action/states/workflowAiAgentPermissionsSelectedObjectIdStateV2';
|
||||
|
||||
export const useResetWorkflowAiAgentPermissionsStateOnCommandMenuClose = () => {
|
||||
const resetSelectedObjectId = useResetRecoilState(
|
||||
workflowAiAgentPermissionsSelectedObjectIdState,
|
||||
const setSelectedObjectId = useSetRecoilStateV2(
|
||||
workflowAiAgentPermissionsSelectedObjectIdStateV2,
|
||||
);
|
||||
const setIsAddingPermission = useSetRecoilState(
|
||||
workflowAiAgentPermissionsIsAddingPermissionState,
|
||||
const setIsAddingPermission = useSetRecoilStateV2(
|
||||
workflowAiAgentPermissionsIsAddingPermissionStateV2,
|
||||
);
|
||||
const resetAgentState = useResetRecoilState(workflowAiAgentActionAgentState);
|
||||
const setAgentState = useSetRecoilStateV2(workflowAiAgentActionAgentStateV2);
|
||||
|
||||
const resetPermissionState = () => {
|
||||
resetSelectedObjectId();
|
||||
setSelectedObjectId(undefined);
|
||||
setIsAddingPermission(false);
|
||||
resetAgentState();
|
||||
setAgentState(undefined);
|
||||
};
|
||||
|
||||
useListenToSidePanelClosing(resetPermissionState);
|
||||
|
||||
+9
-9
@@ -4,12 +4,12 @@ import { useActionRolePermissionFlagConfig } from '@/settings/roles/role-permiss
|
||||
import { useSettingsRolePermissionFlagConfig } from '@/settings/roles/role-permissions/permission-flags/hooks/useSettingsRolePermissionFlagConfig';
|
||||
import { useSnackBar } from '@/ui/feedback/snack-bar-manager/hooks/useSnackBar';
|
||||
import { CRUD_PERMISSIONS } from '@/workflow/workflow-steps/workflow-actions/ai-agent-action/constants/WorkflowAiAgentCrudPermissions';
|
||||
import { workflowAiAgentActionAgentState } from '@/workflow/workflow-steps/workflow-actions/ai-agent-action/states/workflowAiAgentActionAgentState';
|
||||
import { workflowAiAgentPermissionsIsAddingPermissionState } from '@/workflow/workflow-steps/workflow-actions/ai-agent-action/states/workflowAiAgentPermissionsIsAddingPermissionState';
|
||||
import { workflowAiAgentPermissionsSelectedObjectIdState } from '@/workflow/workflow-steps/workflow-actions/ai-agent-action/states/workflowAiAgentPermissionsSelectedObjectIdState';
|
||||
import { useRecoilStateV2 } from '@/ui/utilities/state/jotai/hooks/useRecoilStateV2';
|
||||
import { workflowAiAgentActionAgentStateV2 } from '@/workflow/workflow-steps/workflow-actions/ai-agent-action/states/workflowAiAgentActionAgentStateV2';
|
||||
import { workflowAiAgentPermissionsIsAddingPermissionStateV2 } from '@/workflow/workflow-steps/workflow-actions/ai-agent-action/states/workflowAiAgentPermissionsIsAddingPermissionStateV2';
|
||||
import { workflowAiAgentPermissionsSelectedObjectIdStateV2 } from '@/workflow/workflow-steps/workflow-actions/ai-agent-action/states/workflowAiAgentPermissionsSelectedObjectIdStateV2';
|
||||
import { t } from '@lingui/core/macro';
|
||||
import { useMemo } from 'react';
|
||||
import { useRecoilState } from 'recoil';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
import { v4 } from 'uuid';
|
||||
import {
|
||||
@@ -37,7 +37,7 @@ export const useWorkflowAiAgentPermissionActions = ({
|
||||
}: UseWorkflowAiAgentPermissionActionsParams) => {
|
||||
const { enqueueSuccessSnackBar } = useSnackBar();
|
||||
const [workflowAiAgentActionAgent, setWorkflowAiAgentActionAgent] =
|
||||
useRecoilState(workflowAiAgentActionAgentState);
|
||||
useRecoilStateV2(workflowAiAgentActionAgentStateV2);
|
||||
const { alphaSortedActiveNonSystemObjectMetadataItems: objectMetadataItems } =
|
||||
useFilteredObjectMetadataItems();
|
||||
const settingsPermissionsConfig = useSettingsRolePermissionFlagConfig({
|
||||
@@ -47,11 +47,11 @@ export const useWorkflowAiAgentPermissionActions = ({
|
||||
assignmentCapabilities: { canBeAssignedToAgents: true },
|
||||
});
|
||||
|
||||
const [, setWorkflowAiAgentPermissionsSelectedObjectId] = useRecoilState(
|
||||
workflowAiAgentPermissionsSelectedObjectIdState,
|
||||
const [, setWorkflowAiAgentPermissionsSelectedObjectId] = useRecoilStateV2(
|
||||
workflowAiAgentPermissionsSelectedObjectIdStateV2,
|
||||
);
|
||||
const [, setWorkflowAiAgentPermissionsIsAddingPermission] = useRecoilState(
|
||||
workflowAiAgentPermissionsIsAddingPermissionState,
|
||||
const [, setWorkflowAiAgentPermissionsIsAddingPermission] = useRecoilStateV2(
|
||||
workflowAiAgentPermissionsIsAddingPermissionStateV2,
|
||||
);
|
||||
|
||||
const [createRole] = useCreateOneRoleMutation();
|
||||
|
||||
-7
@@ -1,7 +0,0 @@
|
||||
import { atom } from 'recoil';
|
||||
import { type Agent } from '~/generated-metadata/graphql';
|
||||
|
||||
export const workflowAiAgentActionAgentState = atom<Agent | undefined>({
|
||||
key: 'workflowAiAgentActionAgentState',
|
||||
default: undefined,
|
||||
});
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
import { type Agent } from '~/generated-metadata/graphql';
|
||||
|
||||
import { createStateV2 } from '@/ui/utilities/state/jotai/utils/createStateV2';
|
||||
|
||||
export const workflowAiAgentActionAgentStateV2 = createStateV2<
|
||||
Agent | undefined
|
||||
>({
|
||||
key: 'workflowAiAgentActionAgentStateV2',
|
||||
defaultValue: undefined,
|
||||
});
|
||||
-6
@@ -1,6 +0,0 @@
|
||||
import { atom } from 'recoil';
|
||||
|
||||
export const workflowAiAgentPermissionsIsAddingPermissionState = atom<boolean>({
|
||||
key: 'workflowAiAgentPermissionsIsAddingPermissionState',
|
||||
default: false,
|
||||
});
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
import { createStateV2 } from '@/ui/utilities/state/jotai/utils/createStateV2';
|
||||
|
||||
export const workflowAiAgentPermissionsIsAddingPermissionStateV2 =
|
||||
createStateV2<boolean>({
|
||||
key: 'workflowAiAgentPermissionsIsAddingPermissionStateV2',
|
||||
defaultValue: false,
|
||||
});
|
||||
-8
@@ -1,8 +0,0 @@
|
||||
import { atom } from 'recoil';
|
||||
|
||||
export const workflowAiAgentPermissionsSelectedObjectIdState = atom<
|
||||
string | undefined
|
||||
>({
|
||||
key: 'workflowAiAgentPermissionsSelectedObjectIdState',
|
||||
default: undefined,
|
||||
});
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
import { createStateV2 } from '@/ui/utilities/state/jotai/utils/createStateV2';
|
||||
|
||||
export const workflowAiAgentPermissionsSelectedObjectIdStateV2 = createStateV2<
|
||||
string | undefined
|
||||
>({
|
||||
key: 'workflowAiAgentPermissionsSelectedObjectIdStateV2',
|
||||
defaultValue: undefined,
|
||||
});
|
||||
Reference in New Issue
Block a user