Skip to content

Commit

Permalink
UI: Namespace area fixes (hashicorp#19799) (hashicorp#20024)
Browse files Browse the repository at this point in the history
* UI: Namespace area fixes (hashicorp#19799)

* Revert model changes due to unavailable decorator
  • Loading branch information
hashishaw authored Apr 7, 2023
1 parent 5f71b23 commit c626b64
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 19 deletions.
3 changes: 3 additions & 0 deletions changelog/19799.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
ui: Fix bad link to namespace when namespace name includes `.`
```
20 changes: 10 additions & 10 deletions ui/app/adapters/namespace.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
import ApplicationAdapter from './application';

export default ApplicationAdapter.extend({
export default class NamespaceAdapter extends ApplicationAdapter {
pathForType() {
return 'namespaces';
},
}
urlForFindAll(modelName, snapshot) {
if (snapshot.adapterOptions && snapshot.adapterOptions.forUser) {
return `/${this.urlPrefix()}/internal/ui/namespaces`;
}
return `/${this.urlPrefix()}/namespaces?list=true`;
},
}

urlForCreateRecord(modelName, snapshot) {
const id = snapshot.attr('path');
return this.buildURL(modelName, id);
},
}

createRecord(store, type, snapshot) {
const id = snapshot.attr('path');
return this._super(...arguments).then(() => {
return super.createRecord(...arguments).then(() => {
return { id };
});
},
}

findAll(store, type, sinceToken, snapshot) {
if (snapshot.adapterOptions && typeof snapshot.adapterOptions.namespace !== 'undefined') {
return this.ajax(this.urlForFindAll('namespace', snapshot), 'GET', {
namespace: snapshot.adapterOptions.namespace,
});
}
return this._super(...arguments);
},
return super.findAll(...arguments);
}
query() {
return this.ajax(`/${this.urlPrefix()}/namespaces?list=true`);
},
});
}
}
9 changes: 6 additions & 3 deletions ui/app/components/namespace-link.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ export default Component.extend({
//public api
targetNamespace: null,
showLastSegment: false,
// set to true if targetNamespace is passed in unmodified
// otherwise, this assumes it is parsed as in namespace-picker
unparsed: false,

normalizedNamespace: computed('targetNamespace', function () {
const ns = this.targetNamespace;
return (ns || '').replace(/\.+/g, '/').replace(//g, '.');
normalizedNamespace: computed('targetNamespace', 'unparsed', function () {
const ns = this.targetNamespace || '';
return this.unparsed ? ns : ns.replace(/\.+/g, '/').replace(//g, '.');
}),

namespaceDisplay: computed('normalizedNamespace', 'showLastSegment', function () {
Expand Down
14 changes: 9 additions & 5 deletions ui/app/serializers/namespace.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import ApplicationSerializer from './application';

export default ApplicationSerializer.extend({
export default class NamespaceSerializer extends ApplicationSerializer {
attrs = {
path: { serialize: false },
};

normalizeList(payload) {
const data = payload.data.keys
? payload.data.keys.map((key) => ({
Expand All @@ -11,14 +15,14 @@ export default ApplicationSerializer.extend({
: payload.data;

return data;
},
}

normalizeResponse(store, primaryModelClass, payload, id, requestType) {
const nullResponses = ['deleteRecord', 'createRecord'];
const cid = (id || payload.id || '').replace(/\/$/, '');
const normalizedPayload = nullResponses.includes(requestType)
? { id: cid, path: cid }
: this.normalizeList(payload);
return this._super(store, primaryModelClass, normalizedPayload, id, requestType);
},
});
return super.normalizeResponse(store, primaryModelClass, normalizedPayload, id, requestType);
}
}
2 changes: 1 addition & 1 deletion ui/app/templates/vault/cluster/access/namespaces/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
{{#let (concat this.currentNamespace (if this.currentNamespace "/") list.item.id) as |targetNamespace|}}
{{#if (includes targetNamespace this.accessibleNamespaces)}}
<li class="action">
<NamespaceLink @targetNamespace={{targetNamespace}} @class="is-block">
<NamespaceLink @targetNamespace={{targetNamespace}} @unparsed={{true}} @class="is-block">
Switch to Namespace
</NamespaceLink>
</li>
Expand Down

0 comments on commit c626b64

Please sign in to comment.