Skip to content

Commit

Permalink
record applied datasource layers in frame public API
Browse files Browse the repository at this point in the history
  • Loading branch information
drewdaemon committed Feb 9, 2022
1 parent 4c942d9 commit c5dd500
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export const InnerWorkspacePanel = React.memo(function InnerWorkspacePanel({
const activeDatasourceId = useLensSelector(selectActiveDatasourceId);
const datasourceStates = useLensSelector(selectDatasourceStates);

const { datasourceLayers } = framePublicAPI;
const { datasourceLayers, appliedDatasourceLayers } = framePublicAPI;
const [localState, setLocalState] = useState<WorkspaceState>({
expressionBuildError: undefined,
expandError: false,
Expand Down Expand Up @@ -189,7 +189,7 @@ export const InnerWorkspacePanel = React.memo(function InnerWorkspacePanel({
visualizationState: appliedState?.visualization.state || visualization.state,
datasourceMap,
datasourceStates: appliedState?.datasourceStates || datasourceStates,
datasourceLayers,
datasourceLayers: appliedDatasourceLayers || datasourceLayers,
});

if (ast) {
Expand Down Expand Up @@ -224,6 +224,7 @@ export const InnerWorkspacePanel = React.memo(function InnerWorkspacePanel({
configurationValidationError?.length,
missingRefsErrors.length,
appliedState,
appliedDatasourceLayers,
]);

const expressionExists = Boolean(expression);
Expand Down Expand Up @@ -325,7 +326,7 @@ export const InnerWorkspacePanel = React.memo(function InnerWorkspacePanel({
};

const renderVisualization = () => {
if (expression === null) {
if (!expressionExists) {
return renderEmptyWorkspace();
}
return (
Expand All @@ -343,8 +344,6 @@ export const InnerWorkspacePanel = React.memo(function InnerWorkspacePanel({
);
};

const element = expression !== null ? renderVisualization() : renderEmptyWorkspace();

const dragDropContext = useContext(DragContext);

const renderDragDrop = () => {
Expand Down Expand Up @@ -374,7 +373,7 @@ export const InnerWorkspacePanel = React.memo(function InnerWorkspacePanel({
order={dropProps.order}
>
<EuiPageContentBody className="lnsWorkspacePanelWrapper__pageContentBody">
{element}
{renderVisualization()}
</EuiPageContentBody>
</DragDrop>
);
Expand Down
16 changes: 13 additions & 3 deletions x-pack/plugins/lens/public/state_management/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { createSelector } from '@reduxjs/toolkit';
import { SavedObjectReference } from 'kibana/server';
import { FilterManager } from 'src/plugins/data/public';
import { LensState } from './types';
import { Datasource, DatasourceMap, VisualizationMap } from '../types';
import { Datasource, DatasourceMap, FramePublicAPI, VisualizationMap } from '../types';
import { getDatasourceLayers } from '../editor_frame_service/editor_frame';

export const selectPersistedDoc = (state: LensState) => state.lens.persistedDoc;
Expand Down Expand Up @@ -151,13 +151,23 @@ export const selectDatasourceLayers = createSelector(
export const selectFramePublicAPI = createSelector(
[
selectDatasourceStates,
selectAppliedState,
selectActiveData,
selectInjectedDependencies as SelectInjectedDependenciesFunction<DatasourceMap>,
],
(datasourceStates, activeData, datasourceMap) => {
return {
(datasourceStates, appliedState, activeData, datasourceMap) => {
const api: FramePublicAPI = {
datasourceLayers: getDatasourceLayers(datasourceStates, datasourceMap),
activeData,
};

if (appliedState) {
api.appliedDatasourceLayers = getDatasourceLayers(
appliedState.datasourceStates,
datasourceMap
);
}

return api;
}
);
1 change: 1 addition & 0 deletions x-pack/plugins/lens/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,7 @@ export interface VisualizationSuggestion<T = unknown> {

export interface FramePublicAPI {
datasourceLayers: Record<string, DatasourcePublicAPI>;
appliedDatasourceLayers?: Record<string, DatasourcePublicAPI>; // this is only set when auto-apply is turned off
/**
* Data of the chart currently rendered in the preview.
* This data might be not available (e.g. if the chart can't be rendered) or outdated and belonging to another chart.
Expand Down

0 comments on commit c5dd500

Please sign in to comment.