MCPcopy Index your code
hub / github.com/coder/coder / useOrganizationsFilterMenu

Function useOrganizationsFilterMenu

site/src/modules/tableFiltering/options.tsx:25–87  ·  view source on GitHub ↗
({
	value,
	onChange,
}: Pick<UseFilterMenuOptions, "value" | "onChange">)

Source from the content-addressed store, hash-verified

23// Organization helpers ////////////////////////////////////////////////////////
24
25export const useOrganizationsFilterMenu = ({
26 value,
27 onChange,
28}: Pick<UseFilterMenuOptions, "value" | "onChange">) => {
29 return useFilterMenu({
30 onChange,
31 value,
32 id: "organizations",
33 getSelectedOption: async () => {
34 if (value) {
35 const organizations = await API.getOrganizations();
36 const organization = organizations.find((o) => o.name === value);
37 if (organization) {
38 return {
39 label: organization.display_name || organization.name,
40 value: organization.name,
41 startIcon: (
42 <Avatar
43 key={organization.id}
44 size="sm"
45 fallback={organization.display_name || organization.name}
46 src={organization.icon}
47 />
48 ),
49 };
50 }
51 }
52 return null;
53 },
54 getOptions: async () => {
55 // Only show the organizations for which you can view audit logs.
56 const organizations = await API.getOrganizations();
57 const permissions = await API.checkAuthorization({
58 checks: Object.fromEntries(
59 organizations.map((organization) => [
60 organization.id,
61 {
62 object: {
63 resource_type: "audit_log",
64 organization_id: organization.id,
65 },
66 action: "read",
67 },
68 ]),
69 ),
70 });
71 return organizations
72 .filter((organization) => permissions[organization.id])
73 .map<SelectFilterOption>((organization) => ({
74 label: organization.display_name || organization.name,
75 value: organization.name,
76 startIcon: (
77 <Avatar
78 key={organization.id}
79 size="sm"
80 fallback={organization.display_name || organization.name}
81 src={organization.icon}
82 />

Callers 3

ConnectionLogPageFunction · 0.90
AuditPageFunction · 0.90
useWorkspacesFilterFunction · 0.90

Calls 4

useFilterMenuFunction · 0.90
findMethod · 0.80
checkAuthorizationMethod · 0.80
filterMethod · 0.80

Tested by

no test coverage detected