Skip to content

Commit

Permalink
[7.x] [Inspector] Use "untitled" filename for panels with no title in…
Browse files Browse the repository at this point in the history
… dashboard (#86333) (#87974)

Co-authored-by: Kibana Machine <[email protected]>

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
dej611 and kibanamachine authored Jan 12, 2021
1 parent 8fd8848 commit 7bc78ce
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ interface DataViewComponentProps extends InspectorViewProps {
uiActions: UiActionsStart;
fieldFormats: FieldFormatsStart;
isFilterable: (column: DatatableColumn) => boolean;
options: { fileName?: string };
}

class DataViewComponent extends Component<DataViewComponentProps, DataViewComponentState> {
Expand Down Expand Up @@ -122,7 +123,7 @@ class DataViewComponent extends Component<DataViewComponentProps, DataViewCompon
return (
<DataTableFormat
data={this.state.datatable}
exportTitle={this.props.title}
exportTitle={this.props.options?.fileName || this.props.title}
uiSettings={this.props.uiSettings}
fieldFormats={this.props.fieldFormats}
uiActions={this.props.uiActions}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const getDataViewComponentWrapper = (
fieldFormats={getStartServices().fieldFormats}
uiActions={getStartServices().uiActions}
isFilterable={getStartServices().isFilterable}
options={props.options}
/>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,18 @@ export class InspectPanelAction implements Action<ActionContext> {
if (!(await this.isCompatible({ embeddable })) || adapters === undefined) {
throw new Error('Action not compatible with context');
}

const session = this.inspector.open(adapters, {
title: embeddable.getTitle(),
options: {
fileName:
embeddable.getTitle() || // pick the visible title
embeddable.getInput().title || // or the custom title if used, but currently hidden
embeddable.getOutput().defaultTitle || // or the saved title
// in the very last resort use "untitled"
i18n.translate('embeddableApi.panel.inspectPanel.untitledEmbeddableFilename', {
defaultMessage: 'untitled',
}),
},
});
// Overwrite the embeddables.destroy() function to close the inspector
// before calling the original destroy method
Expand Down
1 change: 1 addition & 0 deletions src/plugins/inspector/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export class InspectorPublicPlugin implements Plugin<Setup, Start> {
views={views}
adapters={adapters}
title={options.title}
options={options.options}
dependencies={{ uiSettings: core.uiSettings }}
/>
),
Expand Down
6 changes: 6 additions & 0 deletions src/plugins/inspector/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ export interface InspectorViewProps<TAdapters extends Adapters = Adapters> {
* The title that the inspector is currently using e.g. a visualization name.
*/
title: string;
/**
* A set of specific options for each view.
*/
options?: unknown;
}

/**
Expand Down Expand Up @@ -61,9 +65,11 @@ export interface InspectorViewDescription {
* Options that can be specified when opening the inspector.
* @property {string} title - An optional title, that will be shown in the header
* of the inspector. Can be used to give more context about what is being inspected.
* @property {unknown} options - A set of specific payload to be passed to inspector views
*/
export interface InspectorOptions {
title?: string;
options?: unknown;
}

export type InspectorSession = OverlayRef;
3 changes: 3 additions & 0 deletions src/plugins/inspector/public/ui/inspector_panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const inspectorTitle = i18n.translate('inspector.title', {
interface InspectorPanelProps {
adapters: Adapters;
title?: string;
options?: unknown;
views: InspectorViewDescription[];
dependencies: {
uiSettings: IUiSettingsClient;
Expand Down Expand Up @@ -76,6 +77,7 @@ export class InspectorPanel extends Component<InspectorPanelProps, InspectorPane
}
},
title: PropTypes.string,
options: PropTypes.object,
};

state: InspectorPanelState = {
Expand Down Expand Up @@ -111,6 +113,7 @@ export class InspectorPanel extends Component<InspectorPanelProps, InspectorPane
<this.state.selectedView.component
adapters={this.props.adapters}
title={this.props.title || ''}
options={this.props.options}
/>
</Suspense>
);
Expand Down

0 comments on commit 7bc78ce

Please sign in to comment.