refactor: 💡 replace ember notify with flash in notify decorator (#1272)

* refactor: 💡 replace ember notify with flash in notify decorator

* refactor: 💡 remove embery-notify and replace last instance
This commit is contained in:
Randall Morey authored and GitHub committed 2022-08-31 10:24:25 -07:00
1 parent cde6abd445
commit 4a6ed0b509
45 files changed
+131 -92

No files matched your search

+11 -4
View File
@@ -12,7 +12,7 @@ export function notifySuccess(notification) {
const method = desc.value;
desc.value = async function () {
const owner = getOwner(this);
const notifyService = owner.lookup('service:notify');
const notifyService = owner.lookup('service:flashMessages');
const intlService = owner.lookup('service:intl');
const candidateKey =
typeof notification === 'function'
@@ -25,7 +25,10 @@ export function notifySuccess(notification) {
// : candidateKey;
const text = intlService.t(candidateKey);
const value = await method.apply(this, arguments);
notifyService.success(text);
notifyService.success(text, {
noticationType: 'success',
dismiss: (flash) => flash.destroyMessage(),
});
return value;
};
};
@@ -49,7 +52,7 @@ export function notifyError(notification, options = { catch: false }) {
const method = desc.value;
desc.value = async function () {
const owner = getOwner(this);
const notifyService = owner.lookup('service:notify');
const notifyService = owner.lookup('service:flashMessages');
const intlService = owner.lookup('service:intl');
try {
@@ -64,7 +67,11 @@ export function notifyError(notification, options = { catch: false }) {
? intlService.t(candidateKey)
: candidateKey;
notifyService.error(text, { closeAfter: null });
notifyService.danger(text, {
noticationType: 'error',
sticky: true,
dismiss: (flash) => flash.destroyMessage(),
});
if (options.catch) {
// squelch the error
+1 -5
View File
@@ -1,13 +1,9 @@
import Controller from '@ember/controller';
import { inject as service } from '@ember/service';
import config from '../config/environment';
export default class ApplicationController extends Controller {
// =services
@service session;
// =attributes
notifyTimeout = config.notifyTimeout;
@service flashMessages;
}
@@ -11,7 +11,7 @@ export default class AccountChangePasswordRoute extends Route {
@service session;
@service intl;
@service notify;
@service router;
// =methods
@@ -10,7 +10,7 @@ export default class ScopesScopeAuthMethodsRoute extends Route {
// =services
@service intl;
@service notify;
@service session;
@service can;
@service resourceFilterStore;
@@ -9,7 +9,7 @@ export default class ScopesScopeAuthMethodsAuthMethodAccountsRoute extends Route
// =services
@service intl;
@service notify;
@service can;
@service router;
@@ -8,7 +8,7 @@ export default class ScopesScopeAuthMethodsAuthMethodAccountsAccountSettingsRout
// =services
@service intl;
@service notify;
@service router;
// =actions
@@ -9,7 +9,7 @@ export default class ScopesScopeAuthMethodsAuthMethodManagedGroupsRoute extends
// =services
@service intl;
@service notify;
@service can;
@service router;
@@ -9,7 +9,7 @@ export default class ScopesScopeAuthenticateMethodRoute extends Route {
// =services
@service session;
@service notify;
@service intl;
@service windowManager;
@service router;
+1 -1
View File
@@ -9,7 +9,7 @@ export default class ScopesScopeGroupsRoute extends Route {
// =services
@service intl;
@service notify;
@service session;
@service can;
@service router;
@@ -10,7 +10,7 @@ export default class ScopesScopeGroupsGroupAddMembersRoute extends Route {
// =services
@service intl;
@service notify;
@service router;
@service store;
@service resourceFilterStore;
@@ -10,7 +10,7 @@ export default class ScopesScopeGroupsGroupMembersRoute extends Route {
// =services
@service intl;
@service notify;
@service resourceFilterStore;
// =methods
@@ -9,7 +9,7 @@ export default class ScopesScopeHostCatalogsRoute extends Route {
// =services
@service intl;
@service notify;
@service session;
@service can;
@service router;
@@ -9,7 +9,7 @@ export default class ScopesScopeHostCatalogsHostCatalogHostSetsRoute extends Rou
// =services
@service intl;
@service notify;
@service can;
@service router;
@@ -9,7 +9,7 @@ export default class ScopesScopeHostCatalogsHostCatalogHostSetsHostSetAddHostsRo
// =services
@service intl;
@service notify;
@service router;
// =methods
@@ -8,7 +8,7 @@ export default class ScopesScopeHostCatalogsHostCatalogHostSetsHostSetCreateAndA
// =services
@service intl;
@service notify;
@service router;
// =methods
@@ -10,7 +10,6 @@ export default class ScopesScopeHostCatalogsHostCatalogHostSetsHostSetHostsRoute
// =services
@service intl;
@service notify;
// =methods
@@ -9,7 +9,7 @@ export default class ScopesScopeHostCatalogsHostCatalogHostsRoute extends Route
// =services
@service intl;
@service notify;
@service can;
@service router;
+1 -1
View File
@@ -9,7 +9,7 @@ export default class ScopesScopeRolesRoute extends Route {
// =services
@service intl;
@service notify;
@service session;
@service can;
@service router;
@@ -10,7 +10,7 @@ export default class ScopesScopeRolesRoleAddPrincipalsRoute extends Route {
// =services
@service intl;
@service notify;
@service router;
@service store;
@service resourceFilterStore;
@@ -8,7 +8,6 @@ export default class ScopesScopeRolesRoleGrantsRoute extends Route {
// =services
@service intl;
@service notify;
// =actions
@@ -8,7 +8,7 @@ import { notifySuccess, notifyError } from 'core/decorators/notify';
export default class ScopesScopeRolesRolePrincipalsRoute extends Route {
// =services
@service intl;
@service notify;
@service resourceFilterStore;
// =methods
+1 -1
View File
@@ -14,7 +14,7 @@ export default class ScopesScopeSessionsRoute extends Route {
// =services
@service intl;
@service notify;
@service session;
@service resourceFilterStore;
@service router;
+1 -1
View File
@@ -9,7 +9,7 @@ export default class ScopesScopeTargetsRoute extends Route {
// =services
@service intl;
@service notify;
@service session;
@service can;
@service router;
@@ -9,7 +9,7 @@ export default class ScopesScopeTargetsTargetAddBrokeredCredentialSourcesRoute e
// =services
@service intl;
@service notify;
@service router;
// =methods
@@ -9,7 +9,7 @@ export default class ScopesScopeTargetsTargetAddHostSourcesRoute extends Route {
// =services
@service intl;
@service notify;
@service router;
// =methods
@@ -10,7 +10,6 @@ export default class ScopesScopeTargetsTargetHostSourcesRoute extends Route {
// =services
@service intl;
@service notify;
// =methods
+1 -1
View File
@@ -9,7 +9,7 @@ export default class ScopesScopeUsersRoute extends Route {
// =services
@service intl;
@service notify;
@service session;
@service can;
@service router;
@@ -9,7 +9,6 @@ export default class ScopesScopeUsersUserAccountsRoute extends Route {
// =services
@service intl;
@service notify;
// =methods
@@ -9,7 +9,7 @@ export default class ScopesScopeUsersUserAddAccountsRoute extends Route {
// =services
@service intl;
@service notify;
@service router;
// =methods
+20 -10
View File
@@ -84,16 +84,26 @@
</Rose::Layout::Global>
<EmberNotify @closeAfter={{this.notifyTimeout}} as |message close|>
<Rose::Notification
@style={{message.type}}
@heading={{t (concat 'states.' message.type)}}
@dismiss={{close}}
@dismissText={{t 'actions.dismiss'}}
>
{{message.text}}
</Rose::Notification>
</EmberNotify>
{{#if this.flashMessages.queue}}
<div class='ember-notify-cn ember-notify-default'>
{{#each this.flashMessages.queue as |flash|}}
<div
class='ember-notify-show callout
{{flash.noticationType}}
ember-view ember-notify clearfix'
>
<Rose::Notification
@style={{flash.noticationType}}
@heading={{t (concat 'states.' flash.noticationType)}}
@dismiss={{fn flash.dismiss flash}}
@dismissText={{t 'actions.dismiss'}}
>
{{flash.message}}
</Rose::Notification>
</div>
{{/each}}
</div>
{{/if}}
<PendingConfirmations as |confirmation accept deny|>
{{#if confirmation.options.isAbandonConfirm}}
+6 -2
View File
@@ -51,7 +51,6 @@ module.exports = function (environment) {
appName: APP_NAME,
companyName: 'HashiCorp',
notifyTimeout: 4000,
sessionPollingTimeoutSeconds: 300,
oidcPollingTimeoutSeconds: 1,
@@ -101,6 +100,10 @@ module.exports = function (environment) {
directory: '../../addons/api/mirage',
},
flashMessageDefaults: {
timeout: 4000,
},
featureFlags: featureEditions[EDITION],
};
@@ -139,7 +142,8 @@ module.exports = function (environment) {
ENV.APP.autoboot = false;
// Notification timeout should be 0 for fast tests
ENV.notifyTimeout = 0;
ENV.flashMessageDefaults.timeout = 0;
ENV.enableConfirmService = false;
// Enable tests for development features
+1 -1
View File
@@ -60,6 +60,7 @@
"ember-cli-code-coverage": "^1.0.3",
"ember-cli-content-security-policy": "^2.0.3",
"ember-cli-dependency-checker": "^3.2.0",
"ember-cli-flash": "^4.0.0",
"ember-cli-htmlbars": "^5.7.1",
"ember-cli-inject-live-reload": "^2.1.0",
"ember-cli-sass": "^10.0.1",
@@ -72,7 +73,6 @@
"ember-load-initializers": "^2.1.2",
"ember-maybe-import-regenerator": "^1.0.0",
"ember-modifier": "^2.1.2",
"ember-notify": "^6.0.1",
"ember-page-title": "^7.0.0",
"ember-pollster": "^0.0.1-beta.2",
"ember-qunit": "^5.1.4",
+3
View File
@@ -0,0 +1,3 @@
import FlashObject from 'ember-cli-flash/flash/object';
FlashObject.reopen({ init() {} });
+2
View File
@@ -4,6 +4,8 @@ import * as QUnit from 'qunit';
import { setApplication } from '@ember/test-helpers';
import { setup } from 'qunit-dom';
//import { start } from 'ember-qunit';
import './helpers/flash-message';
import start from 'ember-exam/test-support/start';
setApplication(Application.create(config.APP));
+1 -5
View File
@@ -1,13 +1,9 @@
import Controller from '@ember/controller';
import { inject as service } from '@ember/service';
import config from '../config/environment';
export default class ApplicationController extends Controller {
// =services
@service session;
// =attributes
notifyTimeout = config.notifyTimeout;
@service flashMessages;
}
+6 -2
View File
@@ -11,7 +11,7 @@ export default class ClusterUrlRoute extends Route {
@service session;
@service clusterUrl;
@service intl;
@service notify;
@service flashMessages;
@service router;
// =attributes
@@ -78,7 +78,11 @@ export default class ClusterUrlRoute extends Route {
const errorMessage = this.intl.t(
'errors.cluster-url-verification-failed.description'
);
this.notify.error(errorMessage, { closeAfter: null });
this.flashMessages.danger(errorMessage, {
noticationType: 'error',
sticky: true,
dismiss: (flash) => flash.destroyMessage(),
});
}
}
}
@@ -9,7 +9,7 @@ export default class ScopesScopeAuthenticateMethodRoute extends Route {
// =services
@service session;
@service notify;
@service ipc;
@service intl;
@service router;
@@ -13,7 +13,7 @@ export default class ScopesScopeProjectsTargetsRoute extends Route {
@service ipc;
@service session;
@service clusterUrl;
@service notify;
@service confirm;
@service resourceFilterStore;
@service router;
@@ -8,7 +8,7 @@ export default class ScopesScopeProjectsTargetsTargetHostsRoute extends Route {
@service ipc;
@service session;
@service clusterUrl;
@service notify;
@service confirm;
// =methods
+20 -10
View File
@@ -90,16 +90,26 @@
</Rose::Layout::Global>
<EmberNotify @closeAfter={{this.notifyTimeout}} as |message close|>
<Rose::Notification
@style={{message.type}}
@heading={{t (concat 'states.' message.type)}}
@dismiss={{close}}
@dismissText={{t 'actions.dismiss'}}
>
{{message.text}}
</Rose::Notification>
</EmberNotify>
{{#if this.flashMessages.queue}}
<div class='ember-notify-cn ember-notify-default'>
{{#each this.flashMessages.queue as |flash|}}
<div
class='ember-notify-show callout
{{flash.noticationType}}
ember-view ember-notify clearfix'
>
<Rose::Notification
@style={{flash.noticationType}}
@heading={{t (concat 'states.' flash.noticationType)}}
@dismiss={{fn flash.dismiss flash}}
@dismissText={{t 'actions.dismiss'}}
>
{{flash.message}}
</Rose::Notification>
</div>
{{/each}}
</div>
{{/if}}
<PendingConfirmations as |confirmation accept deny|>
{{#if confirmation.options.isConnectError}}
+5 -2
View File
@@ -42,7 +42,6 @@ module.exports = function (environment) {
appName: APP_NAME,
notifyTimeout: 4000,
sessionPollingTimeoutSeconds: 300,
oidcPollingTimeoutSeconds: 1,
@@ -54,6 +53,10 @@ module.exports = function (environment) {
},
},
flashMessageDefaults: {
timeout: 4000,
},
featureFlags: {
search: false,
filter: true,
@@ -93,7 +96,7 @@ module.exports = function (environment) {
ENV.APP.autoboot = false;
// Notification timeout should be 0 for fast tests
ENV.notifyTimeout = 0;
ENV.flashMessageDefaults.timeout = 0;
ENV.enableConfirmService = false;
+1 -1
View File
@@ -78,6 +78,7 @@
"ember-cli-babel": "^7.26.8",
"ember-cli-code-coverage": "^1.0.3",
"ember-cli-dependency-checker": "^3.2.0",
"ember-cli-flash": "^4.0.0",
"ember-cli-htmlbars": "^5.7.1",
"ember-cli-inject-live-reload": "^2.1.0",
"ember-cli-sass": "^10.0.1",
@@ -91,7 +92,6 @@
"ember-load-initializers": "^2.1.2",
"ember-maybe-import-regenerator": "^1.0.0",
"ember-modifier": "^2.1.2",
"ember-notify": "^6.0.1",
"ember-page-title": "^7.0.0",
"ember-pollster": "^0.0.1-beta.2",
"ember-qunit": "^5.1.4",
@@ -0,0 +1,3 @@
import FlashObject from 'ember-cli-flash/flash/object';
FlashObject.reopen({ init() {} });
+1
View File
@@ -4,6 +4,7 @@ import * as QUnit from 'qunit';
import { setApplication } from '@ember/test-helpers';
import { setup } from 'qunit-dom';
import { start } from 'ember-qunit';
import './helpers/flash-message';
setApplication(Application.create(config.APP));
+24 -20
View File
@@ -3869,7 +3869,7 @@
ember-cli-babel "^7.22.1"
ember-compatibility-helpers "^1.1.1"
"@ember/render-modifiers@^1.0.2 || ^2.0.0", "@ember/render-modifiers@^2.0.4":
"@ember/render-modifiers@^1.0.2 || ^2.0.0", "@ember/render-modifiers@^2.0.2", "@ember/render-modifiers@^2.0.4":
version "2.0.4"
resolved "https://registry.yarnpkg.com/@ember/render-modifiers/-/render-modifiers-2.0.4.tgz#0ac7af647cb736076dbfcd54ca71e090cd329d71"
integrity sha512-Zh/fo5VUmVzYHkHVvzWVjJ1RjFUxA2jH0zCp2+DQa80Bf3DUXauiEByxU22UkN4LFT55DBFttC0xCQSJG3WTsg==
@@ -9742,9 +9742,9 @@ caniuse-api@^3.0.0:
lodash.uniq "^4.5.0"
caniuse-lite@^1.0.0, caniuse-lite@^1.0.30001109, caniuse-lite@^1.0.30001157, caniuse-lite@^1.0.30001370:
version "1.0.30001370"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001370.tgz#0a30d4f20d38b9e108cc5ae7cc62df9fe66cd5ba"
integrity sha512-3PDmaP56wz/qz7G508xzjx8C+MC2qEm4SYhSEzC9IBROo+dGXFWRuaXkWti0A9tuI00g+toiriVqxtWMgl350g==
version "1.0.30001382"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001382.tgz#4d37f0d0b6fffb826c8e5e1c0f4bf8ce592db949"
integrity sha512-2rtJwDmSZ716Pxm1wCtbPvHtbDWAreTPxXbkc5RkKglow3Ig/4GNGazDI9/BVnXbG/wnv6r3B5FEbkfg9OcTGg==
capture-exit@^2.0.0:
version "2.0.0"
@@ -11839,7 +11839,7 @@ ember-auto-import@^1.11.3:
walk-sync "^0.3.3"
webpack "^4.43.0"
ember-auto-import@^2.4.2:
ember-auto-import@^2.4.1, ember-auto-import@^2.4.2:
version "2.4.2"
resolved "https://registry.yarnpkg.com/ember-auto-import/-/ember-auto-import-2.4.2.tgz#d4d3bc6885a11cf124f606f5c37169bdf76e37ae"
integrity sha512-REh+1aJWpTkvN42a/ga41OuRpUsSW7UQfPr2wPtYx56o/xoSNhVBXejy7yV9ObrkN7gogz6fs2xZwih5cOwpYg==
@@ -12012,6 +12012,18 @@ ember-cli-dependency-checker@^3.2.0:
resolve "^1.5.0"
semver "^5.3.0"
ember-cli-flash@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/ember-cli-flash/-/ember-cli-flash-4.0.0.tgz#e6886a9a76718c7740942eb812d3f5427f15760d"
integrity sha512-FEynX637xuFlmjMptAUBlww+GeYBcalnMYtDtzsBtLvnsBfU2Gd8xZVrCqQaqEAmHobxKLrYdTKu0YSY7ptIuQ==
dependencies:
"@ember/render-modifiers" "^2.0.2"
"@glimmer/component" "^1.1.2"
"@glimmer/tracking" "^1.1.2"
ember-auto-import "^2.4.1"
ember-cli-babel "^7.26.11"
ember-cli-htmlbars "^6.0.1"
ember-cli-get-component-path-option@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/ember-cli-get-component-path-option/-/ember-cli-get-component-path-option-1.0.0.tgz#0d7b595559e2f9050abed804f1d8eff1b08bc771"
@@ -12047,7 +12059,7 @@ ember-cli-htmlbars@^4.0.0, ember-cli-htmlbars@^4.2.1, ember-cli-htmlbars@^4.3.1:
strip-bom "^4.0.0"
walk-sync "^2.0.2"
ember-cli-htmlbars@^5.3.1, ember-cli-htmlbars@^5.3.2, ember-cli-htmlbars@^5.7.1:
ember-cli-htmlbars@^5.3.1, ember-cli-htmlbars@^5.7.1:
version "5.7.1"
resolved "https://registry.yarnpkg.com/ember-cli-htmlbars/-/ember-cli-htmlbars-5.7.1.tgz#eb5b88c7d9083bc27665fb5447a9b7503b32ce4f"
integrity sha512-9laCgL4tSy48orNoQgQKEHp93MaqAs9ZOl7or5q+8iyGGJHW6sVXIYrVv5/5O9HfV6Ts8/pW1rSoaeKyLUE+oA==
@@ -12759,14 +12771,6 @@ ember-named-blocks-polyfill@^0.2.5:
ember-cli-babel "^7.19.0"
ember-cli-version-checker "^5.1.1"
ember-notify@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/ember-notify/-/ember-notify-6.0.1.tgz#bc1c0c623488dbe984bb047d905cbc3d7c56cf8c"
integrity sha512-OzDsj6JpTqMIC0w7AB0umxWmzVX29VfRHTs3c6KZ6ew3D0cUMqI1OclJygXez/NKubPKZI3BSOgg1hohNOwqUQ==
dependencies:
ember-cli-babel "^7.23.1"
ember-cli-htmlbars "^5.3.2"
ember-page-title@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/ember-page-title/-/ember-page-title-7.0.0.tgz#11bebd4901d80757646c9006954a13e4fc187421"
@@ -21700,9 +21704,9 @@ printf@^0.6.1:
integrity sha512-is0ctgGdPJ5951KulgfzvHGwJtZ5ck8l042vRkV6jrkpBzTmb/lueTqguWHy2JfVA+RY6gFVlaZgUS0j7S/dsw==
prismjs@^1.21.0, prismjs@^1.27.0, prismjs@~1.24.0:
version "1.28.0"
resolved "https://registry.yarnpkg.com/prismjs/-/prismjs-1.28.0.tgz#0d8f561fa0f7cf6ebca901747828b149147044b6"
integrity sha512-8aaXdYvl1F7iC7Xm1spqSaY/OJBpYW3v+KJ+F17iYxvdc8sfjW194COK5wVhMZX45tGteiBQgdvD/nhxcRwylw==
version "1.29.0"
resolved "https://registry.yarnpkg.com/prismjs/-/prismjs-1.29.0.tgz#f113555a8fa9b57c35e637bba27509dcf802dd12"
integrity sha512-Kx/1w86q/epKcmte75LNrEoT+lX8pBpavuAbvJWRXar7Hz8jrtF+e3vY751p0R8H9HdArwaCTNDDzHg/ScJK1Q==
private@^0.1.8:
version "0.1.8"
@@ -24979,9 +24983,9 @@ terser-webpack-plugin@^5.1.3:
terser "^5.7.2"
terser@^4.1.2, terser@^4.6.3, terser@^5.14.2, terser@^5.3.0, terser@^5.3.4, terser@^5.7.2:
version "5.14.2"
resolved "https://registry.yarnpkg.com/terser/-/terser-5.14.2.tgz#9ac9f22b06994d736174f4091aa368db896f1c10"
integrity sha512-oL0rGeM/WFQCUd0y2QrWxYnq7tfSuKBiqTjRPWrRgB46WD/kiwHwF8T23z78H6Q6kGCuuHcPB+KULHRdxvVGQA==
version "5.15.0"
resolved "https://registry.yarnpkg.com/terser/-/terser-5.15.0.tgz#e16967894eeba6e1091509ec83f0c60e179f2425"
integrity sha512-L1BJiXVmheAQQy+as0oF3Pwtlo4s3Wi1X2zNZ2NxOB4wx9bdS9Vk67XQENLFdLYGCK/Z2di53mTj/hBafR+dTA==
dependencies:
"@jridgewell/source-map" "^0.3.2"
acorn "^8.5.0"