mirror of
https://github.com/twentyhq/twenty.git
synced 2024-12-23 12:02:10 +03:00
Enable workflow testing + fix header (#8512)
- clean execution header - enable test on workflows + add snack bar - display snack bar error if workflow cannot be tested Behaviour still need to be validated by @Bonapara <img width="880" alt="Capture d’écran 2024-11-15 à 12 16 36" src="https://github.com/user-attachments/assets/1dab0c3b-157c-449f-aee7-4c8cf2e369a6"> <img width="880" alt="Capture d’écran 2024-11-15 à 12 16 48" src="https://github.com/user-attachments/assets/16279611-0a58-4fe6-b117-0192714a6d5c">
This commit is contained in:
parent
ac93d35538
commit
54b28ff7ed
@ -34,7 +34,9 @@ export const WorkflowRunActionEffect = () => {
|
||||
position: index,
|
||||
Icon: IconSettingsAutomation,
|
||||
onClick: async () => {
|
||||
await runWorkflowVersion(activeWorkflowVersion.id);
|
||||
await runWorkflowVersion({
|
||||
workflowVersionId: activeWorkflowVersion.id,
|
||||
});
|
||||
|
||||
enqueueSnackBar('', {
|
||||
variant: SnackBarVariant.Success,
|
||||
|
@ -65,7 +65,10 @@ export const WorkflowRunRecordActionEffect = ({
|
||||
return;
|
||||
}
|
||||
|
||||
await runWorkflowVersion(activeWorkflowVersion.id, selectedRecord);
|
||||
await runWorkflowVersion({
|
||||
workflowVersionId: activeWorkflowVersion.id,
|
||||
payload: selectedRecord,
|
||||
});
|
||||
|
||||
enqueueSnackBar('', {
|
||||
variant: SnackBarVariant.Success,
|
||||
|
@ -15,6 +15,7 @@ import { useDropdown } from '@/ui/layout/dropdown/hooks/useDropdown';
|
||||
import { SHOW_PAGE_ADD_BUTTON_DROPDOWN_ID } from '@/ui/layout/show-page/constants/ShowPageAddButtonDropdownId';
|
||||
|
||||
import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular';
|
||||
import { isWorkflowSubObjectMetadata } from '@/object-metadata/utils/isWorkflowSubObjectMetadata';
|
||||
import { Dropdown } from '../../dropdown/components/Dropdown';
|
||||
import { DropdownMenu } from '../../dropdown/components/DropdownMenu';
|
||||
|
||||
@ -54,7 +55,8 @@ export const ShowPageAddButton = ({
|
||||
activityTargetObject.targetObjectNameSingular ===
|
||||
CoreObjectNameSingular.Task ||
|
||||
activityTargetObject.targetObjectNameSingular ===
|
||||
CoreObjectNameSingular.Note
|
||||
CoreObjectNameSingular.Note ||
|
||||
isWorkflowSubObjectMetadata(activityTargetObject.targetObjectNameSingular)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ import { DropdownMenuItemsContainer } from '@/ui/layout/dropdown/components/Drop
|
||||
import { useDropdown } from '@/ui/layout/dropdown/hooks/useDropdown';
|
||||
import { navigationMemorizedUrlState } from '@/ui/navigation/states/navigationMemorizedUrlState';
|
||||
|
||||
import { isObjectMetadataReadOnly } from '@/object-metadata/utils/isObjectMetadataReadOnly';
|
||||
import { useDestroyOneRecord } from '@/object-record/hooks/useDestroyOneRecord';
|
||||
import { useRestoreManyRecords } from '@/object-record/hooks/useRestoreManyRecords';
|
||||
import { recordStoreFamilyState } from '@/object-record/record-store/states/recordStoreFamilyState';
|
||||
@ -28,9 +29,11 @@ const StyledContainer = styled.div`
|
||||
export const ShowPageMoreButton = ({
|
||||
recordId,
|
||||
objectNameSingular,
|
||||
isRemote,
|
||||
}: {
|
||||
recordId: string;
|
||||
objectNameSingular: string;
|
||||
isRemote: boolean;
|
||||
}) => {
|
||||
const { closeDropdown, toggleDropdown } = useDropdown('more-show-page');
|
||||
const navigationMemorizedUrl = useRecoilValue(navigationMemorizedUrlState);
|
||||
@ -66,6 +69,15 @@ export const ShowPageMoreButton = ({
|
||||
recordStoreFamilyState(recordId),
|
||||
);
|
||||
|
||||
if (
|
||||
isObjectMetadataReadOnly({
|
||||
isRemote,
|
||||
nameSingular: objectNameSingular,
|
||||
})
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
return (
|
||||
<StyledContainer>
|
||||
<Dropdown
|
||||
|
@ -1,15 +1,21 @@
|
||||
import { SnackBarVariant } from '@/ui/feedback/snack-bar-manager/components/SnackBar';
|
||||
import { useSnackBar } from '@/ui/feedback/snack-bar-manager/hooks/useSnackBar';
|
||||
import { useActivateWorkflowVersion } from '@/workflow/hooks/useActivateWorkflowVersion';
|
||||
import { useDeactivateWorkflowVersion } from '@/workflow/hooks/useDeactivateWorkflowVersion';
|
||||
import { useDeleteOneWorkflowVersion } from '@/workflow/hooks/useDeleteOneWorkflowVersion';
|
||||
import { useRunWorkflowVersion } from '@/workflow/hooks/useRunWorkflowVersion';
|
||||
import { useWorkflowWithCurrentVersion } from '@/workflow/hooks/useWorkflowWithCurrentVersion';
|
||||
import { useTheme } from '@emotion/react';
|
||||
import {
|
||||
Button,
|
||||
IconPlayerPlay,
|
||||
IconPlayerStop,
|
||||
IconPower,
|
||||
IconSettingsAutomation,
|
||||
IconTrash,
|
||||
isDefined,
|
||||
} from 'twenty-ui';
|
||||
import { capitalize } from '~/utils/string/capitalize';
|
||||
import { assertWorkflowWithCurrentVersionIsDefined } from '../utils/assertWorkflowWithCurrentVersionIsDefined';
|
||||
|
||||
export const RecordShowPageWorkflowHeader = ({
|
||||
@ -26,6 +32,15 @@ export const RecordShowPageWorkflowHeader = ({
|
||||
const { activateWorkflowVersion } = useActivateWorkflowVersion();
|
||||
const { deactivateWorkflowVersion } = useDeactivateWorkflowVersion();
|
||||
const { deleteOneWorkflowVersion } = useDeleteOneWorkflowVersion();
|
||||
const { runWorkflowVersion } = useRunWorkflowVersion();
|
||||
|
||||
const { enqueueSnackBar } = useSnackBar();
|
||||
const theme = useTheme();
|
||||
|
||||
const trigger = workflowWithCurrentVersion?.currentVersion.trigger;
|
||||
|
||||
const canWorkflowBeTested =
|
||||
trigger?.type === 'MANUAL' && !trigger.settings.objectType;
|
||||
|
||||
return (
|
||||
<>
|
||||
@ -34,7 +49,41 @@ export const RecordShowPageWorkflowHeader = ({
|
||||
variant="secondary"
|
||||
Icon={IconPlayerPlay}
|
||||
disabled={isWaitingForWorkflowWithCurrentVersion}
|
||||
onClick={() => {}}
|
||||
onClick={async () => {
|
||||
assertWorkflowWithCurrentVersionIsDefined(workflowWithCurrentVersion);
|
||||
|
||||
if (!canWorkflowBeTested) {
|
||||
enqueueSnackBar(
|
||||
'Trigger type should be Manual - when no record(s) are selected',
|
||||
{
|
||||
variant: SnackBarVariant.Error,
|
||||
title: 'Workflow cannot be tested',
|
||||
icon: (
|
||||
<IconSettingsAutomation
|
||||
size={16}
|
||||
color={theme.snackBar.error.color}
|
||||
/>
|
||||
),
|
||||
},
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
await runWorkflowVersion({
|
||||
workflowVersionId: workflowWithCurrentVersion.currentVersion.id,
|
||||
});
|
||||
|
||||
enqueueSnackBar('', {
|
||||
variant: SnackBarVariant.Success,
|
||||
title: `${capitalize(workflowWithCurrentVersion.name)} starting...`,
|
||||
icon: (
|
||||
<IconSettingsAutomation
|
||||
size={16}
|
||||
color={theme.snackBar.success.color}
|
||||
/>
|
||||
),
|
||||
});
|
||||
}}
|
||||
/>
|
||||
|
||||
{workflowWithCurrentVersion?.currentVersion?.status === 'DRAFT' &&
|
||||
|
@ -82,7 +82,7 @@ export const RecordShowPageWorkflowVersionHeader = ({
|
||||
<>
|
||||
{showUseAsDraftButton ? (
|
||||
<Button
|
||||
title={`Use as Draft${hasAlreadyDraftVersion ? ' (override)' : ''}`}
|
||||
title={'Use as Draft'}
|
||||
variant="secondary"
|
||||
Icon={IconPencil}
|
||||
disabled={isWaitingForWorkflowVersion}
|
||||
|
@ -15,10 +15,13 @@ export const useRunWorkflowVersion = () => {
|
||||
client: apolloMetadataClient,
|
||||
});
|
||||
|
||||
const runWorkflowVersion = async (
|
||||
workflowVersionId: string,
|
||||
payload?: Record<string, any>,
|
||||
) => {
|
||||
const runWorkflowVersion = async ({
|
||||
workflowVersionId,
|
||||
payload,
|
||||
}: {
|
||||
workflowVersionId: string;
|
||||
payload?: Record<string, any>;
|
||||
}) => {
|
||||
await mutate({
|
||||
variables: { input: { workflowVersionId, payload } },
|
||||
});
|
||||
|
@ -34,6 +34,7 @@ export const RecordShowPageBaseHeader = ({
|
||||
key="more"
|
||||
recordId={record?.id ?? '0'}
|
||||
objectNameSingular={objectNameSingular}
|
||||
isRemote={objectMetadataItem.isRemote}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
|
@ -9,6 +9,10 @@ import { WorkflowCreateOnePostQueryHook } from 'src/modules/workflow/common/quer
|
||||
import { WorkflowCreateOnePreQueryHook } from 'src/modules/workflow/common/query-hooks/workflow-create-one.pre-query.hook';
|
||||
import { WorkflowRunCreateManyPreQueryHook } from 'src/modules/workflow/common/query-hooks/workflow-run-create-many.pre-query.hook';
|
||||
import { WorkflowRunCreateOnePreQueryHook } from 'src/modules/workflow/common/query-hooks/workflow-run-create-one.pre-query.hook';
|
||||
import { WorkflowRunDeleteManyPreQueryHook } from 'src/modules/workflow/common/query-hooks/workflow-run-delete-many.pre-query.hook';
|
||||
import { WorkflowRunDeleteOnePreQueryHook } from 'src/modules/workflow/common/query-hooks/workflow-run-delete-one.pre-query.hook';
|
||||
import { WorkflowRunUpdateManyPreQueryHook } from 'src/modules/workflow/common/query-hooks/workflow-run-update-many.pre-query.hook';
|
||||
import { WorkflowRunUpdateOnePreQueryHook } from 'src/modules/workflow/common/query-hooks/workflow-run-update-one.pre-query.hook';
|
||||
import { WorkflowUpdateManyPreQueryHook } from 'src/modules/workflow/common/query-hooks/workflow-update-many.pre-query.hook';
|
||||
import { WorkflowUpdateOnePreQueryHook } from 'src/modules/workflow/common/query-hooks/workflow-update-one.pre-query.hook';
|
||||
import { WorkflowVersionCreateManyPreQueryHook } from 'src/modules/workflow/common/query-hooks/workflow-version-create-many.pre-query.hook';
|
||||
@ -31,6 +35,10 @@ import { WorkflowVersionValidationWorkspaceService } from 'src/modules/workflow/
|
||||
WorkflowUpdateManyPreQueryHook,
|
||||
WorkflowRunCreateOnePreQueryHook,
|
||||
WorkflowRunCreateManyPreQueryHook,
|
||||
WorkflowRunUpdateOnePreQueryHook,
|
||||
WorkflowRunUpdateManyPreQueryHook,
|
||||
WorkflowRunDeleteOnePreQueryHook,
|
||||
WorkflowRunDeleteManyPreQueryHook,
|
||||
WorkflowVersionCreateOnePreQueryHook,
|
||||
WorkflowVersionCreateManyPreQueryHook,
|
||||
WorkflowVersionUpdateOnePreQueryHook,
|
||||
|
Loading…
Reference in New Issue
Block a user