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

GUI enhancement: handle descriptions for visualizations (#20936) #44702

Merged
merged 5 commits into from
Sep 12, 2019
Merged
Show file tree
Hide file tree
Changes from 3 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,12 +17,14 @@
* under the License.
*/
import { i18n } from '@kbn/i18n';
import { EuiContextMenuPanelDescriptor, EuiBadge } from '@elastic/eui';
import { EuiContextMenuPanelDescriptor, EuiBadge, EuiIcon, EuiToolTip } from '@elastic/eui';
import classNames from 'classnames';
import React from 'react';
import { PanelOptionsMenu } from './panel_options_menu';
import { Action } from '../../actions';
import { IEmbeddable } from '../../embeddables';
import { VisualizeEmbeddable } from '../../../../../../../kibana/public/visualize/embeddable/visualize_embeddable';
import { VISUALIZE_EMBEDDABLE_TYPE } from '../../../../../../../kibana/public/visualize/embeddable/constants';

export interface PanelHeaderProps {
title?: string;
Expand All @@ -47,6 +49,12 @@ function renderBadges(badges: Action[], embeddable: IEmbeddable) {
));
}

function isVisualizeEmbeddable(
embeddable: IEmbeddable | VisualizeEmbeddable
): embeddable is VisualizeEmbeddable {
return embeddable.type === VISUALIZE_EMBEDDABLE_TYPE;
}

export function PanelHeader({
title,
isViewMode,
Expand Down Expand Up @@ -75,6 +83,16 @@ export function PanelHeader({
);
}

let viewDescr = '';
if (isVisualizeEmbeddable(embeddable)) {
const vd = (embeddable as VisualizeEmbeddable).getVisualizationDescription();
if (vd) {
viewDescr = vd;
}
} else {
viewDescr = '';
}

return (
<div
className={classes}
Expand All @@ -83,16 +101,25 @@ export function PanelHeader({
<div
data-test-subj="dashboardPanelTitle"
className="embPanel__title embPanel__dragger"
title={title}
aria-label={i18n.translate('embeddableApi.panel.dashboardPanelAriaLabel', {
defaultMessage: 'Dashboard panel: {title}',
values: {
title,
},
})}
/* title={title} */ /* this is redundant - it shows a tooltip with the view title - and clutters the UI */ aria-label={i18n.translate(
'embeddableApi.panel.dashboardPanelAriaLabel',
{
defaultMessage: 'Dashboard panel: {title}',
values: {
title,
},
}
)}
>
{showTitle ? `${title} ` : ''}
{renderBadges(badges, embeddable)}
{viewDescr !== '' ? (
<EuiToolTip content={viewDescr} delay="regular" position="right">
<EuiIcon type="iInCircle" />
</EuiToolTip>
) : (
''
)}
</div>

<PanelOptionsMenu
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,11 @@ function VisEditor(
}
},
run: async () => {
const onSave = ({ newTitle, newCopyOnSave, isTitleDuplicateConfirmed, onTitleDuplicate }) => {
const onSave = ({ newTitle, newCopyOnSave, isTitleDuplicateConfirmed, onTitleDuplicate, newDescription }) => {
const currentTitle = savedVis.title;
savedVis.title = newTitle;
savedVis.copyOnSave = newCopyOnSave;
savedVis.description = newDescription;
const saveOptions = {
confirmOverwrite: false,
isTitleDuplicateConfirmed,
Expand Down Expand Up @@ -206,6 +207,7 @@ function VisEditor(
showCopyOnSave={savedVis.id ? true : false}
objectType="visualization"
confirmButtonLabel={confirmButtonLabel}
description={savedVis.description}
/>);
showSaveModal(saveModal);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ export class VisualizeEmbeddable extends Embeddable<VisualizeInput, VisualizeOut
});
}

public getVisualizationDescription() {
return this.savedVisualization.description;
}

public getInspectorAdapters() {
if (!this.handler) {
return undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,19 @@ class VisualizeListingTableUi extends Component {
</span>
)
},
{
field: 'description',
name: intl.formatMessage({
id: 'kbn.dashboard.listing.table.descriptionColumnName',
defaultMessage: 'Description',
}),
sortable: true,
render: (field, record) => (
<span>
{record.description}
</span>
)
},
];

return tableColumns;
Expand Down

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

Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,19 @@ import {
EuiOverlayMask,
EuiSpacer,
EuiSwitch,
EuiTextArea,
} from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import React from 'react';
import { EuiText } from '@elastic/eui';
import { VISUALIZE_EMBEDDABLE_TYPE } from '../../../../legacy/core_plugins/kibana/public/visualize/embeddable/constants';

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

interface Props {
Expand All @@ -60,6 +63,7 @@ interface State {
isTitleDuplicateConfirmed: boolean;
hasTitleDuplicate: boolean;
isLoading: boolean;
visualizationDescription: string;
}

export class SavedObjectSaveModal extends React.Component<Props, State> {
Expand All @@ -69,6 +73,7 @@ export class SavedObjectSaveModal extends React.Component<Props, State> {
isTitleDuplicateConfirmed: false,
hasTitleDuplicate: false,
isLoading: false,
visualizationDescription: this.props.description ? this.props.description : '',
};

public render() {
Expand Down Expand Up @@ -96,7 +101,7 @@ export class SavedObjectSaveModal extends React.Component<Props, State> {
{this.renderDuplicateTitleCallout()}

<EuiForm>
{this.props.description && (
{this.props.objectType !== VISUALIZE_EMBEDDABLE_TYPE && this.props.description && (
<EuiFormRow>
<EuiText color="subdued">{this.props.description}</EuiText>
</EuiFormRow>
Expand Down Expand Up @@ -124,6 +129,8 @@ export class SavedObjectSaveModal extends React.Component<Props, State> {
/>
</EuiFormRow>

{this.renderViewDescription()}

{this.props.options}
</EuiForm>
</EuiModalBody>
Expand Down Expand Up @@ -159,6 +166,36 @@ export class SavedObjectSaveModal extends React.Component<Props, State> {
);
}

private renderViewDescription = () => {
if (this.props.objectType !== VISUALIZE_EMBEDDABLE_TYPE) {
return;
}

return (
<EuiFormRow
fullWidth
label={
<FormattedMessage
id="kibana-react.savedObjects.saveModal.descriptionLabel"
defaultMessage="Description"
/>
}
>
<EuiTextArea
data-test-subj="viewDescription"
value={this.state.visualizationDescription}
onChange={this.onDescriptionChange}
/>
</EuiFormRow>
);
};

private onDescriptionChange = (event: React.ChangeEvent<HTMLTextAreaElement>) => {
this.setState({
visualizationDescription: event.target.value,
});
};

private onTitleDuplicate = () => {
this.setState({
isLoading: false,
Expand All @@ -182,6 +219,7 @@ export class SavedObjectSaveModal extends React.Component<Props, State> {
newCopyOnSave: this.state.copyOnSave,
isTitleDuplicateConfirmed: this.state.isTitleDuplicateConfirmed,
onTitleDuplicate: this.onTitleDuplicate,
newDescription: this.state.visualizationDescription,
});
};

Expand Down