Skip to content

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 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 25 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
0a5c431
feat: initial changes for multi-org templates page
jaaydenh Jul 1, 2024
6f96fee
feat: add TemplateCard component
jaaydenh Jul 2, 2024
51ebb67
feat: add component stories
jaaydenh Jul 3, 2024
a0effc6
chore: update template query naming
jaaydenh Jul 3, 2024
be37085
fix: fix formatting
jaaydenh Jul 3, 2024
5649166
feat: template card interaction and navigation
jaaydenh Jul 8, 2024
3ea3aa2
fix: copy updates
jaaydenh Jul 8, 2024
f17a0c3
chore: update TemplateFilter type to include FilterQuery
jaaydenh Jul 9, 2024
0077db0
chore: update typesGenerated.ts
jaaydenh Jul 9, 2024
461202e
feat: update template filter api logic
jaaydenh Jul 9, 2024
66e02fb
fix: fix format
jaaydenh Jul 11, 2024
369c59f
fix: get activeOrg
jaaydenh Jul 11, 2024
c41cdc4
fix: add format annotation
jaaydenh Jul 11, 2024
7f5d35e
chore: use organization display name
jaaydenh Jul 11, 2024
6e2a6d8
feat: client side org filtering
jaaydenh Jul 15, 2024
978c047
fix: use org display name
jaaydenh Jul 15, 2024
aaed038
fix: add ExactName
jaaydenh Jul 15, 2024
8d84ad9
feat: show orgs filter only if more than 1 org
jaaydenh Jul 15, 2024
a1c6169
chore: updates for PR review
jaaydenh Jul 16, 2024
15542c0
fix: fix format
jaaydenh Jul 16, 2024
8f4c56f
chore: add story for multi org
jaaydenh Jul 16, 2024
a282bac
fix: aggregate templates by organization id
jaaydenh Jul 17, 2024
b092644
fix: fix format
jaaydenh Jul 17, 2024
32376e6
fix: check org count
jaaydenh Jul 17, 2024
801138a
fix: update ExactName type
jaaydenh Jul 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
Prev Previous commit
Next Next commit
fix: aggregate templates by organization id
  • Loading branch information
jaaydenh committed Jul 17, 2024
commit a282baceb3ed88fc711a1d5d76014d3a3a3cf15f
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,6 @@ export interface TemplatesPageViewProps {
error?: unknown;
}

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

export const TemplatesPageView: FC<TemplatesPageViewProps> = ({
templatesByOrg,
examples,
Expand All @@ -72,7 +66,6 @@ export const TemplatesPageView: FC<TemplatesPageViewProps> = ({
const navigate = useNavigate();
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]
Expand Down Expand Up @@ -110,19 +103,17 @@ export const TemplatesPageView: FC<TemplatesPageViewProps> = ({
css={{ width: 208, flexShrink: 0, position: "sticky", top: 48 }}
>
<span css={styles.filterCaption}>ORGANIZATION</span>
{orgs.map((org) => (
{Object.entries(templatesByOrg).map((org) => (
<Link
key={org}
to={`?org=${org}`}
key={org[0]}
to={`?org=${org[0]}`}
css={[
styles.tagLink,
org === activeOrg && styles.tagLinkActive,
org[0] === activeOrg && styles.tagLinkActive,
]}
>
{org === "all"
? org
: templatesByOrg[org][0].organization_display_name}
({templatesByOrg[org].length})
{org[0] === "all" ? "all" : org[1][0].organization_display_name}{" "}
({org[1].length})
</Link>
))}
</Stack>
Expand Down
12 changes: 7 additions & 5 deletions site/src/utils/templateAggregators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,20 @@ export const getTemplatesByTag = (
};

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

for (const template of templates) {
const org = template.organization_name;
const org = template.organization_id;
if (orgs[org]) {
orgs[org].push(template);
} else {
orgs[org] = [template];
}
}

return orgs;
const sortedOrgs = Object.fromEntries(
Object.entries(orgs).sort(([, a], [, b]) => a[0].organization_name.localeCompare(b[0].organization_name))
);

return { all: templates, ...sortedOrgs };
};