open-vault/ui/app/components/namespace-picker.js
Jordan Reimer c84d267c61
Sidebar Navigation (#19296)
* Add Helios Design System Components (#19278)

* adds hds dependency

* updates reset import path

* sets minifyCSS advanced option to false

* Remove node-sass (#19376)

* removes node-sass and fixes sass compilation

* fixes active tab li class

* Sidebar Navigation Components (#19446)

* links ember-shared-components addon and imports styles

* adds sidebar frame and nav components

* updates HcNav component name to HcAppFrame and adds sidebar UserMenu component

* adds tests for sidebar components

* fixes tests

* updates user menu styling

* fixes typos in nav cluster component

* changes padding value in sidebar stylesheet to use variable

* Replace and remove old nav components with new ones (#19447)

* links ember-shared-components addon and imports styles

* adds sidebar frame and nav components

* updates activeCluster on auth service and adds activeSession prop for sidebar visibility

* replaces old nav components with new ones in templates

* fixes sidebar visibility issue and updates user menu label class

* removes NavHeader usage

* adds clients index route to redirect to dashboard

* removes unused HcAppFrame footer block and reduces page header top margin

* Nav component cleanup (#19681)

* removes nav-header components

* removes navbar styling

* removes status-menu component and styles

* removes cluster and auth info components

* removes menu-sidebar component and styling

* fixes tests

* Console Panel Updates (#19741)

* updates console panel styling

* adds test for opening and closing the console panel

* updates console panel background color to use hds token

* adds right margin to console panel input

* updates link-status banner styling

* updates hc nav components to new API

* Namespace Picker Updates (#19753)

* updates namespace-picker

* updates namespace picker menu styling

* adds bottom margin to env banner

* updates class order on namespace picker link

* restores manage namespaces refresh icon

* removes manage namespaces nav icon

* removes home link component (#20027)

* Auth and Error View Updates (#19749)

* adds vault logo to auth page

* updates top level error template

* updates loading substate handling and moves policies link from access to cluster nav (#20033)

* moves console panel to bottom of viewport (#20183)

* HDS Sidebar Nav Components (#20197)

* updates nav components to hds

* upgrades project yarn version to 3.5

* fixes issues in app frame component

* updates sidenav actions to use icon button component

* Sidebar navigation acceptance tests (#20270)

* adds sidebar navigation acceptance tests and fixes other test failures

* console panel styling tweaks

* bumps addon version

* remove and ignore yarn install-state file

* fixes auth service and console tests

* moves classes from deleted files after bulma merge

* fixes sass syntax errors blocking build

* cleans up dart sass deprecation warnings

* adds changelog entry

* hides namespace picker when sidebar nav panel is minimized

* style tweaks

* fixes sidebar nav tests

* bumps hds addon to latest version and removes style override

* updates modify-passthrough-response helper

* updates sidebar nav tests

* mfa-setup test fix attempt

* fixes cluster mfa setup test

* remove deprecated yarn ignore-optional flag from makefile

* removes another instance of yarn ignore-optional and updates ui readme

* removes unsupported yarn verbose flag from ci-helper

* hides nav headings when user does not have access to any sub links

* removes unused optional deps and moves lint-staged to dev deps

* updates has-permission helper and permissions service tests

* fixes issue with console panel not filling container width
2023-05-02 19:36:15 -06:00

171 lines
5 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
import { inject as service } from '@ember/service';
import { alias, gt } from '@ember/object/computed';
import Component from '@ember/component';
import { computed } from '@ember/object';
import keyUtils from 'vault/lib/key-utils';
import pathToTree from 'vault/lib/path-to-tree';
import { task, timeout } from 'ember-concurrency';
const { ancestorKeysForKey } = keyUtils;
const DOT_REPLACEMENT = '☃';
const ANIMATION_DURATION = 250;
export default Component.extend({
tagName: '',
namespaceService: service('namespace'),
auth: service(),
store: service(),
namespace: null,
listCapability: null,
canList: false,
init() {
this._super(...arguments);
this.namespaceService?.findNamespacesForUser.perform();
},
didReceiveAttrs() {
this._super(...arguments);
const ns = this.namespace;
const oldNS = this.oldNamespace;
if (!oldNS || ns !== oldNS) {
this.setForAnimation.perform();
this.fetchListCapability.perform();
}
this.set('oldNamespace', ns);
},
fetchListCapability: task(function* () {
try {
const capability = yield this.store.findRecord('capabilities', 'sys/namespaces/');
this.set('listCapability', capability);
this.set('canList', true);
} catch (e) {
// If error out on findRecord call it's because you don't have permissions
// and therefor don't have permission to manage namespaces
this.set('canList', false);
}
}),
setForAnimation: task(function* () {
const leaves = this.menuLeaves;
const lastLeaves = this.lastMenuLeaves;
if (!lastLeaves) {
this.set('lastMenuLeaves', leaves);
yield timeout(0);
return;
}
const isAdding = leaves.length > lastLeaves.length;
const changedLeaf = (isAdding ? leaves : lastLeaves).get('lastObject');
this.set('isAdding', isAdding);
this.set('changedLeaf', changedLeaf);
// if we're adding we want to render immediately an animate it in
// if we're not adding, we need time to move the item out before
// a rerender removes it
if (isAdding) {
this.set('lastMenuLeaves', leaves);
yield timeout(0);
return;
}
yield timeout(ANIMATION_DURATION);
this.set('lastMenuLeaves', leaves);
}).drop(),
isAnimating: alias('setForAnimation.isRunning'),
namespacePath: alias('namespaceService.path'),
// this is an array of namespace paths that the current user
// has access to
accessibleNamespaces: alias('namespaceService.accessibleNamespaces'),
inRootNamespace: alias('namespaceService.inRootNamespace'),
namespaceTree: computed('accessibleNamespaces', function () {
const nsList = this.accessibleNamespaces;
if (!nsList) {
return [];
}
return pathToTree(nsList);
}),
maybeAddRoot(leaves) {
const userRoot = this.auth.authData.userRootNamespace;
if (userRoot === '') {
leaves.unshift('');
}
return leaves.uniq();
},
pathToLeaf(path) {
// dots are allowed in namespace paths
// so we need to preserve them, and replace slashes with dots
// in order to use Ember's get function on the namespace tree
// to pull out the correct level
return (
path
// trim trailing slash
.replace(/\/$/, '')
// replace dots with snowman
.replace(/\.+/g, DOT_REPLACEMENT)
// replace slash with dots
.replace(/\/+/g, '.')
);
},
// an array that keeps track of what additional panels to render
// on the menu stack
// if you're in 'foo/bar/baz',
// this array will be: ['foo', 'foo.bar', 'foo.bar.baz']
// the template then iterates over this, and does Ember.get(namespaceTree, leaf)
// to render the nodes of each leaf
// gets set as 'lastMenuLeaves' in the ember concurrency task above
menuLeaves: computed('namespacePath', 'namespaceTree', 'pathToLeaf', function () {
let ns = this.namespacePath;
ns = (ns || '').replace(/^\//, '');
let leaves = ancestorKeysForKey(ns);
leaves.push(ns);
leaves = this.maybeAddRoot(leaves);
leaves = leaves.map(this.pathToLeaf);
return leaves;
}),
// the nodes at the root of the namespace tree
// these will get rendered as the bottom layer
rootLeaves: computed('namespaceTree', function () {
const tree = this.namespaceTree;
const leaves = Object.keys(tree);
return leaves;
}),
currentLeaf: alias('lastMenuLeaves.lastObject'),
canAccessMultipleNamespaces: gt('accessibleNamespaces.length', 1),
isUserRootNamespace: computed('auth.authData.userRootNamespace', 'namespacePath', function () {
return this.auth.authData.userRootNamespace === this.namespacePath;
}),
namespaceDisplay: computed('namespacePath', 'accessibleNamespaces', 'accessibleNamespaces.[]', function () {
const namespace = this.namespacePath;
if (!namespace) {
return 'root';
}
const parts = namespace?.split('/');
return parts[parts.length - 1];
}),
actions: {
refreshNamespaceList() {
this.namespaceService.findNamespacesForUser.perform();
},
},
});