mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-08-19 08:01:25 +00:00
20 lines
572 B
TypeScript
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)
|
|
}
|