DEV: Error if invalid `@flashType` passed to modal (#22414)

This commit is contained in:
David Taylor 2023-07-04 18:11:29 +01:00 committed by GitHub
parent 9ee1972a2c
commit 1122454904
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 0 deletions

View File

@ -63,6 +63,7 @@
{{yield to="belowHeader"}} {{yield to="belowHeader"}}
{{this.validateFlashType @flashType}}
{{#if @flash}} {{#if @flash}}
<div <div
id="modal-alert" id="modal-alert"

View File

@ -8,6 +8,8 @@ export const CLOSE_INITIATED_BY_ESC = "initiatedByESC";
export const CLOSE_INITIATED_BY_CLICK_OUTSIDE = "initiatedByClickOut"; export const CLOSE_INITIATED_BY_CLICK_OUTSIDE = "initiatedByClickOut";
export const CLOSE_INITIATED_BY_MODAL_SHOW = "initiatedByModalShow"; export const CLOSE_INITIATED_BY_MODAL_SHOW = "initiatedByModalShow";
const FLASH_TYPES = ["success", "error", "warning", "info"];
export default class DModal extends Component { export default class DModal extends Component {
@service modal; @service modal;
@tracked wrapperElement; @tracked wrapperElement;
@ -161,4 +163,11 @@ export default class DModal extends Component {
handleCloseButton() { handleCloseButton() {
this.args.closeModal({ initiatedBy: CLOSE_INITIATED_BY_BUTTON }); this.args.closeModal({ initiatedBy: CLOSE_INITIATED_BY_BUTTON });
} }
@action
validateFlashType(type) {
if (type && !FLASH_TYPES.includes(type)) {
throw `@flashType must be one of ${FLASH_TYPES.join(", ")}`;
}
}
} }