Skip to content

Commit 43ce786

Browse files
committed
fix: force organizations to be readonly array
1 parent 4956ebb commit 43ce786

File tree

5 files changed

+21
-11
lines changed

5 files changed

+21
-11
lines changed

site/src/modules/dashboard/DashboardProvider.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export interface DashboardValue {
1919
entitlements: Entitlements;
2020
experiments: Experiments;
2121
appearance: AppearanceConfig;
22-
organizations: Organization[];
22+
organizations: readonly Organization[];
2323
showOrganizations: boolean;
2424
}
2525

site/src/pages/ManagementSettingsPage/GroupsPage/GroupsPage.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,5 +99,8 @@ export const GroupsPage: FC = () => {
9999

100100
export default GroupsPage;
101101

102-
export const getOrganizationNameByDefault = (organizations: Organization[]) =>
103-
organizations.find((org) => org.is_default)?.name;
102+
export const getOrganizationNameByDefault = (
103+
organizations: readonly Organization[],
104+
) => {
105+
return organizations.find((org) => org.is_default)?.name;
106+
};

site/src/pages/ManagementSettingsPage/ManagementSettingsLayout.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ import { Outlet } from "react-router-dom";
1212
import { DeploySettingsContext } from "../DeploySettingsPage/DeploySettingsLayout";
1313
import { Sidebar } from "./Sidebar";
1414

15-
type OrganizationSettingsValue = {
16-
organizations: Organization[];
17-
};
15+
type OrganizationSettingsValue = Readonly<{
16+
organizations: readonly Organization[];
17+
}>;
1818

1919
export const useOrganizationSettings = (): OrganizationSettingsValue => {
2020
const { organizations } = useDashboard();

site/src/pages/ManagementSettingsPage/OrganizationSettingsPage.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const OrganizationSettingsPage: FC = () => {
5050
// Redirect /organizations => /organizations/default-org, or if they cannot edit
5151
// the default org, then the first org they can edit, if any.
5252
if (!organizationName) {
53-
const editableOrg = organizations
53+
const editableOrg = [...organizations]
5454
.sort((a, b) => {
5555
// Prefer default org (it may not be first).
5656
// JavaScript will happily subtract booleans, but use numbers to keep
@@ -107,5 +107,9 @@ const OrganizationSettingsPage: FC = () => {
107107

108108
export default OrganizationSettingsPage;
109109

110-
const getOrganizationByName = (organizations: Organization[], name: string) =>
111-
organizations.find((org) => org.name === name);
110+
const getOrganizationByName = (
111+
organizations: readonly Organization[],
112+
name: string,
113+
) => {
114+
return organizations.find((org) => org.name === name);
115+
};

site/src/pages/TemplatePage/TemplateRedirectController.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,11 @@ export const TemplateRedirectController: FC = () => {
4545
return <Outlet />;
4646
};
4747

48-
const getOrganizationNameByDefault = (organizations: Organization[]) =>
49-
organizations.find((org) => org.is_default)?.name;
48+
const getOrganizationNameByDefault = (
49+
organizations: readonly Organization[],
50+
) => {
51+
return organizations.find((org) => org.is_default)?.name;
52+
};
5053

5154
// I really hate doing it this way, but React Router does not provide a better way.
5255
const removePrefix = (self: string, prefix: string) =>

0 commit comments

Comments
 (0)