Files
windmill/frontend/src/lib/components/flows/flowModuleNextId.ts
T
2025-09-20 11:00:45 +00:00

20 lines
572 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.length >= 4) {
return acc
} else {
const num = charsToNumber(key)
return Math.max(acc, num + 1)
}
}, 0)
return numberToChars(max)
}