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

Add openAddDataControlFlyout to API #42

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 @@ -40,6 +40,7 @@ import { ControlGroupApi, ControlGroupRuntimeState, ControlGroupSerializedState
import { ControlGroup } from './components/control_group';
import { initSelectionsManager } from './selections_manager';
import { initializeControlGroupUnsavedChanges } from './control_group_unsaved_changes_api';
import { openDataControlEditor } from '../controls/data_controls/open_data_control_editor';

export const getControlGroupEmbeddableFactory = (services: {
core: CoreStart;
Expand Down Expand Up @@ -162,25 +163,27 @@ export const getControlGroupEmbeddableFactory = (services: {
i18n.translate('controls.controlGroup.displayName', {
defaultMessage: 'Controls',
}),
openAddDataControlFlyout: () => {
/* openDataControlEditor({
openAddDataControlFlyout: (settings) => {
const { controlInputTransform } = settings ?? {
controlInputTransform: (state) => state,
};
openDataControlEditor({
initialState: {
grow: DEFAULT_CONTROL_GROW,
width: DEFAULT_CONTROL_WIDTH,
dataViewId: parentApi.lastUsedDataViewId.getValue(),
grow: api.grow.getValue(),
width: api.width.getValue(),
},
onSave: ({ type: controlType, state: initialState }) => {
controlsManager.api.addNewPanel({
api.addNewPanel({
panelType: controlType,
initialState,
initialState: controlInputTransform!(
initialState as Partial<ControlGroupSerializedState>,
Copy link
Owner

Choose a reason for hiding this comment

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

Shouldn't this be Partial<DefaultControlState> since the initialState is the control's initial state?

Copy link
Author

@Heenawter Heenawter Aug 8, 2024

Choose a reason for hiding this comment

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

Definitely a bad cast here, woops! Technically it should be Partial<ControlInput> because of how ControlInputTransform is defined in src/plugins/controls/common/types.ts. But since we don't want to touch any of the stuff that is shared between React controls and legacy at this point, perhaps we just cast to DataControlEditorState? This satisfies Partial<ControlInput>

Copy link
Owner

Choose a reason for hiding this comment

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

sounds good. We can always iterator on this

controlType
),
});
},
controlGroupApi,
services: {
core,
dataViews: dataViewsService,
},
});*/
controlGroupApi: api,
services,
});
},
serializeState: () => {
const { panelsJSON, references } = controlsManager.serializeControls();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
* Side Public License, v 1.
*/

import { Observable } from 'rxjs';

import { DefaultEmbeddableApi } from '@kbn/embeddable-plugin/public';
import { Filter } from '@kbn/es-query';
import {
Expand All @@ -24,10 +26,11 @@ import {
PublishingSubject,
} from '@kbn/presentation-publishing';
import { PublishesDataViews } from '@kbn/presentation-publishing/interfaces/publishes_data_views';
import { Observable } from 'rxjs';
import { ControlStyle, ControlWidth } from '../../types';

import { ParentIgnoreSettings } from '../..';
import { ControlInputTransform } from '../../../common';
import { ControlGroupChainingSystem } from '../../../common/control_group/types';
import { ControlStyle, ControlWidth } from '../../types';
import { DefaultControlState, PublishesControlDisplaySettings } from '../controls/types';
import { ControlFetchContext } from './control_fetch/control_fetch';

Expand Down Expand Up @@ -66,7 +69,9 @@ export type ControlGroupApi = PresentationContainer &
ignoreParentSettings$: PublishingSubject<ParentIgnoreSettings | undefined>;
allowExpensiveQueries$: PublishingSubject<boolean>;
untilInitialized: () => Promise<void>;
openAddDataControlFlyout: () => void;
openAddDataControlFlyout: (settings?: {
Copy link
Owner

@nreese nreese Aug 8, 2024

Choose a reason for hiding this comment

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

Since settings is just a wrapper around controlInputTransform? How about just openAddDataControlFlyout: (controlInputTransform?: ControlInputTransform) => void

Copy link
Author

@Heenawter Heenawter Aug 8, 2024

Choose a reason for hiding this comment

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

There used to be more than one setting for the legacy version of openAddDataControlFlyout (it included an onSave callback) - I still haven't fully narrowed down which ones are necessary, and I won't know until the control group renderer is fully converted. For now, maybe we keep that extra level?

controlInputTransform?: ControlInputTransform;
}) => void;
};

export interface ControlGroupRuntimeState {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { ControlGroupApi } from '../../control_group/types';
import { DataControlEditor } from './data_control_editor';
import { DefaultDataControlState } from './types';

export type DataControlEditorState = Omit<DefaultDataControlState, 'fieldName'> & {
export type DataControlEditorState = Partial<DefaultDataControlState> & {
fieldName?: string;
controlType?: string;
controlId?: string;
Expand Down
Loading