From b4e8b1be8b90573925285ae4df98aaa05b31d1ba Mon Sep 17 00:00:00 2001 From: Randall Morey Date: Thu, 23 Jul 2020 11:31:46 -0400 Subject: [PATCH] chore: add projects CRUDL functionality --- ui/core/app/routes/scopes/scope/projects.js | 4 +++- ui/core/mirage/config.js | 11 ++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/ui/core/app/routes/scopes/scope/projects.js b/ui/core/app/routes/scopes/scope/projects.js index f2a5fa77b..ebc5e97e5 100644 --- a/ui/core/app/routes/scopes/scope/projects.js +++ b/ui/core/app/routes/scopes/scope/projects.js @@ -55,6 +55,7 @@ export default class ScopesScopeProjectsRoute extends Route { async save(project) { try { await project.save(); + this.refresh(); // TODO: replace with translated strings this.notify.success('Save succeeded.'); this.transitionTo('scopes.scope.projects.project', project); @@ -72,7 +73,8 @@ export default class ScopesScopeProjectsRoute extends Route { async delete(project) { try { await project.destroyRecord(); - this.transitionTo('orgs.org.projects'); + this.refresh(); + this.transitionTo('scopes.scope.projects'); // TODO: replace with translated strings this.notify.success('Deleted project succesfully.'); } catch (error) { diff --git a/ui/core/mirage/config.js b/ui/core/mirage/config.js index d27476462..6e554c34a 100644 --- a/ui/core/mirage/config.js +++ b/ui/core/mirage/config.js @@ -24,7 +24,16 @@ export default function() { return scope.scope ? scope.scope.id === scope_id : false }); }); - this.post('/scopes'); + this.post('/scopes', function ({ scopes }, request) { + // Parent scope comes through the payload via `scope_id`, but this needs + // to be expanded to a scope object `scope: {id:..., type:...}` before + // saving, which is the gist of this function. + const attrs = this.normalizedRequestAttrs(); + const parentScopeAttrs = this.serialize(scopes.find(attrs.scopeId)); + delete attrs.scopeId; + attrs.scope = parentScopeAttrs; + return scopes.create(attrs); + }); // To simulate a possible real-world case, org scopes are not returned, // but project scopes are. // TODO this should be expanded to support other scenarios.