mirror of
https://github.com/status-im/consul.git
synced 2025-01-25 05:00:32 +00:00
5fb9df1640
* Adding explicit MPL license for sub-package This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository. * Adding explicit MPL license for sub-package This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository. * Updating the license from MPL to Business Source License Going forward, this project will be licensed under the Business Source License v1.1. Please see our blog post for more details at <Blog URL>, FAQ at www.hashicorp.com/licensing-faq, and details of the license at www.hashicorp.com/bsl. * add missing license headers * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 --------- Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
86 lines
2.3 KiB
JavaScript
86 lines
2.3 KiB
JavaScript
/**
|
|
* Copyright (c) HashiCorp, Inc.
|
|
* SPDX-License-Identifier: BUSL-1.1
|
|
*/
|
|
|
|
import Service, { inject as service } from '@ember/service';
|
|
import callableType from 'consul-ui/utils/callable-type';
|
|
|
|
const TYPE_SUCCESS = 'success';
|
|
const TYPE_ERROR = 'error';
|
|
const defaultStatus = function (type, obj) {
|
|
return type;
|
|
};
|
|
const notificationDefaults = function () {
|
|
return {
|
|
timeout: 6000,
|
|
extendedTimeout: 300,
|
|
destroyOnClick: true,
|
|
};
|
|
};
|
|
export default class FeedbackService extends Service {
|
|
@service('flashMessages') notify;
|
|
@service('logger') logger;
|
|
|
|
notification(action, modelName) {
|
|
return {
|
|
success: (item) => this.success(item, action, undefined, modelName),
|
|
error: (e) => this.error(e, action, undefined, modelName),
|
|
};
|
|
}
|
|
|
|
success(item, action, status = defaultStatus, model) {
|
|
const getAction = callableType(action);
|
|
const getStatus = callableType(status);
|
|
// returning exactly `false` for a feedback action means even though
|
|
// its successful, please skip this notification and don't display it
|
|
if (item !== false) {
|
|
this.notify.clearMessages();
|
|
// TODO right now the majority of `item` is a Transition
|
|
// but you can resolve an object
|
|
this.notify.add({
|
|
...notificationDefaults(),
|
|
type: getStatus(TYPE_SUCCESS),
|
|
// here..
|
|
action: getAction(),
|
|
item: item,
|
|
model: model,
|
|
});
|
|
}
|
|
}
|
|
|
|
error(e, action, status = defaultStatus, model) {
|
|
const getAction = callableType(action);
|
|
const getStatus = callableType(status);
|
|
this.notify.clearMessages();
|
|
this.logger.execute(e);
|
|
if (e.name === 'TransitionAborted') {
|
|
this.notify.add({
|
|
...notificationDefaults(),
|
|
type: getStatus(TYPE_SUCCESS),
|
|
// and here
|
|
action: getAction(),
|
|
model: model,
|
|
});
|
|
} else {
|
|
this.notify.add({
|
|
...notificationDefaults(),
|
|
type: getStatus(TYPE_ERROR, e),
|
|
action: getAction(),
|
|
error: e,
|
|
model: model,
|
|
});
|
|
}
|
|
}
|
|
|
|
async execute(handle, action, status, routeName) {
|
|
let result;
|
|
try {
|
|
result = await handle();
|
|
this.success(result, action, status, routeName);
|
|
} catch (e) {
|
|
this.error(e, action, status, routeName);
|
|
}
|
|
}
|
|
}
|