Skip to content

Commit

Permalink
clean some types
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomThomson committed Jan 29, 2024
1 parent 6265def commit a77c77d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 25 deletions.
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>;

0 comments on commit a77c77d

Please sign in to comment.