-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1379 from kubeshop/devcatalin/feat/preview-config…
…uration-section PvConf#1 - feat: add preview configurations sections
- Loading branch information
Showing
33 changed files
with
673 additions
and
131 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
60 changes: 60 additions & 0 deletions
60
src/components/atoms/KeyValueInput/KeyValueEntryRenderer.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,60 @@ | ||
import React from 'react'; | ||
|
||
import {Select} from 'antd'; | ||
|
||
import {MinusOutlined} from '@ant-design/icons'; | ||
|
||
import Colors from '@styles/Colors'; | ||
|
||
import ValueInput from './ValueInput'; | ||
import {KeyValueEntry} from './types'; | ||
|
||
import * as S from './styled'; | ||
|
||
type KeyValueEntryRendererProps = { | ||
entry: KeyValueEntry; | ||
valueType?: string; | ||
onKeyChange: (newKey: string) => void; | ||
onValueChange: (newValue: string) => void; | ||
onEntryRemove: (entryId: string) => void; | ||
disabled?: boolean; | ||
availableKeys: string[]; | ||
availableValues?: string[]; | ||
}; | ||
|
||
const KeyValueEntryRenderer: React.FC<KeyValueEntryRendererProps> = props => { | ||
const {entry, valueType, onKeyChange, onValueChange, onEntryRemove, disabled, availableKeys, availableValues} = props; | ||
|
||
return ( | ||
<S.KeyValueRemoveButtonContainer key={entry.id}> | ||
<S.KeyValueContainer> | ||
<Select value={entry.key} onChange={onKeyChange} showSearch disabled={disabled}> | ||
{availableKeys.map(key => ( | ||
<Select.Option key={key} value={key}> | ||
{key} | ||
</Select.Option> | ||
))} | ||
</Select> | ||
|
||
{entry.key && valueType && valueType !== 'boolean' && ( | ||
<ValueInput | ||
value={entry.value} | ||
valueType={valueType} | ||
availableValues={availableValues} | ||
onChange={onValueChange} | ||
/> | ||
)} | ||
</S.KeyValueContainer> | ||
|
||
<S.StyledRemoveButton | ||
disabled={disabled} | ||
onClick={() => onEntryRemove(entry.id)} | ||
color={Colors.redError} | ||
size="small" | ||
icon={<MinusOutlined />} | ||
/> | ||
</S.KeyValueRemoveButtonContainer> | ||
); | ||
}; | ||
|
||
export default KeyValueEntryRenderer; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import {Input, Select} from 'antd'; | ||
|
||
import {ANY_VALUE} from './constants'; | ||
|
||
type ValueInputProps = { | ||
value?: string; | ||
valueType: string; | ||
availableValues?: string[]; | ||
onChange: (newValue: string) => void; | ||
disabled?: boolean; | ||
}; | ||
|
||
const ValueInput: React.FC<ValueInputProps> = props => { | ||
const {value, valueType, availableValues, disabled, onChange} = props; | ||
|
||
// TODO: decide if we need a custom input for the stringArray value type | ||
if (valueType === 'string' || valueType === 'stringArray') { | ||
if (availableValues?.length) { | ||
return ( | ||
<Select value={value} onChange={onChange} showSearch disabled={disabled}> | ||
<Select.Option key={ANY_VALUE} value={ANY_VALUE}> | ||
{ANY_VALUE} | ||
</Select.Option> | ||
{availableValues?.map((valueOption: string) => ( | ||
<Select.Option key={valueOption} value={valueOption}> | ||
{valueOption} | ||
</Select.Option> | ||
))} | ||
</Select> | ||
); | ||
} | ||
return <Input value={value} onChange={e => onChange(e.target.value)} disabled={disabled} />; | ||
} | ||
|
||
// TODO: decide if we want to implement more value types | ||
return null; | ||
}; | ||
|
||
export default ValueInput; |
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 @@ | ||
export const ANY_VALUE = '<any>'; |
Oops, something went wrong.