Skip to content

Commit

Permalink
wip 5.4
Browse files Browse the repository at this point in the history
  • Loading branch information
roncodes committed Dec 8, 2023
1 parent ff58983 commit 3be4b02
Show file tree
Hide file tree
Showing 10 changed files with 2,691 additions and 4,035 deletions.
2 changes: 1 addition & 1 deletion .stylelintrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';

module.exports = {
extends: ['stylelint-config-standard', 'stylelint-prettier/recommended'],
extends: ['stylelint-config-standard', 'stylelint-prettier/recommended'],
};
5 changes: 2 additions & 3 deletions addon/services/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { get, set } from '@ember/object';
import { isBlank } from '@ember/utils';
import { dasherize } from '@ember/string';
import { isArray } from '@ember/array';
import { assign } from '@ember/polyfills';
import { singularize, pluralize } from 'ember-inflector';
import { task } from 'ember-concurrency';
import { storageFor } from 'ember-local-storage';
Expand Down Expand Up @@ -256,7 +255,7 @@ export default class FetchService extends Service {
* @return {Promise}
*/
request(path, method = 'GET', data = {}, options = {}) {
const headers = assign(this.getHeaders(), options.headers ?? {});
const headers = Object.assign(this.getHeaders(), options.headers ?? {});
const host = options.host ?? this.host;
const namespace = options.namespace ?? this.namespace;
const url = options.externalRequest === true ? path : [host, namespace, path].filter(Boolean).join('/');
Expand Down Expand Up @@ -574,7 +573,7 @@ export default class FetchService extends Service {
* @return {Promise}
*/
download(path, query = {}, options = {}) {
const headers = assign(this.getHeaders(), options.headers ?? {});
const headers = Object.assign(this.getHeaders(), options.headers ?? {});

return new Promise((resolve, reject) => {
return fetch(`${options.host || this.host}/${options.namespace || this.namespace}/${path}?${!isBlank(query) ? new URLSearchParams(query).toString() : ''}`, {
Expand Down
68 changes: 58 additions & 10 deletions addon/services/universe.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { tracked } from '@glimmer/tracking';
import { inject as service } from '@ember/service';
import { computed, action } from '@ember/object';
import { isBlank } from '@ember/utils';
import { isArray } from '@ember/array';
import { A, isArray } from '@ember/array';
import { later } from '@ember/runloop';
import { dasherize, camelize } from '@ember/string';
import { getOwner } from '@ember/application';
Expand All @@ -14,20 +14,20 @@ import RSVP from 'rsvp';
export default class UniverseService extends Service.extend(Evented) {
@service router;
@service intl;
@tracked headerMenuItems = [];
@tracked organizationMenuItems = [];
@tracked userMenuItems = [];
@tracked headerMenuItems = A([]);
@tracked organizationMenuItems = A([]);
@tracked userMenuItems = A([]);
@tracked adminRegistry = {
menuItems: [],
menuPanels: [],
menuItems: A([]),
menuPanels: A([]),
};
@tracked accountRegistry = {
menuItems: [],
menuPanels: [],
menuItems: A([]),
menuPanels: A([]),
};
@tracked settingsRegistry = {
menuItems: [],
menuPanels: [],
menuItems: A([]),
menuPanels: A([]),
};

/**
Expand Down Expand Up @@ -82,6 +82,54 @@ export default class UniverseService extends Service.extend(Evented) {
return this.settingsRegistry.menuPanels;
}

/**
* Transitions to a given route within a specified Ember engine.
*
* This action dynamically retrieves the specified engine's instance and its configuration to prepend the
* engine's route prefix to the provided route. If the engine instance or its route prefix is not found,
* it falls back to transitioning to the route without the prefix.
*
* @param {string} engineName - The name of the Ember engine.
* @param {string} route - The route to transition to within the engine.
* @param {...any} args - Additional arguments to pass to the router's transitionTo method.
* @returns {Promise} A Promise that resolves with the result of the router's transitionTo method.
*
* @example
* // Transitions to the 'management.fleets.index.new' route within the '@fleetbase/fleet-ops' engine.
* this.transitionToEngineRoute('@fleetbase/fleet-ops', 'management.fleets.index.new');
*/
@action transitionToEngineRoute(engineName, route, ...args) {
const engineInstance = this.getEngineInstance(engineName);

if (engineInstance) {
const config = engineInstance.resolveRegistration('config:environment');

if (config && typeof config.mountedEngineRoutePrefix === 'string') {
return this.router.transitionTo(`${config.mountedEngineRoutePrefix}${route}`, ...args);
}
}

return this.router.transitionTo(route, ...args);
}

/**
* Refreshes the current route.
*
* This action is a simple wrapper around the router's refresh method. It can be used to re-run the
* model hooks and reset the controller properties on the current route, effectively reloading the route.
* This is particularly useful in scenarios where the route needs to be reloaded due to changes in
* state or data.
*
* @returns {Promise} A Promise that resolves with the result of the router's refresh method.
*
* @example
* // To refresh the current route
* this.refreshRoute();
*/
@action refreshRoute() {
return this.router.refresh();
}

/**
* Action to transition to a specified route based on the provided menu item.
*
Expand Down
8 changes: 8 additions & 0 deletions addon/utils/array-unique-by.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default function arrayUniqueBy(arr, key) {
return arr.reduce((unique, item) => {
if (!unique.some((existingItem) => existingItem[key] === item[key])) {
unique.push(item);
}
return unique;
}, []);
}
1 change: 1 addition & 0 deletions app/utils/array-unique-by.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from '@fleetbase/ember-core/utils/array-unique-by';
3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,6 @@
"overrides": {
"broccoli-persistent-filter": "^3.1.3"
},
"peerDependencies": {
"ember-source": ">= 4.0.0"
},
"engines": {
"node": ">= 18"
},
Expand Down
Loading

0 comments on commit 3be4b02

Please sign in to comment.