Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: implement multi-org template gallery#13784

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
jaaydenh merged 25 commits intomainfrommulti-org-template-gallery
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
Show all changes
25 commits
Select commitHold shift + click to select a range
0a5c431
feat: initial changes for multi-org templates page
jaaydenhJul 1, 2024
6f96fee
feat: add TemplateCard component
jaaydenhJul 2, 2024
51ebb67
feat: add component stories
jaaydenhJul 3, 2024
a0effc6
chore: update template query naming
jaaydenhJul 3, 2024
be37085
fix: fix formatting
jaaydenhJul 3, 2024
5649166
feat: template card interaction and navigation
jaaydenhJul 8, 2024
3ea3aa2
fix: copy updates
jaaydenhJul 8, 2024
f17a0c3
chore: update TemplateFilter type to include FilterQuery
jaaydenhJul 9, 2024
0077db0
chore: update typesGenerated.ts
jaaydenhJul 9, 2024
461202e
feat: update template filter api logic
jaaydenhJul 9, 2024
66e02fb
fix: fix format
jaaydenhJul 11, 2024
369c59f
fix: get activeOrg
jaaydenhJul 11, 2024
c41cdc4
fix: add format annotation
jaaydenhJul 11, 2024
7f5d35e
chore: use organization display name
jaaydenhJul 11, 2024
6e2a6d8
feat: client side org filtering
jaaydenhJul 15, 2024
978c047
fix: use org display name
jaaydenhJul 15, 2024
aaed038
fix: add ExactName
jaaydenhJul 15, 2024
8d84ad9
feat: show orgs filter only if more than 1 org
jaaydenhJul 15, 2024
a1c6169
chore: updates for PR review
jaaydenhJul 16, 2024
15542c0
fix: fix format
jaaydenhJul 16, 2024
8f4c56f
chore: add story for multi org
jaaydenhJul 16, 2024
a282bac
fix: aggregate templates by organization id
jaaydenhJul 17, 2024
b092644
fix: fix format
jaaydenhJul 17, 2024
32376e6
fix: check org count
jaaydenhJul 17, 2024
801138a
fix: update ExactName type
jaaydenhJul 17, 2024
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
PrevPrevious commit
NextNext commit
feat: client side org filtering
  • Loading branch information
@jaaydenh
jaaydenh committedJul 17, 2024
commit6e2a6d8482d1eaec9903d59f0eb3dd2e22ee6791
6 changes: 3 additions & 3 deletionssite/src/api/queries/templates.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -47,10 +47,10 @@ export const templatesByOrganizationId = (
};
};

export const templates = (config: TemplateFilter = {}) => {
export const templates = (filter: TemplateFilter = {}) => {
return {
queryKey: ["templates",config],
queryFn: () => API.getTemplates(config),
queryKey: ["templates",filter],
queryFn: () => API.getTemplates(filter),
};
};

Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff 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/starterTemplates";
import { getTemplatesByTag } from "utils/templateAggregators";
import { StarterTemplatesPageView } from "./StarterTemplatesPageView";

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

const meta: Meta<typeof StarterTemplatesPageView> = {
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff 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/starterTemplates";
import type { StarterTemplatesByTag } from "utils/templateAggregators";

const getTagLabel = (tag: string) => {
const labelByTag: Record<string, string> = {
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,6 +6,7 @@ import {
MockTemplateExample,
MockTemplateExample2,
} from "testHelpers/entities";
import { getTemplatesByOrg } from "utils/templateAggregators";
import { TemplatesPageView } from "./TemplatesPageView";

const meta: Meta<typeof TemplatesPageView> = {
Expand All@@ -21,7 +22,7 @@ export const WithTemplates: Story = {
args: {
canCreateTemplates: true,
error: undefined,
templates:[
templatesByOrg: getTemplatesByOrg([
MockTemplate,
{
...MockTemplate,
Expand DownExpand Up@@ -62,7 +63,7 @@ export const WithTemplates: Story = {
display_name: "Deprecated",
description: "Template is incompatible",
},
],
]),
examples: [],
},
};
Expand All@@ -71,15 +72,15 @@ export const EmptyCanCreate: Story = {
args: {
canCreateTemplates: true,
error: undefined,
templates: [],
templatesByOrg: getTemplatesByOrg([]),
examples: [MockTemplateExample, MockTemplateExample2],
},
};

export const EmptyCannotCreate: Story = {
args: {
error: undefined,
templates: [],
templatesByOrg: getTemplatesByOrg([]),
examples: [MockTemplateExample, MockTemplateExample2],
canCreateTemplates: false,
},
Expand All@@ -90,7 +91,7 @@ export const Error: Story = {
error: mockApiError({
message: "Something went wrong fetching templates.",
}),
templates: undefined,
templatesByOrg: undefined,
examples: undefined,
canCreateTemplates: false,
},
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
import type { Interpolation, Theme } from "@emotion/react";
import type { FC } from "react";
import { Link, useNavigate } from "react-router-dom";
import type {Template,TemplateExample } from "api/typesGenerated";
import { Link, useNavigate, useSearchParams } from "react-router-dom";
import type { TemplateExample } from "api/typesGenerated";
import { ErrorAlert } from "components/Alert/ErrorAlert";
import {
HelpTooltip,
Expand All@@ -12,6 +12,7 @@ import {
HelpTooltipTitle,
HelpTooltipTrigger,
} from "components/HelpTooltip/HelpTooltip";
import { Loader } from "components/Loader/Loader";
import { Margins } from "components/Margins/Margins";
import {
PageHeader,
Expand All@@ -21,6 +22,7 @@ import {
import { Stack } from "components/Stack/Stack";
import { TemplateCard } from "modules/templates/TemplateCard/TemplateCard";
import { docs } from "utils/docs";
import type { TemplatesByOrg } from "utils/templateAggregators";
import { CreateTemplateButton } from "../CreateTemplateButton";
import { EmptyTemplates } from "../EmptyTemplates";

Expand DownExpand Up@@ -49,51 +51,32 @@ const TemplateHelpTooltip: FC = () => {
};

export interface TemplatesPageViewProps {
templates: Template[] | undefined;
templatesByOrg?: TemplatesByOrg;
examples: TemplateExample[] | undefined;
canCreateTemplates: boolean;
query: string | undefined;
error?: unknown;
}

export type TemplatesByOrg = Record<
string,
{ displayName: string; count: number }
>;

const getTemplatesByOrg = (templates: Template[]): TemplatesByOrg => {
const orgs: TemplatesByOrg = {
all: { displayName: "All Organizations", count: 0 },
};

templates.forEach((template) => {
if (orgs[template.organization_name]) {
orgs[template.organization_name].count += 1;
} else {
orgs[template.organization_name] = {
displayName: template.organization_display_name,
count: 1,
};
}

orgs.all.count += 1;
});

return orgs;
const sortOrgs = (templatesByOrg: TemplatesByOrg) => {
return templatesByOrg
? Object.keys(templatesByOrg).sort((a, b) => a.localeCompare(b))
: undefined;
};

export const TemplatesPageView: FC<TemplatesPageViewProps> = ({
templates,
templatesByOrg,
examples,
canCreateTemplates,
query,
error,
}) => {
const navigate = useNavigate();
const isEmpty = templates && templates.length === 0;
const q = query?.split(":") || [];
const activeOrg = q[0] === "organization" ? query?.split(":")[1] : "all";
const templatesByOrg = getTemplatesByOrg(templates ?? []);
const [urlParams] = useSearchParams();
const isEmpty = templatesByOrg && templatesByOrg["all"].length === 0;
const orgs = templatesByOrg ? sortOrgs(templatesByOrg) : undefined;
const activeOrg = urlParams.get("org") ?? "all";
const visibleTemplates = templatesByOrg
? templatesByOrg[activeOrg]
: undefined;

return (
<Margins>
Expand All@@ -108,7 +91,7 @@ export const TemplatesPageView: FC<TemplatesPageViewProps> = ({
<TemplateHelpTooltip />
</Stack>
</PageHeaderTitle>
{templates && templates.length > 0 && (
{!isEmpty && (
<PageHeaderSubtitle>
Select a template to create a workspace.
</PageHeaderSubtitle>
Expand All@@ -119,19 +102,28 @@ export const TemplatesPageView: FC<TemplatesPageViewProps> = ({
<ErrorAlert error={error} css={{ marginBottom: 32 }} />
)}

{Boolean(!templatesByOrg) && <Loader />}

<Stack direction="row" spacing={4} alignItems="flex-start">
<Stack css={{ width: 208, flexShrink: 0, position: "sticky", top: 48 }}>
<span css={styles.filterCaption}>ORGANIZATION</span>
{Object.entries(templatesByOrg).map(([key, value]) => (
<Link
key={key}
to={key !== "all" ? `?filter=organization:${key}` : "?"}
css={[styles.tagLink, key === activeOrg && styles.tagLinkActive]}
>
{value.displayName} ({value.count ?? 0})
</Link>
))}
</Stack>
{templatesByOrg && orgs && (
<Stack
css={{ width: 208, flexShrink: 0, position: "sticky", top: 48 }}
>
<span css={styles.filterCaption}>ORGANIZATION</span>
{orgs.map((org) => (
<Link
key={org}
to={`?org=${org}`}
css={[
styles.tagLink,
org === activeOrg && styles.tagLinkActive,
]}
>
{org} ({templatesByOrg[org].length})
</Link>
))}
</Stack>
)}

<div
css={{
Expand All@@ -147,8 +139,8 @@ export const TemplatesPageView: FC<TemplatesPageViewProps> = ({
examples={examples ?? []}
/>
) : (
templates &&
templates.map((template) => (
visibleTemplates &&
visibleTemplates.map((template) => (
<TemplateCard
css={(theme) => ({
backgroundColor: theme.palette.background.paper,
Expand Down
17 changes: 8 additions & 9 deletionssite/src/pages/TemplatesPage/TemplatesPage.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
import type { FC } from "react";
import { Helmet } from "react-helmet-async";
import { useQuery } from "react-query";
import { useSearchParams } from "react-router-dom";
import {
templateExamples,
templatesByOrganizationId,
templates,
} from "api/queries/templates";
import { useAuthenticated } from "contexts/auth/RequireAuth";
import { useDashboard } from "modules/dashboard/useDashboard";
import { filterParamsKey } from "utils/filters";
import { pageTitle } from "utils/page";
import { getTemplatesByOrg } from "utils/templateAggregators";
import { TemplatesPageView as MultiOrgTemplatesPageView } from "./MultiOrgTemplatePage/TemplatesPageView";
import { TemplatesPageView } from "./TemplatePage/TemplatesPageView";

export const TemplatesPage: FC = () => {
const { permissions } = useAuthenticated();
const { organizationId, experiments } = useDashboard();
const [searchParams] = useSearchParams();
const query = searchParams.get(filterParamsKey) || undefined;

const templatesByOrganizationIdQuery = useQuery(
templatesByOrganizationId(organizationId),
);
const templatesQuery = useQuery(templates({ q: query }));
const templatesQuery = useQuery(templates());
const templatesByOrg = templatesQuery.data
? getTemplatesByOrg(templatesQuery.data)
: undefined;
const examplesQuery = useQuery({
...templateExamples(organizationId),
enabled: permissions.createTemplates,
Expand All@@ -41,11 +41,10 @@ export const TemplatesPage: FC = () => {
</Helmet>
{multiOrgExperimentEnabled ? (
<MultiOrgTemplatesPageView
error={error}
canCreateTemplates={permissions.createTemplates}
templatesByOrg={templatesByOrg}
examples={examplesQuery.data}
templates={templatesQuery.data}
query={query}
canCreateTemplates={permissions.createTemplates}
error={error}
/>
) : (
<TemplatesPageView
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
import type { TemplateExample } from "api/typesGenerated";
import type {Template,TemplateExample } from "api/typesGenerated";

export type StarterTemplatesByTag = Record<string, TemplateExample[]>;
export type TemplatesByOrg = Record<string, Template[]>;

export const getTemplatesByTag = (
templates: TemplateExample[],
Expand All@@ -22,3 +23,20 @@ export const getTemplatesByTag = (

return tags;
};

export const getTemplatesByOrg = (templates: Template[]): TemplatesByOrg => {
const orgs: TemplatesByOrg = {
all: templates,
};

templates.forEach((template) => {
const org = template.organization_name;
if (orgs[org]) {
orgs[org].push(template);
} else {
orgs[org] = [template];
}
});

return orgs;
};

[8]ページ先頭

©2009-2025 Movatter.jp