Ghost/ghost/admin/app/helpers/reset-query-params.js
Kevin Ansfield a3c71b8ba8 Fixed query params not resetting when deleting a custom view
no issue

- added a `transitionTo` after deleting a custom view that transitions to the `posts` route with default query params
- refactored `reset-posts-query` helper to a more generic `reset-query-params` helper
  - moved default query params definitions to this helper and expose them so we have a single source of truth
  - exposed `resetQueryParams()` function from the helper for use outside of templates
  - adjust the function and helper behaviour to accept the route name as the first param so that `router.currentRouteName` can be used as a generic reset
2020-02-03 16:38:14 +00:00

23 lines
661 B
JavaScript

import {helper} from '@ember/component/helper';
export const DEFAULT_QUERY_PARAMS = {
posts: {
type: null,
author: null,
tag: null,
order: null
}
};
// in order to reset query params to their defaults when using <LinkTo> or
// `transitionTo` it's necessary to explicitly set each param. This helper makes
// it easier to provide a "resetting" link, especially when used with custom views
export function resetQueryParams(routeName, newParams) {
return Object.assign({}, DEFAULT_QUERY_PARAMS[routeName], newParams);
}
export default helper(function (params/*, hash*/) {
return resetQueryParams(...params);
});