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

clean some types #40

Merged
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 @@ -5,10 +5,8 @@
* 2.0.
*/

import type { HasType } from '@kbn/presentation-publishing';
import { Embeddable } from '@kbn/embeddable-plugin/public';
import type { HasVisualizeConfig, VisualizeEmbeddable } from '@kbn/visualizations-plugin/public';
import { apiHasVisualizeConfig } from '@kbn/visualizations-plugin/public';

export function isLegacyMap(embeddable: Embeddable) {
return (
Expand All @@ -18,11 +16,6 @@ export function isLegacyMap(embeddable: Embeddable) {
);
}

type LegacyMapApi = HasType & Partial<HasVisualizeConfig>;

export function isLegacyMapApi(api: LegacyMapApi) {
if (!apiHasVisualizeConfig(api)) {
return false;
}
export function isLegacyMapApi(api: HasVisualizeConfig) {
return ['region_map', 'tile_map'].includes(api.getVis().type?.name);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import { i18n } from '@kbn/i18n';
import { type EmbeddableApiContext, apiHasType, apiIsOfType } from '@kbn/presentation-publishing';
import { createAction } from '@kbn/ui-actions-plugin/public';
import { apiHasVisualizeConfig } from '@kbn/visualizations-plugin/public';
import { type FilterByMapExtentActionApi } from './types';
import { MAP_SAVED_OBJECT_TYPE } from '../../../common/constants';
import { isLegacyMapApi } from '../../legacy_visualizations/is_legacy_map';
Expand Down Expand Up @@ -52,10 +53,11 @@ export const filterByMapExtentAction = createAction<EmbeddableApiContext>({
return 'filter';
},
isCompatible: async ({ embeddable }: EmbeddableApiContext) => {
if (!isApiCompatible(embeddable)) return false;
return embeddable.disableTriggers
? false
: apiIsOfType(embeddable, MAP_SAVED_OBJECT_TYPE) || isLegacyMapApi(embeddable);
if (!isApiCompatible(embeddable) || embeddable.disableTriggers) return false;
return (
apiIsOfType(embeddable, MAP_SAVED_OBJECT_TYPE) ||
(apiHasVisualizeConfig(embeddable) && isLegacyMapApi(embeddable))
);
},
execute: async ({ embeddable }: EmbeddableApiContext) => {
const { openModal } = await import('./modal');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
*/

import { apiIsOfType } from '@kbn/presentation-publishing';
import { type HasLensConfig, apiHasLensConfig } from '@kbn/lens-plugin/public';
import { apiHasVisualizeConfig } from '@kbn/visualizations-plugin/public';
import { apiHasLensConfig } from '@kbn/lens-plugin/public';
import { MAP_SAVED_OBJECT_TYPE } from '../../../common/constants';
import { isLegacyMapApi } from '../../legacy_visualizations/is_legacy_map';
import { mapEmbeddablesSingleton } from '../../embeddable/map_embeddables_singleton';
Expand All @@ -16,14 +17,9 @@ export function isCompatible(api: SynchronizeMovementActionApi) {
if (!mapEmbeddablesSingleton.hasMultipleMaps()) {
return false;
}

if (apiHasLensConfig(api) && (api as HasLensConfig).getSavedVis()?.visualizationType === 'lnsChoropleth') {
return true;
}

if (isLegacyMapApi(api)) {
return true;
}

return apiIsOfType(api, MAP_SAVED_OBJECT_TYPE);
return (
apiIsOfType(api, MAP_SAVED_OBJECT_TYPE) ||
(apiHasLensConfig(api) && api.getSavedVis()?.visualizationType === 'lnsChoropleth') ||
(apiHasVisualizeConfig(api) && isLegacyMapApi(api))
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ import type { HasType } from '@kbn/presentation-publishing';
import type { HasLensConfig } from '@kbn/lens-plugin/public';
import type { HasVisualizeConfig } from '@kbn/visualizations-plugin/public';

export type SynchronizeMovementActionApi = HasType<'lens' | 'visualization' | 'map'> &
Partial<HasLensConfig & HasVisualizeConfig>;
export type SynchronizeMovementActionApi =
| HasType<'map' | 'visualization' | 'lens'>
| Partial<HasLensConfig | HasVisualizeConfig>;
Loading