Skip to content

Commit

Permalink
Go back to 1.6 code for namespace selector
Browse files Browse the repository at this point in the history
  • Loading branch information
wg102 committed Aug 31, 2023
1 parent b382626 commit 109a721
Showing 1 changed file with 11 additions and 74 deletions.
85 changes: 11 additions & 74 deletions components/centraldashboard/public/components/namespace-selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,6 @@ import localizationMixin from './localization-mixin.js';

import {html, PolymerElement} from '@polymer/polymer/polymer-element.js';

export const ALL_NAMESPACES = 'All namespaces';
export const ALL_NAMESPACES_ALLOWED_LIST = ['jupyter', 'volumes',
'tensorboards'];

const allNamespacesAllowedPaths = ALL_NAMESPACES_ALLOWED_LIST
.map(( p)=>`/_/${p}/`);

/**
* Component to retrieve and allow namespace selection. Bubbles the selected
* items up to the query string in the 'ns' parameter.
Expand Down Expand Up @@ -98,8 +91,7 @@ export class NamespaceSelector extends localizationMixin(PolymerElement) {
attr-for-selected="name" selected="{{selected}}">
<template is="dom-repeat" items="{{namespaces}}" as="n">
<paper-item name="[[n.namespace]]" title$='[[n.role]]'
owner$='[[isOwner(n.role)]]'
disabled$="[[n.disabled]]">
owner$='[[isOwner(n.role)]]'>
[[n.namespace]]
<template is="dom-if" if="[[isOwner(n.role)]]">
<span class="owner">
Expand All @@ -119,7 +111,6 @@ export class NamespaceSelector extends localizationMixin(PolymerElement) {
static get properties() {
return {
queryParams: Object,
route: Object,
namespaces: Array,
selected: {
type: String,
Expand All @@ -128,7 +119,6 @@ export class NamespaceSelector extends localizationMixin(PolymerElement) {
notify: true,
},
allNamespaces: {type: Boolean, value: false},
user: String,
selectedNamespaceIsOwned: {
type: Boolean,
readOnly: true,
Expand All @@ -151,7 +141,6 @@ export class NamespaceSelector extends localizationMixin(PolymerElement) {
'_queryParamChanged(queryParams.ns)',
'_ownedContextChanged(namespaces, selected)',
'validate(selected, namespaces)',
'onRouteChange(route, queryParams)',
];
}

Expand Down Expand Up @@ -192,70 +181,18 @@ export class NamespaceSelector extends localizationMixin(PolymerElement) {
/**
* Validate internal state of the selector, and change selected state
* if needed
* @param {string} selected
* @param {[object]} namespaces
*/
validate(selected, namespaces) {
validate() {
const {namespaces} = this;
if (!namespaces) return;
const allNs = namespaces.map((i) => i.namespace);
if (allNs.includes(selected)) return;

const owned = this.getDefaultNamespace();

// Disable all-namespaces selector for AAW
// if (selected === ALL_NAMESPACES
// && allNamespacesAllowedPaths.includes(this.route.path)) {
// return;
// }

let newNamespace = '';
if (owned && owned.namespace) {
newNamespace = owned.namespace;
} else if (allNs.includes('kubeflow')) {
newNamespace = 'kubeflow';
}
this.selected = newNamespace;
}

/**
* Get the default namespace when needed by the namespace selector.
* @return {string}
*/
getDefaultNamespace() {
// Restore the user's previous namespace choice
const localStorageKey = '/centraldashboard/selectedNamespace/' +
(this.user && '.' + this.user || '');
const previousNamespaceName = localStorage.getItem(localStorageKey);
if (previousNamespaceName) {
const previousNamespace = this.namespaces.find(
(n) => n.namespace === previousNamespaceName);
if (previousNamespace) {
return previousNamespace;
}
}

return this.namespaces.find(
(n) => n.role == 'owner');
}

/**
* Observe route and query parameter changes and ensure that the 'ns' query
* query parameter has the correct value when a user navigates to another
* page that the 'All namespace' selection is not allowed.
* @param {object} route
* @param {object} queryParams
*/
onRouteChange(route, queryParams) {
if (route && !allNamespacesAllowedPaths.includes(route.path)
&& this.selected === ALL_NAMESPACES) {
const ns = this.getDefaultNamespace();
// Fix in order to ensure that the 'ns' parameter is not being
// overwritten by iron-location.
// See:
setTimeout(() => {
this.set('queryParams.ns', ns.namespace);
});
}
const nsSet = new Set(namespaces.map((i) => i.namespace));
if (nsSet.has(this.selected)) return;

const owned = namespaces.find((n) => n.role == 'owner');
this.selected = (owned && owned.namespace)
|| (nsSet.has('kubeflow')
? 'kubeflow'
: '');
}

/**
Expand Down

0 comments on commit 109a721

Please sign in to comment.