@@ -12,6 +12,9 @@ import { SeedOptions } from './components/SeedOptions';
1212import {
1313 getBaselinePreset ,
1414 getCustomAccountData ,
15+ getCustomEventsData ,
16+ getCustomMaintenanceData ,
17+ getCustomNotificationsData ,
1518 getCustomProfileData ,
1619 getExtraPresets ,
1720 getExtraPresetsMap ,
@@ -20,6 +23,9 @@ import {
2023 isMSWEnabled ,
2124 saveBaselinePreset ,
2225 saveCustomAccountData ,
26+ saveCustomEventsData ,
27+ saveCustomMaintenanceData ,
28+ saveCustomNotificationsData ,
2329 saveCustomProfileData ,
2430 saveExtraPresets ,
2531 saveExtraPresetsMap ,
@@ -28,7 +34,13 @@ import {
2834 saveSeedsCountMap ,
2935} from './utils' ;
3036
31- import type { Account , Profile } from '@linode/api-v4' ;
37+ import type {
38+ Account ,
39+ AccountMaintenance ,
40+ Event ,
41+ Notification ,
42+ Profile ,
43+ } from '@linode/api-v4' ;
3244import type {
3345 MockPresetBaselineId ,
3446 MockPresetCrudId ,
@@ -62,6 +74,15 @@ export const ServiceWorkerTool = () => {
6274 const [ customProfileData , setCustomProfileData ] = React . useState <
6375 null | Profile | undefined
6476 > ( getCustomProfileData ( ) ) ;
77+ const [ customEventsData , setCustomEventsData ] = React . useState <
78+ Event [ ] | null | undefined
79+ > ( getCustomEventsData ( ) ) ;
80+ const [ customMaintenanceData , setCustomMaintenanceData ] = React . useState <
81+ AccountMaintenance [ ] | null | undefined
82+ > ( getCustomMaintenanceData ( ) ) ;
83+ const [ customNotificationsData , setCustomNotificationsData ] = React . useState <
84+ Notification [ ] | null | undefined
85+ > ( getCustomNotificationsData ( ) ) ;
6586 const [ presetsCountMap , setPresetsCountMap ] = React . useState < {
6687 [ key : string ] : number ;
6788 } > ( loadedPresetsMap ) ;
@@ -83,18 +104,41 @@ export const ServiceWorkerTool = () => {
83104 React . useEffect ( ( ) => {
84105 const currentAccountData = getCustomAccountData ( ) ;
85106 const currentProfileData = getCustomProfileData ( ) ;
107+ const currentEventsData = getCustomEventsData ( ) ;
108+ const currentMaintenanceData = getCustomMaintenanceData ( ) ;
109+ const currentNotificationsData = getCustomNotificationsData ( ) ;
86110 const hasCustomAccountChanges =
87111 JSON . stringify ( currentAccountData ) !== JSON . stringify ( customAccountData ) ;
88112 const hasCustomProfileChanges =
89113 JSON . stringify ( currentProfileData ) !== JSON . stringify ( customProfileData ) ;
114+ const hasCustomEventsChanges =
115+ JSON . stringify ( currentEventsData ) !== JSON . stringify ( customEventsData ) ;
116+ const hasCustomMaintenanceChanges =
117+ JSON . stringify ( currentMaintenanceData ) !==
118+ JSON . stringify ( customMaintenanceData ) ;
119+ const hasCustomNotificationsChanges =
120+ JSON . stringify ( currentNotificationsData ) !==
121+ JSON . stringify ( customNotificationsData ) ;
90122
91- if ( hasCustomAccountChanges || hasCustomProfileChanges ) {
123+ if (
124+ hasCustomAccountChanges ||
125+ hasCustomProfileChanges ||
126+ hasCustomEventsChanges ||
127+ hasCustomMaintenanceChanges ||
128+ hasCustomNotificationsChanges
129+ ) {
92130 setSaveState ( ( prev ) => ( {
93131 ...prev ,
94132 hasUnsavedChanges : true ,
95133 } ) ) ;
96134 }
97- } , [ customAccountData , customProfileData ] ) ;
135+ } , [
136+ customAccountData ,
137+ customEventsData ,
138+ customMaintenanceData ,
139+ customNotificationsData ,
140+ customProfileData ,
141+ ] ) ;
98142
99143 const globalHandlers = {
100144 applyChanges : ( ) => {
@@ -112,6 +156,21 @@ export const ServiceWorkerTool = () => {
112156 if ( extraPresets . includes ( 'profile:custom' ) && customProfileData ) {
113157 saveCustomProfileData ( customProfileData ) ;
114158 }
159+ if ( extraPresets . includes ( 'events:custom' ) && customEventsData ) {
160+ saveCustomEventsData ( customEventsData ) ;
161+ }
162+ if (
163+ extraPresets . includes ( 'maintenance:custom' ) &&
164+ customMaintenanceData
165+ ) {
166+ saveCustomMaintenanceData ( customMaintenanceData ) ;
167+ }
168+ if (
169+ extraPresets . includes ( 'notifications:custom' ) &&
170+ customNotificationsData
171+ ) {
172+ saveCustomNotificationsData ( customNotificationsData ) ;
173+ }
115174
116175 const promises = seeders . map ( ( seederId ) => {
117176 const seeder = dbSeeders . find ( ( dbSeeder ) => dbSeeder . id === seederId ) ;
@@ -138,6 +197,9 @@ export const ServiceWorkerTool = () => {
138197 setPresetsCountMap ( getExtraPresetsMap ( ) ) ;
139198 setCustomAccountData ( getCustomAccountData ( ) ) ;
140199 setCustomProfileData ( getCustomProfileData ( ) ) ;
200+ setCustomEventsData ( getCustomEventsData ( ) ) ;
201+ setCustomMaintenanceData ( getCustomMaintenanceData ( ) ) ;
202+ setCustomNotificationsData ( getCustomNotificationsData ( ) ) ;
141203 setSaveState ( {
142204 hasSaved : false ,
143205 hasUnsavedChanges : false ,
@@ -148,18 +210,27 @@ export const ServiceWorkerTool = () => {
148210 mswDB . clear ( 'mockState' ) ;
149211 mswDB . clear ( 'seedState' ) ;
150212 seederHandlers . removeAll ( ) ;
213+
151214 setBaselinePreset ( 'baseline:static-mocking' ) ;
152215 setExtraPresets ( [ ] ) ;
153216 setPresetsCountMap ( { } ) ;
154217 setCustomAccountData ( null ) ;
155218 setCustomProfileData ( null ) ;
219+ setCustomEventsData ( null ) ;
220+ setCustomMaintenanceData ( null ) ;
221+ setCustomNotificationsData ( null ) ;
222+
156223 saveBaselinePreset ( 'baseline:static-mocking' ) ;
157224 saveExtraPresets ( [ ] ) ;
158225 saveSeeders ( [ ] ) ;
159226 saveSeedsCountMap ( { } ) ;
160227 saveExtraPresetsMap ( { } ) ;
161228 saveCustomAccountData ( null ) ;
162229 saveCustomProfileData ( null ) ;
230+ saveCustomEventsData ( null ) ;
231+ saveCustomMaintenanceData ( null ) ;
232+ saveCustomNotificationsData ( null ) ;
233+
163234 setSaveState ( {
164235 hasSaved : false ,
165236 hasUnsavedChanges : true ,
@@ -370,9 +441,15 @@ export const ServiceWorkerTool = () => {
370441 < div className = "dev-tools__list-box" >
371442 < ExtraPresetOptions
372443 customAccountData = { customAccountData }
444+ customEventsData = { customEventsData }
445+ customMaintenanceData = { customMaintenanceData }
446+ customNotificationsData = { customNotificationsData }
373447 customProfileData = { customProfileData }
374448 handlers = { extraPresets }
375449 onCustomAccountChange = { setCustomAccountData }
450+ onCustomEventsChange = { setCustomEventsData }
451+ onCustomMaintenanceChange = { setCustomMaintenanceData }
452+ onCustomNotificationsChange = { setCustomNotificationsData }
376453 onCustomProfileChange = { setCustomProfileData }
377454 onPresetCountChange = { presetHandlers . changeCount }
378455 onSelectChange = { presetHandlers . changeSelect }
0 commit comments