Skip to content

Commit 67da5f3

Browse files
committed
Implement LabelGroupWithTooltip component to display extra workspaces
Signed-off-by: Charles Thao <[email protected]>
1 parent f289510 commit 67da5f3

File tree

3 files changed

+101
-45
lines changed

3 files changed

+101
-45
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import React from 'react';
2+
import { Label, LabelProps } from '@patternfly/react-core/dist/esm/components/Label';
3+
import { Tooltip } from '@patternfly/react-core/dist/esm/components/Tooltip';
4+
import { Flex, FlexItem } from '@patternfly/react-core/dist/esm/layouts/Flex';
5+
6+
export interface LabelGroupWithTooltipProps {
7+
labels: string[];
8+
limit: number;
9+
isCompact?: boolean;
10+
variant?: LabelProps['variant'];
11+
icon?: React.ReactNode;
12+
status?: LabelProps['status'];
13+
color?: LabelProps['color'];
14+
}
15+
16+
export const LabelGroupWithTooltip: React.FC<LabelGroupWithTooltipProps> = ({
17+
labels,
18+
limit,
19+
isCompact = false,
20+
variant = 'filled',
21+
icon,
22+
status,
23+
color,
24+
}) => {
25+
if (labels.length === 0) {
26+
return null;
27+
}
28+
29+
const visibleLabels = labels.slice(0, limit);
30+
const remainingLabels = labels.slice(limit);
31+
const hasMore = remainingLabels.length > 0;
32+
33+
return (
34+
<Flex gap={{ default: 'gapXs' }}>
35+
{visibleLabels.map((label, index) => (
36+
<FlexItem key={`${label}-${index}`}>
37+
<Label isCompact={isCompact} variant={variant} icon={icon} status={status} color={color}>
38+
{label}
39+
</Label>
40+
</FlexItem>
41+
))}
42+
{hasMore && (
43+
<FlexItem>
44+
<Tooltip content={`${remainingLabels.join(', ')}`}>
45+
<Label isCompact={isCompact} variant={variant} color={color}>
46+
+{remainingLabels.length} more
47+
</Label>
48+
</Tooltip>
49+
</FlexItem>
50+
)}
51+
</Flex>
52+
);
53+
};

workspaces/frontend/src/app/pages/Workspaces/Form/properties/secrets/SecretsAttachModal.tsx

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ import { Flex, FlexItem } from '@patternfly/react-core/dist/esm/layouts/Flex';
1717
import { Label, LabelGroup } from '@patternfly/react-core/dist/esm/components/Label';
1818
import { Tooltip } from '@patternfly/react-core/dist/esm/components/Tooltip';
1919
import { InfoCircleIcon } from '@patternfly/react-icons/dist/esm/icons/info-circle-icon';
20-
import { Truncate } from '@patternfly/react-core/dist/esm/components/Truncate';
20+
import { WrenchIcon } from '@patternfly/react-icons/dist/esm/icons/wrench-icon';
2121
import { Stack, StackItem } from '@patternfly/react-core/dist/esm/layouts/Stack';
2222
import { SecretsSecretListItem } from '~/generated/data-contracts';
2323
import { isValidDefaultMode } from '~/app/pages/Workspaces/Form/helpers';
2424
import ThemeAwareFormGroupWrapper from '~/shared/components/ThemeAwareFormGroupWrapper';
25+
import { LabelGroupWithTooltip } from '~/app/components/LabelGroupWithTooltip';
2526

2627
export interface SecretsAttachModalProps {
2728
isOpen: boolean;
@@ -112,41 +113,47 @@ export const SecretsAttachModal: React.FC<SecretsAttachModalProps> = ({
112113
<LabelGroup>
113114
<Label isCompact>Type: {secret.type}</Label>
114115
{secret.immutable && <Label isCompact>Immutable</Label>}
116+
{!secret.canMount && <Label isCompact>Unmountable</Label>}
115117
</LabelGroup>
116118
</StackItem>
117119
{secret.mounts && (
118-
<StackItem style={{ paddingLeft: '1.25ch' }}>
119-
Mounted to:&ensp;
120-
<Truncate
121-
content={secret.mounts.map((mount) => mount.name).join(', ')}
122-
position="end"
123-
maxCharsDisplayed={100}
124-
/>
120+
<StackItem style={{ marginLeft: '1.25ch', marginTop: '0.25rem' }}>
121+
<Flex gap={{ default: 'gapXs' }}>
122+
<FlexItem>Mounted to:</FlexItem>
123+
<FlexItem>
124+
<LabelGroupWithTooltip
125+
labels={secret.mounts.map((mount) => mount.name)}
126+
limit={5}
127+
variant="outline"
128+
icon={<WrenchIcon color="teal" />}
129+
isCompact
130+
color="teal"
131+
/>
132+
</FlexItem>
133+
</Flex>
125134
</StackItem>
126135
)}
127136
</Stack>
128137
</FlexItem>
129138
<FlexItem>
130-
{secret.canMount && (
131-
<Tooltip
132-
aria="none"
133-
aria-live="polite"
134-
content={
135-
<Stack>
136-
<StackItem>
137-
{`Created at: ${new Date(secret.audit.createdAt).toLocaleString()} by
139+
<Tooltip
140+
aria="none"
141+
aria-live="polite"
142+
content={
143+
<Stack>
144+
<StackItem>
145+
{`Created at: ${new Date(secret.audit.createdAt).toLocaleString()} by
138146
${secret.audit.createdBy}`}
139-
</StackItem>
140-
<StackItem>
141-
{`Updated at: ${new Date(secret.audit.updatedAt).toLocaleString()} by
147+
</StackItem>
148+
<StackItem>
149+
{`Updated at: ${new Date(secret.audit.updatedAt).toLocaleString()} by
142150
${secret.audit.updatedBy}`}
143-
</StackItem>
144-
</Stack>
145-
}
146-
>
147-
<InfoCircleIcon />
148-
</Tooltip>
149-
)}
151+
</StackItem>
152+
</Stack>
153+
}
154+
>
155+
<InfoCircleIcon />
156+
</Tooltip>
150157
</FlexItem>
151158
</Flex>
152159
),

workspaces/frontend/src/shared/mock/mockNotebookServiceData.ts

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,18 @@ const buildMockSecretList = (startIndex: number, count: number) => {
169169
return secrets;
170170
};
171171

172+
const buildMockSecretMountList = (startIndex: number, count: number) => {
173+
const mounts = [];
174+
for (let i = startIndex; i <= startIndex + count; i++) {
175+
mounts.push({
176+
name: `workspace-${i}`,
177+
group: `group-${i}`,
178+
kind: `kind-${i}`,
179+
});
180+
}
181+
return mounts;
182+
};
183+
172184
export const mockAllWorkspaces = [
173185
mockWorkspace1,
174186
mockWorkspace2,
@@ -197,32 +209,16 @@ export const mockSecretsList = [
197209
buildMockSecret({
198210
name: 'secret-1',
199211
immutable: true,
200-
mounts: [
201-
{
202-
name: 'workspace-1',
203-
group: 'group-1',
204-
kind: 'kind-1',
205-
},
206-
],
212+
mounts: buildMockSecretMountList(1, 5),
207213
}),
208214
buildMockSecret({
209215
name: 'secret-2',
210216
canMount: false,
217+
mounts: buildMockSecretMountList(1, 2),
211218
}),
212219
buildMockSecret({
213220
name: 'secret-3',
214-
mounts: [
215-
{
216-
name: 'workspace-1',
217-
group: 'group-1',
218-
kind: 'kind-1',
219-
},
220-
{
221-
name: 'workspace-2, workspace-3, workspace-4, workspace-5, workspace-6, workspace-7, workspace-8, workspace-9, workspace-10',
222-
group: 'group-2',
223-
kind: 'kind-2',
224-
},
225-
],
221+
mounts: buildMockSecretMountList(1, 20),
226222
}),
227223
...buildMockSecretList(4, 20),
228224
];

0 commit comments

Comments
 (0)