Files
coder/site/src/utils/deployOptions.ts
T
Steven Masley beac36027f chore: generate any interface as Deployment Option in TypeScript (#9917)
* chore: handle interfaces as "any" in typescript

Use generated Deployment Option
2023-09-28 16:14:28 -05:00

42 lines
974 B
TypeScript

import { ClibaseGroup, ClibaseOption } from "api/typesGenerated";
import { useMemo } from "react";
const deploymentOptions = (
options: ClibaseOption[],
...names: string[]
): ClibaseOption[] => {
const found: ClibaseOption[] = [];
for (const name of names) {
const option = options.find((o) => o.name === name);
if (option) {
found.push(option);
} else {
throw new Error(`Deployment option ${name} not found`);
}
}
return found;
};
export const useDeploymentOptions = (
options: ClibaseOption[],
...names: string[]
): ClibaseOption[] => {
return useMemo(() => deploymentOptions(options, ...names), [options, names]);
};
export const deploymentGroupHasParent = (
group: ClibaseGroup | undefined,
parent: string,
): boolean => {
if (!group) {
return false;
}
if (group.parent) {
return deploymentGroupHasParent(group.parent, parent);
}
if (group.name === parent) {
return true;
}
return false;
};