Skip to content

Commit e4f5bf7

Browse files
committed
Pass in ids instead of entire orgs
1 parent 83bf388 commit e4f5bf7

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

site/src/api/queries/organizations.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { API } from "api/api";
33
import type {
44
AuthorizationResponse,
55
CreateOrganizationRequest,
6-
Organization,
76
UpdateOrganizationRequest,
87
} from "api/typesGenerated";
98
import { meKey } from "./users";
@@ -169,9 +168,9 @@ export const organizationPermissions = (organizationId: string | undefined) => {
169168
* If organizations are undefined, return a disabled query.
170169
*/
171170
export const organizationsPermissions = (
172-
organizations: Organization[] | undefined,
171+
organizationIds: string[] | undefined,
173172
) => {
174-
if (!organizations) {
173+
if (!organizationIds) {
175174
return { enabled: false };
176175
}
177176

@@ -215,10 +214,10 @@ export const organizationsPermissions = (
215214

216215
// The endpoint takes a flat array, so to avoid collisions prepend each
217216
// check with the org ID (the key can be anything we want).
218-
const prefixedChecks = organizations
219-
.map((org) =>
220-
Object.entries(checks(org.id)).map(([key, val]) => [
221-
`${org.id}.${key}`,
217+
const prefixedChecks = organizationIds
218+
.map((orgId) =>
219+
Object.entries(checks(orgId)).map(([key, val]) => [
220+
`${orgId}.${key}`,
222221
val,
223222
]),
224223
)

site/src/pages/ManagementSettingsPage/OrganizationSettingsPage.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ const OrganizationSettingsPage: FC = () => {
3535
organizations && organizationName
3636
? getOrganizationByName(organizations, organizationName)
3737
: undefined;
38-
const permissionsQuery = useQuery(organizationsPermissions(organizations));
38+
const permissionsQuery = useQuery(
39+
organizationsPermissions(organizations?.map((o) => o.id)),
40+
);
3941

4042
const permissions = permissionsQuery.data;
4143
if (!organizations || !permissions) {

site/src/pages/ManagementSettingsPage/Sidebar.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ export const Sidebar: FC = () => {
2525
organization?: string;
2626
};
2727

28-
const orgPermissionsQuery = useQuery(organizationsPermissions(organizations));
28+
const orgPermissionsQuery = useQuery(
29+
organizationsPermissions(organizations?.map((o) => o.id)),
30+
);
2931

3032
// Sometimes a user can read an organization but cannot actually do anything
3133
// with it. For now, these are filtered out so you only see organizations you

0 commit comments

Comments
 (0)