Skip to content

Commit 4ade224

Browse files
committed
chore: cleanup
1 parent 09e96ea commit 4ade224

File tree

2 files changed

+23
-16
lines changed

2 files changed

+23
-16
lines changed

site/src/pages/ManagementSettingsPage/CustomRolesPage/CreateEditRolePage.tsx

+8-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { patchOrganizationRole, organizationRoles } from "api/queries/roles";
1010
import type { PatchRoleRequest } from "api/typesGenerated";
1111
import { displayError } from "components/GlobalSnackbar/utils";
1212
import { Loader } from "components/Loader/Loader";
13-
import { PageHeader } from "components/PageHeader/PageHeader";
13+
import { PageHeader, PageHeaderTitle } from "components/PageHeader/PageHeader";
1414
import { useAuthenticated } from "contexts/auth/RequireAuth";
1515
import { nameValidator } from "utils/formUtils";
1616
import { pageTitle } from "utils/page";
@@ -20,13 +20,13 @@ export const CreateEditRolePage: FC = () => {
2020
const { permissions } = useAuthenticated();
2121
const queryClient = useQueryClient();
2222
const navigate = useNavigate();
23-
const { organization, roleName } = useParams() as {
23+
const { organization = "default", roleName } = useParams() as {
2424
organization: string;
2525
roleName: string;
2626
};
2727
const { assignOrgRole: canAssignOrgRole } = permissions;
2828
const patchOrganizationRoleMutation = useMutation(
29-
patchOrganizationRole(queryClient, organization ?? "default"),
29+
patchOrganizationRole(queryClient, organization),
3030
);
3131
const { data: roleData, isLoading } = useQuery(
3232
organizationRoles(organization),
@@ -95,7 +95,11 @@ export const CreateEditRolePage: FC = () => {
9595
</>
9696
)
9797
}
98-
></PageHeader>
98+
>
99+
<PageHeaderTitle>
100+
{role ? "Edit" : "Create"} custom role
101+
</PageHeaderTitle>
102+
</PageHeader>
99103

100104
<CreateEditRolePageView
101105
role={role}

site/src/pages/ManagementSettingsPage/CustomRolesPage/CreateEditRolePageView.tsx

+15-12
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import {
2626
FormSection,
2727
HorizontalForm,
2828
} from "components/Form/Form";
29-
import { PageHeader, PageHeaderTitle } from "components/PageHeader/PageHeader";
3029
import { getFormHelpers } from "utils/formUtils";
3130

3231
export type CreateEditRolePageViewProps = {
@@ -48,11 +47,6 @@ export const CreateEditRolePageView: FC<CreateEditRolePageViewProps> = ({
4847

4948
return (
5049
<>
51-
<PageHeader css={{ paddingTop: 8 }}>
52-
<PageHeaderTitle>
53-
{role ? "Edit" : "Create"} custom role
54-
</PageHeaderTitle>
55-
</PageHeader>
5650
<HorizontalForm onSubmit={form.handleSubmit}>
5751
<FormSection
5852
title="Role settings"
@@ -101,6 +95,14 @@ interface ActionCheckboxesProps {
10195
form: ReturnType<typeof useFormik<Role>> & { values: Role };
10296
}
10397

98+
const ResourceActionComparator = (
99+
p: Permission,
100+
resource: string,
101+
action: string,
102+
) =>
103+
p.resource_type === resource &&
104+
(p.action.toString() === "*" || p.action === action);
105+
104106
const ActionCheckboxes: FC<ActionCheckboxesProps> = ({ permissions, form }) => {
105107
const [checkedActions, setCheckActions] = useState(permissions);
106108

@@ -146,18 +148,19 @@ const ActionCheckboxes: FC<ActionCheckboxesProps> = ({ permissions, form }) => {
146148
<Checkbox
147149
name={`${resourceKey}:${actionKey}`}
148150
checked={
149-
checkedActions?.some(
150-
(p) =>
151-
p.resource_type === resourceKey &&
152-
(p.action.toString() === "*" ||
153-
p.action === actionKey),
151+
checkedActions?.some((p) =>
152+
ResourceActionComparator(
153+
p,
154+
resourceKey,
155+
actionKey,
156+
),
154157
) || false
155158
}
156159
onChange={(e) => handleCheckChange(e, form)}
157160
/>
158161
{actionKey}
159162
</span>{" "}
160-
-{" "}
163+
&ndash;{" "}
161164
<span css={styles.actionDescription}>{value}</span>
162165
</li>
163166
);

0 commit comments

Comments
 (0)