-
Notifications
You must be signed in to change notification settings - Fork 899
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
b414acf
d65c619
232b31b
dfd2f3a
604d5cb
2f41967
5f08835
4f20032
6a2fafd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import type { FC } from "react"; | ||
import { useSearchParams } from "react-router-dom"; | ||
import { | ||
Filter, | ||
MenuSkeleton, | ||
SearchFieldSkeleton, | ||
useFilter, | ||
} from "components/Filter/filter"; | ||
import { useFilterMenu } from "components/Filter/menu"; | ||
import { | ||
Check failure on line 10 in site/src/pages/TemplatesPage/TemplatesFilter.tsx
|
||
SelectFilter, | ||
SelectFilterOption, | ||
} from "components/Filter/SelectFilter"; | ||
import { API } from "api/api"; | ||
Check failure on line 14 in site/src/pages/TemplatesPage/TemplatesFilter.tsx
|
||
import { UserAvatar } from "components/UserAvatar/UserAvatar"; | ||
import { docs } from "utils/docs"; | ||
import { Organization } from "api/typesGenerated"; | ||
Check failure on line 17 in site/src/pages/TemplatesPage/TemplatesFilter.tsx
|
||
|
||
export const TemplatesFilter: FC = () => { | ||
const searchParamsResult = useSearchParams(); | ||
const filter = useFilter({ | ||
fallbackFilter: "deprecated:false", | ||
searchParamsResult, | ||
onUpdate: () => {}, // reset pagination | ||
}); | ||
|
||
const organizationMenu = useFilterMenu({ | ||
onChange: (option) => | ||
filter.update({ ...filter.values, template: option?.value }), | ||
value: filter.values.organization, | ||
id: "status", | ||
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", name: "Deprecated templates" }, | ||
]} | ||
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="sm" | ||
username={org.display_name} | ||
avatarURL={org.icon} | ||
/> | ||
), | ||
}); |
Uh oh!
There was an error while loading. Please reload this page.