Files
windmill/frontend/src/lib/components/flows/flowModuleNextId.ts
T
Ruben Fiszel 6c6dfbc121 flow vscode extension improvements (#2536)
* flow dev

* vscode flow extension improvements
2023-11-01 13:10:10 +01:00

19 lines
623 B
TypeScript

import type { OpenFlow } from '$lib/gen'
import { dfs } from './dfs'
import type { FlowState } from './flowState'
import { charsToNumber, numberToChars } from './idUtils'
// Computes the next available id
export function nextId(flowState: FlowState, fullFlow: OpenFlow): string {
const allIds = dfs(fullFlow.value.modules, (fm) => fm.id)
const max = allIds.concat(Object.keys(flowState)).reduce((acc, key) => {
if (key === 'failure' || key.includes('branch') || key.includes('loop')) {
return acc
} else {
const num = charsToNumber(key)
return Math.max(acc, num + 1)
}
}, 0)
return numberToChars(max)
}