-
Notifications
You must be signed in to change notification settings - Fork 900
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(core): Reactify rename pipeline modal (#7368)
* refactor(core): Reactify rename pipeline modal * condense code that updates button icon
- Loading branch information
1 parent
0d88644
commit 6a47557
Showing
7 changed files
with
136 additions
and
222 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
123 changes: 123 additions & 0 deletions
123
app/scripts/modules/core/src/pipeline/config/actions/rename/RenamePipelineModal.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,123 @@ | ||
import * as React from 'react'; | ||
import { map, without } from 'lodash'; | ||
import { Modal } from 'react-bootstrap'; | ||
import { Form } from 'formik'; | ||
|
||
import { Application } from 'core/application'; | ||
import { IPipeline } from 'core/domain'; | ||
import { ModalClose } from 'core/modal'; | ||
import { PipelineConfigService } from 'core/pipeline'; | ||
import { | ||
FormikFormField, | ||
IModalComponentProps, | ||
IValidator, | ||
SpinFormik, | ||
TextInput, | ||
Validators, | ||
} from 'core/presentation'; | ||
|
||
export interface IRenamePipelineModalProps extends IModalComponentProps { | ||
application: Application; | ||
pipeline: IPipeline; | ||
} | ||
|
||
interface IRenamePipelineCommand { | ||
name: string; | ||
} | ||
|
||
export function RenamePipelineModal(props: IRenamePipelineModalProps) { | ||
const { application, closeModal, dismissModal, pipeline } = props; | ||
const [errorMessage, setErrorMessage] = React.useState<string>(null); | ||
const [saveError, setSaveError] = React.useState<boolean>(false); | ||
const [saving, setSaving] = React.useState<boolean>(false); | ||
const existingNames = without(map(application.pipelineConfigs.data, 'name'), pipeline.name); | ||
const pipelineType = pipeline.strategy === true ? 'Strategy' : 'Pipeline'; | ||
const initialValues: IRenamePipelineCommand = { name: pipeline.name }; | ||
|
||
const validPipelineName = (): IValidator => { | ||
return (val: string) => { | ||
const message = `${pipelineType} cannot contain: \\ ? % #`; | ||
return val && !/^[^\\\^/^?^%^#]*$/i.test(val) && message; | ||
}; | ||
}; | ||
|
||
function renamePipeline(command: IRenamePipelineCommand) { | ||
setSaving(true); | ||
PipelineConfigService.renamePipeline(application.name, pipeline, pipeline.name, command.name).then( | ||
() => { | ||
application.pipelineConfigs.refresh(); | ||
closeModal(command.name); | ||
}, | ||
response => { | ||
setSaving(false); | ||
setSaveError(true); | ||
setErrorMessage(response.message || 'No message provided'); | ||
}, | ||
); | ||
} | ||
|
||
return ( | ||
<> | ||
<SpinFormik<IRenamePipelineCommand> | ||
initialValues={initialValues} | ||
onSubmit={renamePipeline} | ||
render={formik => ( | ||
<Form className="form-horizontal"> | ||
<Modal key="modal" show={true} onHide={() => {}}> | ||
<ModalClose dismiss={dismissModal} /> | ||
<Modal.Header> | ||
<h3>Rename Pipeline</h3> | ||
</Modal.Header> | ||
<Modal.Body> | ||
{saveError && ( | ||
<div className="alert alert-danger"> | ||
<p>Could not rename pipeline.</p> | ||
<p> | ||
<b>Reason: </b> | ||
{errorMessage} | ||
</p> | ||
<p> | ||
<a | ||
className="btn btn-link" | ||
onClick={e => { | ||
e.preventDefault(); | ||
setSaveError(false); | ||
}} | ||
> | ||
[dismiss] | ||
</a> | ||
</p> | ||
</div> | ||
)} | ||
<FormikFormField | ||
name="name" | ||
label={`${pipelineType} Name`} | ||
input={inputProps => <TextInput {...inputProps} className="form-control input-sm" />} | ||
required={true} | ||
validate={[ | ||
Validators.valueUnique(existingNames, `There is already a ${pipelineType} with that name.`), | ||
validPipelineName(), | ||
]} | ||
/> | ||
</Modal.Body> | ||
<Modal.Footer> | ||
<button className="btn btn-default" onClick={dismissModal} type="button"> | ||
Cancel | ||
</button> | ||
<button | ||
className="btn btn-primary" | ||
disabled={!formik.isValid || !formik.dirty} | ||
type="submit" | ||
onClick={() => renamePipeline(formik.values)} | ||
> | ||
<span className={saving ? 'fa fa-cog fa-spin' : 'far fa-check-circle'} /> | ||
Rename {pipelineType} | ||
</button> | ||
</Modal.Footer> | ||
</Modal> | ||
</Form> | ||
)} | ||
/> | ||
</> | ||
); | ||
} |
53 changes: 0 additions & 53 deletions
53
app/scripts/modules/core/src/pipeline/config/actions/rename/rename.module.js
This file was deleted.
Oops, something went wrong.
103 changes: 0 additions & 103 deletions
103
...ts/modules/core/src/pipeline/config/actions/rename/renamePipelineModal.controller.spec.js
This file was deleted.
Oops, something went wrong.
54 changes: 0 additions & 54 deletions
54
app/scripts/modules/core/src/pipeline/config/actions/rename/renamePipelineModal.html
This file was deleted.
Oops, something went wrong.
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