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

Commit 95f731d

Browse files
committed
feat: add labels to summary mode
Fixes #4041 this also tweaks the Form layout a bit more Fixes #4040
1 parent 41246c3 commit 95f731d

File tree

8 files changed

+105
-43
lines changed

8 files changed

+105
-43
lines changed

packages/test/bin/runMochaLayersv2.sh

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ if [ -z "$WEBPACK_CLIENT_URL" ]; then
4141
echo "Using WEBPACK_CLIENT_URL=$WEBPACK_CLIENT_URL"
4242
fi
4343

44-
for i in $@; do
45-
export LAYER=$i
44+
if [ $# = 0 ]; then
4645
"$TEST_ROOT"/bin/runTest.sh
47-
done
46+
else
47+
for i in $@; do
48+
export LAYER=$i
49+
"$TEST_ROOT"/bin/runTest.sh
50+
done
51+
fi

plugins/plugin-client-common/web/css/static/Form.scss

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,40 @@
88
grid-template-columns: repeat(auto-fill, minmax(3em, auto));
99
flex: unset;
1010

11+
.kui--form-item--for-label .bx--form-item {
12+
.bx--label {
13+
color: var(--color-base0D);
14+
}
15+
.bx--text-input {
16+
background-color: var(--color-base04);
17+
color: var(--color-base07);
18+
}
19+
}
20+
1121
.bx--form-item {
1222
font-size: 0.875em;
13-
}
14-
}
1523

16-
.bx--text-input {
17-
font-size: 1em;
18-
line-height: 1.125em;
19-
height: 2.5em;
20-
padding: 0 1em;
21-
color: var(--color-text-01);
22-
background-color: var(--color-base03);
23-
border-bottom-color: var(--color-base02);
24+
.bx--text-input {
25+
font-size: 1em;
26+
line-height: 1.125em;
27+
height: 2.5em;
28+
padding: 0 1em;
29+
color: var(--color-text-01);
30+
background-color: var(--color-base03);
31+
border-bottom-color: var(--color-base02);
2432

25-
&:focus,
26-
&:active {
27-
outline-color: var(--active-tab-color);
28-
}
29-
}
33+
&:focus,
34+
&:active {
35+
outline-color: var(--active-tab-color);
36+
}
37+
}
3038

31-
.bx--label {
32-
color: var(--color-text-02);
33-
font-size: 0.875em;
34-
margin-bottom: 0.5em;
35-
line-height: 1em;
39+
.bx--label {
40+
color: var(--color-text-02);
41+
font-size: 0.875em;
42+
margin-bottom: 0.5em;
43+
line-height: 1em;
44+
}
45+
}
3646
}
3747
}

plugins/plugin-client-common/web/css/static/sidecar-main.css

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,10 +308,10 @@ body.os-win32 .kui--sidecar .sidecar-bottom-stripe-button-container:hover .sidec
308308
justify-content: center;
309309
}
310310
.kui--sidecar .sidecar-header-icon {
311-
display: flex;
312-
justify-content: center;
313-
align-items: center;
314311
text-transform: uppercase;
312+
overflow: hidden;
313+
white-space: nowrap;
314+
text-overflow: ellipsis;
315315
}
316316
.kui--sidecar .sidecar-toolbar-text a,
317317
.kui--sidecar .sidecar-toolbar-text a:hover {

plugins/plugin-kubectl/src/lib/view/modes/Form.tsx

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,70 @@
1717
import * as React from 'react'
1818
import { Form, TextInput } from 'carbon-components-react'
1919

20+
import { FormMap } from './table-to-map'
21+
import { KubeResource } from '../../model/resource'
22+
23+
import '@kui-shell/plugin-client-common/web/css/static/Form.scss'
24+
import 'carbon-components/scss/components/form/_form.scss'
25+
2026
/** @return a ReactElement */
21-
export default function SidecarForm({ map }: { map: Record<string, string> }) {
27+
export default function SidecarForm({
28+
nested,
29+
map,
30+
className
31+
}: {
32+
nested?: boolean
33+
map: FormMap
34+
className?: string
35+
}) {
2236
return (
23-
<Form className="page-content padding-content scrollable kui--placeholder-primary">
37+
<Form className={nested ? className : `padding-content scrollable ${className || ''}`}>
2438
{Object.keys(map).map((key, idx) => {
25-
const colspan = Math.max(Math.ceil(key.length / 5), Math.ceil(map[key].length / 3.5))
39+
const vvalue = map[key]
40+
const value =
41+
(typeof vvalue === 'number' ? vvalue.toLocaleString() : typeof vvalue !== 'object' ? vvalue : vvalue.label) ||
42+
''
43+
44+
const colspan = Math.max(Math.ceil(key.length / 9), Math.ceil(value.length / 6))
2645
const style = { gridColumn: `span ${colspan}` }
46+
const className = typeof vvalue !== 'object' ? undefined : 'kui--form-item--for-label'
2747

2848
return (
29-
<div key={idx} style={style}>
30-
<TextInput readOnly id={`kubectl-summary-${key}`} labelText={key} defaultValue={map[key]} />
49+
<div key={idx} style={style} className={className}>
50+
<TextInput readOnly id={`kubectl-summary-${key}`} labelText={key} defaultValue={value} />
3151
</div>
3252
)
3353
})}
3454
</Form>
3555
)
3656
}
3757

58+
export function FormWithLabels(props: { map: FormMap; resource: KubeResource }) {
59+
const labelMap: FormMap = {}
60+
if (props.resource.metadata && props.resource.metadata.labels) {
61+
for (const key in props.resource.metadata.labels) {
62+
labelMap[`${key} label`] = { label: props.resource.metadata.labels[key] }
63+
}
64+
}
65+
66+
return (
67+
<div className="padding-content scrollable">
68+
<SidecarForm nested map={props.map} />
69+
<SidecarForm nested map={labelMap} className="top-pad" />
70+
</div>
71+
)
72+
}
73+
74+
export function renderFormWithLabels(map: FormMap, resource: KubeResource) {
75+
return {
76+
react: function SidecarFormWithLabelsProvider() {
77+
return <FormWithLabels map={map} resource={resource} />
78+
}
79+
}
80+
}
81+
3882
/** @return a ReactProvider */
39-
export function renderForm(map: Record<string, string>) {
83+
export function renderForm(map: FormMap) {
4084
return {
4185
react: function SidecarFormProvider() {
4286
return <SidecarForm map={map} />

plugins/plugin-kubectl/src/lib/view/modes/configmap-summary.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import { i18n, Tab, ModeRegistration } from '@kui-shell/core'
1818

19-
import { renderForm } from './Form'
19+
import { renderFormWithLabels } from './Form'
2020
import { getDefaultSummaryMap } from './summary'
2121
import { ConfigMap, isConfigMap } from '../../model/resource'
2222

@@ -43,7 +43,7 @@ async function content(tab: Tab, cm: ConfigMap, args: { argvNoOptions: string[]
4343
}
4444
}
4545

46-
return renderForm(map)
46+
return renderFormWithLabels(map, cm)
4747
}
4848

4949
/**

plugins/plugin-kubectl/src/lib/view/modes/crd-summary.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import Debug from 'debug'
1818
import { i18n, Tab, Table, ModeRegistration } from '@kui-shell/core'
1919

20-
import { renderForm } from './Form'
20+
import { renderFormWithLabels } from './Form'
2121
import { command } from './show-crd-managed-resources'
2222
import { CustomResourceDefinition, isCustomResourceDefinition } from '../../model/resource'
2323

@@ -48,7 +48,7 @@ async function content(tab: Tab, crd: CustomResourceDefinition, args: { argvNoOp
4848
)
4949
const countObj = { 'Resource count': resources.length }
5050

51-
return renderForm(Object.assign(baseResponse, countObj))
51+
return renderFormWithLabels(Object.assign(baseResponse, countObj), crd)
5252
} catch (err) {
5353
// safeguarding here, in case of unexpected errors collecting
5454
// optional information; see

plugins/plugin-kubectl/src/lib/view/modes/summary.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019 IBM Corporation
2+
* Copyright 2019-2020 IBM Corporation
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,14 +17,11 @@
1717
import { i18n, Tab, Table, ModeRegistration } from '@kui-shell/core'
1818

1919
import toMap from './table-to-map'
20-
import { renderForm } from './Form'
20+
import { renderFormWithLabels } from './Form'
2121
import { getCommandFromArgs } from '../../util/util'
2222
import { fqnOf } from '../../../controller/kubectl/fqn'
2323
import { KubeResource, isSummarizableKubeResource, isKubeResourceWithItsOwnSummary } from '../../model/resource'
2424

25-
import '@kui-shell/plugin-client-common/web/css/static/Form.scss'
26-
import 'carbon-components/scss/components/form/_form.scss'
27-
2825
const strings = i18n('plugin-kubectl')
2926

3027
export function getDefaultSummaryMap(
@@ -56,7 +53,8 @@ async function renderSummary(
5653
return resource.summary
5754
}
5855

59-
return renderForm(await getDefaultSummaryMap(tab, resource, args))
56+
const map = await await getDefaultSummaryMap(tab, resource, args)
57+
return renderFormWithLabels(map, resource)
6058
}
6159

6260
/**

plugins/plugin-kubectl/src/lib/view/modes/table-to-map.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@
1616

1717
import { Table } from '@kui-shell/core'
1818

19+
export interface LabelValue {
20+
label: string
21+
}
22+
23+
export type FormMap = Record<string, number | string | LabelValue>
24+
1925
export function capitalize(str: string) {
2026
return str === 'IP' ? str : str.charAt(0).toUpperCase() + str.slice(1).toLowerCase()
2127
}
@@ -24,7 +30,7 @@ export function capitalize(str: string) {
2430
* Turn a one-row Table into a Map
2531
*
2632
*/
27-
export default function toMap(table: Table): Record<string, string> {
33+
export default function toMap(table: Table): FormMap {
2834
return table.body.reduce((map, row) => {
2935
map[capitalize(row.key)] = row.name
3036

0 commit comments

Comments
 (0)