-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17615 from ElectronicBlueberry/workflow-editor-st…
…ep-multiselect Workflow Editor Item Selection
- Loading branch information
Showing
34 changed files
with
1,325 additions
and
188 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
36 changes: 36 additions & 0 deletions
36
client/src/components/Workflow/Editor/Actions/cloneStep.ts
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,36 @@ | ||
import type { Step, WorkflowStepStore } from "@/stores/workflowStepStore"; | ||
|
||
/** | ||
* Copies a step and increments a trailing number in it's label, | ||
* or adds said trailing number | ||
* | ||
* @param step step to clone | ||
* @param labelSet set containing all labels. Will me mutated to include new label | ||
* @returns cloned step | ||
*/ | ||
export function cloneStepWithUniqueLabel(step: Readonly<Step>, labelSet: Set<string>): Step { | ||
const newStep = structuredClone(step) as Step; | ||
|
||
if (newStep.label) { | ||
while (labelSet.has(newStep.label)) { | ||
const number = newStep.label.match(/[0-9]+$/)?.[0]; | ||
|
||
if (number) { | ||
const count = parseInt(number); | ||
newStep.label = newStep.label?.replace(/[0-9]+$/, `${count + 1}`); | ||
} else { | ||
newStep.label += " 2"; | ||
} | ||
} | ||
|
||
labelSet.add(newStep.label); | ||
} | ||
|
||
return newStep; | ||
} | ||
|
||
export function getLabelSet(store: WorkflowStepStore): Set<string> { | ||
const steps = Object.values(store.steps); | ||
const labels = steps.flatMap((step) => (step.label ? [step.label] : [])); | ||
return new Set(labels); | ||
} |
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
Oops, something went wrong.