Skip to content
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

adding support for template refs: #371

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions website/src/components/gallery/ShowcaseCard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import React from "react";
import styleCSS from "./styles.module.css";
import { type User } from "../../../data/tags";
import { type Template } from "../../../data/tags";
import useBaseUrl from "@docusaurus/useBaseUrl";
import {
Card,
Expand Down Expand Up @@ -60,7 +60,7 @@ const darkTheme: PartialTheme = {
},
};

function ShowcaseCard({ user }: { user: User }): JSX.Element {
function ShowcaseCard({ user }: { user: Template }): JSX.Element {
const styles = useStyles();
const title = user.title;
const tags = user.tags;
Expand Down
4 changes: 2 additions & 2 deletions website/src/components/gallery/ShowcaseCardPanel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import React from "react";
import styles from "./styles.module.css";
import { Tags, type User, type TagType } from "../../../data/tags";
import { Tags, type Template, type TagType } from "../../../data/tags";
import { TagList } from "../../../data/users";
import { sortBy } from "@site/src/utils/jsUtils";
import useBaseUrl from "@docusaurus/useBaseUrl";
Expand Down Expand Up @@ -87,7 +87,7 @@ function CopyButton({ url, colorMode }: { url: string; colorMode: string }) {
);
}

export default function ShowcaseCardPanel({ user }: { user: User }) {
export default function ShowcaseCardPanel({ user }: { user: Template }) {
const [
isPopupVisibleTemplateDetails,
{ toggle: toggleIsPopupVisibleTemplateDetails },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import React from "react";
import styles from "./styles.module.css";
import { type User } from "../../../data/tags";
import { type Template } from "../../../data/tags";
import {
makeStyles,
Link as FluentUILink,
Expand Down Expand Up @@ -115,7 +115,7 @@ export default function ShowcaseMultipleAuthors({
user,
cardPanel,
}: {
user: User;
user: Template;
cardPanel: boolean;
}) {
const { colorMode } = useColorMode();
Expand Down
2 changes: 1 addition & 1 deletion website/src/components/gallery/ShowcaseTag/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import React from "react";
import styles from "./styles.module.css";
import { Tag, Tags, type User, type TagType } from "../../../data/tags";
import { Tag, Tags, type Template, type TagType } from "../../../data/tags";
import { TagList } from "../../../data/users";
import { sortBy } from "@site/src/utils/jsUtils";
import { Badge, Tooltip, makeStyles } from "@fluentui/react-components";
Expand Down
10 changes: 8 additions & 2 deletions website/src/data/tags.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ export type Tag = {
type?: string;
};

export type User = {
export type Template = {
title: string;
description: string;
preview: string;
website: string;
author: string;
source: string | null;
tags: TagType[];
ref: string;
};

// NN: Updated TagType to suit Static Web Apps
Expand Down Expand Up @@ -105,7 +106,8 @@ export type TagType =
| "ruby"
| "rubyonrails"
| "serverlessapi"
| "langchain";
| "langchain"
| "aiApps";

// LIST OF AVAILABLE TAGS
// Each tag in lit about must have a defined object here
Expand Down Expand Up @@ -137,6 +139,10 @@ export const Tags: { [type in TagType]: Tag } = {
label: "Popular",
description: "This tag is used for popular templates.",
},
aiApps: {
label: "AI Apps",
description: "This tag is used for AI Apps templates gallery.",
},

//============ FOR REGULAR USE

Expand Down
30 changes: 26 additions & 4 deletions website/src/data/users.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* eslint-disable global-require */

import { sortBy } from '../utils/jsUtils';
import { TagType, User, Tags } from './tags';
import { TagType, Template, Tags } from './tags';
import templates from '../../static/templates.json'

// *** ADDING DATA TO AZD GALLERY ****/
Expand All @@ -16,12 +16,34 @@ import templates from '../../static/templates.json'
// *************** CARD DATA STARTS HERE ***********************
// Add your site to this list
// prettier-ignore
const expandedTemplates: Template[] = [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we use a Set to prevent duplicate data?


const expand = async (source:Template[]):Promise<Template[]> => {
await Promise.all(source.map(async (template) => {
if (template.ref) {
const resp = await fetch(template.ref);
const data = await resp.json() as Template[];
data.forEach((d) => {
expandedTemplates.push({...d, tags: [...d.tags, ...(template.tags || [])]});
});
} else {
expandedTemplates.push(template)
}
}));

return expandedTemplates;
}

export const unsortedUsers: User[] = templates as User[]
export const unsortedUsers = (async ():Promise<Template[]> => {
if (expandedTemplates.length !== 0) {
return expandedTemplates;
}
return expand(templates as Template[]);
})();

export const TagList = Object.keys(Tags) as TagType[];
function sortUsers() {
let result = unsortedUsers;
async function sortUsers() {
let result = await unsortedUsers;
// Sort by site name
result = sortBy(result, (user) => user.title.toLowerCase());
return result;
Expand Down
31 changes: 16 additions & 15 deletions website/src/pages/ShowcaseCardPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
UserState,
InputValue,
} from "../components/gallery/ShowcaseTemplateSearch";
import { type User, type TagType } from "../data/tags";
import { type Template, type TagType } from "../data/tags";
import { sortedUsers, unsortedUsers } from "../data/users";
import { Text, Combobox, Option, Spinner } from "@fluentui/react-components";
import ShowcaseCards from "./ShowcaseCards";
Expand All @@ -32,19 +32,19 @@ const SORT_BY_OPTIONS = [
"Alphabetical (Z - A)",
];

function readSortChoice(rule: string): User[] {
async function readSortChoice(rule: string): Promise<Template[]> {
if (rule == SORT_BY_OPTIONS[0]) {
const copyUnsortedUser = unsortedUsers.slice();
const copyUnsortedUser = (await unsortedUsers).slice();
return copyUnsortedUser.reverse();
} else if (rule == SORT_BY_OPTIONS[1]) {
return unsortedUsers;
return await unsortedUsers;
} else if (rule == SORT_BY_OPTIONS[2]) {
return sortedUsers;
return await sortedUsers;
} else if (rule == SORT_BY_OPTIONS[3]) {
const copySortedUser = sortedUsers.slice();
const copySortedUser = (await sortedUsers).slice();
return copySortedUser.reverse();
}
return sortedUsers;
return await sortedUsers;
}

const SearchNameQueryKey = "name";
Expand All @@ -54,7 +54,7 @@ function readSearchName(search: string) {
}

function filterUsers(
users: User[],
users: Template[],
selectedTags: TagType[],
searchName: string | null
) {
Expand All @@ -81,16 +81,17 @@ export default function ShowcaseCardPage() {

const [selectedTags, setSelectedTags] = useState<TagType[]>([]);
const [searchName, setSearchName] = useState<string | null>(null);
const [selectedUsers, setSelectedUsers] = useState<User[]>([]);
const [selectedUsers, setSelectedUsers] = useState<Template[]>([]);
const location = useLocation<UserState>();

useEffect(() => {
setSelectedTags(readSearchTags(location.search));
setSelectedUsers(readSortChoice(selectedOptions[0]));
setSearchName(readSearchName(location.search));
restoreUserState(location.state);

setLoading(false);
readSortChoice(selectedOptions[0]).then(templates =>{
setSelectedTags(readSearchTags(location.search));
setSelectedUsers(templates);
setSearchName(readSearchName(location.search));
restoreUserState(location.state);
setLoading(false);
})
}, [location, selectedOptions]);

var cards = useMemo(
Expand Down
4 changes: 2 additions & 2 deletions website/src/pages/ShowcaseCards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

import React from "react";
import ShowcaseEmptyResult from "../components/gallery/ShowcaseEmptyResult";
import { type User, type TagType } from "../data/tags";
import { type Template, type TagType } from "../data/tags";
import styles from "./styles.module.css";
import ShowcaseCard from "../components/gallery/ShowcaseCard";
import ShowcaseContributionCard from "../components/gallery/ShowcaseContributionCard";

export default function ShowcaseCards({
filteredUsers,
}: {
filteredUsers: User[];
filteredUsers: Template[];
}) {
const len = filteredUsers ? filteredUsers.length : 0;
if (len === 0) {
Expand Down
4 changes: 4 additions & 0 deletions website/static/templates.json
Original file line number Diff line number Diff line change
Expand Up @@ -1677,5 +1677,9 @@
"appinsights",
"blobstorage"
]
},
{
"ref": "https://cacheddkci2rpqggas.blob.core.windows.net/ai-templates/templates.json",
"tags": ["aiApps"]
}
]