1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-07-12 13:48:35 +02:00
unleash.unleash/frontend/src/component/strategies/CreateStrategy/CreateStrategy.jsx
Fredrik Strand Oseberg 10eabb366f Offline mode (#312)
* move all icons to offline mode

* Reorder imports

* revert yarn.lock to original

* resolve errors

* use ConditionalRender, revert material icon css

* add all other font weights

* fix: add library icon

Co-authored-by: Aneesh Relan <aneesh.r@lucideustech.com>
2021-06-29 10:21:54 +02:00

130 lines
4.0 KiB
JavaScript

import PropTypes from 'prop-types';
import { Typography, TextField, Button } from '@material-ui/core';
import { Add } from '@material-ui/icons';
import PageContent from '../../common/PageContent/PageContent';
import ConditionallyRender from '../../common/ConditionallyRender/ConditionallyRender';
import { styles as commonStyles, FormButtons } from '../../common';
import { trim } from '../../common/util';
import StrategyParameters from './StrategyParameters/StrategyParameters';
const CreateStrategy = ({
input,
setValue,
appParameter,
onCancel,
editMode = false,
errors,
onSubmit,
clearErrors,
updateParameter,
}) => {
const getHeaderTitle = () => {
if (editMode) return 'Edit strategy';
return 'Create a new strategy';
};
return (
<PageContent headerContent={getHeaderTitle()}>
<ConditionallyRender
condition={editMode}
show={
<Typography variant="body1">
Be careful! Changing a strategy definition might also
require changes to the implementation in the clients.
</Typography>
}
/>
<form
onSubmit={onSubmit}
className={commonStyles.contentSpacing}
style={{ maxWidth: '400px' }}
>
<TextField
label="Strategy name"
name="name"
placeholder=""
disabled={editMode}
error={Boolean(errors.name)}
helperText={errors.name}
onChange={({ target }) => {
clearErrors();
setValue('name', trim(target.value));
}}
value={input.name}
variant="outlined"
size="small"
/>
<TextField
className={commonStyles.fullwidth}
multiline
rows={2}
label="Description"
name="description"
placeholder=""
onChange={({ target }) =>
setValue('description', target.value)
}
value={input.description}
variant="outlined"
size="small"
/>
<StrategyParameters
input={input.parameters}
count={input.parameters.length}
updateParameter={updateParameter}
/>
<Button
onClick={e => {
e.preventDefault();
appParameter();
}}
startIcon={<Add />}
>
Add parameter
</Button>
<ConditionallyRender
condition={editMode}
show={
<Button
type="submit"
variant="contained"
color="primary"
style={{ display: 'block' }}
>
Update
</Button>
}
elseShow={
<FormButtons
submitText={'Create'}
onCancel={onCancel}
/>
}
/>
</form>
</PageContent>
);
};
CreateStrategy.propTypes = {
input: PropTypes.object,
setValue: PropTypes.func,
appParameter: PropTypes.func,
updateParameter: PropTypes.func,
clear: PropTypes.func,
onCancel: PropTypes.func,
onSubmit: PropTypes.func,
errors: PropTypes.object,
editMode: PropTypes.bool,
clearErrors: PropTypes.func,
};
export default CreateStrategy;