Refactor route action helper - icu-6773 (#1427)
* refactor: 💡 explicitly inject the store service - icu-6770 ✅ Closes: icu-6770 * refactor: 💡 upgrade to ember-intl 6.0.1 includes locale initialization and smoke tests * refactor: 💡 migrate admin and desktop to ember-intl 6.x ✅ Closes: icu-6771 * chore: 🤖 exclude cldr-core@38.1.0 from license checking this license was manually checked * fix: 🐛 fix text naming and linting * refactor: 💡 pull route-action local and update for ember 4 ✅ Closes: icu-6773
This commit is contained in:
1 parent
0c819d6d12
commit
561ed0b2e1
4 files changed
+72
-33
No files matched your search
@@ -0,0 +1,64 @@
|
||||
import Helper from '@ember/component/helper';
|
||||
import { inject as service } from '@ember/service';
|
||||
import { join } from '@ember/runloop';
|
||||
import { runInDebug, assert } from '@ember/debug';
|
||||
import { A } from '@ember/array';
|
||||
|
||||
/**
|
||||
* This helper is a modern update on ember-route-action-helper, which is
|
||||
* now unmaintained.
|
||||
*
|
||||
* See https://github.com/DockYard/ember-route-action-helper
|
||||
*/
|
||||
export default class RouteActionHelper extends Helper {
|
||||
// =services
|
||||
|
||||
@service router;
|
||||
|
||||
// =attributes
|
||||
|
||||
get routes() {
|
||||
const { currentInfos, mapBy } = this.currentInfos;
|
||||
return A(currentInfos).mapBy(mapBy).reverse();
|
||||
}
|
||||
|
||||
get currentInfos() {
|
||||
// eslint-disable-next-line ember/no-private-routing-service
|
||||
const routerLib = this.router._router._routerMicrolib;
|
||||
return {
|
||||
currentInfos:
|
||||
routerLib.currentRouteInfos || routerLib.currentHandlerInfos,
|
||||
mapBy: (routerLib.currentRouteInfos && 'route') || 'handler',
|
||||
};
|
||||
}
|
||||
|
||||
// =methods
|
||||
|
||||
compute([actionName, ...outerArgs]) {
|
||||
const { action, handler } = this.getRouteWithAction(actionName);
|
||||
|
||||
runInDebug(() => {
|
||||
assert(
|
||||
`
|
||||
[boundary-core-helper-route-action]
|
||||
Unable to find action ${actionName}
|
||||
`,
|
||||
handler
|
||||
);
|
||||
});
|
||||
|
||||
return (...innerArgs) =>
|
||||
join(handler, action, ...outerArgs.concat(innerArgs));
|
||||
}
|
||||
|
||||
getRouteWithAction(actionName) {
|
||||
let action;
|
||||
const handler = A(this.routes).find((route) => {
|
||||
const actions = route.actions || route._actions;
|
||||
action = actions[actionName];
|
||||
return typeof action === 'function';
|
||||
});
|
||||
|
||||
return { action, handler };
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user