All files / src/lib/electron/dialog confirmDeleteCustomEvent.ts

81.82% Statements 9/11
25% Branches 2/8
50% Functions 1/2
81.82% Lines 9/11

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 431x 1x   1x   1x 1x 1x 1x     1x                                                           1x  
import { dialog } from "electron";
import l10n from "shared/lib/lang/l10n";
 
const MAX_SCENE_NAMES = 5;
 
export enum DeleteScriptConfirmButton {
  delete = 0,
  deleteReferences,
  cancel,
}
 
const confirmDeleteCustomEvent = (
  name: string,
  sceneNames: string[],
  count: number
) => {
  const foundReferences =
    sceneNames.length > 0
      ? sceneNames.slice(0, MAX_SCENE_NAMES).join(", ") +
        (sceneNames.length > MAX_SCENE_NAMES ? "..." : "")
      : l10n("FIELD_SCRIPT");
  return dialog.showMessageBoxSync({
    type: "info",
    buttons: [
      l10n("MENU_DELETE_SCRIPT"),
      l10n("DIALOG_DELETE_SCRIPT_AND_REFERENCES"),
      l10n("DIALOG_CANCEL"),
    ],
    defaultId: 0,
    cancelId: 2,
    title: l10n("DIALOG_DELETE_CUSTOM_EVENT", { name }),
    message: l10n("DIALOG_DELETE_CUSTOM_EVENT", { name }),
    detail: l10n(
      count === 1
        ? "DIALOG_DELETE_CUSTOM_EVENT_USED_SINGLAR"
        : "DIALOG_DELETE_CUSTOM_EVENT_USED",
      { count, sceneNames: foundReferences }
    ),
  });
};
 
export default confirmDeleteCustomEvent;