All files / platform/core/src/services/UIDialogService UIDialogService.ts

62.96% Statements 17/27
80% Branches 4/5
41.66% Functions 5/12
61.53% Lines 16/26

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98      34x   34x                           34x         34x                                           46x                                                 80x             80x 80x   80x 80x   80x 80x   80x 80x   80x       34x      
import type { ManagedDialogProps } from 'platform/ui-next/src/contextProviders/ManagedDialog';
type DialogOptions = ManagedDialogProps;
 
const name = 'uiDialogService';
 
const serviceImplementation = {
  _show: (options: DialogOptions) => {
    console.warn('show() NOT IMPLEMENTED');
    return '';
  },
  _hide: (id: string) => console.warn('hide() NOT IMPLEMENTED'),
  _hideAll: () => console.warn('hideAll() NOT IMPLEMENTED'),
  _isEmpty: () => {
    console.warn('isEmpty() NOT IMPLEMENTED');
    return true;
  },
  _customComponent: null,
};
 
class UIDialogService {
  static REGISTRATION = {
    name,
    altName: 'UIDialogService',
    create: (): UIDialogService => {
      return new UIDialogService();
    },
  };
 
  readonly name = name;
 
  /**
   * Show a new UI dialog
   *
   * @param {DialogOptions} options - The dialog options
   * @returns {string} The dialog id
   */
  show(options: DialogOptions): string {
    return serviceImplementation._show(options);
  }
 
  /**
   * Hide a specific dialog by id
   *
   * @param {string} id - The dialog id to hide
   */
  hide(id: string): void {
    return serviceImplementation._hide(id);
  }
 
  /**
   * Hide all currently shown dialogs
   */
  hideAll(): void {
    return serviceImplementation._hideAll();
  }
 
  /**
   * Check if there are any dialogs currently shown
   *
   * @returns {boolean} True if no dialogs are shown
   */
  isEmpty(): boolean {
    return serviceImplementation._isEmpty();
  }
 
  /**
   * This provides flexibility in customizing the Modal's default component
   *
   * @returns {React.Component}
   */
  getCustomComponent() {
    return serviceImplementation._customComponent;
  }
 
  /**
   * Set the service implementation
   */
  setServiceImplementation({ show, hide, hideAll, isEmpty, customComponent }: any): void {
    if (show) {
      serviceImplementation._show = show;
    }
    if (hide) {
      serviceImplementation._hide = hide;
    }
    if (hideAll) {
      serviceImplementation._hideAll = hideAll;
    }
    if (isEmpty) {
      serviceImplementation._isEmpty = isEmpty;
    }
    Iif (customComponent) {
      serviceImplementation._customComponent = customComponent;
    }
  }
}
 
export default UIDialogService;