Skip to content

Commit 25a54d9

Browse files
committed
frontend: Add Storybook stories for DeleteMultipleButton
1 parent 51c2b8b commit 25a54d9

25 files changed

+1292
-69
lines changed
Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
/*
2+
* Copyright 2025 The Kubernetes Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import { Meta, StoryFn } from '@storybook/react';
18+
import { getTestDate } from '../../../helpers/testHelpers';
19+
import { KubeObject } from '../../../lib/k8s/KubeObject';
20+
import { TestContext } from '../../../test';
21+
import { PureDeleteMultipleButton, PureDeleteMultipleButtonProps } from './DeleteMultipleButton';
22+
23+
const createMockPod = (name: string, namespace: string = 'default', cluster: string = 'default') =>
24+
new KubeObject(
25+
{
26+
kind: 'Pod',
27+
apiVersion: 'v1',
28+
metadata: {
29+
name,
30+
namespace,
31+
uid: `uid-${name}`,
32+
creationTimestamp: getTestDate().toISOString(),
33+
},
34+
},
35+
cluster
36+
);
37+
38+
const createMockDeployment = (
39+
name: string,
40+
namespace: string = 'default',
41+
cluster: string = 'default'
42+
) =>
43+
new KubeObject(
44+
{
45+
kind: 'Deployment',
46+
apiVersion: 'apps/v1',
47+
metadata: {
48+
name,
49+
namespace,
50+
uid: `uid-${name}`,
51+
creationTimestamp: getTestDate().toISOString(),
52+
},
53+
},
54+
cluster
55+
);
56+
57+
const createMockService = (
58+
name: string,
59+
namespace: string = 'default',
60+
cluster: string = 'default'
61+
) =>
62+
new KubeObject(
63+
{
64+
kind: 'Service',
65+
apiVersion: 'v1',
66+
metadata: {
67+
name,
68+
namespace,
69+
uid: `uid-${name}`,
70+
creationTimestamp: getTestDate().toISOString(),
71+
},
72+
},
73+
cluster
74+
);
75+
76+
const singlePod = [createMockPod('nginx-pod')];
77+
78+
const multiplePods = [
79+
createMockPod('nginx-pod-1'),
80+
createMockPod('nginx-pod-2'),
81+
createMockPod('redis-pod'),
82+
];
83+
84+
const mixedResources = [
85+
createMockDeployment('nginx-deployment'),
86+
createMockService('redis-service'),
87+
createMockPod('app-pod'),
88+
];
89+
90+
const multiClusterItems = [
91+
createMockPod('nginx-pod', 'default', 'cluster-1'),
92+
createMockPod('redis-pod', 'default', 'cluster-2'),
93+
createMockPod('app-pod', 'kube-system', 'cluster-1'),
94+
];
95+
96+
export default {
97+
title: 'Resource/DeleteMultipleButton',
98+
component: PureDeleteMultipleButton,
99+
argTypes: {
100+
onToggleOpen: { action: 'toggle open' },
101+
onConfirm: { action: 'confirm delete' },
102+
},
103+
decorators: [
104+
Story => (
105+
<TestContext>
106+
<Story />
107+
</TestContext>
108+
),
109+
],
110+
} as Meta;
111+
112+
const Template: StoryFn<PureDeleteMultipleButtonProps> = args => (
113+
<PureDeleteMultipleButton {...args} />
114+
);
115+
116+
const defaultArgs = {
117+
items: multiplePods,
118+
open: false,
119+
loading: false,
120+
error: undefined,
121+
};
122+
123+
// Button disabled with no selection
124+
export const NoSelection = Template.bind({});
125+
NoSelection.args = {
126+
...defaultArgs,
127+
items: [],
128+
};
129+
130+
// Button enabled showing selection count
131+
export const SingleItem = Template.bind({});
132+
SingleItem.args = {
133+
...defaultArgs,
134+
items: singlePod,
135+
};
136+
137+
export const MultipleItems = Template.bind({});
138+
MultipleItems.args = {
139+
...defaultArgs,
140+
items: multiplePods,
141+
};
142+
143+
// Batch delete confirmation dialog
144+
export const ConfirmDialogOpen = Template.bind({});
145+
ConfirmDialogOpen.args = {
146+
...defaultArgs,
147+
open: true,
148+
};
149+
150+
export const ConfirmDialogMixedTypes = Template.bind({});
151+
ConfirmDialogMixedTypes.args = {
152+
...defaultArgs,
153+
items: mixedResources,
154+
open: true,
155+
};
156+
157+
export const ConfirmDialogMultiCluster = Template.bind({});
158+
ConfirmDialogMultiCluster.args = {
159+
...defaultArgs,
160+
items: multiClusterItems,
161+
open: true,
162+
};
163+
164+
// Delete progress indicator
165+
export const DeleteProgressIndicator = Template.bind({});
166+
DeleteProgressIndicator.args = {
167+
...defaultArgs,
168+
open: true,
169+
loading: true,
170+
};
171+
// Error states
172+
export const NetworkError = Template.bind({});
173+
NetworkError.args = {
174+
...defaultArgs,
175+
open: true,
176+
error: 'Network error: Unable to connect to cluster.',
177+
};
178+
179+
export const PermissionDeniedError = Template.bind({});
180+
PermissionDeniedError.args = {
181+
...defaultArgs,
182+
items: mixedResources,
183+
open: true,
184+
error:
185+
'Permission denied: You do not have permission to delete resources in namespace "default".',
186+
};
187+
188+
// Button style variants
189+
export const ActionButtonStyle = Template.bind({});
190+
ActionButtonStyle.args = {
191+
...defaultArgs,
192+
buttonStyle: 'action',
193+
};
194+
195+
export const MenuButtonStyle = Template.bind({});
196+
MenuButtonStyle.args = {
197+
...defaultArgs,
198+
buttonStyle: 'menu',
199+
};

0 commit comments

Comments
 (0)