Skip to content

Mutation: updateProject.step -> transitionProject #1532

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 2 commits into from
Jun 13, 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
1 change: 1 addition & 0 deletions src/scenes/Projects/Overview/ProjectOverview.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ fragment ProjectOverview on Project {
canEdit
value
transitions {
key
to
label
type
Expand Down
32 changes: 15 additions & 17 deletions src/scenes/Projects/Update/ProjectWorkflowDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
import { AutocompleteField } from '../../../components/form/AutocompleteField';
import { Link } from '../../../components/Routing';
import { ProjectOverviewFragment } from '../Overview/ProjectOverview.graphql';
import { UpdateProjectDocument } from './UpdateProject.graphql';
import { TransitionProjectDocument } from './TransitionProject.graphql';

type UpdateProjectDialogProps = Except<
DialogFormProps<SubmitAction & { project?: { step?: ProjectStep } }>,
Expand All @@ -41,7 +41,7 @@ export const ProjectWorkflowDialog = ({
project,
...props
}: UpdateProjectDialogProps) => {
const [updateProject] = useMutation(UpdateProjectDocument);
const [transitionProject] = useMutation(TransitionProjectDocument);
const { classes } = useStyles();
const { canBypassTransitions, transitions } = project.step;

Expand All @@ -68,23 +68,23 @@ export const ProjectWorkflowDialog = ({
submitLabel={canBypassTransitions ? undefined : false}
sendIfClean
changesetAware
onSubmit={async ({ submitAction, project: submittedProjectFields }) => {
onSubmit={async ({
submitAction: transitionKey,
project: submittedProjectFields,
}) => {
const step = submittedProjectFields?.step;
// If clicking save for step override, but there is no step, do nothing.
if (!submitAction && !step) {
if (!transitionKey && !step) {
return;
}

await updateProject({
await transitionProject({
variables: {
input: {
project: {
id: project.id,
// remove index suffix used to make submit action unique
step:
(submitAction?.split(':')[0] as ProjectStep | null) ?? step,
},
changeset: project.changeset?.id,
project: project.id,
...(transitionKey
? { transition: transitionKey }
: { bypassTo: step }),
},
},
});
Expand All @@ -96,22 +96,20 @@ export const ProjectWorkflowDialog = ({
>
<SubmitError />
<Grid container direction="column" spacing={1}>
{transitions.map((transition, i) => (
{transitions.map((transition) => (
<Tooltip
title={
transition.disabledReason ??
`This will change the project step to ${
ProjectStepLabels[transition.to]
}`
}
key={i}
key={transition.key}
>
<Grid item>
<SubmitButton
{...transitionTypeStyles[transition.type]}
// Ensure submit action/step is unique by appending index. This prevents
// multiple spinners for the same next step with different labels.
action={`${transition.to}:${i}`}
action={transition.key}
disabled={transition.disabled}
>
{transition.label}
Expand Down
6 changes: 6 additions & 0 deletions src/scenes/Projects/Update/TransitionProject.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
mutation TransitionProject($input: ExecuteProjectTransitionInput!) {
transitionProject(input: $input) {
...ProjectOverview
...RecalculateChangesetDiff
}
}
Loading