Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
restrict multiple selections of a revision in traffic modal
- Loading branch information
Showing
7 changed files
with
163 additions
and
29 deletions.
There are no files selected for viewing
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
33 changes: 33 additions & 0 deletions
33
...es/knative-plugin/src/components/traffic-splitting/TrafficModalRevisionsDropdownField.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,33 @@ | ||
import * as React from 'react'; | ||
import { useField } from 'formik'; | ||
import { DropdownField } from '@console/shared'; | ||
import { RevisionItems } from '../../utils/traffic-splitting-utils'; | ||
|
||
type TrafficModalRevisionsDropdownFieldProps = { | ||
revisionItems: RevisionItems; | ||
name: string; | ||
title: string; | ||
}; | ||
|
||
const TrafficModalRevisionsDropdownField: React.FC<TrafficModalRevisionsDropdownFieldProps> = ({ | ||
revisionItems, | ||
name, | ||
title, | ||
}) => { | ||
const [field] = useField(name); | ||
const dropdownItems = | ||
!field.value || Object.values(revisionItems).includes(field.value) | ||
? revisionItems | ||
: { ...revisionItems, [field.value]: field.value }; | ||
return ( | ||
<DropdownField | ||
name={name} | ||
items={dropdownItems} | ||
title={field.value || title} | ||
fullWidth | ||
required | ||
/> | ||
); | ||
}; | ||
|
||
export default TrafficModalRevisionsDropdownField; |
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
37 changes: 37 additions & 0 deletions
37
...in/src/components/traffic-splitting/__tests__/TrafficModalRevisionsDropdownField.spec.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 * as React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import { DropdownField } from '@console/shared'; | ||
import { formikFormProps } from '@console/shared/src/test-utils/formik-props-utils'; | ||
import TrafficModalRevisionsDropdownField from '../TrafficModalRevisionsDropdownField'; | ||
|
||
const props = { | ||
...formikFormProps, | ||
revisionItems: { | ||
'overlayimage-bwpxq': 'overlayimage-bwpxq', | ||
'overlayimage-n2b7n': 'overlayimage-n2b7n', | ||
}, | ||
}; | ||
|
||
jest.mock('formik', () => ({ | ||
useField: jest.fn(() => [{ value: 'overlayimage-tkvz5' }, {}]), | ||
})); | ||
|
||
describe('TrafficModalRevisionsDropdownField', () => { | ||
it('should include the current value of the field in the dropdown items', () => { | ||
const wrapper = shallow( | ||
<TrafficModalRevisionsDropdownField {...props} name="revisionName" title="Select Revision" />, | ||
); | ||
expect( | ||
wrapper | ||
.find(DropdownField) | ||
.first() | ||
.props().items, | ||
).toHaveProperty('overlayimage-tkvz5', 'overlayimage-tkvz5'); | ||
expect( | ||
wrapper | ||
.find(DropdownField) | ||
.first() | ||
.props().title, | ||
).toBe('overlayimage-tkvz5'); | ||
}); | ||
}); |
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