Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* under the License.
*/
import {
htmlIdGenerator,
EuiButton,
EuiButtonEmpty,
EuiCallOut,
Expand Down Expand Up @@ -67,7 +68,10 @@ interface State {
visualizationDescription: string;
}

const generateId = htmlIdGenerator();

export class SavedObjectSaveModal extends React.Component<Props, State> {
private warning = React.createRef<HTMLDivElement>();
public readonly state = {
title: this.props.title,
copyOnSave: false,
Expand All @@ -79,6 +83,7 @@ export class SavedObjectSaveModal extends React.Component<Props, State> {

public render() {
const { isTitleDuplicateConfirmed, hasTitleDuplicate, title } = this.state;
const duplicateWarningId = generateId();

return (
<EuiOverlayMask>
Expand All @@ -99,7 +104,7 @@ export class SavedObjectSaveModal extends React.Component<Props, State> {
</EuiModalHeader>

<EuiModalBody>
{this.renderDuplicateTitleCallout()}
{this.renderDuplicateTitleCallout(duplicateWarningId)}

<EuiForm>
{this.props.objectType !== VISUALIZE_EMBEDDABLE_TYPE && this.props.description && (
Expand Down Expand Up @@ -127,6 +132,7 @@ export class SavedObjectSaveModal extends React.Component<Props, State> {
isInvalid={
(!isTitleDuplicateConfirmed && hasTitleDuplicate) || title.length === 0
}
aria-describedby={this.state.hasTitleDuplicate ? duplicateWarningId : undefined}
/>
</EuiFormRow>

Expand Down Expand Up @@ -188,6 +194,10 @@ export class SavedObjectSaveModal extends React.Component<Props, State> {
isTitleDuplicateConfirmed: true,
hasTitleDuplicate: true,
});

if (this.warning.current) {
this.warning.current.focus();
}
};

private saveSavedObject = async () => {
Expand Down Expand Up @@ -255,43 +265,46 @@ export class SavedObjectSaveModal extends React.Component<Props, State> {
);
};

private renderDuplicateTitleCallout = () => {
private renderDuplicateTitleCallout = (duplicateWarningId: string) => {
if (!this.state.hasTitleDuplicate) {
return;
}

return (
<>
<EuiCallOut
title={
<FormattedMessage
id="kibana-react.savedObjects.saveModal.duplicateTitleLabel"
defaultMessage="A {objectType} with the title '{title}' already exists"
values={{ objectType: this.props.objectType, title: this.state.title }}
/>
}
color="warning"
data-test-subj="titleDupicateWarnMsg"
>
<p>
<FormattedMessage
id="kibana-react.savedObjects.saveModal.duplicateTitleDescription"
defaultMessage="Clicking {confirmSaveLabel} overwrites the existing {objectType}."
values={{
objectType: this.props.objectType,
confirmSaveLabel: (
<strong>
{this.props.confirmButtonLabel
? this.props.confirmButtonLabel
: i18n.translate('kibana-react.savedObjects.saveModal.saveButtonLabel', {
defaultMessage: 'Save',
})}
</strong>
),
}}
/>
</p>
</EuiCallOut>
<div ref={this.warning} tabIndex={-1}>
<EuiCallOut
title={
<FormattedMessage
id="kibana-react.savedObjects.saveModal.duplicateTitleLabel"
defaultMessage="A {objectType} with the title '{title}' already exists"
values={{ objectType: this.props.objectType, title: this.state.title }}
/>
}
color="warning"
data-test-subj="titleDupicateWarnMsg"
id={duplicateWarningId}
>
<p>
<FormattedMessage
id="kibana-react.savedObjects.saveModal.duplicateTitleDescription"
defaultMessage="Clicking {confirmSaveLabel} overwrites the existing {objectType}."
values={{
objectType: this.props.objectType,
confirmSaveLabel: (
<strong>
{this.props.confirmButtonLabel
? this.props.confirmButtonLabel
: i18n.translate('kibana-react.savedObjects.saveModal.saveButtonLabel', {
defaultMessage: 'Save',
})}
</strong>
),
}}
/>
</p>
</EuiCallOut>
</div>
<EuiSpacer />
</>
);
Expand Down