@fleetbase/ember-core 0.1.7 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,12 +1,13 @@
1
1
  import Service from '@ember/service';
2
2
  import { inject as service } from '@ember/service';
3
- import { action } from '@ember/object';
3
+ import { action, get } from '@ember/object';
4
4
  import { isArray } from '@ember/array';
5
5
  import { dasherize } from '@ember/string';
6
6
  import { later } from '@ember/runloop';
7
7
  import { pluralize } from 'ember-inflector';
8
8
  import { format as formatDate } from 'date-fns';
9
9
  import getModelName from '../utils/get-model-name';
10
+ import getWithDefault from '../utils/get-with-default';
10
11
  import humanize from '../utils/humanize';
11
12
  import first from '../utils/first';
12
13
 
@@ -47,7 +48,7 @@ export default class CrudService extends Service {
47
48
  * @void
48
49
  */
49
50
  @action delete(model, options = {}) {
50
- const modelName = getModelName(model, options?.modelName, { humanize: true, capitalizeWords: true });
51
+ const modelName = getModelName(model, get(options, 'modelName'), { humanize: true, capitalizeWords: true });
51
52
 
52
53
  this.modalsManager.confirm({
53
54
  title: `Are you sure to delete this ${modelName}?`,
@@ -98,7 +99,7 @@ export default class CrudService extends Service {
98
99
  }
99
100
 
100
101
  const firstModel = first(selected);
101
- const modelName = getModelName(firstModel, options?.modelName, { humanize: true, capitalizeWords: true });
102
+ const modelName = getModelName(firstModel, get(options, 'modelName'), { humanize: true, capitalizeWords: true });
102
103
 
103
104
  // make sure all are the same type
104
105
  selected = selected.filter((m) => getModelName(m) === getModelName(firstModel));
@@ -126,9 +127,11 @@ export default class CrudService extends Service {
126
127
  }
127
128
 
128
129
  const firstModel = first(selected);
129
- const modelName = getModelName(firstModel, options?.modelName, { humanize: true, capitalizeWords: true });
130
+ const modelName = getModelName(firstModel, get(options, 'modelName'), { humanize: true, capitalizeWords: true });
130
131
  const count = selected.length;
131
132
  const actionMethod = (typeof options.actionMethod === 'string' ? options.actionMethod : `POST`).toLowerCase();
133
+ const fetchParams = getWithDefault(options, 'fetchParams', {});
134
+ const fetchOptions = getWithDefault(options, 'fetchOptions', {});
132
135
 
133
136
  this.modalsManager.show('modals/bulk-action-model', {
134
137
  title: `Bulk ${verb} ${pluralize(modelName)}`,
@@ -152,9 +155,14 @@ export default class CrudService extends Service {
152
155
 
153
156
  modal.startLoading();
154
157
 
155
- return this.fetch[actionMethod](options.actionPath, {
156
- ids: selected.map((model) => model.id),
157
- })
158
+ return this.fetch[actionMethod](
159
+ options.actionPath,
160
+ {
161
+ ids: selected.map((model) => model.id),
162
+ ...fetchParams,
163
+ },
164
+ fetchOptions
165
+ )
158
166
  .then((response) => {
159
167
  this.notifications.success(response.message ?? options.successNotification ?? `${count} ${pluralize(modelName, count)} were updated successfully.`);
160
168
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fleetbase/ember-core",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "description": "Provides all the core services, decorators and utilities for building a Fleetbase extension for the Console.",
5
5
  "keywords": [
6
6
  "fleetbase-core",