Skip to content
This repository was archived by the owner on Jul 30, 2025. It is now read-only.

Commit b405eca

Browse files
committed
feat: use PatternFly LabelGroup for kubernetes Labels tab
Adds `{ spec: { as: 'labels' } }` to DescriptionList model part of #8116
1 parent 5d06667 commit b405eca

File tree

11 files changed

+133
-12
lines changed

11 files changed

+133
-12
lines changed

packages/core/src/models/DescriptionList.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ export default interface DescriptionList {
2121
kind: 'DescriptionList'
2222

2323
spec: {
24+
/** Display as a list of key-value pairs (default), or as a list of labels */
25+
as?: 'default' | 'labels'
26+
2427
groups: {
2528
/** The term being described */
2629
term: string

plugins/plugin-client-common/src/components/Content/KuiContent.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,11 @@ export default class KuiContent extends React.PureComponent<KuiMMRProps, State>
146146
return (
147147
<div className="flex-fill flex-layout flex-align-stretch">
148148
<div className="scrollable scrollable-auto scrollable-x flex-fill flex-layout flex-align-stretch">
149-
<DescriptionList groups={mode.content.spec.groups} className="left-pad right-pad" />
149+
<DescriptionList
150+
as={mode.content.spec.as}
151+
groups={mode.content.spec.groups}
152+
className="left-pad right-pad"
153+
/>
150154
</div>
151155
</div>
152156
)

plugins/plugin-client-common/src/components/spi/DescriptionList/impl/PatternFly.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function columnModifier(maxWidth: number) {
4242
}
4343
}
4444

45-
export default function PatternFlyDescriptionList(props: Props) {
45+
export default function PatternFlyDescriptionList(props: Omit<Props, 'as'>) {
4646
const maxWidth = props.groups.reduce(
4747
(max, group) => Math.max(max, group.term.length /*, group.description.toString().length */),
4848
0
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright 2021 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 React from 'react'
18+
import { LabelGroup, Label } from '@patternfly/react-core'
19+
20+
import Props from '../model'
21+
22+
import '../../../../../web/scss/components/DescriptionList/PatternFlyLabelList.scss'
23+
24+
export default function PatternFlyDescriptionList(props: Omit<Props, 'as'>) {
25+
return (
26+
<div
27+
className={[props.className, 'kui--description-list', 'kui--label-list', 'flex-fill', 'padding-content'].join(
28+
' '
29+
)}
30+
>
31+
<LabelGroup className="kui--description-list-group" numLabels={10}>
32+
{props.groups.map((group, idx) => (
33+
<Label key={idx} className="kui--description-list-term" data-term={group.term}>
34+
<span className="map-key">{group.term}</span>
35+
<strong className="slightly-deemphasize small-left-pad small-right-pad">|</strong>
36+
<span className="map-value">{group.description}</span>
37+
</Label>
38+
))}
39+
</LabelGroup>
40+
</div>
41+
)
42+
}

plugins/plugin-client-common/src/components/spi/DescriptionList/index.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,15 @@
1717
import React from 'react'
1818
import Props from './model'
1919

20-
const PatternFly4 = React.lazy(() => import('./impl/PatternFly'))
20+
const PatternFly4DescriptionList = React.lazy(() => import('./impl/PatternFly'))
21+
const PatternFly4LabelList = React.lazy(() => import('./impl/PatternFlyLabelList'))
2122

2223
export { Props }
2324

2425
export default function DescriptionListSpi(props: Props): React.ReactElement {
25-
return <PatternFly4 {...props} />
26+
if (!props.as || props.as === 'default') {
27+
return <PatternFly4DescriptionList {...props} />
28+
} else {
29+
return <PatternFly4LabelList {...props} />
30+
}
2631
}

plugins/plugin-client-common/src/components/spi/DescriptionList/model.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@ import { DescriptionList } from '@kui-shell/core'
1818

1919
export default interface Props {
2020
className?: string
21+
as: DescriptionList['spec']['as']
2122
groups: DescriptionList['spec']['groups']
2223
}

plugins/plugin-client-common/web/scss/PatternFly/kui-alignment.scss

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,8 @@
187187
@mixin pf-t-dark {
188188
--pf-global--Color--dark-100: var(--color-base06);
189189
--pf-global--Color--dark-200: var(--color-base05);
190-
--pf-global--Color--100: var(--pf-global--Color--light-100);
191-
--pf-global--Color--200: var(--pf-global--Color--light-200);
190+
--pf-global--Color--100: var(--pf-global--Color--dark-100);
191+
--pf-global--Color--200: var(--pf-global--Color--dark-200);
192192
--pf-global--BorderColor--100: var(--pf-global--BorderColor--light-100);
193193
--pf-global--primary-color--100: var(--pf-global--primary-color--light-100);
194194
--pf-global--link--Color: var(--pf-global--link--Color--light);
@@ -201,7 +201,7 @@
201201
@mixin kui-patternfly-alignment-dark {
202202
@include kui-patternfly-alignment-base;
203203
--pf-global--palette--black-100: var(--color-base00);
204-
--pf-global--palette--black-150: var(--color-base00);
204+
--pf-global--palette--black-150: var(--color-base01);
205205
--pf-global--palette--black-200: var(--color-base01);
206206
--pf-global--palette--black-300: var(--color-base02);
207207
--pf-global--palette--black-400: var(--color-base02);
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright 2021 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 'mixins';
18+
19+
@include LabelList {
20+
font-size: 0.75rem;
21+
22+
@include DescriptionListTerm {
23+
background-color: var(--color-base02);
24+
}
25+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright 2021 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+
@mixin DescriptionList {
18+
.kui--description-list {
19+
@content;
20+
}
21+
}
22+
23+
@mixin LabelList {
24+
.kui--label-list {
25+
@content;
26+
}
27+
}
28+
29+
@mixin DescriptionListTerm {
30+
.kui--description-list-term {
31+
@content;
32+
}
33+
}

plugins/plugin-client-common/web/scss/components/DescriptionList/common.scss

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@
1414
* limitations under the License.
1515
*/
1616

17-
.kui--description-list {
17+
@import 'mixins';
18+
19+
@include DescriptionList {
1820
/* override terminal rule on .repl */
1921
white-space: normal;
22+
23+
@include DescriptionListTerm {
24+
font-size: inherit;
25+
}
2026
}

0 commit comments

Comments
 (0)