Skip to content

Commit

Permalink
move/rename overlay mount and unmount types from banner to parent module
Browse files Browse the repository at this point in the history
Signed-off-by: pgayvallet <pierre.gayvallet@elastic.co>
  • Loading branch information
pgayvallet committed Oct 16, 2019
1 parent f82c2e9 commit 5f63498
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 32 deletions.
4 changes: 2 additions & 2 deletions src/core/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ export {
} from './http';

export {
MountPoint,
UnmountCallback,
OverlayStart,
OverlayBannerMount,
OverlayBannerUnmount,
OverlayBannersStart,
OverlayRef,
} from './overlays';
Expand Down
29 changes: 6 additions & 23 deletions src/core/public/overlays/banners/banners_service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,19 @@ import { BannersList } from './banners_list';
import { UiSettingsClientContract } from '../../ui_settings';
import { I18nStart } from '../../i18n';
import { UserBannerService } from './user_banner_service';

/**
* A function that will unmount the banner from the element.
* @public
*/
export type OverlayBannerUnmount = () => void;

/**
* A function that will mount the banner inside the provided element.
* @param element an element to render into
* @returns a {@link OverlayBannerUnmount}
* @public
*/
export type OverlayBannerMount = (element: HTMLElement) => OverlayBannerUnmount;
import { MountPoint } from '../types';

/** @public */
export interface OverlayBannersStart {
/**
* Add a new banner
*
* @param mount {@link OverlayBannerMount}
* @param mount {@link MountPoint}
* @param priority optional priority order to display this banner. Higher priority values are shown first.
* @returns a unique identifier for the given banner to be used with {@link OverlayBannersStart.remove} and
* {@link OverlayBannersStart.replace}
*/
add(mount: OverlayBannerMount, priority?: number): string;
add(mount: MountPoint, priority?: number): string;

/**
* Remove a banner
Expand All @@ -70,7 +57,7 @@ export interface OverlayBannersStart {
* @returns a new identifier for the given banner to be used with {@link OverlayBannersStart.remove} and
* {@link OverlayBannersStart.replace}
*/
replace(id: string | undefined, mount: OverlayBannerMount, priority?: number): string;
replace(id: string | undefined, mount: MountPoint, priority?: number): string;

/** @internal */
get$(): Observable<OverlayBanner[]>;
Expand All @@ -80,7 +67,7 @@ export interface OverlayBannersStart {
/** @internal */
export interface OverlayBanner {
readonly id: string;
readonly mount: OverlayBannerMount;
readonly mount: MountPoint;
readonly priority: number;
}

Expand Down Expand Up @@ -110,20 +97,16 @@ export class OverlayBannersService {
if (!banners$.value.has(id)) {
return false;
}

banners$.next(banners$.value.remove(id));

return true;
},

replace(id: string | undefined, mount: OverlayBannerMount, priority = 0) {
replace(id: string | undefined, mount: MountPoint, priority = 0) {
if (!id || !banners$.value.has(id)) {
return this.add(mount, priority);
}

const nextId = genId();
const nextBanner = { id: nextId, mount, priority };

banners$.next(banners$.value.remove(id).add(nextId, nextBanner));
return nextId;
},
Expand Down
7 changes: 1 addition & 6 deletions src/core/public/overlays/banners/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,4 @@
* under the License.
*/

export {
OverlayBannerMount,
OverlayBannerUnmount,
OverlayBannersStart,
OverlayBannersService,
} from './banners_service';
export { OverlayBannersStart, OverlayBannersService } from './banners_service';
3 changes: 2 additions & 1 deletion src/core/public/overlays/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@
* under the License.
*/

export { OverlayBannerMount, OverlayBannerUnmount, OverlayBannersStart } from './banners';
export { MountPoint, UnmountCallback } from './types';
export { OverlayBannersStart } from './banners';
export { OverlayService, OverlayStart, OverlayRef } from './overlay_service';
35 changes: 35 additions & 0 deletions src/core/public/overlays/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

/**
* A function that will mount the banner inside the provided element.
* @param element the container element to render into
* @returns a {@link UnmountCallback} that unmount the element on call.
*
* @public
*/
export type MountPoint = (element: HTMLElement) => UnmountCallback;

/**
* A function that will unmount the element previously mounted by
* the associated {@link MountPoint}
*
* @public
*/
export type UnmountCallback = () => void;

0 comments on commit 5f63498

Please sign in to comment.