Skip to content

Commit

Permalink
[Maps] Always show solution layers (#86053)
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasneirynck committed Jan 19, 2021
1 parent dc30e94 commit 55d1065
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 19 deletions.
18 changes: 13 additions & 5 deletions x-pack/plugins/maps/public/classes/layers/layer_wizard_registry.ts
Expand Up @@ -29,30 +29,38 @@ export type LayerWizard = {
checkVisibility?: () => Promise<boolean>;
description: string;
disabledReason?: string;
getIsDisabled?: () => Promise<boolean> | boolean;
icon: string | FunctionComponent<any>;
getIsDisabled?: () => boolean;
prerequisiteSteps?: Array<{ id: string; label: string }>;
renderWizard(renderWizardArguments: RenderWizardArguments): ReactElement<any>;
title: string;
};

export type LayerWizardWithMeta = LayerWizard & {
isVisible: boolean;
isDisabled: boolean;
};

const registry: LayerWizard[] = [];

export function registerLayerWizard(layerWizard: LayerWizard) {
registry.push({
checkVisibility: async () => {
return true;
},
getIsDisabled: async () => {
return false;
},
...layerWizard,
});
}

export async function getLayerWizards(): Promise<LayerWizard[]> {
const promises = registry.map(async (layerWizard) => {
export async function getLayerWizards(): Promise<LayerWizardWithMeta[]> {
const promises = registry.map(async (layerWizard: LayerWizard) => {
return {
...layerWizard,
// @ts-ignore
isVisible: await layerWizard.checkVisibility(),
isVisible: await layerWizard.checkVisibility!(),
isDisabled: await layerWizard.getIsDisabled!(),
};
});
return (await Promise.all(promises)).filter(({ isVisible }) => {
Expand Down
Expand Up @@ -37,8 +37,6 @@ export function registerLayerWizards() {

// Registration order determines display order
registerLayerWizard(uploadLayerWizardConfig);
registerLayerWizard(ObservabilityLayerWizardConfig);
registerLayerWizard(SecurityLayerWizardConfig);
// @ts-ignore
registerLayerWizard(esDocumentsLayerWizardConfig);
// @ts-ignore
Expand All @@ -62,5 +60,7 @@ export function registerLayerWizards() {
registerLayerWizard(wmsLayerWizardConfig);

registerLayerWizard(mvtVectorSourceWizardConfig);
registerLayerWizard(ObservabilityLayerWizardConfig);
registerLayerWizard(SecurityLayerWizardConfig);
registered = true;
}
Expand Up @@ -14,14 +14,18 @@ import { getIndexPatternService } from '../../../../kibana_services';

export const ObservabilityLayerWizardConfig: LayerWizard = {
categories: [LAYER_WIZARD_CATEGORY.ELASTICSEARCH, LAYER_WIZARD_CATEGORY.SOLUTIONS],
checkVisibility: async () => {
getIsDisabled: async () => {
try {
await getIndexPatternService().get(APM_INDEX_PATTERN_ID);
return true;
} catch (e) {
return false;
} catch (e) {
return true;
}
},
disabledReason: i18n.translate('xpack.maps.observability.disabledDesc', {
defaultMessage:
'Cannot find APM index pattern. To get started with Observably, go to Observability > Overview.',
}),
description: i18n.translate('xpack.maps.observability.desc', {
defaultMessage: 'APM layers',
}),
Expand Down
Expand Up @@ -13,10 +13,14 @@ import { SecurityLayerTemplate } from './security_layer_template';

export const SecurityLayerWizardConfig: LayerWizard = {
categories: [LAYER_WIZARD_CATEGORY.ELASTICSEARCH, LAYER_WIZARD_CATEGORY.SOLUTIONS],
checkVisibility: async () => {
getIsDisabled: async () => {
const indexPatterns = await getSecurityIndexPatterns();
return indexPatterns.length > 0;
return indexPatterns.length === 0;
},
disabledReason: i18n.translate('xpack.maps.security.disabledDesc', {
defaultMessage:
'Cannot find security index pattern. To get started with Security, go to Security > Overview.',
}),
description: i18n.translate('xpack.maps.security.desc', {
defaultMessage: 'Security layers',
}),
Expand Down
Expand Up @@ -23,6 +23,7 @@ describe('LayerWizardSelect', () => {
{
categories: [LAYER_WIZARD_CATEGORY.ELASTICSEARCH],
description: 'mock wizard without icon',
isDisabled: false,
renderWizard: () => {
return <div />;
},
Expand All @@ -31,6 +32,7 @@ describe('LayerWizardSelect', () => {
{
categories: [LAYER_WIZARD_CATEGORY.SOLUTIONS],
description: 'mock wizard with icon',
isDisabled: false,
icon: 'logoObservability',
renderWizard: () => {
return <div />;
Expand Down
Expand Up @@ -19,7 +19,11 @@ import {
} from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import { i18n } from '@kbn/i18n';
import { getLayerWizards, LayerWizard } from '../../../classes/layers/layer_wizard_registry';
import {
getLayerWizards,
LayerWizard,
LayerWizardWithMeta,
} from '../../../classes/layers/layer_wizard_registry';
import { LAYER_WIZARD_CATEGORY } from '../../../../common/constants';
import './layer_wizard_select.scss';

Expand All @@ -30,7 +34,7 @@ interface Props {
interface State {
activeCategories: LAYER_WIZARD_CATEGORY[];
hasLoadedWizards: boolean;
layerWizards: LayerWizard[];
layerWizards: LayerWizardWithMeta[];
selectedCategory: LAYER_WIZARD_CATEGORY | null;
}

Expand Down Expand Up @@ -140,34 +144,33 @@ export class LayerWizardSelect extends Component<Props, State> {
}

const wizardCards = this.state.layerWizards
.filter((layerWizard: LayerWizard) => {
.filter((layerWizard: LayerWizardWithMeta) => {
return this.state.selectedCategory
? layerWizard.categories.includes(this.state.selectedCategory!)
: true;
})
.map((layerWizard: LayerWizard) => {
.map((layerWizard: LayerWizardWithMeta) => {
const icon = layerWizard.icon ? <EuiIcon type={layerWizard.icon} size="l" /> : undefined;

const onClick = () => {
this.props.onSelect(layerWizard);
};

const isDisabled = layerWizard.getIsDisabled ? layerWizard.getIsDisabled() : false;
const card = (
<EuiCard
title={layerWizard.title}
titleSize="xs"
icon={icon}
onClick={onClick}
description={layerWizard.description}
isDisabled={isDisabled}
isDisabled={layerWizard.isDisabled}
data-test-subj={_.camelCase(layerWizard.title)}
/>
);

return (
<EuiFlexItem key={layerWizard.title}>
{isDisabled && layerWizard.disabledReason ? (
{layerWizard.isDisabled && layerWizard.disabledReason ? (
<EuiToolTip
position="top"
anchorClassName="mapMapLayerWizardSelect__tooltip"
Expand Down

0 comments on commit 55d1065

Please sign in to comment.