Repository: hashicorp/vault
File: ui/app/services/namespace.js (JavaScript)

Code before:
import { getRelativePath } from 'core/utils/sanitize-path';
import { tracked } from '@glimmer/tracking';
import { buildWaiter } from '@ember/test-waiters';

const waiter = buildWaiter('namespaces');
const ROOT_NAMESPACE = '';
export default class NamespaceService extends Service {
  @service auth;
  @service flags;
  @service store;

  // populated by the query param on the cluster route
  @tracked path = '';
  // list of namespaces available to the current user under the
  // current namespace
  @tracked accessibleNamespaces = null;

  get userRootNamespace() {
    return this.auth.authData?.userRootNamespace;
  }

  get inRootNamespace() {
    return this.path === ROOT_NAMESPACE;
  }

  // the "root" namespace is "admin/" for HVD managed clusters accessing the UI
  get inHvdAdminNamespace() {
    return this.flags.isHvdManaged && this.path === 'admin/';
  }

  get currentNamespace() {
    if (this.inRootNamespace) return 'root';

    const parts = this.path?.split('/');
    return parts[parts.length - 1];
  }

  get relativeNamespace() {
    // relative namespace is the current namespace minus the user's root.
    // so if we're in app/staging/group1 but the user's root is app, the
    // relative namespace is staging/group
    return getRelativePath(this.path, this.userRootNamespace);
  }

  setNamespace(path) {
    if (!path) {
      this.path = '';
      return;
    }
    this.path = path;
  }

Review comment (suggestion):
```suggestion
  // the top-level namespace is "admin/" for HVD managed clusters accessing the UI 
  // (similar to "root" for self-managed clusters)
  // this getter checks if the user is specifically at the administrative namespace level
```

Code after:
import { getRelativePath } from 'core/utils/sanitize-path';
import { tracked } from '@glimmer/tracking';
import { buildWaiter } from '@ember/test-waiters';

const waiter = buildWaiter('namespaces');
const ROOT_NAMESPACE = '';
export default class NamespaceService extends Service {
  @service auth;
  @service flags;
  @service store;

  // populated by the query param on the cluster route
  @tracked path = '';
  // list of namespaces available to the current user under the
  // current namespace
  @tracked accessibleNamespaces = null;

  get userRootNamespace() {
    return this.auth.authData?.userRootNamespace;
  }

  get inRootNamespace() {
    return this.path === ROOT_NAMESPACE;
  }

  // the top-level namespace is "admin/" for HVD managed clusters accessing the UI
  // (similar to "root" for self-managed clusters)
  // this getter checks if the user is specifically at the administrative namespace level
  get inHvdAdminNamespace() {
    return this.flags.isHvdManaged && this.path === 'admin/';
  }

  get currentNamespace() {
    if (this.inRootNamespace) return 'root';

    const parts = this.path?.split('/');
    return parts[parts.length - 1];
  }

  get relativeNamespace() {
    // relative namespace is the current namespace minus the user's root.
    // so if we're in app/staging/group1 but the user's root is app, the
    // relative namespace is staging/group
    return getRelativePath(this.path, this.userRootNamespace);
  }

  setNamespace(path) {
    if (!path) {
      this.path = '';
      return;
    }