-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(app): improved target branch selection (#407)
* feat(app): improved target branch selection * design tweaks * feat(app): simplify target branch description --------- Co-authored-by: Ondřej Pešička <77627332+OPesicka@users.noreply.github.com> Co-authored-by: OPesicka <ondrejpesicka@gmail.com>
- Loading branch information
1 parent
3e5d9cb
commit dada486
Showing
7 changed files
with
198 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
...[organizationId]/project/[projectId]/flow/[flowId]/edit/step-form/target-branch-input.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { Flex } from "@flows/styled-system/jsx"; | ||
import { type FC } from "react"; | ||
import { Controller } from "react-hook-form"; | ||
import { t } from "translations"; | ||
import { Button, Text } from "ui"; | ||
|
||
import { type FooterActionPlacement, useFlowEditForm } from "../edit-constants"; | ||
|
||
type Props = { | ||
fieldName: | ||
| `steps.${number}.wait.${number}` | ||
| `steps.${number}.${number}.${number}.wait.${number}` | ||
| `steps.${number}.footerActions.${FooterActionPlacement}.${number}` | ||
| `steps.${number}.${number}.${number}.footerActions.${FooterActionPlacement}.${number}`; | ||
}; | ||
|
||
export const TargetBranchInput: FC<Props> = ({ fieldName }) => { | ||
const { watch, control } = useFlowEditForm(); | ||
|
||
const nextStepBranchCount = (() => { | ||
const isForkStep = fieldName.includes(".wait") | ||
? fieldName.split(".").length === 6 | ||
: fieldName.split(".").length === 7; | ||
if (isForkStep) return null; | ||
const stepNumberString = fieldName.split(".").at(1); | ||
if (stepNumberString === undefined) return null; | ||
const nextStepNumber = Number(stepNumberString) + 1; | ||
const nextStep = watch(`steps.${nextStepNumber}`); | ||
if (!Array.isArray(nextStep)) return null; | ||
return nextStep.length; | ||
})(); | ||
|
||
if (nextStepBranchCount === null) return null; | ||
|
||
const targetBranchFieldName = `${fieldName}.targetBranch` as const; | ||
|
||
return ( | ||
<Controller | ||
control={control} | ||
name={targetBranchFieldName} | ||
render={({ field }) => { | ||
const options = Array(nextStepBranchCount) | ||
.fill(null) | ||
.map((_, i) => i); | ||
|
||
return ( | ||
<> | ||
<Text mt="space16">{t.steps.targetBranchLabel}</Text> | ||
<Text color="subtle" variant="bodyXs" mb="space8"> | ||
{t.steps.targetBranchDescription} | ||
</Text> | ||
|
||
<Flex cardWrap="-" overflowX="auto" display="inline-flex"> | ||
<Button | ||
variant={field.value === null ? "black" : "ghost"} | ||
onClick={() => field.onChange(null)} | ||
size="small" | ||
> | ||
None | ||
</Button> | ||
{options.map((opt) => { | ||
const active = field.value === opt; | ||
return ( | ||
<Button | ||
key={opt} | ||
size="small" | ||
variant={active ? "black" : "ghost"} | ||
onClick={() => field.onChange(opt)} | ||
> | ||
{opt} | ||
</Button> | ||
); | ||
})} | ||
</Flex> | ||
</> | ||
); | ||
}} | ||
/> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters