Glimmerize alert-banner (#19105)

* glimmerize alert-banner

* remove conditional commented out

* add assert to require type

* add assert for if message type not included

* amend alert-inline test
This commit is contained in:
Angel Garbarino 2023-02-09 11:25:16 -07:00 committed by GitHub
parent 78522ed923
commit 39123773c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 59 additions and 84 deletions

View File

@ -1,16 +1,16 @@
{{#if this.licenseExpired}} {{#if this.licenseExpired}}
<div class="license-banner-wrapper" data-test-license-banner data-test-license-banner-expired> <div class="license-banner-wrapper" data-test-license-banner data-test-license-banner-expired>
<AlertBanner <AlertBanner
@bannerType="license"
@type="danger" @type="danger"
@title="License expired" @title="License expired"
@message="Your Vault license expired on {{date-format @message="Your Vault license expired on {{date-format
@expiry @expiry
'MMM d, yyyy' 'MMM d, yyyy'
}}. Add a new license to your configuration and restart Vault." }}. Add a new license to your configuration and restart Vault."
@marginless={{true}} class="message-marginless"
> >
<DocLink @path="/vault/tutorials/enterprise/hashicorp-enterprise-license"> <DocLink @path="/vault/tutorials/enterprise/hashicorp-enterprise-license">
<Icon @name="learn-link" />
Read documentation Read documentation
</DocLink> </DocLink>
</AlertBanner> </AlertBanner>
@ -18,7 +18,6 @@
{{else if (lte this.licenseExpiringInDays 30)}} {{else if (lte this.licenseExpiringInDays 30)}}
<div class="license-banner-wrapper" data-test-license-banner data-test-license-banner-warning> <div class="license-banner-wrapper" data-test-license-banner data-test-license-banner-warning>
<AlertBanner <AlertBanner
@bannerType="license"
@type="warning" @type="warning"
@title="Vault license expiring" @title="Vault license expiring"
@message="Your Vault license will expire in {{this.licenseExpiringInDays}} days at {{date-format @message="Your Vault license will expire in {{this.licenseExpiringInDays}} days at {{date-format
@ -29,9 +28,10 @@
'Add a new license to your configuration.' 'Add a new license to your configuration.'
'Keep in mind that your next license will need to be autoloaded' 'Keep in mind that your next license will need to be autoloaded'
}}" }}"
@marginless={{true}} class="message-marginless"
> >
<DocLink @path="/vault/tutorials/enterprise/hashicorp-enterprise-license"> <DocLink @path="/vault/tutorials/enterprise/hashicorp-enterprise-license">
<Icon @name="learn-link" />
Read documentation Read documentation
</DocLink> </DocLink>
</AlertBanner> </AlertBanner>

View File

@ -1,11 +1,4 @@
<AlertBanner @type="warning" @message="Vault is sealed" @yieldWithoutColumn={{true}} class="is-marginless"> <AlertBanner @type="warning" class="is-marginless" @title="Vault is sealed" />
<div class="is-flex is-flex-v-centered">
<div>
<span class="message-title">Warning</span>
Vault is sealed
</div>
</div>
</AlertBanner>
{{#if this.showJoinForm}} {{#if this.showJoinForm}}
<div class="box is-marginless is-shadowless"> <div class="box is-marginless is-shadowless">
<h2 class="title is-5" data-test-join-header> <h2 class="title is-5" data-test-join-header>

View File

@ -0,0 +1,32 @@
<div data-test-alert-banner="alert" class="message {{this.alertType.class}}" ...attributes>
<div class="columns is-mobile is-variable is-1">
<div class="column is-narrow message-icon">
<Icon class={{this.alertType.glyphClass}} aria-hidden="true" @name={{this.alertType.glyph}} />
</div>
<div class="column">
<div class="message-title">
{{or @title this.alertType.text}}
{{#if @showLoading}}
<Icon class="loading" aria-hidden="true" @name="loading" />
{{/if}}
{{#if @progressBar}}
<progress
value={{@progressBar.value}}
max={{@progressBar.max}}
class="progress is-success is-medium is-inline-block"
></progress>
{{/if}}
</div>
{{#if @message}}
<p class="alert-banner-message-body">
{{@message}}
</p>
{{/if}}
{{#if (has-block)}}
<p class="message-actions">
{{yield}}
</p>
{{/if}}
</div>
</div>
</div>

View File

@ -1,7 +1,6 @@
import Component from '@ember/component'; import Component from '@glimmer/component';
import { computed } from '@ember/object';
import { messageTypes } from 'core/helpers/message-types'; import { messageTypes } from 'core/helpers/message-types';
import layout from '../templates/components/alert-banner'; import { assert } from '@ember/debug';
/** /**
* @module AlertBanner * @module AlertBanner
@ -13,36 +12,17 @@ import layout from '../templates/components/alert-banner';
* ``` * ```
* *
* @param {String} type=null - The banner type. This comes from the message-types helper. * @param {String} type=null - The banner type. This comes from the message-types helper.
* @param {String} [secondIconType=null] - If you want a second icon to appear to the right of the title. This comes from the message-types helper.
* @param {Object} [progressBar=null] - An object containing a value and maximum for a progress bar. Will be displayed next to the message title.
* @param {String} [message=null] - The message to display within the banner. * @param {String} [message=null] - The message to display within the banner.
* @param {Object} [progressBar=null] - An object containing a value and maximum for a progress bar. Will be displayed next to the message title.
* @param {Boolean} [showLoading=false] - Shows a loading icon to the right of the title.
* @param {String} [title=null] - A title to show above the message. If this is not provided, there are default values for each type of alert. * @param {String} [title=null] - A title to show above the message. If this is not provided, there are default values for each type of alert.
* @param {String} [bannerType=alert] - Defaults to 'alert', can be used to specify an alert banner's test selector
*
*/ */
export default Component.extend({ export default class AlertBanner extends Component {
layout, get alertType() {
type: null, if (!this.args.type) {
message: null, assert('alert-banner component expects attr type');
title: null, }
secondIconType: null, return messageTypes([this.args.type]);
progressBar: null, }
yieldWithoutColumn: false, }
marginless: false,
classNameBindings: ['containerClass'],
bannerType: 'alert',
containerClass: computed('type', 'marginless', function () {
const base = this.marginless ? 'message message-marginless ' : 'message ';
return base + messageTypes([this.type]).class;
}),
alertType: computed('type', function () {
return messageTypes([this.type]);
}),
secondAlertType: computed('secondIconType', function () {
return messageTypes([this.secondIconType]);
}),
});

View File

@ -1,4 +1,5 @@
import { helper as buildHelper } from '@ember/component/helper'; import { helper as buildHelper } from '@ember/component/helper';
import { assert } from '@ember/debug';
export const MESSAGE_TYPES = { export const MESSAGE_TYPES = {
info: { info: {
@ -34,6 +35,9 @@ export const MESSAGE_TYPES = {
}; };
export function messageTypes([type]) { export function messageTypes([type]) {
if (!([type] in MESSAGE_TYPES)) {
assert('type is not a valid message type.');
}
return MESSAGE_TYPES[type]; return MESSAGE_TYPES[type];
} }

View File

@ -1,36 +0,0 @@
<div data-test-alert-banner={{this.bannerType}}>
<div class="columns is-mobile is-variable is-1">
<div class="column is-narrow message-icon">
<Icon class={{this.alertType.glyphClass}} aria-hidden="true" @name={{this.alertType.glyph}} />
</div>
{{#if @yieldWithoutColumn}}
{{yield}}
{{else}}
<div class="column">
<div class="message-title">
{{or @title this.alertType.text}}
{{#if @secondIconType}}
<Icon class={{this.secondAlertType.glyphClass}} aria-hidden="true" @name={{this.secondAlertType.glyph}} />
{{/if}}
{{#if @progressBar}}
<progress
value={{this.progressBar.value}}
max={{this.progressBar.max}}
class="progress is-success is-medium is-inline-block"
></progress>
{{/if}}
</div>
{{#if @message}}
<p class="alert-banner-message-body">
{{@message}}
</p>
{{/if}}
{{#if (has-block)}}
<p class="message-actions">
{{yield}}
</p>
{{/if}}
</div>
{{/if}}
</div>
</div>

View File

@ -53,7 +53,7 @@
<AlertBanner <AlertBanner
@title="Syncing in progress" @title="Syncing in progress"
@type="info" @type="info"
@secondIconType="loading" @showLoading={{true}}
@message="The cluster is syncing. This happens when the secondary is too far behind the primary to use the normal stream-wals state for catching up." @message="The cluster is syncing. This happens when the secondary is too far behind the primary to use the normal stream-wals state for catching up."
data-test-isSyncing data-test-isSyncing
/> />

View File

@ -62,7 +62,7 @@
@type="danger" @type="danger"
@title={{if crossSignRow.hasUnsupportedParams crossSignRow.hasError "Cross-sign failed"}} @title={{if crossSignRow.hasUnsupportedParams crossSignRow.hasError "Cross-sign failed"}}
@message={{if crossSignRow.hasUnsupportedParams crossSignRow.hasUnsupportedParams crossSignRow.hasError}} @message={{if crossSignRow.hasUnsupportedParams crossSignRow.hasUnsupportedParams crossSignRow.hasError}}
@marginless={{true}} class="message-marginless"
/> />
{{/if}} {{/if}}
</div> </div>

View File

@ -8,6 +8,7 @@ module('Integration | Component | alert-inline', function (hooks) {
hooks.beforeEach(function () { hooks.beforeEach(function () {
this.set('message', 'some very important alert'); this.set('message', 'some very important alert');
this.set('type', 'warning');
}); });
test('it renders alert message with correct class args', async function (assert) { test('it renders alert message with correct class args', async function (assert) {
@ -17,6 +18,7 @@ module('Integration | Component | alert-inline', function (hooks) {
@isMarginless={{true}} @isMarginless={{true}}
@sizeSmall={{true}} @sizeSmall={{true}}
@message={{this.message}} @message={{this.message}}
@type={{this.type}}
/> />
`); `);
assert.dom('[data-test-inline-error-message]').hasText('some very important alert'); assert.dom('[data-test-inline-error-message]').hasText('some very important alert');
@ -27,7 +29,7 @@ module('Integration | Component | alert-inline', function (hooks) {
test('it yields to block text', async function (assert) { test('it yields to block text', async function (assert) {
await render(hbs` await render(hbs`
<AlertInline @message={{this.message}}> <AlertInline @message={{this.message}} @type={{this.type}}>
A much more important alert A much more important alert
</AlertInline> </AlertInline>
`); `);
@ -49,7 +51,6 @@ module('Integration | Component | alert-inline', function (hooks) {
}); });
test('it renders correctly for type=warning', async function (assert) { test('it renders correctly for type=warning', async function (assert) {
this.set('type', 'warning');
await render(hbs` await render(hbs`
<AlertInline <AlertInline
@type={{this.type}} @type={{this.type}}
@ -65,6 +66,7 @@ module('Integration | Component | alert-inline', function (hooks) {
<AlertInline <AlertInline
@message={{this.message}} @message={{this.message}}
@mimicRefresh={{true}} @mimicRefresh={{true}}
@type={{this.type}}
/> />
`); `);
assert assert