refactor: 💡 Move save back to route to unblock other work (#1598)

This commit is contained in:
Zhihe Li authored and GitHub committed 2023-01-23 14:32:31 -05:00
1 parent cf16bf8e33
commit da59684f25
4 files changed
+38 -44

No files matched your search

@@ -1,5 +1,5 @@
<Rose::Form
@onSubmit={{this.submit}}
@onSubmit={{@submit}}
@cancel={{@cancel}}
@disabled={{@model.isSaving}}
@showEditToggle={{if @model.isNew false true}}
@@ -1,10 +1,8 @@
import Component from '@glimmer/component';
import { TYPES_TARGET } from 'api/models/target';
import { loading } from 'ember-loading';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';
import { notifyError } from 'core/decorators/notify';
import { tracked } from '@glimmer/tracking';
// NOTE: this is all a temporary solution till we have a resource type helper.
const types = [...TYPES_TARGET].reverse();
const icons = {
@@ -18,10 +16,6 @@ export default class FormTargetComponent extends Component {
this.args.model.egress_worker_filter?.length;
@tracked migrateWorkerFilter = false;
// =services
@service confirm;
@service intl;
// =properties
/**
@@ -78,39 +72,4 @@ export default class FormTargetComponent extends Component {
this.args.model.egress_worker_filter = this.args.model.worker_filter;
this.args.model.worker_filter = '';
}
@action
@loading
@notifyError(({ message }) => message)
async submit() {
const target = this.args.model;
const numHostSources = target.host_sources?.length;
const address = target.address;
if (address && numHostSources) {
try {
await this.confirm.confirm(
this.intl.t(
'resources.target.questions.delete-host-sources.message',
{ numHostSources }
),
{
title: 'resources.target.questions.delete-host-sources.title',
confirm: 'actions.remove-resources',
}
);
} catch (e) {
// if the user denies, do nothing and return
return;
}
await target.removeHostSources(
target.host_sources.map((hs) => hs.host_source_id)
);
// After saving the host sources, the model gets reset to an empty address,
// so we need to update the address with the previous value before saving
target.address = address;
}
await this.args.submit();
}
}