Ghost/ghost/admin/app/components/modal-custom-view-form.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

55 lines
1.7 KiB
JavaScript

import ModalComponent from 'ghost-admin/components/modal-base';
import {resetQueryParams} from 'ghost-admin/helpers/reset-query-params';
import {inject as service} from '@ember/service';
import {task, timeout} from 'ember-concurrency';
export default ModalComponent.extend({
customViews: service(),
router: service(),
delayedModelColor: '',
confirm() {},
init() {
this._super(...arguments);
this.set('model', this.customViews.editView());
this._setDelayedModelColor.perform();
},
actions: {
changeColor(event) {
let color = event.target.value;
this.set('model.color', color);
this.set('delayedModelColor', color);
},
confirm() {
return this.saveTask.perform();
}
},
saveTask: task(function* () {
let view = yield this.customViews.saveViewTask.perform(this.model);
this.send('closeModal');
return view;
}),
deleteTask: task(function* () {
let view = yield this.customViews.deleteViewTask.perform(this.model);
let routeName = this.router.currentRouteName;
this.send('closeModal');
this.router.transitionTo(routeName, {queryParams: resetQueryParams(routeName)});
return view;
}),
// this is a hack to get around radio buttons not working with liquid-fire.
// The DOM is duplicated whilst animating-in so browsers end up setting the
// checked property on the temporary DOM. Delaying the value being set
// allows us to ensure we're updating the checked property after animation
_setDelayedModelColor: task(function* () {
yield timeout(200);
this.set('delayedModelColor', this.model.color);
})
});