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

Reactify visualize app #67848

Merged
merged 27 commits into from
Jun 29, 2020
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
ba5ac21
Reactify visualize app
sulemanof Jun 12, 2020
727583a
Fix typescript failures after merging master
sulemanof Jun 12, 2020
fcc3508
Make sure refresh button works
sulemanof Jun 12, 2020
f2691e7
Subscribe filter manager fetches
sulemanof Jun 12, 2020
619e408
Use redirect to landing page
sulemanof Jun 12, 2020
e5f45a6
Update savedSearch type
sulemanof Jun 12, 2020
ef776c1
Add check for TSVB is loaded
sulemanof Jun 12, 2020
3664bf3
Merge branch 'master' into np/reactify_visualize
sulemanof Jun 17, 2020
cd21384
Fix comments
sulemanof Jun 17, 2020
c030614
Fix uiState persistence on vis load
sulemanof Jun 17, 2020
a43752a
Remove extra div around TableListView
sulemanof Jun 17, 2020
6879ea7
Update DTS selectors
sulemanof Jun 18, 2020
6d51a08
Add error handling for embeddable
sulemanof Jun 18, 2020
cc84a37
Remove extra argument from useEditorUpdates effect
sulemanof Jun 19, 2020
5ff42f4
Update comments, fix typos
sulemanof Jun 19, 2020
fc15832
Remove extra div wrapper
sulemanof Jun 19, 2020
e90e0b6
Apply design suggestions
sulemanof Jun 19, 2020
3566a34
Merge remote-tracking branch 'upstream/master' into np/reactify_visua…
sulemanof Jun 19, 2020
03dec22
Revert accidental config changes
sulemanof Jun 19, 2020
160dbb9
Merge branch 'master' into np/reactify_visualize
elasticmachine Jun 23, 2020
ca17287
Merge branch 'master' into np/reactify_visualize
sulemanof Jun 24, 2020
3e943e2
Apply navigating to dashboard
sulemanof Jun 24, 2020
60c9f16
Apply redirect legacy urls
sulemanof Jun 25, 2020
c9572f5
Merge remote-tracking branch 'upstream/master' into np/reactify_visua…
sulemanof Jun 29, 2020
151e6a1
Apply incoming changes
sulemanof Jun 29, 2020
1120db1
Apply incoming changes
sulemanof Jun 29, 2020
c1e999a
Merge branch 'np/reactify_visualize' of github.com:sulemanof/kibana i…
sulemanof Jun 29, 2020
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 @@ -23,7 +23,6 @@ import { createInputControlVisController } from './vis_controller';
import { getControlsTab } from './components/editor/controls_tab';
import { OptionsTab } from './components/editor/options_tab';
import { InputControlVisDependencies } from './plugin';
import { defaultFeedbackMessage } from '../../kibana_utils/public';

export function createInputControlVisTypeDefinition(deps: InputControlVisDependencies) {
const InputControlVisController = createInputControlVisController(deps);
Expand All @@ -39,7 +38,6 @@ export function createInputControlVisTypeDefinition(deps: InputControlVisDepende
defaultMessage: 'Create interactive controls for easy dashboard manipulation.',
}),
stage: 'experimental',
feedbackMessage: defaultFeedbackMessage,
visualization: InputControlVisController,
visConfig: {
defaults: {
Expand Down
1 change: 0 additions & 1 deletion src/plugins/kibana_utils/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,3 @@ export { distinctUntilChangedWithInitialValue } from './distinct_until_changed_w
export { url } from './url';
export { now } from './now';
export { calculateObjectHash } from './calculate_object_hash';
export { defaultFeedbackMessage } from './default_feedback_message';
1 change: 0 additions & 1 deletion src/plugins/kibana_utils/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export {
UiComponentInstance,
url,
createGetterSetter,
defaultFeedbackMessage,
} from '../common';
export * from './core';
export * from '../common/errors';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import { ButtonIconSide } from '@elastic/eui';

export type TopNavMenuAction = (anchorElement: EventTarget) => void;
export type TopNavMenuAction = (anchorElement: HTMLElement) => void;

export interface TopNavMenuData {
id?: string;
Expand All @@ -29,7 +29,7 @@ export interface TopNavMenuData {
testId?: string;
className?: string;
disableButton?: boolean | (() => boolean);
tooltip?: string | (() => string);
tooltip?: string | (() => string | undefined);
emphasize?: boolean;
iconType?: string;
iconSide?: ButtonIconSide;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,17 @@ export class SavedObjectLoader {
}

/**
* Retrieve a saved object by id. Returns a promise that completes when the object finishes
* Retrieve a saved object by id or create new one.
* Returns a promise that completes when the object finishes
* initializing.
* @param id
* @param opts
* @returns {Promise<SavedObject>}
*/
async get(id?: string) {
async get(opts?: Record<string, unknown> | string) {
// can accept object as argument in accordance to SavedVis class
// see src/plugins/saved_objects/public/saved_object/saved_object_loader.ts
// @ts-ignore
const obj = new this.Class(id);
const obj = new this.Class(opts);
return obj.init();
}

Expand Down
1 change: 1 addition & 0 deletions src/plugins/saved_objects/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export interface SavedObjectSaveOpts {
confirmOverwrite?: boolean;
isTitleDuplicateConfirmed?: boolean;
onTitleDuplicate?: () => void;
returnToOrigin?: boolean;
}

export interface SavedObjectCreationOpts {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@ import { i18n } from '@kbn/i18n';
import { keyCodes, EuiButtonIcon, EuiFlexGroup, EuiFlexItem } from '@elastic/eui';
import { EventEmitter } from 'events';

import { Vis, PersistedState } from 'src/plugins/visualizations/public';
import { SavedSearch } from 'src/plugins/discover/public';
import {
Vis,
PersistedState,
VisualizeEmbeddableContract,
} from 'src/plugins/visualizations/public';
import { TimeRange } from 'src/plugins/data/public';
import { SavedObject } from 'src/plugins/saved_objects/public';
import { DefaultEditorNavBar, OptionTab } from './navbar';
import { DefaultEditorControls } from './controls';
import { setStateParamValue, useEditorReducer, useEditorFormState, discardChanges } from './state';
Expand All @@ -34,18 +38,20 @@ import { SidebarTitle } from './sidebar_title';
import { Schema } from '../../schemas';

interface DefaultEditorSideBarProps {
embeddableHandler: VisualizeEmbeddableContract;
isCollapsed: boolean;
onClickCollapse: () => void;
optionTabs: OptionTab[];
uiState: PersistedState;
vis: Vis;
isLinkedSearch: boolean;
eventEmitter: EventEmitter;
savedSearch?: SavedSearch;
savedSearch?: SavedObject;
timeRange: TimeRange;
}

function DefaultEditorSideBar({
embeddableHandler,
isCollapsed,
onClickCollapse,
optionTabs,
Expand Down Expand Up @@ -104,12 +110,12 @@ function DefaultEditorSideBar({
aggs: state.data.aggs ? (state.data.aggs.aggs.map((agg) => agg.toJSON()) as any) : [],
},
});
eventEmitter.emit('updateVis');
embeddableHandler.reload();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of emitting an event from a particular editor, and handle it in visualize as:

image

reload it inside an editor outright (IMHO it's more evident)

eventEmitter.emit('dirtyStateChange', {
isDirty: false,
});
setTouched(false);
}, [vis, state, formState.invalid, setTouched, isDirty, eventEmitter]);
}, [vis, state, formState.invalid, setTouched, isDirty, eventEmitter, embeddableHandler]);

const onSubmit: KeyboardEventHandler<HTMLFormElement> = useCallback(
(event) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@ import { FormattedMessage } from '@kbn/i18n/react';
import { i18n } from '@kbn/i18n';

import { Vis } from 'src/plugins/visualizations/public';
import { SavedSearch } from 'src/plugins/discover/public';
import { SavedObject } from 'src/plugins/saved_objects/public';
import { useKibana } from '../../../../kibana_react/public';

interface LinkedSearchProps {
savedSearch: SavedSearch;
savedSearch: SavedObject;
eventEmitter: EventEmitter;
}

interface SidebarTitleProps {
isLinkedSearch: boolean;
savedSearch?: SavedSearch;
savedSearch?: SavedObject;
vis: Vis;
eventEmitter: EventEmitter;
}
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/vis_default_editor/public/default_editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function DefaultEditor({

embeddableHandler.render(visRef.current);
setTimeout(() => {
eventEmitter.emit('apply');
eventEmitter.emit('embeddableRendered');
});

return () => embeddableHandler.destroy();
Expand Down Expand Up @@ -102,6 +102,7 @@ function DefaultEditor({
initialWidth={editorInitialWidth}
>
<DefaultEditorSideBar
embeddableHandler={embeddableHandler}
isCollapsed={isCollapsed}
onClickCollapse={onClickCollapse}
optionTabs={optionTabs}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export class VisEditor extends Component {

updateVisState = debounce(() => {
this.props.vis.params = this.state.model;
this.props.eventEmitter.emit('updateVis');
this.props.embeddableHandler.reload();
this.props.eventEmitter.emit('dirtyStateChange', {
isDirty: false,
});
Expand Down Expand Up @@ -187,6 +187,7 @@ export class VisEditor extends Component {
autoApply={this.state.autoApply}
model={model}
embeddableHandler={this.props.embeddableHandler}
eventEmitter={this.props.eventEmitter}
vis={this.props.vis}
timeRange={this.props.timeRange}
uiState={this.uiState}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class VisEditorVisualizationUI extends Component {

this._handler = embeddableHandler;
await this._handler.render(this._visEl.current);
this.props.eventEmitter.emit('embeddableRendered');

this._subscription = this._handler.handler.data$.subscribe((data) => {
this.setPanelInterval(data.value.visData);
Expand Down Expand Up @@ -279,6 +280,7 @@ VisEditorVisualizationUI.propTypes = {
uiState: PropTypes.object,
onToggleAutoApply: PropTypes.func,
embeddableHandler: PropTypes.object,
eventEmitter: PropTypes.object,
timeRange: PropTypes.object,
dirty: PropTypes.bool,
autoApply: PropTypes.bool,
Expand Down
2 changes: 0 additions & 2 deletions src/plugins/vis_type_timeseries/public/metrics_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import { metricsRequestHandler } from './request_handler';
import { EditorController } from './application';
// @ts-ignore
import { PANEL_TYPES } from '../common/panel_types';
import { defaultFeedbackMessage } from '../../kibana_utils/public';
import { VisEditor } from './application/components/vis_editor_lazy';

export const metricsVisDefinition = {
Expand All @@ -34,7 +33,6 @@ export const metricsVisDefinition = {
defaultMessage: 'Build time-series using a visual pipeline interface',
}),
icon: 'visVisualBuilder',
feedbackMessage: defaultFeedbackMessage,
visConfig: {
defaults: {
id: '61ca57f0-469d-11e7-af02-69e470af7417',
Expand Down
2 changes: 0 additions & 2 deletions src/plugins/vis_type_vega/public/vega_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { i18n } from '@kbn/i18n';
import { DefaultEditorSize } from '../../vis_default_editor/public';
import { VegaVisualizationDependencies } from './plugin';
import { VegaVisEditor } from './components';
import { defaultFeedbackMessage } from '../../kibana_utils/public';

import { createVegaRequestHandler } from './vega_request_handler';
// @ts-ignore
Expand Down Expand Up @@ -56,6 +55,5 @@ export const createVegaTypeDefinition = (dependencies: VegaVisualizationDependen
showFilterBar: true,
},
stage: 'experimental',
feedbackMessage: defaultFeedbackMessage,
};
};
1 change: 1 addition & 0 deletions src/plugins/visualizations/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,5 @@ export {
VisSavedObject,
VisResponseValue,
} from './types';
export { VisualizationListItem } from './vis_types/vis_type_alias_registry';
export { VISUALIZE_ENABLE_LABS_SETTING } from '../common/constants';
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export const convertFromSerializedVis = (vis: SerializedVis): ISavedVis => {
title: vis.title,
description: vis.description,
visState: {
title: vis.title,
type: vis.type,
aggs: vis.data.aggs,
params: vis.params,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export function createSavedVisLoader(services: SavedObjectKibanaServicesWithVisu
source.icon = source.type.icon;
source.image = source.type.image;
source.typeTitle = source.type.title;
source.editUrl = `#/edit/${id}`;
source.editUrl = `/edit/${id}`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this should be #/edit/${id} for now as the PR isn't switching to path routing yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm not wrong, this is used only used in visualize for navigating to a visualization from the listing page. In new implementation, history.push is used for navigating, where the history object is a hash history object, so it accepts paths without leading #.
Apart from this case, I didn't find any usages of this.
Navigating from other apps (e.x. from discover/dashboard/canvas) works well.
If I missed smth, please let me know! 🙂


return source;
};
Expand Down
1 change: 1 addition & 0 deletions src/plugins/visualizations/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export type VisualizationControllerConstructor = new (
) => VisualizationController;

export interface SavedVisState {
title: string;
type: string;
params: VisParams;
aggs: AggConfigOptions[];
Expand Down
17 changes: 15 additions & 2 deletions src/plugins/visualizations/public/vis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import { isFunction, defaults, cloneDeep } from 'lodash';
import { Assign } from '@kbn/utility-types';
import { i18n } from '@kbn/i18n';
import { PersistedState } from './persisted_state';
import { getTypes, getAggs, getSearch, getSavedSearchLoader } from './services';
import { VisType } from './vis_types';
Expand Down Expand Up @@ -105,7 +106,13 @@ export class Vis {
private getType(visType: string) {
const type = getTypes().get(visType);
if (!type) {
throw new Error(`Invalid type "${visType}"`);
const errorMessage = i18n.translate('visualizations.visualizationTypeInvalidMessage', {
defaultMessage: 'Invalid visualization type "{visType}"',
values: {
visType,
},
});
throw new Error(errorMessage);
}
return type;
}
Expand Down Expand Up @@ -150,7 +157,13 @@ export class Vis {
const configStates = this.initializeDefaultsFromSchemas(aggs, this.type.schemas.all || []);
if (!this.data.indexPattern) {
if (aggs.length) {
throw new Error('trying to initialize aggs without index pattern');
const errorMessage = i18n.translate(
'visualizations.initializeWithoutIndexPatternErrorMessage',
{
defaultMessage: 'Trying to initialize aggs without index pattern',
}
);
throw new Error(errorMessage);
}
return;
}
Expand Down
9 changes: 2 additions & 7 deletions src/plugins/visualizations/public/vis_types/base_vis_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export interface BaseVisTypeOptions {
icon?: string;
image?: string;
stage?: 'experimental' | 'beta' | 'production';
feedbackMessage?: string;
options?: Record<string, any>;
visualization: VisualizationControllerConstructor;
visConfig?: Record<string, any>;
Expand All @@ -48,7 +47,7 @@ export class BaseVisType {
icon?: string;
image?: string;
stage: 'experimental' | 'beta' | 'production';
feedbackMessage: string;
isExperimental: boolean;
options: Record<string, any>;
visualization: VisualizationControllerConstructor;
visConfig: Record<string, any>;
Expand Down Expand Up @@ -87,7 +86,7 @@ export class BaseVisType {
this.editorConfig = _.defaultsDeep({}, opts.editorConfig, { collections: {} });
this.options = _.defaultsDeep({}, opts.options, defaultOptions);
this.stage = opts.stage || 'production';
this.feedbackMessage = opts.feedbackMessage || '';
this.isExperimental = opts.stage === 'experimental';
this.hidden = opts.hidden || false;
this.requestHandler = opts.requestHandler || 'courier';
this.responseHandler = opts.responseHandler || 'none';
Expand All @@ -97,10 +96,6 @@ export class BaseVisType {
this.useCustomNoDataScreen = opts.useCustomNoDataScreen || false;
}

shouldMarkAsExperimentalInUI() {
return this.stage === 'experimental';
}

public get schemas() {
if (this.editorConfig && this.editorConfig.schemas) {
return this.editorConfig.schemas;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export interface VisualizationListItem {
title: string;
description?: string;
typeTitle: string;
image?: string;
}

export interface VisualizationsAppExtension {
Expand Down
5 changes: 0 additions & 5 deletions src/plugins/visualize/public/application/_app.scss

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
// visChart__legend--small
// visChart__legend-isLoading

@import 'app';
@import 'editor/index';
@import 'listing/index';
.visAppWrapper {
display: flex;
flex-direction: column;
flex-grow: 1;
}
Loading