- Notifications
You must be signed in to change notification settings - Fork1.1k
chore: update workspaces page filter to include organization controls#14597
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
f90f0884956ebb43ce7866570b51b2512a73211805cdcc90799a379266a55a6d7c957174d5ff88acc33b5a0c5236829017dcfb84f836a2d46696c0ade554d63b410f7c8f922683788e736eba475e0689d7c1e859552b93dba8515d17a9e8c7c7a9fb775486ff7f8c3ed40167f38068675db14006dbfe06File 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| import{API}from"api/api"; | ||
| importtype{AuditLogResponse}from"api/typesGenerated"; | ||
| import{useFilterParamsKey}from"components/Filter/Filter"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. MY HERO | ||
| importtype{UsePaginatedQueryOptions}from"hooks/usePaginatedQuery"; | ||
| exportfunctionpaginatedAudits( | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -125,38 +125,40 @@ const BaseSkeleton: FC<SkeletonProps> = ({ children, ...skeletonProps }) => { | ||
| ); | ||
| }; | ||
| export const MenuSkeleton: FC = () => { | ||
| return <BaseSkeleton css={{ minWidth: 200, flexShrink: 0 }} />; | ||
| }; | ||
| type FilterProps = { | ||
| filter: ReturnType<typeof useFilter>; | ||
| optionsSkeleton: ReactNode; | ||
| isLoading: boolean; | ||
| learnMoreLink?: string; | ||
| learnMoreLabel2?: string; | ||
| learnMoreLink2?: string; | ||
| error?: unknown; | ||
| options?: ReactNode; | ||
| presets: PresetFilter[]; | ||
| /** | ||
| * The CSS media query breakpoint that defines when the UI will try | ||
| * displaying all options on one row, regardless of the number of options | ||
| * present | ||
| */ | ||
| singleRowBreakpoint?: Breakpoint; | ||
| }; | ||
| export const Filter: FC<FilterProps> = ({ | ||
| filter, | ||
| isLoading, | ||
| error, | ||
| optionsSkeleton, | ||
| options, | ||
| learnMoreLink, | ||
| learnMoreLabel2, | ||
| learnMoreLink2, | ||
| presets, | ||
| singleRowBreakpoint = "lg", | ||
| }) => { | ||
| const theme = useTheme(); | ||
| // Storing local copy of the filter query so that it can be updated more | ||
| @@ -187,15 +189,18 @@ export const Filter: FC<FilterProps> = ({ | ||
| display: "flex", | ||
| gap: 8, | ||
| marginBottom: 16, | ||
| flexWrap: "wrap", | ||
| [theme.breakpoints.up(singleRowBreakpoint)]: { | ||
| flexWrap: "nowrap", | ||
| }, | ||
| }} | ||
| > | ||
| {isLoading ? ( | ||
| <> | ||
| <BaseSkeleton width="100%" /> | ||
| {optionsSkeleton} | ||
| </> | ||
Comment on lines +200 to +203 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Inlined the base skeleton because:
| ||
| ) : ( | ||
| <> | ||
| <InputGroup css={{ width: "100%" }}> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -52,7 +52,7 @@ export const SelectFilter: FC<SelectFilterProps> = ({ | ||
| <SelectMenuTrigger> | ||
| <SelectMenuButton | ||
| startIcon={selectedOption?.startIcon} | ||
| css={{flexBasis:width, flexGrow: 1 }} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more.
| ||
| aria-label={label} | ||
| > | ||
| {selectedOption?.label ?? placeholder} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -19,8 +19,8 @@ export const useUserFilterMenu = ({ | ||
| >) => { | ||
| const { user: me } = useAuthenticated(); | ||
| const addMeAsFirstOption = (options:readonlySelectFilterOption[]) => { | ||
| const filtered= options.filter((o) =>o.value !== me.username); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. the only way this line would make me happier is if you did the thing I like where the closure names the parameter | ||
| return [ | ||
| { | ||
| label: me.username, | ||
| @@ -33,7 +33,7 @@ export const useUserFilterMenu = ({ | ||
| /> | ||
| ), | ||
| }, | ||
| ...filtered, | ||
| ]; | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| /** | ||
| * @file Defines a centralized place for filter dropdown groups that are | ||
| * relevant across multiple pages within the Coder UI. | ||
| * | ||
| * @todo 2024-09-06 - Figure out how to move the user dropdown group into this | ||
| * file (or whether there are enough subtle differences that it's not worth | ||
| * centralizing the logic). We currently have two separate implementations for | ||
| * the workspaces and audits page that have a risk of getting out of sync. | ||
| */ | ||
| import { API } from "api/api"; | ||
| import { | ||
| SelectFilter, | ||
| type SelectFilterOption, | ||
| SelectFilterSearch, | ||
| } from "components/Filter/SelectFilter"; | ||
| import { | ||
| type UseFilterMenuOptions, | ||
| useFilterMenu, | ||
| } from "components/Filter/menu"; | ||
| import { UserAvatar } from "components/UserAvatar/UserAvatar"; | ||
| import type { FC } from "react"; | ||
| // Organization helpers //////////////////////////////////////////////////////// | ||
| export const useOrganizationsFilterMenu = ({ | ||
| value, | ||
| onChange, | ||
| }: Pick<UseFilterMenuOptions<SelectFilterOption>, "value" | "onChange">) => { | ||
| return useFilterMenu({ | ||
| onChange, | ||
| value, | ||
| id: "organizations", | ||
| getSelectedOption: async () => { | ||
| if (value) { | ||
| const organizations = await API.getOrganizations(); | ||
| const organization = organizations.find((o) => o.name === value); | ||
| if (organization) { | ||
| return { | ||
| label: organization.display_name || organization.name, | ||
| value: organization.name, | ||
| startIcon: ( | ||
| <UserAvatar | ||
| key={organization.id} | ||
| size="xs" | ||
| username={organization.display_name || organization.name} | ||
| avatarURL={organization.icon} | ||
| /> | ||
| ), | ||
| }; | ||
| } | ||
| } | ||
| return null; | ||
| }, | ||
| getOptions: async () => { | ||
| // Only show the organizations for which you can view audit logs. | ||
| const organizations = await API.getOrganizations(); | ||
| const permissions = await API.checkAuthorization({ | ||
| checks: Object.fromEntries( | ||
| organizations.map((organization) => [ | ||
| organization.id, | ||
| { | ||
| object: { | ||
| resource_type: "audit_log", | ||
| organization_id: organization.id, | ||
| }, | ||
| action: "read", | ||
| }, | ||
| ]), | ||
| ), | ||
| }); | ||
| return organizations | ||
| .filter((organization) => permissions[organization.id]) | ||
| .map<SelectFilterOption>((organization) => ({ | ||
| label: organization.display_name || organization.name, | ||
| value: organization.name, | ||
| startIcon: ( | ||
| <UserAvatar | ||
| key={organization.id} | ||
| size="xs" | ||
| username={organization.display_name || organization.name} | ||
| avatarURL={organization.icon} | ||
| /> | ||
| ), | ||
| })); | ||
| }, | ||
| }); | ||
| }; | ||
| export type OrganizationsFilterMenu = ReturnType< | ||
| typeof useOrganizationsFilterMenu | ||
| >; | ||
| interface OrganizationsMenuProps { | ||
| menu: OrganizationsFilterMenu; | ||
| width?: number; | ||
| } | ||
| export const OrganizationsMenu: FC<OrganizationsMenuProps> = ({ | ||
| menu, | ||
| width, | ||
| }) => { | ||
| return ( | ||
| <SelectFilter | ||
| label="Select an organization" | ||
| placeholder="All organizations" | ||
| emptyText="No organizations found" | ||
| options={menu.searchOptions} | ||
| onSelect={menu.selectOption} | ||
| selectedOption={menu.selectedOption ?? undefined} | ||
| selectFilterSearch={ | ||
| <SelectFilterSearch | ||
| inputProps={{ "aria-label": "Search organization" }} | ||
| placeholder="Search organization..." | ||
| value={menu.query} | ||
| onChange={menu.setQuery} | ||
| /> | ||
| } | ||
| width={width} | ||
| /> | ||
| ); | ||
| }; |
Uh oh!
There was an error while loading.Please reload this page.