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

64.51% Statements 20/31
83.33% Branches 5/6
42.85% Functions 6/14
63.33% Lines 19/30

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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120      55x   55x                               55x         55x                         5x                 69x                                                                     127x                           127x 127x   127x 127x   127x 127x   127x 127x   127x 127x   127x       55x      
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;
  },
  _updatePosition: (id: string, position: { x: number; y: number }) =>
    console.warn('updatePosition() NOT IMPLEMENTED'),
  _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();
  }
 
  /**
   * Update the position of a specific dialog by id
   *
   * @param {string} id - The dialog id to update
   * @param {{ x: number; y: number }} position - The new position
   */
  updatePosition(id: string, position: { x: number; y: number }): void {
    return serviceImplementation._updatePosition(id, position);
  }
 
  /**
   * 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,
    updatePosition,
    customComponent,
  }: any): void {
    if (show) {
      serviceImplementation._show = show;
    }
    if (hide) {
      serviceImplementation._hide = hide;
    }
    if (hideAll) {
      serviceImplementation._hideAll = hideAll;
    }
    if (isEmpty) {
      serviceImplementation._isEmpty = isEmpty;
    }
    if (updatePosition) {
      serviceImplementation._updatePosition = updatePosition;
    }
    Iif (customComponent) {
      serviceImplementation._customComponent = customComponent;
    }
  }
}
 
export default UIDialogService;