UI: Namespace area fixes (#19799)
This commit is contained in:
parent
59d3f5110d
commit
b7049eb3fc
|
@ -0,0 +1,3 @@
|
||||||
|
```release-note:bug
|
||||||
|
ui: Fix bad link to namespace when namespace name includes `.`
|
||||||
|
```
|
|
@ -5,28 +5,28 @@
|
||||||
|
|
||||||
import ApplicationAdapter from './application';
|
import ApplicationAdapter from './application';
|
||||||
|
|
||||||
export default ApplicationAdapter.extend({
|
export default class NamespaceAdapter extends ApplicationAdapter {
|
||||||
pathForType() {
|
pathForType() {
|
||||||
return 'namespaces';
|
return 'namespaces';
|
||||||
},
|
}
|
||||||
urlForFindAll(modelName, snapshot) {
|
urlForFindAll(modelName, snapshot) {
|
||||||
if (snapshot.adapterOptions && snapshot.adapterOptions.forUser) {
|
if (snapshot.adapterOptions && snapshot.adapterOptions.forUser) {
|
||||||
return `/${this.urlPrefix()}/internal/ui/namespaces`;
|
return `/${this.urlPrefix()}/internal/ui/namespaces`;
|
||||||
}
|
}
|
||||||
return `/${this.urlPrefix()}/namespaces?list=true`;
|
return `/${this.urlPrefix()}/namespaces?list=true`;
|
||||||
},
|
}
|
||||||
|
|
||||||
urlForCreateRecord(modelName, snapshot) {
|
urlForCreateRecord(modelName, snapshot) {
|
||||||
const id = snapshot.attr('path');
|
const id = snapshot.attr('path');
|
||||||
return this.buildURL(modelName, id);
|
return this.buildURL(modelName, id);
|
||||||
},
|
}
|
||||||
|
|
||||||
createRecord(store, type, snapshot) {
|
createRecord(store, type, snapshot) {
|
||||||
const id = snapshot.attr('path');
|
const id = snapshot.attr('path');
|
||||||
return this._super(...arguments).then(() => {
|
return super.createRecord(...arguments).then(() => {
|
||||||
return { id };
|
return { id };
|
||||||
});
|
});
|
||||||
},
|
}
|
||||||
|
|
||||||
findAll(store, type, sinceToken, snapshot) {
|
findAll(store, type, sinceToken, snapshot) {
|
||||||
if (snapshot.adapterOptions && typeof snapshot.adapterOptions.namespace !== 'undefined') {
|
if (snapshot.adapterOptions && typeof snapshot.adapterOptions.namespace !== 'undefined') {
|
||||||
|
@ -34,9 +34,9 @@ export default ApplicationAdapter.extend({
|
||||||
namespace: snapshot.adapterOptions.namespace,
|
namespace: snapshot.adapterOptions.namespace,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return this._super(...arguments);
|
return super.findAll(...arguments);
|
||||||
},
|
}
|
||||||
query() {
|
query() {
|
||||||
return this.ajax(`/${this.urlPrefix()}/namespaces?list=true`);
|
return this.ajax(`/${this.urlPrefix()}/namespaces?list=true`);
|
||||||
},
|
}
|
||||||
});
|
}
|
||||||
|
|
|
@ -16,10 +16,13 @@ export default Component.extend({
|
||||||
//public api
|
//public api
|
||||||
targetNamespace: null,
|
targetNamespace: null,
|
||||||
showLastSegment: false,
|
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 () {
|
normalizedNamespace: computed('targetNamespace', 'unparsed', function () {
|
||||||
const ns = this.targetNamespace;
|
const ns = this.targetNamespace || '';
|
||||||
return (ns || '').replace(/\.+/g, '/').replace(/☃/g, '.');
|
return this.unparsed ? ns : ns.replace(/\.+/g, '/').replace(/☃/g, '.');
|
||||||
}),
|
}),
|
||||||
|
|
||||||
namespaceDisplay: computed('normalizedNamespace', 'showLastSegment', function () {
|
namespaceDisplay: computed('normalizedNamespace', 'showLastSegment', function () {
|
||||||
|
|
|
@ -4,21 +4,21 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import Model, { attr } from '@ember-data/model';
|
import Model, { attr } from '@ember-data/model';
|
||||||
import { computed } from '@ember/object';
|
import { withExpandedAttributes } from 'vault/decorators/model-expanded-attributes';
|
||||||
import { expandAttributeMeta } from 'vault/utils/field-to-attrs';
|
|
||||||
|
|
||||||
export default Model.extend({
|
@withExpandedAttributes()
|
||||||
path: attr('string', {
|
export default class NamespaceModel extends Model {
|
||||||
|
@attr('string', {
|
||||||
validationAttr: 'pathIsValid',
|
validationAttr: 'pathIsValid',
|
||||||
invalidMessage: 'You have entered and invalid path please only include letters, numbers, -, ., and _.',
|
invalidMessage: 'You have entered and invalid path please only include letters, numbers, -, ., and _.',
|
||||||
}),
|
})
|
||||||
pathIsValid: computed('path', function () {
|
path;
|
||||||
|
|
||||||
|
get pathIsValid() {
|
||||||
return this.path && this.path.match(/^[\w\d-.]+$/g);
|
return this.path && this.path.match(/^[\w\d-.]+$/g);
|
||||||
}),
|
}
|
||||||
description: attr('string', {
|
|
||||||
editType: 'textarea',
|
get fields() {
|
||||||
}),
|
return ['path'].map((f) => this.allByKey[f]);
|
||||||
fields: computed(function () {
|
}
|
||||||
return expandAttributeMeta(this, ['path']);
|
}
|
||||||
}),
|
|
||||||
});
|
|
||||||
|
|
|
@ -5,7 +5,11 @@
|
||||||
|
|
||||||
import ApplicationSerializer from './application';
|
import ApplicationSerializer from './application';
|
||||||
|
|
||||||
export default ApplicationSerializer.extend({
|
export default class NamespaceSerializer extends ApplicationSerializer {
|
||||||
|
attrs = {
|
||||||
|
path: { serialize: false },
|
||||||
|
};
|
||||||
|
|
||||||
normalizeList(payload) {
|
normalizeList(payload) {
|
||||||
const data = payload.data.keys
|
const data = payload.data.keys
|
||||||
? payload.data.keys.map((key) => ({
|
? payload.data.keys.map((key) => ({
|
||||||
|
@ -16,7 +20,7 @@ export default ApplicationSerializer.extend({
|
||||||
: payload.data;
|
: payload.data;
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
},
|
}
|
||||||
|
|
||||||
normalizeResponse(store, primaryModelClass, payload, id, requestType) {
|
normalizeResponse(store, primaryModelClass, payload, id, requestType) {
|
||||||
const nullResponses = ['deleteRecord', 'createRecord'];
|
const nullResponses = ['deleteRecord', 'createRecord'];
|
||||||
|
@ -24,6 +28,6 @@ export default ApplicationSerializer.extend({
|
||||||
const normalizedPayload = nullResponses.includes(requestType)
|
const normalizedPayload = nullResponses.includes(requestType)
|
||||||
? { id: cid, path: cid }
|
? { id: cid, path: cid }
|
||||||
: this.normalizeList(payload);
|
: this.normalizeList(payload);
|
||||||
return this._super(store, primaryModelClass, normalizedPayload, id, requestType);
|
return super.normalizeResponse(store, primaryModelClass, normalizedPayload, id, requestType);
|
||||||
},
|
}
|
||||||
});
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@
|
||||||
{{#let (concat this.currentNamespace (if this.currentNamespace "/") list.item.id) as |targetNamespace|}}
|
{{#let (concat this.currentNamespace (if this.currentNamespace "/") list.item.id) as |targetNamespace|}}
|
||||||
{{#if (includes targetNamespace this.accessibleNamespaces)}}
|
{{#if (includes targetNamespace this.accessibleNamespaces)}}
|
||||||
<li class="action">
|
<li class="action">
|
||||||
<NamespaceLink @targetNamespace={{targetNamespace}} @class="is-block">
|
<NamespaceLink @targetNamespace={{targetNamespace}} @unparsed={{true}} @class="is-block">
|
||||||
Switch to Namespace
|
Switch to Namespace
|
||||||
</NamespaceLink>
|
</NamespaceLink>
|
||||||
</li>
|
</li>
|
||||||
|
|
Loading…
Reference in New Issue