MCPcopy
hub / github.com/home-assistant/frontend / showDialog

Function showDialog

src/dialogs/make-dialog-manager.ts:81–194  ·  view source on GitHub ↗
(
  element: LitElement & ProvideHassElement,
  dialogTag: string,
  dialogParams: unknown,
  dialogImport?: () => Promise<unknown>,
  parentElement?: LitElement,
  addHistory = true,
  dialogAnchor?: Element
)

Source from the content-addressed store, hash-verified

79 * @returns `true` if the dialog was shown (or could be shown), `false` if it could not be loaded.
80 */
81export const showDialog = async (
82 element: LitElement & ProvideHassElement,
83 dialogTag: string,
84 dialogParams: unknown,
85 dialogImport?: () => Promise<unknown>,
86 parentElement?: LitElement,
87 addHistory = true,
88 dialogAnchor?: Element
89): Promise<boolean> => {
90 if (!(dialogTag in LOADED)) {
91 if (!dialogImport) {
92 if (__DEV__) {
93 // eslint-disable-next-line
94 console.warn(
95 "Asked to show dialog that's not loaded and can't be imported"
96 );
97 }
98 return false;
99 }
100 LOADED[dialogTag] = {
101 element: dialogImport().then(() => {
102 const dialogEl = document.createElement(dialogTag) as
103 | HassDialogNext
104 | HassDialog;
105
106 if ("showDialog" in dialogEl) {
107 // provide hass for legacy persistent dialogs
108 element.provideHass(dialogEl);
109 }
110
111 dialogEl.addEventListener("dialog-closed", _handleClosed);
112 dialogEl.addEventListener("dialog-closed", _handleClosedFocus);
113
114 return dialogEl;
115 }),
116 };
117 }
118
119 if (addHistory) {
120 const { history } = mainWindow;
121 if (history.state?.dialog && !OPEN_DIALOG_STACK.length) {
122 // theres is a dialog state in history, but no dialogs open
123 // wait for history.back() to update the state
124 await new Promise((resolve) => {
125 setTimeout(resolve);
126 });
127 return showDialog(
128 element,
129 dialogTag,
130 dialogParams,
131 dialogImport,
132 parentElement,
133 addHistory,
134 dialogAnchor
135 );
136 }
137 const dialogIndex = OPEN_DIALOG_STACK.findIndex(
138 (state) => state.dialogTag === dialogTag

Callers 4

registerDialogMethod · 0.90
_handleMoreInfoMethod · 0.90
DemoHaSelectorClass · 0.90
makeDialogManagerFunction · 0.85

Calls 6

ancestorsWithPropertyFunction · 0.90
deepActiveElementFunction · 0.90
addEventListenerMethod · 0.80
provideHassMethod · 0.65
showDialogMethod · 0.65
createElementMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…