Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
b4972da
First version of new by-value editor
Jul 15, 2020
f5061c7
Adding missing null check
Jul 17, 2020
8d334c0
Making typescript play nicely
Jul 20, 2020
6295a08
Fixing failing tests
Jul 20, 2020
96daa2a
Merge branch 'master' into visualize-by-value-editor
elasticmachine Jul 20, 2020
0bf02a3
:poop: Draft code to debug the issue
dej611 Jul 16, 2020
66a1973
:recycle: Revert changes shape
dej611 Aug 3, 2020
2db2de9
:bug: Fix the cloning issue for the placeholder and final embeddable …
dej611 Aug 4, 2020
c01d56b
:fire: Remove double loading state handler
dej611 Aug 4, 2020
d5025d4
:recycle: Limit the key to the type
dej611 Aug 4, 2020
688576c
:mute: Remove debugging logs
dej611 Aug 4, 2020
02265a4
:recycle: Refactor addOrUpdateEmbeddable method
dej611 Aug 5, 2020
38aa24b
:white_check_mark: Add replacePanel test
dej611 Aug 5, 2020
46d7b63
:rotating_light: Fix unused import
dej611 Aug 5, 2020
b63976a
Merge branch 'master' into visualize-by-value-editor
Aug 10, 2020
db912df
Merge branch 'master' into visualize-by-value-editor
elasticmachine Aug 10, 2020
8e871ce
Applying PR comments
Aug 10, 2020
09a8f9b
Fixing eslint errors
Aug 10, 2020
a201c2a
Fix save as behavior
Aug 11, 2020
24c1948
Fixing HTMLElement type
Aug 11, 2020
d4b69dc
Passing in setOriginatingApp parameter
Aug 11, 2020
875be62
Redirect back to dashboard if input is missing
Aug 12, 2020
cc59f71
Fixing i18n error
Aug 13, 2020
29c6a31
Merge branch 'master' into visualize-by-value-editor
Aug 13, 2020
1741aae
Unlink saved search
Aug 13, 2020
1259c98
Merge branch 'master' into visualize-by-value-editor
Aug 17, 2020
99ad8ea
Merge remote-tracking branch 'upstream/master' into fix/embeddable-pa…
dej611 Aug 17, 2020
228d007
Fix duplicating embeddable by reference
Aug 17, 2020
09381f3
Merge branch 'visualize-by-value-editor' of github.com:majagrubic/kib…
ThomThomson Aug 17, 2020
9562949
Merged #72256 and #74253 in order to test panel reactivity for by val…
ThomThomson Aug 17, 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 @@ -468,9 +468,14 @@ export class DashboardAppController {
const explicitInput = {
savedVis: input,
};
const embeddableId =
'embeddableId' in incomingEmbeddable
? incomingEmbeddable.embeddableId
: undefined;
container.addOrUpdateEmbeddable<EmbeddableInput>(
incomingEmbeddable.type,
explicitInput
explicitInput,
embeddableId
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
ContactCardEmbeddableInput,
ContactCardEmbeddable,
ContactCardEmbeddableOutput,
EMPTY_EMBEDDABLE,
} from '../../embeddable_plugin_test_samples';
import { embeddablePluginMock } from 'src/plugins/embeddable/public/mocks';

Expand Down Expand Up @@ -100,6 +101,48 @@ test('DashboardContainer.addNewEmbeddable', async () => {
expect(embeddableInContainer.id).toBe(embeddable.id);
});

test('DashboardContainer.replacePanel', async (done) => {
const ID = '123';
const initialInput = getSampleDashboardInput({
panels: {
[ID]: getSampleDashboardPanel<ContactCardEmbeddableInput>({
explicitInput: { firstName: 'Sam', id: ID },
type: CONTACT_CARD_EMBEDDABLE,
}),
},
});

const container = new DashboardContainer(initialInput, options);
let counter = 0;

const subscriptionHandler = jest.fn(({ panels }) => {
counter++;
expect(panels[ID]).toBeDefined();
// It should be called exactly 2 times and exit the second time
switch (counter) {
case 1:
return expect(panels[ID].type).toBe(CONTACT_CARD_EMBEDDABLE);

case 2: {
expect(panels[ID].type).toBe(EMPTY_EMBEDDABLE);
subscription.unsubscribe();
done();
}

default:
throw Error('Called too many times!');
}
});

const subscription = container.getInput$().subscribe(subscriptionHandler);

// replace the panel now
container.replacePanel(container.getInput().panels[ID], {
type: EMPTY_EMBEDDABLE,
explicitInput: { id: ID },
});
});

test('Container view mode change propagates to existing children', async () => {
const initialInput = getSampleDashboardInput({
panels: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,45 +168,42 @@ export class DashboardContainer extends Container<InheritedChildInput, Dashboard
previousPanelState: DashboardPanelState<EmbeddableInput>,
newPanelState: Partial<PanelState>
) {
// TODO: In the current infrastructure, embeddables in a container do not react properly to
// changes. Removing the existing embeddable, and adding a new one is a temporary workaround
// until the container logic is fixed.
const finalPanels = { ...this.input.panels };
delete finalPanels[previousPanelState.explicitInput.id];
const newPanelId = newPanelState.explicitInput?.id ? newPanelState.explicitInput.id : uuid.v4();
finalPanels[newPanelId] = {
...previousPanelState,
...newPanelState,
gridData: {
...previousPanelState.gridData,
i: newPanelId,
},
explicitInput: {
...newPanelState.explicitInput,
id: newPanelId,
// Because the embeddable type can change, we have to operate at the container level here
return this.updateInput({
panels: {
...this.input.panels,
[previousPanelState.explicitInput.id]: {
...previousPanelState,
...newPanelState,
gridData: {
...previousPanelState.gridData,
},
explicitInput: {
...newPanelState.explicitInput,
id: previousPanelState.explicitInput.id,
},
},
},
};
this.updateInput({
panels: finalPanels,
lastReloadRequestTime: new Date().getTime(),
});
}

public async addOrUpdateEmbeddable<
EEI extends EmbeddableInput = EmbeddableInput,
EEO extends EmbeddableOutput = EmbeddableOutput,
E extends IEmbeddable<EEI, EEO> = IEmbeddable<EEI, EEO>
>(type: string, explicitInput: Partial<EEI>) {
if (explicitInput.id && this.input.panels[explicitInput.id]) {
this.replacePanel(this.input.panels[explicitInput.id], {
>(type: string, explicitInput: Partial<EEI>, embeddableId?: string) {
const idToReplace = embeddableId || explicitInput.id;
if (idToReplace && this.input.panels[idToReplace]) {
this.replacePanel(this.input.panels[idToReplace], {
type,
explicitInput: {
...explicitInput,
id: uuid.v4(),
// TS does not catch up with the typeguard above, so it needs to be explicit
id: idToReplace,
},
});
} else {
this.addNewEmbeddable<EEI, EEO, E>(type, explicitInput);
return this.addNewEmbeddable<EEI, EEO, E>(type, explicitInput);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,13 +265,16 @@ class DashboardGridUi extends React.Component<DashboardGridProps, State> {
<div
style={{ zIndex: focusedPanelIndex === panel.explicitInput.id ? 2 : 'auto' }}
className={classes}
// This key is required for the ReactGridLayout to work properly
key={panel.explicitInput.id}
data-test-subj="dashboardPanel"
ref={(reactGridItem) => {
this.gridItems[panel.explicitInput.id] = reactGridItem;
}}
>
<EmbeddableChildPanel
// This key is used to force rerendering on embeddable type change while the id remains the same
key={panel.type}
embeddableId={panel.explicitInput.id}
container={this.props.container}
PanelComponent={this.props.PanelComponent}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,18 @@ test('is compatible when edit url is available, in edit mode and editable', asyn
test('redirects to app using state transfer', async () => {
applicationMock.currentAppId$ = of('superCoolCurrentApp');
const action = new EditPanelAction(getFactory, applicationMock, stateTransferMock);
const embeddable = new EditableEmbeddable({ id: '123', viewMode: ViewMode.EDIT }, true);
const input = { id: '123', viewMode: ViewMode.EDIT };
const embeddable = new EditableEmbeddable(input, true);
embeddable.getOutput = jest.fn(() => ({ editApp: 'ultraVisualize', editPath: '/123' }));
await action.execute({ embeddable });
expect(stateTransferMock.navigateToEditor).toHaveBeenCalledWith('ultraVisualize', {
path: '/123',
state: { originatingApp: 'superCoolCurrentApp' },
state: {
originatingApp: 'superCoolCurrentApp',
byValueMode: true,
embeddableId: '123',
valueInput: input,
},
});
});

Expand Down
20 changes: 17 additions & 3 deletions src/plugins/embeddable/public/lib/actions/edit_panel_action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ import { take } from 'rxjs/operators';
import { ViewMode } from '../types';
import { EmbeddableFactoryNotFoundError } from '../errors';
import { EmbeddableStart } from '../../plugin';
import { IEmbeddable, EmbeddableEditorState, EmbeddableStateTransfer } from '../..';
import {
IEmbeddable,
EmbeddableEditorState,
EmbeddableStateTransfer,
SavedObjectEmbeddableInput,
} from '../..';

export const ACTION_EDIT_PANEL = 'editPanel';

Expand Down Expand Up @@ -109,8 +114,17 @@ export class EditPanelAction implements Action<ActionContext> {
const app = embeddable ? embeddable.getOutput().editApp : undefined;
const path = embeddable ? embeddable.getOutput().editPath : undefined;
if (app && path) {
const state = this.currentAppId ? { originatingApp: this.currentAppId } : undefined;
return { app, path, state };
if (this.currentAppId) {
const byValueMode = !(embeddable.getInput() as SavedObjectEmbeddableInput).savedObjectId;
const state: EmbeddableEditorState = {
originatingApp: this.currentAppId,
byValueMode,
valueInput: byValueMode ? embeddable.getInput() : undefined,
embeddableId: embeddable.id,
};
return { app, path, state };
}
return { app, path };
}
}

Expand Down
34 changes: 24 additions & 10 deletions src/plugins/embeddable/public/lib/containers/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import uuid from 'uuid';
import { merge, Subscription } from 'rxjs';
import { startWith, pairwise } from 'rxjs/operators';
import {
Embeddable,
EmbeddableInput,
Expand Down Expand Up @@ -54,7 +55,12 @@ export abstract class Container<
parent?: Container
) {
super(input, output, parent);
this.subscription = this.getInput$().subscribe(() => this.maybeUpdateChildren());
this.subscription = this.getInput$()
// At each update event, get both the previous and current state
.pipe(startWith(input), pairwise())
.subscribe(([{ panels: prevPanels }, { panels: currentPanels }]) => {
this.maybeUpdateChildren(currentPanels, prevPanels);
});
}

public updateInputForChild<EEI extends EmbeddableInput = EmbeddableInput>(
Expand Down Expand Up @@ -328,16 +334,24 @@ export abstract class Container<
return embeddable;
}

private maybeUpdateChildren() {
const allIds = Object.keys({ ...this.input.panels, ...this.output.embeddableLoaded });
private maybeUpdateChildren(
currentPanels: TContainerInput['panels'],
prevPanels: TContainerInput['panels']
) {
const allIds = Object.keys({ ...currentPanels, ...this.output.embeddableLoaded });
allIds.forEach((id) => {
if (this.input.panels[id] !== undefined && this.output.embeddableLoaded[id] === undefined) {
this.onPanelAdded(this.input.panels[id]);
} else if (
this.input.panels[id] === undefined &&
this.output.embeddableLoaded[id] !== undefined
) {
this.onPanelRemoved(id);
if (currentPanels[id] !== undefined && this.output.embeddableLoaded[id] === undefined) {
return this.onPanelAdded(currentPanels[id]);
}
if (currentPanels[id] === undefined && this.output.embeddableLoaded[id] !== undefined) {
return this.onPanelRemoved(id);
}
// In case of type change, remove and add a panel with the same id
if (currentPanels[id] && prevPanels[id]) {
if (currentPanels[id].type !== prevPanels[id].type) {
this.onPanelRemoved(id);
this.onPanelAdded(currentPanels[id]);
}
}
});
}
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/embeddable/public/lib/state_transfer/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export interface EmbeddableEditorState {
originatingApp: string;
byValueMode?: boolean;
valueInput?: EmbeddableInput;
embeddableId?: string;
}

export function isEmbeddableEditorState(state: unknown): state is EmbeddableEditorState {
Expand All @@ -49,6 +50,7 @@ export interface EmbeddablePackageByReferenceState {
export interface EmbeddablePackageByValueState {
type: string;
input: EmbeddableInput;
embeddableId?: string;
}

export type EmbeddablePackageState =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export function TopNavMenuItem(props: TopNavMenuData) {
iconType: props.iconType,
iconSide: props.iconSide,
'data-test-subj': props.testId,
className: props.className,
};

const btn = props.emphasize ? (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ class DefaultEditorController {
]
: visType.editorConfig.optionTabs),
];

this.state = {
vis,
optionTabs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ export const createVisEmbeddableFromObject = (deps: VisualizeEmbeddableFactoryDe
try {
const visId = vis.id as string;

const editPath = visId ? savedVisualizations.urlFor(visId) : '';
const editPath = visId ? savedVisualizations.urlFor(visId) : '#/edit_by_value';

const editUrl = visId
? getHttp().basePath.prepend(`/app/visualize${savedVisualizations.urlFor(visId)}`)
: '';
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/visualize/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import { schema, TypeOf } from '@kbn/config-schema';

export const configSchema = schema.object({
showNewVisualizeFlow: schema.boolean({ defaultValue: false }),
showNewVisualizeFlow: schema.boolean({ defaultValue: true }),
});

export type ConfigSchema = TypeOf<typeof configSchema>;
10 changes: 9 additions & 1 deletion src/plugins/visualize/public/application/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ import { Route, Switch, useLocation } from 'react-router-dom';
import { syncQueryStateWithUrl } from '../../../data/public';
import { useKibana } from '../../../kibana_react/public';
import { VisualizeServices } from './types';
import { VisualizeEditor, VisualizeListing, VisualizeNoMatch } from './components';
import {
VisualizeEditor,
VisualizeListing,
VisualizeNoMatch,
VisualizeByValueEditor,
} from './components';
import { VisualizeConstants } from './visualize_constants';

export const VisualizeApp = () => {
Expand All @@ -48,6 +53,9 @@ export const VisualizeApp = () => {

return (
<Switch>
<Route exact path={`${VisualizeConstants.EDIT_BY_VALUE_PATH}`}>
<VisualizeByValueEditor />
</Route>
<Route path={[VisualizeConstants.CREATE_PATH, `${VisualizeConstants.EDIT_PATH}/:id`]}>
<VisualizeEditor />
</Route>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@
export { VisualizeListing } from './visualize_listing';
export { VisualizeEditor } from './visualize_editor';
export { VisualizeNoMatch } from './visualize_no_match';
export { VisualizeByValueEditor } from './visualize_byvalue_editor';
Loading