Skip to content

feat: implement deprecated flag for templates to prevent new workspaces #10745

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add params to getTemplates on FE
  • Loading branch information
Emyrk committed Nov 20, 2023
commit 00cc2b8033aae4320182d204a8c5e7cd0161a5ab
11 changes: 8 additions & 3 deletions site/src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,16 +220,21 @@ export const getTemplate = async (
return response.data;
};


export interface TemplateOptions {
readonly deprecated?: boolean;
}

export const getTemplates = async (
organizationId: string,
deprecated?: boolean,
options?: TemplateOptions,
): Promise<TypesGen.Template[]> => {
const params = {} as Record<string, string>;
if (deprecated !== undefined) {
if (options && options.deprecated !== undefined) {
// Just want to check if it isn't undefined. If it has
// a boolean value, convert it to a string and include
// it as a param.
params["deprecated"] = String(deprecated);
params["deprecated"] = String(options.deprecated);
}

const response = await axios.get<TypesGen.Template[]>(
Expand Down
2 changes: 1 addition & 1 deletion site/src/api/queries/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const getTemplatesQueryKey = (orgId: string, deprecated?: boolean) => [
export const templates = (orgId: string, deprecated?: boolean) => {
return {
queryKey: getTemplatesQueryKey(orgId, deprecated),
queryFn: () => API.getTemplates(orgId, deprecated),
queryFn: () => API.getTemplates(orgId, {deprecated}),
};
};

Expand Down
4 changes: 2 additions & 2 deletions site/src/pages/WorkspacesPage/filter/menus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const useTemplateFilterMenu = ({
id: "template",
getSelectedOption: async () => {
// Show all templates including deprecated
const templates = await getTemplates(orgId, undefined);
const templates = await getTemplates(orgId);
const template = templates.find((template) => template.name === value);
if (template) {
return {
Expand All @@ -34,7 +34,7 @@ export const useTemplateFilterMenu = ({
},
getOptions: async (query) => {
// Show all templates including deprecated
const templates = await getTemplates(orgId, undefined);
const templates = await getTemplates(orgId);
const filteredTemplates = templates.filter(
(template) =>
template.name.toLowerCase().includes(query.toLowerCase()) ||
Expand Down