Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -12,7 +12,7 @@ import { ControlGroupApi, ControlGroupSerializedState } from '@kbn/controls-plug
import { EmbeddablePackageState } from '@kbn/embeddable-plugin/public';
import { StateComparators } from '@kbn/presentation-publishing';
import { omit } from 'lodash';
import { BehaviorSubject, debounceTime, merge } from 'rxjs';
import { BehaviorSubject, debounceTime, merge, first, skipWhile, switchMap } from 'rxjs';
import { v4 } from 'uuid';
import {
getReferencesForControls,
Expand Down Expand Up @@ -271,6 +271,21 @@ export function getDashboardApi({
},
setControlGroupApi: (controlGroupApi: ControlGroupApi) =>
controlGroupApi$.next(controlGroupApi),
untilControlsInitialized: async () => {
return new Promise((resolve) => {
controlGroupApi$
.pipe(
skipWhile((controlGroupApi) => !controlGroupApi),
switchMap(async (controlGroupApi) => {
await controlGroupApi?.untilInitialized();
}),
first()
)
.subscribe(() => {
resolve();
});
});
},
} as DashboardInternalApi,
cleanup: () => {
dataLoadingManager.cleanup();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,5 @@ export interface DashboardInternalApi {
getSerializedStateForControlGroup: () => SerializedPanelState<ControlGroupSerializedState>;
registerChildApi: (api: DefaultEmbeddableApi) => void;
setControlGroupApi: (controlGroupApi: ControlGroupApi) => void;
untilControlsInitialized: () => Promise<void>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,23 +79,18 @@ export const DashboardViewport = ({
};
}, [controlGroupApi]);

// Bug in main where panels are loaded before control filters are ready
// Want to migrate to react embeddable controls with same behavior
// TODO - do not load panels until control filters are ready
/*
const [dashboardInitialized, setDashboardInitialized] = useState(false);
const [controlsReady, setControlsReady] = useState(false);
useEffect(() => {
let ignore = false;
dashboard.untilContainerInitialized().then(() => {
dashboardInternalApi.untilControlsInitialized().then(() => {
if (!ignore) {
setDashboardInitialized(true);
setControlsReady(true);
}
});
return () => {
ignore = true;
};
}, [dashboard]);
*/
}, [dashboardInternalApi]);

return (
<div
Expand Down Expand Up @@ -140,7 +135,9 @@ export const DashboardViewport = ({
data-description={description}
data-shared-items-count={panelCount}
>
<DashboardGrid dashboardContainerRef={dashboardContainerRef} />
{viewMode === 'print' || controlsReady ? (
<DashboardGrid dashboardContainerRef={dashboardContainerRef} />
) : null}
</div>
</div>
);
Expand Down