Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable workflow testing + fix header #8512

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ export const WorkflowRunActionEffect = () => {
position: index,
Icon: IconSettingsAutomation,
onClick: async () => {
await runWorkflowVersion(activeWorkflowVersion.id);
await runWorkflowVersion({
workflowVersionId: activeWorkflowVersion.id,
});
thomtrp marked this conversation as resolved.
Show resolved Hide resolved

enqueueSnackBar('', {
thomtrp marked this conversation as resolved.
Show resolved Hide resolved
variant: SnackBarVariant.Success,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ export const WorkflowRunRecordActionEffect = ({
return;
}

await runWorkflowVersion(activeWorkflowVersion.id, selectedRecord);
await runWorkflowVersion({
workflowVersionId: activeWorkflowVersion.id,
payload: selectedRecord,
});
thomtrp marked this conversation as resolved.
Show resolved Hide resolved

enqueueSnackBar('', {
variant: SnackBarVariant.Success,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -54,7 +55,8 @@ export const ShowPageAddButton = ({
activityTargetObject.targetObjectNameSingular ===
CoreObjectNameSingular.Task ||
activityTargetObject.targetObjectNameSingular ===
CoreObjectNameSingular.Note
CoreObjectNameSingular.Note ||
isWorkflowSubObjectMetadata(activityTargetObject.targetObjectNameSingular)
) {
return;
thomtrp marked this conversation as resolved.
Show resolved Hide resolved
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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);
Expand Down Expand Up @@ -66,6 +69,15 @@ export const ShowPageMoreButton = ({
recordStoreFamilyState(recordId),
);

if (
isObjectMetadataReadOnly({
isRemote,
nameSingular: objectNameSingular,
})
) {
return;
thomtrp marked this conversation as resolved.
Show resolved Hide resolved
}

return (
<StyledContainer>
<Dropdown
Expand Down
Original file line number Diff line number Diff line change
@@ -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 = ({
Expand All @@ -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 (
<>
Expand All @@ -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,
thomtrp marked this conversation as resolved.
Show resolved Hide resolved
title: `${capitalize(workflowWithCurrentVersion.name)} starting...`,
icon: (
<IconSettingsAutomation
size={16}
color={theme.snackBar.success.color}
/>
),
});
}}
/>

{workflowWithCurrentVersion?.currentVersion?.status === 'DRAFT' &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 } },
});
thomtrp marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const RecordShowPageBaseHeader = ({
key="more"
recordId={record?.id ?? '0'}
objectNameSingular={objectNameSingular}
isRemote={objectMetadataItem.isRemote}
/>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -31,6 +35,10 @@ import { WorkflowVersionValidationWorkspaceService } from 'src/modules/workflow/
WorkflowUpdateManyPreQueryHook,
WorkflowRunCreateOnePreQueryHook,
WorkflowRunCreateManyPreQueryHook,
WorkflowRunUpdateOnePreQueryHook,
WorkflowRunUpdateManyPreQueryHook,
WorkflowRunDeleteOnePreQueryHook,
WorkflowRunDeleteManyPreQueryHook,
WorkflowVersionCreateOnePreQueryHook,
WorkflowVersionCreateManyPreQueryHook,
WorkflowVersionUpdateOnePreQueryHook,
Expand Down
Loading