- Notifications
You must be signed in to change notification settings - Fork926
feat: filter templates by organization#14254
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
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
b414acf
d65c619
232b31b
dfd2f3a
604d5cb
2f41967
5f08835
4f20032
6a2fafd
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import type { FC } from "react"; | ||
import { API } from "api/api"; | ||
import type { Organization } from "api/typesGenerated"; | ||
import { | ||
Filter, | ||
MenuSkeleton, | ||
SearchFieldSkeleton, | ||
type useFilter, | ||
} from "components/Filter/filter"; | ||
import { useFilterMenu } from "components/Filter/menu"; | ||
import { | ||
SelectFilter, | ||
type SelectFilterOption, | ||
} from "components/Filter/SelectFilter"; | ||
import { UserAvatar } from "components/UserAvatar/UserAvatar"; | ||
interface TemplatesFilterProps { | ||
filter: ReturnType<typeof useFilter>; | ||
} | ||
export const TemplatesFilter: FC<TemplatesFilterProps> = ({ filter }) => { | ||
const organizationMenu = useFilterMenu({ | ||
onChange: (option) => | ||
filter.update({ ...filter.values, organization: option?.value }), | ||
value: filter.values.organization, | ||
id: "organization", | ||
getSelectedOption: async () => { | ||
if (!filter.values.organization) { | ||
return null; | ||
} | ||
const org = await API.getOrganization(filter.values.organization); | ||
return orgOption(org); | ||
}, | ||
getOptions: async () => { | ||
const orgs = await API.getMyOrganizations(); | ||
return orgs.map(orgOption); | ||
}, | ||
}); | ||
return ( | ||
<Filter | ||
presets={[ | ||
{ query: "", name: "All templates" }, | ||
{ query: "deprecated:true", name: "Deprecated templates" }, | ||
]} | ||
// TODO: Add docs for this | ||
// learnMoreLink={docs("/templates#template-filtering")} | ||
isLoading={false} | ||
filter={filter} | ||
options={ | ||
<> | ||
<SelectFilter | ||
placeholder="All organizations" | ||
label="Select an organization" | ||
options={organizationMenu.searchOptions} | ||
selectedOption={organizationMenu.selectedOption ?? undefined} | ||
onSelect={organizationMenu.selectOption} | ||
/> | ||
</> | ||
} | ||
skeleton={ | ||
<> | ||
<SearchFieldSkeleton /> | ||
<MenuSkeleton /> | ||
</> | ||
} | ||
/> | ||
); | ||
}; | ||
const orgOption = (org: Organization): SelectFilterOption => ({ | ||
label: org.display_name || org.name, | ||
value: org.name, | ||
startIcon: ( | ||
<UserAvatar | ||
key={org.id} | ||
size="xs" | ||
username={org.display_name} | ||
avatarURL={org.icon} | ||
/> | ||
), | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -6,7 +6,7 @@ import StopOutlined from "@mui/icons-material/StopOutlined"; | ||
import LoadingButton from "@mui/lab/LoadingButton"; | ||
import Button from "@mui/material/Button"; | ||
import Divider from "@mui/material/Divider"; | ||
import type { ComponentProps, FC } from "react"; | ||
import type { UseQueryResult } from "react-query"; | ||
import { hasError, isApiValidationError } from "api/errors"; | ||
import type { Template, Workspace } from "api/typesGenerated"; | ||
@@ -65,7 +65,7 @@ export interface WorkspacesPageViewProps { | ||
canChangeVersions: boolean; | ||
} | ||
export const WorkspacesPageView: FC<WorkspacesPageViewProps> = ({ | ||
aslilac marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
workspaces, | ||
error, | ||
limit, | ||
@@ -86,7 +86,7 @@ export const WorkspacesPageView = ({ | ||
templatesFetchStatus, | ||
canCreateTemplate, | ||
canChangeVersions, | ||
}) => { | ||
// Let's say the user has 5 workspaces, but tried to hit page 100, which does | ||
// not exist. In this case, the page is not valid and we want to show a better | ||
// error message. | ||
Uh oh!
There was an error while loading.Please reload this page.