-
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: Migrate user code to new validation message API
- Loading branch information
1 parent
4c5f532
commit a9469e9
Showing
5 changed files
with
28 additions
and
46 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
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
48 changes: 20 additions & 28 deletions
48
app/scripts/modules/core/src/pipeline/manualExecution/layout/ManualExecutionFieldLayout.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 |
---|---|---|
@@ -1,38 +1,30 @@ | ||
import * as React from 'react'; | ||
import { isEmpty } from 'lodash'; | ||
|
||
import { IValidationMessageProps, ValidationMessage } from 'core/validation'; | ||
import { IFieldLayoutProps } from 'core/presentation'; | ||
import { ILayoutProps } from 'core/presentation'; | ||
|
||
export class ManualExecutionFieldLayout extends React.Component<IFieldLayoutProps> { | ||
public render() { | ||
const { label, help, input, actions, touched, required, validationMessage, validationStatus } = this.props; | ||
export function ManualExecutionFieldLayout(props: ILayoutProps) { | ||
const { label, help, input, actions, validation, required } = props; | ||
|
||
const showLabel = !isEmpty(label) || !isEmpty(help); | ||
const showLabel = !isEmpty(label) || !isEmpty(help); | ||
const { hidden, messageNode } = validation; | ||
|
||
const renderMessage = (message: React.ReactNode, type: IValidationMessageProps['type']) => | ||
typeof message === 'string' ? <ValidationMessage type={type} message={message} /> : message; | ||
|
||
const isErrorOrWarning = validationStatus === 'error' || validationStatus === 'warning'; | ||
const validation = isErrorOrWarning && !touched ? null : renderMessage(validationMessage, validationStatus); | ||
|
||
return ( | ||
<div className="sp-margin-m-bottom"> | ||
<div className="form-group"> | ||
{showLabel && ( | ||
<label className="col-md-4 sm-label-right break-word"> | ||
{label} | ||
{required && <span>*</span>} {help} | ||
</label> | ||
)} | ||
<div className="col-md-6"> | ||
<div> | ||
{input} {actions} | ||
</div> | ||
<div className="message">{validation}</div> | ||
return ( | ||
<div className="sp-margin-m-bottom"> | ||
<div className="form-group"> | ||
{showLabel && ( | ||
<label className="col-md-4 sm-label-right break-word"> | ||
{label} | ||
{required && <span>*</span>} {help} | ||
</label> | ||
)} | ||
<div className="col-md-6"> | ||
<div> | ||
{input} {actions} | ||
</div> | ||
{!hidden && <div className="message">{messageNode}</div>} | ||
</div> | ||
</div> | ||
); | ||
} | ||
</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