Skip to content

Commit 7636e32

Browse files
blaketastic2Blake Jackson
andauthored
feat: display labels on execution detail page (#882)
* display labels on execution detail page Signed-off-by: Blake Jackson <blake@BB8.local> * updates from PR review Signed-off-by: Blake Jackson <blake@BB8.local> --------- Signed-off-by: Blake Jackson <blake@BB8.local> Co-authored-by: Blake Jackson <blake@BB8.local>
1 parent b686df9 commit 7636e32

File tree

6 files changed

+113
-1
lines changed

6 files changed

+113
-1
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import React from 'react';
2+
import Chip from '@mui/material/Chip';
3+
import makeStyles from '@mui/styles/makeStyles';
4+
5+
type ValuesType = {[p: string]: string};
6+
interface Props {
7+
values: ValuesType;
8+
}
9+
10+
const useStyles = makeStyles({
11+
chipContainer: {
12+
display: 'flex',
13+
flexWrap: 'wrap',
14+
width: '100%',
15+
maxWidth: '420px'
16+
},
17+
chip: {
18+
margin: '2px 2px 2px 0',
19+
},
20+
});
21+
22+
23+
export const ExecutionLabels: React.FC<Props> = ({values}) => {
24+
const classes = useStyles();
25+
return (
26+
<div className={classes.chipContainer}>
27+
{Object.entries(values).map(([key, value]) => (
28+
<Chip
29+
color='info'
30+
key={key}
31+
label={value ? `${key}: ${value}` : key}
32+
className={classes.chip}
33+
/>
34+
))}
35+
</div>
36+
);
37+
};

packages/oss-console/src/components/Executions/ExecutionDetails/ExecutionMetadata.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { ExecutionContext } from '../contexts';
1414
import { ExpandableExecutionError } from '../Tables/ExpandableExecutionError';
1515
import { ExecutionMetadataLabels } from './constants';
1616
import { ExecutionMetadataExtra } from './ExecutionMetadataExtra';
17+
import { ExecutionLabels } from './ExecutionLabels';
1718

1819
const StyledContainer = styled('div')(({ theme }) => {
1920
return {
@@ -69,6 +70,7 @@ export const ExecutionMetadata: React.FC<{}> = () => {
6970
const startedAt = execution?.closure?.startedAt;
7071
const workflowId = execution?.closure?.workflowId;
7172

73+
const { labels } = execution.spec;
7274
const {
7375
referenceExecution,
7476
systemMetadata ,
@@ -118,9 +120,19 @@ export const ExecutionMetadata: React.FC<{}> = () => {
118120
<RouterLink
119121
className={commonStyles.primaryLinks}
120122
to={Routes.ExecutionDetails.makeUrl(parentNodeExecution.executionId)}
121-
>
123+
>
122124
{parentNodeExecution.executionId.name}
123125
</RouterLink>
126+
),
127+
});
128+
}
129+
130+
if (labels != null && labels.values != null) {
131+
details.push({
132+
label: ExecutionMetadataLabels.labels,
133+
value: (
134+
Object.entries(labels.values).length > 0 ?
135+
<ExecutionLabels values={labels.values} /> : dashedValueString
124136
)
125137
})
126138
}

packages/oss-console/src/components/Executions/ExecutionDetails/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export enum ExecutionMetadataLabels {
1313
interruptible = 'Interruptible override',
1414
overwriteCache = 'Overwrite cached outputs',
1515
parent = 'Parent',
16+
labels = 'Labels',
1617
}
1718

1819
export const tabs = {
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import React from 'react';
2+
import { render, screen } from '@testing-library/react';
3+
import '@testing-library/jest-dom';
4+
import { ExecutionLabels } from '../ExecutionLabels';
5+
6+
jest.mock('@mui/material/Chip', () => (props: any) => (
7+
<div data-testid="chip" {...props}>{props.label}</div>
8+
));
9+
10+
describe('ExecutionLabels', () => {
11+
it('renders chips with key-value pairs correctly', () => {
12+
const values = {
13+
'random/uuid': 'f8b9ff18-4811-4bcc-aefd-4f4ec4de469d',
14+
'bar': 'baz',
15+
'foo': '',
16+
};
17+
18+
render(<ExecutionLabels values={values} />);
19+
20+
expect(screen.getByText('random/uuid: f8b9ff18-4811-4bcc-aefd-4f4ec4de469d')).toBeInTheDocument();
21+
expect(screen.getByText('bar: baz')).toBeInTheDocument();
22+
expect(screen.getByText('foo')).toBeInTheDocument();
23+
});
24+
25+
it('applies correct styles to chip container', () => {
26+
const values = {
27+
'key': 'value',
28+
};
29+
30+
const { container } = render(<ExecutionLabels values={values} />);
31+
const chipContainer = container.firstChild;
32+
33+
expect(chipContainer).toHaveStyle('display: flex');
34+
expect(chipContainer).toHaveStyle('flex-wrap: wrap');
35+
expect(chipContainer).toHaveStyle('width: 100%');
36+
expect(chipContainer).toHaveStyle('max-width: 420px');
37+
});
38+
39+
it('renders correct number of chips', () => {
40+
const values = {
41+
'key1': 'value1',
42+
'key2': 'value2',
43+
'key3': 'value3',
44+
};
45+
46+
render(<ExecutionLabels values={values} />);
47+
48+
const chips = screen.getAllByTestId('chip');
49+
expect(chips.length).toBe(3);
50+
});
51+
});

packages/oss-console/src/components/Executions/ExecutionDetails/test/ExecutionMetadata.test.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const interruptibleTestId = `metadata-${ExecutionMetadataLabels.interruptible}`;
1616
const overwriteCacheTestId = `metadata-${ExecutionMetadataLabels.overwriteCache}`;
1717
const relatedToTestId = `metadata-${ExecutionMetadataLabels.relatedTo}`;
1818
const parentNodeExecutionTestId = `metadata-${ExecutionMetadataLabels.parent}`
19+
const labelsTestId = `metadata-${ExecutionMetadataLabels.labels}`;
1920

2021
jest.mock('../../../../models/Launch/api', () => ({
2122
getLaunchPlan: jest.fn(() => Promise.resolve({ spec: {} })),
@@ -118,4 +119,9 @@ describe('ExecutionMetadata', () => {
118119
const { getByTestId } = renderMetadata();
119120
expect(getByTestId(parentNodeExecutionTestId)).toHaveTextContent('name');
120121
})
122+
123+
it('shows labels if spec has them', () => {
124+
const { getByTestId } = renderMetadata();
125+
expect(getByTestId(labelsTestId)).toHaveTextContent("key: value");
126+
})
121127
});

packages/oss-console/src/models/__mocks__/executionsData.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ export const createMockExecutionSpec: () => ExecutionSpec = () => ({
100100
launchPlan: { ...MOCK_LAUNCH_PLAN_ID },
101101
notifications: { notifications: [] },
102102
metadata: generateExecutionMetadata(),
103+
labels: {
104+
values: {
105+
"key": "value"
106+
}
107+
}
103108
});
104109

105110
export const createMockExecution: (id?: string | number) => Execution = (id = 1) => {

0 commit comments

Comments
 (0)