mirror of
https://github.com/coder/coder.git
synced 2026-11-09 08:01:34 +08:00
* chore: handle interfaces as "any" in typescript Use generated Deployment Option
42 lines
974 B
TypeScript
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;
|
|
};
|