8034c7725f
Reorganizes `twenty-ui`'s component organization to follow how the best
UI libraries (MUI, Mantine, Base UI, Polaris) structure their source,
now that the package has stabilized.
**Taxonomy** — dissolves the meaningless `components/` junk-drawer and
the 107-file `display/` mega-category. New domains/subpaths:
`data-display`, `typography`, `icon`, `surfaces`; `feedback` and
`layout` absorb the rest (banners/callout/info + placeholders →
feedback; modal/card → surfaces; motion + separators → layout).
**Per-component layout** — every component is now
`<domain>/<ComponentName>/<ComponentName>.tsx` with colocated
styles/stories/types, `internal/` for private helpers and `parts/` for
re-exported compound sub-parts. The redundant inner `/components/` is
gone. `icon` and `json-visualizer` are kept as cohesive subsystems.
**Also:** adds a tree-shakeable root barrel (`import { Button } from
'twenty-ui'`), the generator now owns `individual-entry.ts`, and a real
barrel-leak bug is fixed (private `internals/` parts were leaking into
the public API).
Consumer imports (~1.2k files) and the `twenty-sdk` UI aggregator were
updated by codemod. The change is **export-neutral** except 16
intentionally-removed private internals symbols (all verified
unconsumed). Gates green: typecheck, lint, build, size-limit, storybook.
<!-- This is an auto-generated description by cubic. -->
<a
href="https://cubic.dev/pr/twentyhq/twenty/pull/21745?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>
<!-- End of auto-generated description by cubic. -->
221 lines
7.7 KiB
TypeScript
221 lines
7.7 KiB
TypeScript
import { AppChip } from '@/applications/components/AppChip';
|
|
import { useLogicFunctionThirdPartyApplicationInformation } from '@/logic-functions/hooks/useLogicFunctionThirdPartyApplicationInformation';
|
|
import { useUpdateSidePanelPageInfo } from '@/side-panel/hooks/useUpdateSidePanelPageInfo';
|
|
import { useSidePanelWorkflowIdOrThrow } from '@/side-panel/pages/workflow/hooks/useSidePanelWorkflowIdOrThrow';
|
|
import { sidePanelWorkflowStepIdComponentState } from '@/side-panel/pages/workflow/states/sidePanelWorkflowStepIdComponentState';
|
|
import { sidePanelPageState } from '@/side-panel/states/sidePanelPageState';
|
|
import { useUpdateOneRecord } from '@/object-record/hooks/useUpdateOneRecord';
|
|
import { TitleInput } from '@/ui/input/components/TitleInput';
|
|
import { useAtomComponentStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomComponentStateValue';
|
|
import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
|
|
import { useGetUpdatableWorkflowVersionOrThrow } from '@/workflow/hooks/useGetUpdatableWorkflowVersionOrThrow';
|
|
import { useWorkflowWithCurrentVersion } from '@/workflow/hooks/useWorkflowWithCurrentVersion';
|
|
import { getAgentIdFromStep } from '@/workflow/utils/getAgentIdFromStep';
|
|
import { getStepDefinitionOrThrow } from '@/workflow/utils/getStepDefinitionOrThrow';
|
|
import { getWorkflowVisualizerComponentInstanceId } from '@/workflow/utils/getWorkflowVisualizerComponentInstanceId';
|
|
import { useUpdateAgentLabel } from '@/workflow/workflow-steps/hooks/useUpdateAgentLabel';
|
|
import { useUpdateWorkflowVersionStep } from '@/workflow/workflow-steps/hooks/useUpdateWorkflowVersionStep';
|
|
import { getActionIcon } from '@/workflow/workflow-steps/workflow-actions/utils/getActionIcon';
|
|
import { getActionIconColorOrThrow } from '@/workflow/workflow-steps/workflow-actions/utils/getActionIconColorOrThrow';
|
|
import { getTriggerIcon } from '@/workflow/workflow-trigger/utils/getTriggerIcon';
|
|
import { getTriggerIconColor } from '@/workflow/workflow-trigger/utils/getTriggerIconColor';
|
|
import { t } from '@lingui/core/macro';
|
|
import { useContext, useState } from 'react';
|
|
import { CoreObjectNameSingular, SidePanelPages } from 'twenty-shared/types';
|
|
import { isDefined } from 'twenty-shared/utils';
|
|
import { TRIGGER_STEP_ID } from 'twenty-shared/workflow';
|
|
import { useIcons } from 'twenty-ui/icon';
|
|
import { SidePanelPageInfoLayout } from './SidePanelPageInfoLayout';
|
|
import { ThemeContext } from 'twenty-ui/theme-constants';
|
|
|
|
export const SidePanelWorkflowStepInfo = ({
|
|
sidePanelPageInstanceId,
|
|
}: {
|
|
sidePanelPageInstanceId: string;
|
|
}) => {
|
|
const { theme } = useContext(ThemeContext);
|
|
const { getIcon } = useIcons();
|
|
|
|
const sidePanelPage = useAtomStateValue(sidePanelPageState);
|
|
|
|
const workflowId = useSidePanelWorkflowIdOrThrow();
|
|
|
|
const sidePanelWorkflowStepId = useAtomComponentStateValue(
|
|
sidePanelWorkflowStepIdComponentState,
|
|
sidePanelPageInstanceId,
|
|
);
|
|
|
|
const workflowWithCurrentVersion = useWorkflowWithCurrentVersion(workflowId);
|
|
|
|
const isReadonly =
|
|
sidePanelPage === SidePanelPages.WorkflowStepView ||
|
|
sidePanelPage === SidePanelPages.WorkflowRunStepView;
|
|
|
|
const { updateSidePanelPageInfo } = useUpdateSidePanelPageInfo();
|
|
|
|
const instanceId = getWorkflowVisualizerComponentInstanceId({
|
|
recordId: workflowId,
|
|
});
|
|
const { getUpdatableWorkflowVersion } =
|
|
useGetUpdatableWorkflowVersionOrThrow(instanceId);
|
|
|
|
const { updateWorkflowVersionStep } = useUpdateWorkflowVersionStep();
|
|
const { updateOneRecord: updateOneWorkflowVersion } = useUpdateOneRecord();
|
|
|
|
const {
|
|
trigger,
|
|
steps,
|
|
id: workflowVersionId,
|
|
} = workflowWithCurrentVersion?.currentVersion ?? {
|
|
trigger: null,
|
|
steps: null,
|
|
id: undefined,
|
|
};
|
|
|
|
const isTriggerStep = sidePanelWorkflowStepId === TRIGGER_STEP_ID;
|
|
|
|
const stepDefinition =
|
|
isDefined(sidePanelWorkflowStepId) && isDefined(trigger)
|
|
? isTriggerStep || isDefined(steps)
|
|
? getStepDefinitionOrThrow({
|
|
stepId: sidePanelWorkflowStepId,
|
|
trigger,
|
|
steps,
|
|
})
|
|
: undefined
|
|
: undefined;
|
|
|
|
const isTrigger = stepDefinition?.type === 'trigger';
|
|
|
|
const logicFunctionId =
|
|
stepDefinition?.type === 'action' &&
|
|
stepDefinition.definition.type === 'LOGIC_FUNCTION'
|
|
? stepDefinition.definition.settings.input.logicFunctionId
|
|
: undefined;
|
|
|
|
const thirdPartyApplicationInformation =
|
|
useLogicFunctionThirdPartyApplicationInformation(logicFunctionId);
|
|
|
|
const agentId = getAgentIdFromStep(stepDefinition);
|
|
const { updateAgentLabel } = useUpdateAgentLabel(agentId);
|
|
const stepName =
|
|
isDefined(stepDefinition) && isDefined(stepDefinition.definition)
|
|
? isTrigger
|
|
? (stepDefinition.definition.name ??
|
|
(stepDefinition.definition.type === 'MANUAL'
|
|
? t`Launch manually`
|
|
: t`Trigger`))
|
|
: (stepDefinition.definition.name ?? t`Action`)
|
|
: '';
|
|
|
|
const [editedTitle, setEditedTitle] = useState<string | null>(null);
|
|
|
|
const title =
|
|
editedTitle ?? (isDefined(stepName) && stepName !== '' ? stepName : '');
|
|
|
|
const handleTitleChange = (newTitle: string) => {
|
|
setEditedTitle(newTitle);
|
|
};
|
|
|
|
if (
|
|
!isDefined(workflowId) ||
|
|
!isDefined(sidePanelWorkflowStepId) ||
|
|
!isDefined(workflowWithCurrentVersion?.currentVersion) ||
|
|
!isDefined(stepDefinition) ||
|
|
!isDefined(stepDefinition.definition)
|
|
) {
|
|
return null;
|
|
}
|
|
|
|
const headerIcon = isTrigger
|
|
? getTriggerIcon(stepDefinition.definition)
|
|
: getActionIcon(stepDefinition.definition.type);
|
|
|
|
const headerIconColor = isTrigger
|
|
? getTriggerIconColor(stepDefinition.definition.type)
|
|
: getActionIconColorOrThrow(stepDefinition.definition.type);
|
|
|
|
const headerType = isTrigger ? t`Trigger` : t`Action`;
|
|
|
|
const label = isDefined(thirdPartyApplicationInformation)
|
|
? thirdPartyApplicationInformation.name
|
|
: headerType;
|
|
|
|
const Icon = getIcon(headerIcon ?? 'IconDefault');
|
|
|
|
const saveTitle = async () => {
|
|
if (!isDefined(workflowVersionId) || !isDefined(workflowId)) {
|
|
return;
|
|
}
|
|
|
|
updateSidePanelPageInfo({
|
|
pageTitle: title,
|
|
pageIcon: Icon,
|
|
});
|
|
|
|
const targetWorkflowVersionId = await getUpdatableWorkflowVersion();
|
|
|
|
if (isTrigger) {
|
|
await updateOneWorkflowVersion({
|
|
objectNameSingular: CoreObjectNameSingular.WorkflowVersion,
|
|
idToUpdate: targetWorkflowVersionId,
|
|
updateOneRecordInput: {
|
|
trigger: {
|
|
...stepDefinition.definition,
|
|
name: title,
|
|
} as typeof stepDefinition.definition,
|
|
},
|
|
});
|
|
} else {
|
|
await updateWorkflowVersionStep({
|
|
workflowVersionId: targetWorkflowVersionId,
|
|
step: {
|
|
...stepDefinition.definition,
|
|
name: title,
|
|
},
|
|
});
|
|
|
|
if (isDefined(agentId)) {
|
|
await updateAgentLabel(title);
|
|
}
|
|
}
|
|
};
|
|
|
|
return (
|
|
<SidePanelPageInfoLayout
|
|
icon={
|
|
isDefined(thirdPartyApplicationInformation) ? (
|
|
<AppChip
|
|
applicationId={thirdPartyApplicationInformation.applicationId}
|
|
size="md"
|
|
chipOnly
|
|
/>
|
|
) : headerIcon ? (
|
|
<Icon size={theme.icon.size.md} stroke={theme.icon.stroke.sm} />
|
|
) : undefined
|
|
}
|
|
iconColor={
|
|
isDefined(thirdPartyApplicationInformation)
|
|
? undefined
|
|
: headerIconColor
|
|
}
|
|
title={
|
|
<TitleInput
|
|
instanceId={`workflow-step-title-${sidePanelPageInstanceId}`}
|
|
disabled={isReadonly}
|
|
sizeVariant="sm"
|
|
value={title}
|
|
onChange={handleTitleChange}
|
|
placeholder={headerType}
|
|
onEnter={saveTitle}
|
|
onEscape={() => setEditedTitle(null)}
|
|
onClickOutside={saveTitle}
|
|
onTab={saveTitle}
|
|
onShiftTab={saveTitle}
|
|
/>
|
|
}
|
|
label={label}
|
|
/>
|
|
);
|
|
};
|