Skip to content

disable publish and cancel buttons once it begins #8097

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

Merged
merged 1 commit into from
Jun 10, 2025
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 @@ -22,6 +22,7 @@ import { NodeFieldElementOverlay } from 'features/nodes/components/sidePanel/bui
import { useDoesWorkflowHaveUnsavedChanges } from 'features/nodes/components/sidePanel/workflow/IsolatedWorkflowBuilderWatcher';
import {
$isInPublishFlow,
$isPublishing,
$isReadyToDoValidationRun,
$isSelectingOutputNode,
$outputNodeId,
Expand Down Expand Up @@ -183,13 +184,14 @@ SelectOutputNodeButton.displayName = 'SelectOutputNodeButton';

const CancelPublishButton = memo(() => {
const { t } = useTranslation();
const isPublishing = useStore($isPublishing);
const onClick = useCallback(() => {
$isInPublishFlow.set(false);
$isSelectingOutputNode.set(false);
$outputNodeId.set(null);
}, []);
return (
<Button leftIcon={<PiXBold />} onClick={onClick}>
<Button leftIcon={<PiXBold />} onClick={onClick} isDisabled={isPublishing}>
{t('common.cancel')}
</Button>
);
Expand All @@ -198,6 +200,7 @@ CancelPublishButton.displayName = 'CancelDeployButton';

const PublishWorkflowButton = memo(() => {
const { t } = useTranslation();
const isPublishing = useStore($isPublishing);
const isReadyToDoValidationRun = useStore($isReadyToDoValidationRun);
const isReadyToEnqueue = useStore($isReadyToEnqueue);
const doesWorkflowHaveUnsavedChanges = useDoesWorkflowHaveUnsavedChanges();
Expand All @@ -211,6 +214,7 @@ const PublishWorkflowButton = memo(() => {

const enqueue = useEnqueueWorkflows();
const onClick = useCallback(async () => {
$isPublishing.set(true);
const result = await withResultAsync(() => enqueue(true, true));
if (result.isErr()) {
toast({
Expand Down Expand Up @@ -244,8 +248,30 @@ const PublishWorkflowButton = memo(() => {
});
log.debug(parseify(result.value), 'Enqueued batch');
}
$isPublishing.set(false);
}, [enqueue, projectUrl, t]);

const isDisabled = useMemo(() => {
return (
!allowPublishWorkflows ||
!isReadyToEnqueue ||
doesWorkflowHaveUnsavedChanges ||
hasUnpublishableNodes ||
!isReadyToDoValidationRun ||
!(outputNodeId !== null && !isSelectingOutputNode) ||
isPublishing
);
}, [
allowPublishWorkflows,
doesWorkflowHaveUnsavedChanges,
hasUnpublishableNodes,
isReadyToDoValidationRun,
isReadyToEnqueue,
isSelectingOutputNode,
outputNodeId,
isPublishing,
]);

return (
<PublishTooltip
isWorkflowSaved={!doesWorkflowHaveUnsavedChanges}
Expand All @@ -255,19 +281,8 @@ const PublishWorkflowButton = memo(() => {
hasPublishableInputs={inputs.publishable.length > 0}
hasUnpublishableInputs={inputs.unpublishable.length > 0}
>
<Button
leftIcon={<PiLightningFill />}
isDisabled={
!allowPublishWorkflows ||
!isReadyToEnqueue ||
doesWorkflowHaveUnsavedChanges ||
hasUnpublishableNodes ||
!isReadyToDoValidationRun ||
!(outputNodeId !== null && !isSelectingOutputNode)
}
onClick={onClick}
>
{t('workflows.builder.publish')}
<Button leftIcon={<PiLightningFill />} isDisabled={isDisabled} onClick={onClick}>
{isPublishing ? t('workflows.builder.publishing') : t('workflows.builder.publish')}
</Button>
</PublishTooltip>
);
Expand Down Expand Up @@ -337,6 +352,10 @@ export const StartPublishFlowButton = memo(() => {
$isInPublishFlow.set(true);
}, []);

const isDisabled = useMemo(() => {
return !allowPublishWorkflows || !isReadyToEnqueue || doesWorkflowHaveUnsavedChanges || hasUnpublishableNodes;
}, [allowPublishWorkflows, doesWorkflowHaveUnsavedChanges, hasUnpublishableNodes, isReadyToEnqueue]);

return (
<PublishTooltip
isWorkflowSaved={!doesWorkflowHaveUnsavedChanges}
Expand All @@ -346,15 +365,7 @@ export const StartPublishFlowButton = memo(() => {
hasPublishableInputs={inputs.publishable.length > 0}
hasUnpublishableInputs={inputs.unpublishable.length > 0}
>
<Button
onClick={onClick}
leftIcon={<PiLightningFill />}
variant="ghost"
size="sm"
isDisabled={
!allowPublishWorkflows || !isReadyToEnqueue || doesWorkflowHaveUnsavedChanges || hasUnpublishableNodes
}
>
<Button onClick={onClick} leftIcon={<PiLightningFill />} variant="ghost" size="sm" isDisabled={isDisabled}>
{t('workflows.builder.publish')}
</Button>
</PublishTooltip>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { useGetBatchStatusQuery } from 'services/api/endpoints/queue';
import { useGetWorkflowQuery } from 'services/api/endpoints/workflows';
import { assert } from 'tsafe';

export const $isPublishing = atom(false);
export const $isInPublishFlow = atom(false);
export const $outputNodeId = atom<string | null>(null);
export const $isSelectingOutputNode = atom(false);
Expand Down