open-vault/ui/app/components/namespace-link.js
Angel Garbarino fd8250adf9
Bug: switching between namespaces using the namespace-link caused the model not to refresh (#10572)
* fix issue with model not reloading on href-to previously tried to fix after upgrade.

* replace with normalizednamepsace and setup for testing

* add the same functionality to the switch namespace link

* meep, wrong branch

* wow it's friday, correct branch

* add changelog for upgrade, didn't do earlier.

* another friday move

* correct change to changelog for ember upgrade

* remove and make another pr

* remove href-to dep and add comment
2021-01-04 14:26:26 -07:00

54 lines
1.6 KiB
JavaScript

import Ember from 'ember';
import { inject as service } from '@ember/service';
import { alias } from '@ember/object/computed';
import Component from '@ember/component';
import { computed } from '@ember/object';
export default Component.extend({
namespaceService: service('namespace'),
currentNamespace: alias('namespaceService.path'),
tagName: '',
//public api
targetNamespace: null,
showLastSegment: false,
normalizedNamespace: computed('targetNamespace', function() {
let ns = this.targetNamespace;
return (ns || '').replace(/\.+/g, '/').replace(/☃/g, '.');
}),
namespaceDisplay: computed('normalizedNamespace', 'showLastSegment', function() {
let ns = this.normalizedNamespace;
let showLastSegment = this.showLastSegment;
let parts = ns.split('/');
if (ns === '') {
return 'root';
}
return showLastSegment ? parts[parts.length - 1] : ns;
}),
isCurrentNamespace: computed('targetNamespace', 'currentNamespace', function() {
return this.currentNamespace === this.targetNamespace;
}),
get namespaceLink() {
if (Ember.testing) {
if (this.normalizedNamespace) {
return `/ui/vault/secrets?namespace=${this.normalizedNamespace}`;
}
return `/ui/vault/secrets`;
}
let origin =
window.location.protocol +
'//' +
window.location.hostname +
(window.location.port ? ':' + window.location.port : '');
if (!this.normalizedNamespace) return `${origin}/ui/vault/secrets`;
// The full URL/origin is required so that the page is reloaded.
return `${origin}/ui/vault/secrets?namespace=${encodeURIComponent(this.normalizedNamespace)}`;
},
});