Skip to content

Commit

Permalink
Moved labsService to flyout.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
cqliu1 committed Sep 30, 2021
1 parent fd80ede commit 5163ffd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
SavedObjectFinderUi,
SavedObjectMetaData,
} from '../../../../../../src/plugins/saved_objects/public/';
import { useEmbeddablesService, useLabsService, usePlatformService } from '../../services';
import { useEmbeddablesService, usePlatformService } from '../../services';

const strings = {
getNoItemsText: () =>
Expand All @@ -29,17 +29,20 @@ export interface Props {
onClose: () => void;
onSelect: (id: string, embeddableType: string, isByValueEnabled?: boolean) => void;
availableEmbeddables: string[];
isByValueEnabled?: boolean;
}

export const AddEmbeddableFlyout: FC<Props> = ({ onSelect, availableEmbeddables, onClose }) => {
export const AddEmbeddableFlyout: FC<Props> = ({
onSelect,
availableEmbeddables,
onClose,
isByValueEnabled,
}) => {
const embeddablesService = useEmbeddablesService();
const labsService = useLabsService();
const platformService = usePlatformService();
const { getEmbeddableFactories } = embeddablesService;
const { getSavedObjects, getUISettings } = platformService;

const isByValueEnabled = labsService.isProjectEnabled('labs:canvas:byValueEmbeddable');

const onAddPanel = useCallback(
(id: string, savedObjectType: string) => {
const embeddableFactories = getEmbeddableFactories();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { addElement } from '../../state/actions/elements';
import { getSelectedPage } from '../../state/selectors/workpad';
import { EmbeddableTypes } from '../../../canvas_plugin_src/expression_types/embeddable';
import { State } from '../../../types';
import { useLabsService } from '../../services';

const allowedEmbeddables = {
[EmbeddableTypes.map]: (id: string) => {
Expand Down Expand Up @@ -66,6 +67,9 @@ export const AddEmbeddablePanel: React.FunctionComponent<FlyoutProps> = ({
availableEmbeddables,
...restProps
}) => {
const labsService = useLabsService();
const isByValueEnabled = labsService.isProjectEnabled('labs:canvas:byValueEmbeddable');

const dispatch = useDispatch();
const pageId = useSelector<State, string>((state) => getSelectedPage(state));

Expand All @@ -75,7 +79,7 @@ export const AddEmbeddablePanel: React.FunctionComponent<FlyoutProps> = ({
);

const onSelect = useCallback(
(id: string, type: string, isByValueEnabled?: boolean): void => {
(id: string, type: string): void => {
const partialElement = {
expression: `markdown "Could not find embeddable for type ${type}" | render`,
};
Expand All @@ -92,14 +96,15 @@ export const AddEmbeddablePanel: React.FunctionComponent<FlyoutProps> = ({
addEmbeddable(pageId, partialElement);
restProps.onClose();
},
[addEmbeddable, pageId, restProps]
[addEmbeddable, pageId, restProps, isByValueEnabled]
);

return (
<EmbeddableFlyoutPortal
{...restProps}
availableEmbeddables={availableEmbeddables || []}
onSelect={onSelect}
isByValueEnabled={isByValueEnabled}
/>
);
};

0 comments on commit 5163ffd

Please sign in to comment.