-
Notifications
You must be signed in to change notification settings - Fork 891
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 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 all commits
f90f088
4956ebb
43ce786
6570b51
b2512a7
3211805
cdcc907
99a3792
66a55a6
d7c9571
74d5ff8
8acc33b
5a0c523
6829017
dcfb84f
836a2d4
6696c0a
de554d6
3b410f7
c8f9226
83788e7
36eba47
5e0689d
7c1e859
552b93d
ba8515d
17a9e8c
7c7a9fb
775486f
f7f8c3e
d40167f
3806867
5db1400
6dbfe06
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -125,38 +125,40 @@ const BaseSkeleton: FC<SkeletonProps> = ({ children, ...skeletonProps }) => { | |
); | ||
}; | ||
|
||
export const SearchFieldSkeleton: FC = () => { | ||
return <BaseSkeleton width="100%" />; | ||
}; | ||
|
||
export const MenuSkeleton: FC = () => { | ||
return <BaseSkeleton css={{ minWidth: 200, flexShrink: 0 }} />; | ||
}; | ||
|
||
type FilterProps = { | ||
filter: ReturnType<typeof useFilter>; | ||
skeleton: ReactNode; | ||
optionsSkeleton: ReactNode; | ||
isLoading: boolean; | ||
learnMoreLink?: string; | ||
learnMoreLabel2?: string; | ||
learnMoreLink2?: string; | ||
error?: unknown; | ||
options?: ReactNode; | ||
presets: PresetFilter[]; | ||
breakpoint?: Breakpoint; | ||
|
||
/** | ||
* 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, | ||
skeleton, | ||
optionsSkeleton, | ||
options, | ||
learnMoreLink, | ||
learnMoreLabel2, | ||
learnMoreLink2, | ||
presets, | ||
breakpoint = "md", | ||
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: "nowrap", | ||
flexWrap: "wrap", | ||
|
||
[theme.breakpoints.down(breakpoint)]: { | ||
flexWrap: "wrap", | ||
[theme.breakpoints.up(singleRowBreakpoint)]: { | ||
flexWrap: "nowrap", | ||
}, | ||
}} | ||
> | ||
{isLoading ? ( | ||
skeleton | ||
<> | ||
<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={{ width, flexGrow: 1 }} | ||
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: SelectFilterOption[]) => { | ||
options = options.filter((option) => option.value !== me.username); | ||
const addMeAsFirstOption = (options: readonly SelectFilterOption[]) => { | ||
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 = ({ | |
/> | ||
), | ||
}, | ||
...options, | ||
...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} | ||
/> | ||
); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MY HERO