-
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.
display labels on execution detail page
Signed-off-by: Blake Jackson <[email protected]>
- Loading branch information
Blake Jackson
authored and
Blake Jackson
committed
Jul 9, 2024
1 parent
a24c4d3
commit 87b662d
Showing
6 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
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,36 @@ | ||
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: 4, | ||
}, | ||
}); | ||
|
||
|
||
export const ExecutionLabels: React.FC<Props> = ({values}) => { | ||
const classes = useStyles(); | ||
return ( | ||
<div className={classes.chipContainer}> | ||
{Object.entries(values).map(([key, value]) => ( | ||
<Chip | ||
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