Skip to content

Commit 7aa578b

Browse files
upcoming: [UIE-9781] - Add CRUD MSW mocks for Locks(Linodes is in scope). (#13286)
* upcoming: [UIE-9781] - Add CRUD MSW mocks for Resource Locking feature(RESPROT2) * Added changeset: Add MSW crud for Resource Locking feature(RESPROT2) * Refactored the types to re-use Entity and entityFactory. * Address review comments by Ganesh * Added changeset: Added locks property to Linode interface,added lock create and delete event keys, refactored Lock types
1 parent fea3859 commit 7aa578b

File tree

23 files changed

+585
-14
lines changed

23 files changed

+585
-14
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@linode/api-v4": Upcoming Features
3+
---
4+
5+
Added locks property to Linode interface,added lock create and delete event keys, refactored Lock types ([#13286](https://github.com/linode/manager/pull/13286))

packages/api-v4/src/account/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,8 @@ export const EventActionKeys = [
434434
'lke_pool_delete',
435435
'lke_pool_recycle',
436436
'lke_token_rotate',
437+
'lock_create',
438+
'lock_delete',
437439
'longviewclient_create',
438440
'longviewclient_delete',
439441
'longviewclient_update',

packages/api-v4/src/linodes/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { MaintenancePolicySlug } from '../account/types';
22
import type { CloudPulseAlertsPayload } from '../cloudpulse/types';
3+
import type { LockType } from '../locks/types';
34
import type { IPAddress, IPRange } from '../networking/types';
45
import type { LinodePlacementGroupPayload } from '../placement-groups/types';
56
import type { Region, RegionSite } from '../regions';
@@ -44,6 +45,7 @@ export interface Linode {
4445
ipv6: null | string;
4546
label: string;
4647
lke_cluster_id: null | number;
48+
locks: LockType[];
4749
maintenance_policy?: MaintenancePolicySlug;
4850
placement_group: LinodePlacementGroupPayload | null;
4951
region: string;

packages/api-v4/src/locks/types.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,11 @@
1+
import type { Entity } from '../account/types';
12
import type { EntityType } from '../entities';
23

34
/**
45
* Types of locks that can be applied to a resource
56
*/
67
export type LockType = 'cannot_delete' | 'cannot_delete_with_subresources';
78

8-
/**
9-
* Entity information attached to a lock
10-
*/
11-
export interface LockEntity {
12-
id: number | string;
13-
label?: string;
14-
type: EntityType;
15-
url?: string;
16-
}
17-
189
/**
1910
* Request payload for creating a lock
2011
* POST /v4beta/locks
@@ -34,7 +25,7 @@ export interface CreateLockPayload {
3425
*/
3526
export interface ResourceLock {
3627
/** Information about the locked entity */
37-
entity: LockEntity;
28+
entity: Entity;
3829
/** Unique identifier for the lock */
3930
id: number;
4031
/** Type of lock applied */
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@linode/manager": Upcoming Features
3+
---
4+
5+
Add MSW crud for Resource Locking feature(RESPROT2) ([#13286](https://github.com/linode/manager/pull/13286))

packages/manager/src/factories/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export * from './images';
2424
export * from './kernels';
2525
export * from './kubernetesCluster';
2626
export * from './linodeConfigs';
27+
export * from './locks';
2728
export * from './longviewClient';
2829
export * from './longviewDisks';
2930
export * from './longviewProcess';
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Factory } from '@linode/utilities';
2+
3+
import { entityFactory } from './events';
4+
5+
import type { ResourceLock } from '@linode/api-v4';
6+
7+
export const lockFactory = Factory.Sync.makeFactory<ResourceLock>({
8+
id: Factory.each((i) => i),
9+
lock_type: 'cannot_delete',
10+
entity: entityFactory.build({
11+
type: 'linode',
12+
}),
13+
});

packages/manager/src/features/Events/factories/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export * from './lassie';
1818
export * from './linode';
1919
export * from './lish';
2020
export * from './lke';
21+
export * from './lock';
2122
export * from './longviewclient';
2223
export * from './managed';
2324
export * from './nodebalancer';
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import * as React from 'react';
2+
3+
import { EventLink } from '../EventLink';
4+
5+
import type { PartialEventMap } from '../types';
6+
7+
export const lock: PartialEventMap<'lock'> = {
8+
lock_create: {
9+
notification: (e) => (
10+
<>
11+
A <strong>resource lock</strong> has been created for{' '}
12+
{e.secondary_entity ? (
13+
<EventLink event={e} to="secondaryEntity" />
14+
) : (
15+
'resource'
16+
)}
17+
.
18+
</>
19+
),
20+
},
21+
lock_delete: {
22+
notification: (e) => (
23+
<>
24+
A <strong>resource lock</strong> has been removed from{' '}
25+
{e.secondary_entity ? (
26+
<EventLink event={e} to="secondaryEntity" />
27+
) : (
28+
'resource'
29+
)}
30+
.
31+
</>
32+
),
33+
},
34+
};

packages/manager/src/hooks/useEventHandlers.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ export const eventHandlers: {
7474
},
7575
{
7676
filter: (event) =>
77-
event.action.startsWith('linode') || event.action.startsWith('backups'),
77+
event.action.startsWith('linode') ||
78+
event.action.startsWith('backups') ||
79+
event.action.startsWith('lock'),
7880
handler: linodeEventsHandler,
7981
},
8082
{

0 commit comments

Comments
 (0)