-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: display labels on execution detail page (#882)
* display labels on execution detail page Signed-off-by: Blake Jackson <[email protected]> * updates from PR review Signed-off-by: Blake Jackson <[email protected]> --------- Signed-off-by: Blake Jackson <[email protected]> Co-authored-by: Blake Jackson <[email protected]>
- Loading branch information
1 parent
b686df9
commit 7636e32
Showing
6 changed files
with
113 additions
and
1 deletion.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
packages/oss-console/src/components/Executions/ExecutionDetails/ExecutionLabels.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import React from 'react'; | ||
import Chip from '@mui/material/Chip'; | ||
import makeStyles from '@mui/styles/makeStyles'; | ||
|
||
type ValuesType = {[p: string]: string}; | ||
interface Props { | ||
values: ValuesType; | ||
} | ||
|
||
const useStyles = makeStyles({ | ||
chipContainer: { | ||
display: 'flex', | ||
flexWrap: 'wrap', | ||
width: '100%', | ||
maxWidth: '420px' | ||
}, | ||
chip: { | ||
margin: '2px 2px 2px 0', | ||
}, | ||
}); | ||
|
||
|
||
export const ExecutionLabels: React.FC<Props> = ({values}) => { | ||
const classes = useStyles(); | ||
return ( | ||
<div className={classes.chipContainer}> | ||
{Object.entries(values).map(([key, value]) => ( | ||
<Chip | ||
color='info' | ||
key={key} | ||
label={value ? `${key}: ${value}` : key} | ||
className={classes.chip} | ||
/> | ||
))} | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...ages/oss-console/src/components/Executions/ExecutionDetails/test/ExecutionLabels.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import '@testing-library/jest-dom'; | ||
import { ExecutionLabels } from '../ExecutionLabels'; | ||
|
||
jest.mock('@mui/material/Chip', () => (props: any) => ( | ||
<div data-testid="chip" {...props}>{props.label}</div> | ||
)); | ||
|
||
describe('ExecutionLabels', () => { | ||
it('renders chips with key-value pairs correctly', () => { | ||
const values = { | ||
'random/uuid': 'f8b9ff18-4811-4bcc-aefd-4f4ec4de469d', | ||
'bar': 'baz', | ||
'foo': '', | ||
}; | ||
|
||
render(<ExecutionLabels values={values} />); | ||
|
||
expect(screen.getByText('random/uuid: f8b9ff18-4811-4bcc-aefd-4f4ec4de469d')).toBeInTheDocument(); | ||
expect(screen.getByText('bar: baz')).toBeInTheDocument(); | ||
expect(screen.getByText('foo')).toBeInTheDocument(); | ||
}); | ||
|
||
it('applies correct styles to chip container', () => { | ||
const values = { | ||
'key': 'value', | ||
}; | ||
|
||
const { container } = render(<ExecutionLabels values={values} />); | ||
const chipContainer = container.firstChild; | ||
|
||
expect(chipContainer).toHaveStyle('display: flex'); | ||
expect(chipContainer).toHaveStyle('flex-wrap: wrap'); | ||
expect(chipContainer).toHaveStyle('width: 100%'); | ||
expect(chipContainer).toHaveStyle('max-width: 420px'); | ||
}); | ||
|
||
it('renders correct number of chips', () => { | ||
const values = { | ||
'key1': 'value1', | ||
'key2': 'value2', | ||
'key3': 'value3', | ||
}; | ||
|
||
render(<ExecutionLabels values={values} />); | ||
|
||
const chips = screen.getAllByTestId('chip'); | ||
expect(chips.length).toBe(3); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters