Skip to content

Commit cfd40d8

Browse files
authored
tech-story: [M3-10364] - MSW CRUD: Add custom grants to profile preset to prevent type error when using restricted profile preset (linode#12756)
* where are we going with this * something like this?? p1 * add back in service tool worker changes * combine profile and grants preset * Added changeset: MSW CRUD: Fix type error when using custom restricted profile preset and add grants preset support * rename things * more renaming * missed some renaming
1 parent f7989de commit cfd40d8

File tree

10 files changed

+320
-98
lines changed

10 files changed

+320
-98
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@linode/manager": Tech Stories
3+
---
4+
5+
MSW CRUD: Fix type error when using custom restricted profile preset and add grants preset support ([#12756](https://github.com/linode/manager/pull/12756))

packages/manager/src/dev-tools/ServiceWorkerTool.tsx

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
getBaselinePreset,
1414
getCustomAccountData,
1515
getCustomEventsData,
16+
getCustomGrantsData,
1617
getCustomMaintenanceData,
1718
getCustomNotificationsData,
1819
getCustomProfileData,
@@ -26,6 +27,7 @@ import {
2627
saveBaselinePreset,
2728
saveCustomAccountData,
2829
saveCustomEventsData,
30+
saveCustomGrantsData,
2931
saveCustomMaintenanceData,
3032
saveCustomNotificationsData,
3133
saveCustomProfileData,
@@ -42,6 +44,7 @@ import type {
4244
Account,
4345
AccountMaintenance,
4446
Event,
47+
Grants,
4548
Notification,
4649
PermissionType,
4750
Profile,
@@ -92,6 +95,9 @@ export const ServiceWorkerTool = () => {
9295
const [customEventsData, setCustomEventsData] = React.useState<
9396
Event[] | null | undefined
9497
>(getCustomEventsData());
98+
const [customGrantsData, setCustomGrantsData] = React.useState<
99+
Grants | null | undefined
100+
>(getCustomGrantsData());
95101
const [customMaintenanceData, setCustomMaintenanceData] = React.useState<
96102
AccountMaintenance[] | null | undefined
97103
>(getCustomMaintenanceData());
@@ -118,6 +124,7 @@ export const ServiceWorkerTool = () => {
118124

119125
React.useEffect(() => {
120126
const currentAccountData = getCustomAccountData();
127+
const currentGrantsData = getCustomGrantsData();
121128
const currentProfileData = getCustomProfileData();
122129
const currentUserAccountPermissionsData =
123130
getCustomUserAccountPermissionsData();
@@ -128,6 +135,8 @@ export const ServiceWorkerTool = () => {
128135
const currentNotificationsData = getCustomNotificationsData();
129136
const hasCustomAccountChanges =
130137
JSON.stringify(currentAccountData) !== JSON.stringify(customAccountData);
138+
const hasCustomGrantsChanges =
139+
JSON.stringify(currentGrantsData) !== JSON.stringify(customGrantsData);
131140
const hasCustomProfileChanges =
132141
JSON.stringify(currentProfileData) !== JSON.stringify(customProfileData);
133142
const hasCustomEventsChanges =
@@ -148,6 +157,7 @@ export const ServiceWorkerTool = () => {
148157

149158
if (
150159
hasCustomAccountChanges ||
160+
hasCustomGrantsChanges ||
151161
hasCustomProfileChanges ||
152162
hasCustomEventsChanges ||
153163
hasCustomMaintenanceChanges ||
@@ -164,6 +174,7 @@ export const ServiceWorkerTool = () => {
164174
customAccountData,
165175
customEventsData,
166176
customMaintenanceData,
177+
customGrantsData,
167178
customNotificationsData,
168179
customProfileData,
169180
customUserAccountPermissionsData,
@@ -183,8 +194,13 @@ export const ServiceWorkerTool = () => {
183194
saveCustomAccountData(customAccountData);
184195
}
185196

186-
if (extraPresets.includes('profile:custom') && customProfileData) {
187-
saveCustomProfileData(customProfileData);
197+
if (extraPresets.includes('profile-grants:custom')) {
198+
if (customProfileData) {
199+
saveCustomProfileData(customProfileData);
200+
}
201+
if (customGrantsData) {
202+
saveCustomGrantsData(customGrantsData);
203+
}
188204
}
189205
if (extraPresets.includes('events:custom') && customEventsData) {
190206
saveCustomEventsData(customEventsData);
@@ -238,6 +254,7 @@ export const ServiceWorkerTool = () => {
238254
setSeedsCountMap(getSeedsCountMap());
239255
setPresetsCountMap(getExtraPresetsMap());
240256
setCustomAccountData(getCustomAccountData());
257+
setCustomGrantsData(getCustomGrantsData());
241258
setCustomProfileData(getCustomProfileData());
242259
setCustomEventsData(getCustomEventsData());
243260
setCustomMaintenanceData(getCustomMaintenanceData());
@@ -261,6 +278,7 @@ export const ServiceWorkerTool = () => {
261278
setExtraPresets([]);
262279
setPresetsCountMap({});
263280
setCustomAccountData(null);
281+
setCustomGrantsData(null);
264282
setCustomProfileData(null);
265283
setCustomEventsData(null);
266284
setCustomMaintenanceData(null);
@@ -275,6 +293,7 @@ export const ServiceWorkerTool = () => {
275293
saveExtraPresetsMap({});
276294
saveCustomAccountData(null);
277295
saveCustomProfileData(null);
296+
saveCustomGrantsData(null);
278297
saveCustomEventsData(null);
279298
saveCustomMaintenanceData(null);
280299
saveCustomNotificationsData(null);
@@ -492,6 +511,7 @@ export const ServiceWorkerTool = () => {
492511
<ExtraPresetOptions
493512
customAccountData={customAccountData}
494513
customEventsData={customEventsData}
514+
customGrantsData={customGrantsData}
495515
customMaintenanceData={customMaintenanceData}
496516
customNotificationsData={customNotificationsData}
497517
customProfileData={customProfileData}
@@ -504,6 +524,7 @@ export const ServiceWorkerTool = () => {
504524
handlers={extraPresets}
505525
onCustomAccountChange={setCustomAccountData}
506526
onCustomEventsChange={setCustomEventsData}
527+
onCustomGrantsChange={setCustomGrantsData}
507528
onCustomMaintenanceChange={setCustomMaintenanceData}
508529
onCustomNotificationsChange={setCustomNotificationsData}
509530
onCustomProfileChange={setCustomProfileData}

packages/manager/src/dev-tools/components/ExtraPresetOptions.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ import { ExtraPresetMaintenance } from './ExtraPresetMaintenance';
99
import { ExtraPresetNotifications } from './ExtraPresetNotifications';
1010
import { ExtraPresetOptionCheckbox } from './ExtraPresetOptionCheckbox';
1111
import { ExtraPresetOptionSelect } from './ExtraPresetOptionSelect';
12-
import { ExtraPresetProfile } from './ExtraPresetProfile';
12+
import { ExtraPresetProfileAndGrants } from './ExtraPresetProfileAndGrants';
1313
import { ExtraPresetUserAccountPermissions } from './ExtraPresetUserAccountPermissions';
1414
import { ExtraPresetUserEntityPermissions } from './ExtraPresetUserEntityPermissions';
1515

1616
import type {
1717
Account,
1818
AccountMaintenance,
1919
Event,
20+
Grants,
2021
Notification,
2122
PermissionType,
2223
Profile,
@@ -25,6 +26,7 @@ import type {
2526
export interface ExtraPresetOptionsProps {
2627
customAccountData?: Account | null;
2728
customEventsData?: Event[] | null;
29+
customGrantsData?: Grants | null;
2830
customMaintenanceData?: AccountMaintenance[] | null;
2931
customNotificationsData?: Notification[] | null;
3032
customProfileData?: null | Profile;
@@ -33,6 +35,7 @@ export interface ExtraPresetOptionsProps {
3335
handlers: string[];
3436
onCustomAccountChange?: (data: Account | null | undefined) => void;
3537
onCustomEventsChange?: (data: Event[] | null | undefined) => void;
38+
onCustomGrantsChange?: (data: Grants | null | undefined) => void;
3639
onCustomMaintenanceChange?: (
3740
data: AccountMaintenance[] | null | undefined
3841
) => void;
@@ -59,6 +62,7 @@ export const ExtraPresetOptions = ({
5962
customAccountData,
6063
customProfileData,
6164
customEventsData,
65+
customGrantsData,
6266
customMaintenanceData,
6367
customNotificationsData,
6468
customUserAccountPermissionsData,
@@ -67,6 +71,7 @@ export const ExtraPresetOptions = ({
6771
onCustomAccountChange,
6872
onCustomProfileChange,
6973
onCustomEventsChange,
74+
onCustomGrantsChange,
7075
onCustomMaintenanceChange,
7176
onCustomNotificationsChange,
7277
onCustomUserAccountPermissionsChange,
@@ -120,11 +125,13 @@ export const ExtraPresetOptions = ({
120125
onTogglePreset={onTogglePreset}
121126
/>
122127
)}
123-
{currentGroupType === 'profile' && (
124-
<ExtraPresetProfile
128+
{currentGroupType === 'profile & grants' && (
129+
<ExtraPresetProfileAndGrants
130+
customGrantsData={customGrantsData}
125131
customProfileData={customProfileData}
126132
handlers={handlers}
127-
onFormChange={onCustomProfileChange}
133+
onFormChangeGrants={onCustomGrantsChange}
134+
onFormChangeProfile={onCustomProfileChange}
128135
onTogglePreset={onTogglePreset}
129136
/>
130137
)}

0 commit comments

Comments
 (0)