Skip to content

fix: revert "implement multi-org template gallery" #14013

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 1 commit into from
Jul 25, 2024
Merged
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
Revert "feat: implement multi-org template gallery (#13784)"
This reverts commit 554c4ab.
  • Loading branch information
Kira-Pilot authored Jul 25, 2024
commit 5f2d22a7bdab4c3b650e2e2e9b16d9f6a25b8b80
10 changes: 2 additions & 8 deletions codersdk/organizations.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,9 +405,8 @@ func (c *Client) TemplatesByOrganization(ctx context.Context, organizationID uui
}

type TemplateFilter struct {
OrganizationID uuid.UUID `json:"organization_id,omitempty" format:"uuid" typescript:"-"`
FilterQuery string `json:"q,omitempty"`
ExactName string `json:"exact_name,omitempty" typescript:"-"`
OrganizationID uuid.UUID
ExactName string
}

// asRequestOption returns a function that can be used in (*Client).Request.
Expand All @@ -425,11 +424,6 @@ func (f TemplateFilter) asRequestOption() RequestOption {
params = append(params, fmt.Sprintf("exact_name:%q", f.ExactName))
}

if f.FilterQuery != "" {
// If custom stuff is added, just add it on here.
params = append(params, f.FilterQuery)
}

q := r.URL.Query()
q.Set("q", strings.Join(params, " "))
r.URL.RawQuery = q.Encode()
Expand Down
10 changes: 1 addition & 9 deletions site/src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ class ApiMethods {
return response.data;
};

getTemplatesByOrganizationId = async (
getTemplates = async (
organizationId: string,
options?: TemplateOptions,
): Promise<TypesGen.Template[]> => {
Expand All @@ -619,14 +619,6 @@ class ApiMethods {
return response.data;
};

getTemplates = async (
options?: TypesGen.TemplateFilter,
): Promise<TypesGen.Template[]> => {
const url = getURLWithSearchParams("/api/v2/templates", options);
const response = await this.axios.get<TypesGen.Template[]>(url);
return response.data;
};

getTemplateByName = async (
organizationId: string,
name: string,
Expand Down
4 changes: 2 additions & 2 deletions site/src/api/queries/audits.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { API } from "api/api";
import type { AuditLogResponse } from "api/typesGenerated";
import { useFilterParamsKey } from "components/Filter/filter";
import type { UsePaginatedQueryOptions } from "hooks/usePaginatedQuery";
import { filterParamsKey } from "utils/filters";

export function paginatedAudits(
searchParams: URLSearchParams,
): UsePaginatedQueryOptions<AuditLogResponse, string> {
return {
searchParams,
queryPayload: () => searchParams.get(filterParamsKey) ?? "",
queryPayload: () => searchParams.get(useFilterParamsKey) ?? "",
queryKey: ({ payload, pageNumber }) => {
return ["auditLogs", payload, pageNumber] as const;
},
Expand Down
32 changes: 9 additions & 23 deletions site/src/api/queries/templates.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { MutationOptions, QueryClient, QueryOptions } from "react-query";
import { API } from "api/api";
import type {
TemplateFilter,
CreateTemplateRequest,
CreateTemplateVersionRequest,
ProvisionerJob,
Expand Down Expand Up @@ -31,26 +30,16 @@ export const templateByName = (
};
};

const getTemplatesByOrganizationIdQueryKey = (
organizationId: string,
deprecated?: boolean,
) => [organizationId, "templates", deprecated];

export const templatesByOrganizationId = (
organizationId: string,
deprecated?: boolean,
) => {
return {
queryKey: getTemplatesByOrganizationIdQueryKey(organizationId, deprecated),
queryFn: () =>
API.getTemplatesByOrganizationId(organizationId, { deprecated }),
};
};
const getTemplatesQueryKey = (organizationId: string, deprecated?: boolean) => [
organizationId,
"templates",
deprecated,
];

export const templates = (filter?: TemplateFilter) => {
export const templates = (organizationId: string, deprecated?: boolean) => {
return {
queryKey: ["templates", filter],
queryFn: () => API.getTemplates(filter),
queryKey: getTemplatesQueryKey(organizationId, deprecated),
queryFn: () => API.getTemplates(organizationId, { deprecated }),
};
};

Expand Down Expand Up @@ -103,10 +92,7 @@ export const setGroupRole = (

export const templateExamples = (organizationId: string) => {
return {
queryKey: [
...getTemplatesByOrganizationIdQueryKey(organizationId),
"examples",
],
queryKey: [...getTemplatesQueryKey(organizationId), "examples"],
queryFn: () => API.getTemplateExamples(organizationId),
};
};
Expand Down
3 changes: 2 additions & 1 deletion site/src/api/typesGenerated.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions site/src/components/Filter/filter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
import { InputGroup } from "components/InputGroup/InputGroup";
import { SearchField } from "components/SearchField/SearchField";
import { useDebouncedFunction } from "hooks/debounce";
import { filterParamsKey } from "utils/filters";

export type PresetFilter = {
name: string;
Expand All @@ -36,19 +35,21 @@ type UseFilterConfig = {
onUpdate?: (newValue: string) => void;
};

export const useFilterParamsKey = "filter";

export const useFilter = ({
fallbackFilter = "",
searchParamsResult,
onUpdate,
}: UseFilterConfig) => {
const [searchParams, setSearchParams] = searchParamsResult;
const query = searchParams.get(filterParamsKey) ?? fallbackFilter;
const query = searchParams.get(useFilterParamsKey) ?? fallbackFilter;

const update = (newValues: string | FilterValues) => {
const serialized =
typeof newValues === "string" ? newValues : stringifyFilter(newValues);

searchParams.set(filterParamsKey, serialized);
searchParams.set(useFilterParamsKey, serialized);
setSearchParams(searchParams);

if (onUpdate !== undefined) {
Expand Down
40 changes: 0 additions & 40 deletions site/src/modules/templates/TemplateCard/TemplateCard.stories.tsx

This file was deleted.

144 changes: 0 additions & 144 deletions site/src/modules/templates/TemplateCard/TemplateCard.tsx

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { templateExamples } from "api/queries/templates";
import type { TemplateExample } from "api/typesGenerated";
import { useDashboard } from "modules/dashboard/useDashboard";
import { pageTitle } from "utils/page";
import { getTemplatesByTag } from "utils/templateAggregators";
import { getTemplatesByTag } from "utils/starterTemplates";
import { StarterTemplatesPageView } from "./StarterTemplatesPageView";

const StarterTemplatesPage: FC = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
MockTemplateExample,
MockTemplateExample2,
} from "testHelpers/entities";
import { getTemplatesByTag } from "utils/templateAggregators";
import { getTemplatesByTag } from "utils/starterTemplates";
import { StarterTemplatesPageView } from "./StarterTemplatesPageView";

const meta: Meta<typeof StarterTemplatesPageView> = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from "components/PageHeader/PageHeader";
import { Stack } from "components/Stack/Stack";
import { TemplateExampleCard } from "modules/templates/TemplateExampleCard/TemplateExampleCard";
import type { StarterTemplatesByTag } from "utils/templateAggregators";
import type { StarterTemplatesByTag } from "utils/starterTemplates";

const getTagLabel = (tag: string) => {
const labelByTag: Record<string, string> = {
Expand Down
Loading
Loading