Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 10 additions & 1 deletion site/src/pages/WorkspacesPage/WorkspacesButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ import OpenIcon from "@mui/icons-material/OpenInNewOutlined";
import Link from "@mui/material/Link";
import type { Template } from "api/typesGenerated";
import { Avatar } from "components/Avatar/Avatar";

// Add module augmentation for the Template interface
declare module "api/typesGenerated" {
interface Template {
deleted?: boolean;
}
}
import { Button } from "components/Button/Button";
import { Loader } from "components/Loader/Loader";
import { MenuSearch } from "components/Menu/MenuSearch";
Expand Down Expand Up @@ -37,7 +44,9 @@ export const WorkspacesButton: FC<WorkspacesButtonProps> = ({
// Dataset should always be small enough that client-side filtering should be
// good enough. Can swap out down the line if it becomes an issue
const [searchTerm, setSearchTerm] = useState("");
const processed = sortTemplatesByUsersDesc(templates ?? [], searchTerm);
// Filter out deleted templates (if the deleted property exists)
const filteredTemplates = (templates ?? []).filter((template) => !template.deleted);
const processed = sortTemplatesByUsersDesc(filteredTemplates, searchTerm);

let emptyState: ReactNode = undefined;
if (templates?.length === 0) {
Expand Down
4 changes: 2 additions & 2 deletions site/src/pages/WorkspacesPage/WorkspacesPageView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ export const WorkspacesPageView: FC<WorkspacesPageViewProps> = ({
<Margins>
<PageHeader
actions={
<WorkspacesButton
!filterProps.filter.query.includes("deleted:true") && (<WorkspacesButton
templates={templates}
templatesFetchStatus={templatesFetchStatus}
>
New workspace
</WorkspacesButton>
</WorkspacesButton>)
}
>
<PageHeaderTitle>
Expand Down
27 changes: 19 additions & 8 deletions site/src/pages/WorkspacesPage/filter/menus.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import { API } from "api/api";
import type { Template, WorkspaceStatus } from "api/typesGenerated";

// Add module augmentation for the Template interface
declare module "api/typesGenerated" {
interface Template {
deleted?: boolean;
}
}
import { Avatar } from "components/Avatar/Avatar";
import {
SelectFilter,
Expand All @@ -26,9 +33,11 @@ export const useTemplateFilterMenu = ({
value,
id: "template",
getSelectedOption: async () => {
// Show all templates including deprecated
// Show all templates including deprecated but filter out deleted templates
const templates = await API.getTemplates();
const template = templates.find((template) => template.name === value);
const template = templates
.filter((t) => !t.deleted)
.find((template) => template.name === value);
if (template) {
return {
label: template.display_name || template.name,
Expand All @@ -39,13 +48,15 @@ export const useTemplateFilterMenu = ({
return null;
},
getOptions: async (query) => {
// Show all templates including deprecated
// Show all templates including deprecated but filter out deleted templates
const templates = await API.getTemplates();
const filteredTemplates = templates.filter(
(template) =>
template.name.toLowerCase().includes(query.toLowerCase()) ||
template.display_name.toLowerCase().includes(query.toLowerCase()),
);
const filteredTemplates = templates
.filter((t) => !t.deleted)
.filter(
(template) =>
template.name.toLowerCase().includes(query.toLowerCase()) ||
template.display_name.toLowerCase().includes(query.toLowerCase()),
);
return filteredTemplates.map((template) => ({
label: template.display_name || template.name,
value: template.name,
Expand Down
Loading