Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ui/saved_objects components -> New Platform #43416

Merged
merged 11 commits into from
Aug 30, 2019
Merged
517 changes: 54 additions & 463 deletions src/legacy/ui/public/saved_objects/components/saved_object_finder.tsx

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -16,256 +16,10 @@
* specific language governing permissions and limitations
* under the License.
*/
import {
EuiButton,
EuiButtonEmpty,
EuiCallOut,
EuiFieldText,
EuiForm,
EuiFormRow,
EuiModal,
EuiModalBody,
EuiModalFooter,
EuiModalHeader,
EuiModalHeaderTitle,
EuiOverlayMask,
EuiSpacer,
EuiSwitch,
} from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import React, { Fragment } from 'react';
import { EuiText } from '@elastic/eui';

interface OnSaveProps {
newTitle: string;
newCopyOnSave: boolean;
isTitleDuplicateConfirmed: boolean;
onTitleDuplicate: () => void;
}

interface Props {
onSave: (props: OnSaveProps) => void;
onClose: () => void;
title: string;
showCopyOnSave: boolean;
objectType: string;
confirmButtonLabel?: React.ReactNode;
options?: React.ReactNode;
description?: string;
}

interface State {
title: string;
copyOnSave: boolean;
isTitleDuplicateConfirmed: boolean;
hasTitleDuplicate: boolean;
isLoading: boolean;
}

export class SavedObjectSaveModal extends React.Component<Props, State> {
public readonly state = {
title: this.props.title,
copyOnSave: false,
isTitleDuplicateConfirmed: false,
hasTitleDuplicate: false,
isLoading: false,
};

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

return (
<EuiOverlayMask>
<form onSubmit={this.onFormSubmit}>
<EuiModal
data-test-subj="savedObjectSaveModal"
className="dshSaveModal"
onClose={this.props.onClose}
>
<EuiModalHeader>
<EuiModalHeaderTitle>
<FormattedMessage
id="common.ui.savedObjects.saveModal.saveTitle"
defaultMessage="Save {objectType}"
values={{ objectType: this.props.objectType }}
/>
</EuiModalHeaderTitle>
</EuiModalHeader>

<EuiModalBody>
{this.renderDuplicateTitleCallout()}

<EuiForm>
{this.props.description && (
<EuiFormRow>
<EuiText color="subdued">{this.props.description}</EuiText>
</EuiFormRow>
)}
{this.renderCopyOnSave()}

<EuiFormRow
fullWidth
label={
<FormattedMessage
id="common.ui.savedObjects.saveModal.titleLabel"
defaultMessage="Title"
/>
}
>
<EuiFieldText
fullWidth
autoFocus
data-test-subj="savedObjectTitle"
value={title}
onChange={this.onTitleChange}
isInvalid={
(!isTitleDuplicateConfirmed && hasTitleDuplicate) || title.length === 0
}
/>
</EuiFormRow>

{this.props.options}
</EuiForm>
</EuiModalBody>

<EuiModalFooter>
<EuiButtonEmpty data-test-subj="saveCancelButton" onClick={this.props.onClose}>
<FormattedMessage
id="common.ui.savedObjects.saveModal.cancelButtonLabel"
defaultMessage="Cancel"
/>
</EuiButtonEmpty>

<EuiButton
fill
data-test-subj="confirmSaveSavedObjectButton"
isLoading={isLoading}
isDisabled={title.length === 0}
type="submit"
>
{this.props.confirmButtonLabel ? (
this.props.confirmButtonLabel
) : (
<FormattedMessage
id="common.ui.savedObjects.saveModal.confirmSaveButtonLabel"
defaultMessage="Confirm Save"
/>
)}
</EuiButton>
</EuiModalFooter>
</EuiModal>
</form>
</EuiOverlayMask>
);
}

private onTitleDuplicate = () => {
this.setState({
isLoading: false,
isTitleDuplicateConfirmed: true,
hasTitleDuplicate: true,
});
};

private saveSavedObject = async () => {
if (this.state.isLoading) {
// ignore extra clicks
return;
}

this.setState({
isLoading: true,
});

await this.props.onSave({
newTitle: this.state.title,
newCopyOnSave: this.state.copyOnSave,
isTitleDuplicateConfirmed: this.state.isTitleDuplicateConfirmed,
onTitleDuplicate: this.onTitleDuplicate,
});
};

private onTitleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
this.setState({
title: event.target.value,
isTitleDuplicateConfirmed: false,
hasTitleDuplicate: false,
});
};

private onCopyOnSaveChange = (event: React.ChangeEvent<HTMLInputElement>) => {
this.setState({
copyOnSave: event.target.checked,
});
};

private onFormSubmit = (event: React.FormEvent<HTMLFormElement>) => {
event.preventDefault();
this.saveSavedObject();
};

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

return (
<Fragment>
<EuiCallOut
title={
<FormattedMessage
id="common.ui.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="common.ui.savedObjects.saveModal.duplicateTitleDescription"
defaultMessage="Click {confirmSaveLabel} to save the {objectType} with the duplicate title."
values={{
objectType: this.props.objectType,
confirmSaveLabel: (
<strong>
<FormattedMessage
id="common.ui.savedObjects.saveModal.duplicateTitleDescription.confirmSaveText"
defaultMessage="Confirm Save"
/>
</strong>
),
}}
/>
</p>
</EuiCallOut>
<EuiSpacer />
</Fragment>
);
};

private renderCopyOnSave = () => {
if (!this.props.showCopyOnSave) {
return;
}

return (
<Fragment>
<EuiSwitch
data-test-subj="saveAsNewCheckbox"
checked={this.state.copyOnSave}
onChange={this.onCopyOnSaveChange}
label={
<FormattedMessage
id="common.ui.savedObjects.saveModal.saveAsNewLabel"
defaultMessage="Save as a new {objectType}"
values={{ objectType: this.props.objectType }}
/>
}
/>
<EuiSpacer />
</Fragment>
);
};
}
/**
* @deprecated
*
* Do not import this component from here. Import from `src/plugins/kibana_react` instead.
*/
export { SavedObjectSaveModal } from '../../../../../plugins/kibana_react/public';
streamich marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions src/plugins/kibana_react/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* under the License.
*/

export * from './saved_objects';
export * from './exit_full_screen_button';
export * from './context';
export * from './overlays';
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions src/plugins/kibana_react/public/saved_objects/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export * from './saved_object_finder';
export * from './saved_object_save_modal';
Loading