Skip to content

Commit

Permalink
eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
nreese committed Jul 16, 2024
1 parent abb54a6 commit 89731ad
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { ControlGroupChainingSystem } from '@kbn/controls-plugin/common';
import { Filter } from '@kbn/es-query';
import { BehaviorSubject, skip } from 'rxjs';
import { chaining$ } from './chaining';
import { ControlPanelState } from "../types";
import { ControlPanelState } from '../types';

const FILTER_ALPHA = {
meta: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
PublishingSubject,
} from '@kbn/presentation-publishing';
import { BehaviorSubject, combineLatest, debounceTime, map, Observable, switchMap } from 'rxjs';
import { ControlPanelState } from "../types";
import { ControlPanelState } from '../types';

export interface ChainingContext {
chainingFilters?: Filter[] | undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,12 @@ export const getControlGroupEmbeddableFactory = (services: {
...controlsManager.api,
controlFetch$: (controlUuid: string) =>
controlFetch$(
chaining$(controlUuid, chainingSystem$, controlsManager.controlsInOrder$, controlsManager.getControlApi),
chaining$(
controlUuid,
chainingSystem$,
controlsManager.controlsInOrder$,
controlsManager.getControlApi
),
controlGroupFetch$(ignoreParentSettings$, parentApi ? parentApi : {})
),
ignoreParentSettings$,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,32 @@
*/

import { v4 as generateId } from 'uuid';
import { HasSerializedChildState, PanelPackage, PresentationContainer } from "@kbn/presentation-containers";
import {
HasSerializedChildState,
PanelPackage,
PresentationContainer,
} from '@kbn/presentation-containers';
import { Reference } from '@kbn/content-management-utils';
import { BehaviorSubject, merge } from "rxjs";
import { ControlPanelsState, ControlPanelState } from "./types";
import { DefaultControlApi } from '../types';
import { BehaviorSubject, merge } from 'rxjs';
import { PublishingSubject } from '@kbn/presentation-publishing';
import { omit } from 'lodash';
import { ControlPanelsState, ControlPanelState } from './types';
import { DefaultControlApi } from '../types';

export function initControlsManager(controlPanelsState: ControlPanelsState) {
const children$ = new BehaviorSubject<{ [key: string]: DefaultControlApi }>({});
const controlsInOrder$ = new BehaviorSubject<Array<ControlPanelState & { id: string }>>(
Object.keys(controlPanelsState)
.map((key) => ({
id: key,
...controlPanelsState[key]
...controlPanelsState[key],
}))
.sort((a, b) => (a.order > b.order ? 1 : -1))
);

function untilControlLoaded(id: string): DefaultControlApi | Promise<DefaultControlApi | undefined> {
function untilControlLoaded(
id: string
): DefaultControlApi | Promise<DefaultControlApi | undefined> {
if (children$.value[id]) {
return children$.value[id];
}
Expand All @@ -40,7 +46,9 @@ export function initControlsManager(controlPanelsState: ControlPanelsState) {
}

// control removed before the control finished loading.
const controlState = controlsInOrder$.value.find(controlPanelState => controlPanelState.id === id);
const controlState = controlsInOrder$.value.find(
(controlPanelState) => controlPanelState.id === id
);
if (!controlState) {
subscription.unsubscribe();
resolve(undefined);
Expand All @@ -63,18 +71,20 @@ export function initControlsManager(controlPanelsState: ControlPanelsState) {
type: panelType,
order: controlsInOrder.length,
...(initialState ?? {}),
}
},
]);
return await untilControlLoaded(id);
}

function removePanel(panelId: string) {
controlsInOrder$.next(controlsInOrder$.value.filter(({ id }) => id !==panelId));
controlsInOrder$.next(controlsInOrder$.value.filter(({ id }) => id !== panelId));
children$.next(omit(children$.value, panelId));
}

return {
controlsInOrder$: controlsInOrder$ as PublishingSubject<Array<ControlPanelState & { id: string }>>,
controlsInOrder$: controlsInOrder$ as PublishingSubject<
Array<ControlPanelState & { id: string }>
>,
getControlApi,
setControlApi: (uuid: string, controlApi: DefaultControlApi) => {
children$.next({
Expand Down Expand Up @@ -106,10 +116,10 @@ export function initControlsManager(controlPanelsState: ControlPanelsState) {
explicitInputPanels[id] = {
grow,
order: index,
type: controlApi.type,
type: controlApi.type,
width,
/** Re-add the `explicitInput` layer on serialize so control group saved object retains shape */
explicitInput: rest
explicitInput: rest,
};
});

Expand All @@ -120,14 +130,16 @@ export function initControlsManager(controlPanelsState: ControlPanelsState) {
},
api: {
getSerializedStateForChild: (childId: string) => {
const controlPanelState = controlsInOrder$.getValue().find(controlPanelState => controlPanelState.id === childId);
const controlPanelState = controlsInOrder$
.getValue()
.find((element) => element.id === childId);
return controlPanelState ? { rawState: controlPanelState } : undefined;
},
children$: children$ as PublishingSubject<{
[key: string]: DefaultControlApi;
}>,
getPanelCount: () => {
return controlsInOrder$.value.length
return controlsInOrder$.value.length;
},
addNewPanel,
removePanel,
Expand All @@ -137,5 +149,5 @@ export function initControlsManager(controlPanelsState: ControlPanelsState) {
return controlApi ? controlApi.uuid : '';
},
} as PresentationContainer & HasSerializedChildState<ControlPanelState>,
}
}
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ export const deserializeControlGroup = (
defaultControlGrow: DEFAULT_CONTROL_GROW,
defaultControlWidth: DEFAULT_CONTROL_WIDTH,
};
};
};

0 comments on commit 89731ad

Please sign in to comment.