Skip to content

Commit

Permalink
/csi routes to /storage routes and a routeRedirector util
Browse files Browse the repository at this point in the history
  • Loading branch information
philrenaud committed Feb 20, 2025
1 parent ec0cf86 commit e802bfd
Show file tree
Hide file tree
Showing 42 changed files with 245 additions and 39 deletions.
3 changes: 2 additions & 1 deletion ui/.ember-cli
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
Setting `disableAnalytics` to true will prevent any data from being sent.
*/
"disableAnalytics": false,
"proxy": "http://127.0.0.1:4646"
// "proxy": "http://127.0.0.1:4646"
"proxy": "http://52.91.187.55:4646"
}
2 changes: 1 addition & 1 deletion ui/app/components/global-search/control.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ export default class GlobalSearchControl extends Component {
);
});
} else if (model.type === 'plugin') {
this.router.transitionTo('csi.plugins.plugin', model.id);
this.router.transitionTo('storage.plugins.plugin', model.id);
} else if (model.type === 'allocation') {
this.router.transitionTo('allocations.allocation', model.id);
}
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default class IndexController extends Controller.extend(
Searchable
) {
@service userSettings;
@controller('csi/plugins') pluginsController;
@controller('storage/plugins') pluginsController;

@alias('pluginsController.isForbidden') isForbidden;

Expand Down Expand Up @@ -65,7 +65,7 @@ export default class IndexController extends Controller.extend(
@action
gotoPlugin(plugin, event) {
lazyClick([
() => this.transitionToRoute('csi.plugins.plugin', plugin.plainId),
() => this.transitionToRoute('storage.plugins.plugin', plugin.plainId),
event,
]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ export default class CsiPluginsPluginController extends Controller {
return [
{
label: 'Plugins',
args: ['csi.plugins'],
args: ['storage.plugins'],
},
{
label: plainId,
args: ['csi.plugins.plugin', plainId],
args: ['storage.plugins.plugin', plainId],
},
];
}
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default class IndexController extends Controller.extend(
@service system;
@service userSettings;
@service keyboard;
@controller('csi/volumes') volumesController;
@controller('storage/volumes') volumesController;

@alias('volumesController.isForbidden')
isForbidden;
Expand Down Expand Up @@ -115,7 +115,7 @@ export default class IndexController extends Controller.extend(
lazyClick([
() =>
this.transitionToRoute(
'csi.volumes.volume',
'storage.volumes.volume',
volume.get('idWithNamespace')
),
event,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ export default class VolumeController extends Controller {
return [
{
label: 'Volumes',
args: ['csi.volumes'],
args: ['storage.volumes'],
},
{
label: volume.name,
args: [
'csi.volumes.volume',
'storage.volumes.volume',
volume.plainId,
qpBuilder({
volumeNamespace: volume.get('namespace.name') || 'default',
Expand Down
5 changes: 4 additions & 1 deletion ui/app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ Router.map(function () {

this.route('topology');

this.route('csi', function () {
// Only serves as a redirect to storage
this.route('csi');

this.route('storage', function () {
this.route('volumes', function () {
this.route('volume', { path: '/:volume_name' });
});
Expand Down
7 changes: 7 additions & 0 deletions ui/app/routes/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* SPDX-License-Identifier: BUSL-1.1
*/

// @ts-check

/* eslint-disable ember/no-controller-access-in-routes */
import { inject as service } from '@ember/service';
import { later, next } from '@ember/runloop';
Expand All @@ -11,6 +13,7 @@ import { AbortError } from '@ember-data/adapter/error';
import RSVP from 'rsvp';
import { action } from '@ember/object';
import classic from 'ember-classic-decorator';
import { handleRouteRedirects } from '../utils/route-redirector';

@classic
export default class ApplicationRoute extends Route {
Expand All @@ -33,6 +36,10 @@ export default class ApplicationRoute extends Route {
}

async beforeModel(transition) {
if (handleRouteRedirects(transition, this.router)) {
return;
}

let promises;

// service:router#transitionTo can cause this to rerun because of refreshModel on
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ import Route from '@ember/routing/route';

export default class IndexRoute extends Route {
redirect() {
this.transitionTo('csi.volumes');
this.transitionTo('storage.volumes');
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion ui/app/services/keyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export default class KeyboardService extends Service {
},
{
label: 'Go to Storage',
action: () => this.router.transitionTo('csi.volumes'),
action: () => this.router.transitionTo('storage.volumes'),
rebindable: true,
},
{
Expand Down
2 changes: 1 addition & 1 deletion ui/app/templates/allocations/allocation/task/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@
<td data-test-volume-client-source>
{{#if row.model.isCSI}}
<LinkTo
@route="csi.volumes.volume"
@route="storage.volumes.volume"
@model={{concat
(format-volume-name
source=row.model.source
Expand Down
2 changes: 1 addition & 1 deletion ui/app/templates/components/gutter-menu.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
{{/if}}
<li {{keyboard-shortcut menuLevel=true pattern=(array "g" "r") }}>
<LinkTo
@route="csi"
@route="storage"
@activeClass="is-active"
data-test-gutter-link="storage"
>
Expand Down
4 changes: 2 additions & 2 deletions ui/app/templates/components/plugin-subnav.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<div data-test-subnav="plugins" class="tabs is-subnav" {{did-insert this.keyboard.registerNav type="subnav"}} {{will-destroy this.keyboard.unregisterSubnav}}>
<ul>
<li data-test-tab="overview"><LinkTo @route="csi.plugins.plugin.index" @model={{@plugin}} @activeClass="is-active">Overview</LinkTo></li>
<li data-test-tab="allocations"><LinkTo @route="csi.plugins.plugin.allocations" @model={{@plugin}} @activeClass="is-active">Allocations</LinkTo></li>
<li data-test-tab="overview"><LinkTo @route="storage.plugins.plugin.index" @model={{@plugin}} @activeClass="is-active">Overview</LinkTo></li>
<li data-test-tab="allocations"><LinkTo @route="storage.plugins.plugin.allocations" @model={{@plugin}} @activeClass="is-active">Allocations</LinkTo></li>
</ul>
</div>
4 changes: 2 additions & 2 deletions ui/app/templates/components/storage-subnav.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
<div class="tabs is-subnav" {{did-insert this.keyboard.registerNav type="subnav"}} {{will-destroy this.keyboard.unregisterSubnav}}>
<ul>
<li data-test-tab="volumes">
<LinkTo @route="csi.volumes.index" @activeClass="is-active">
<LinkTo @route="storage.volumes.index" @activeClass="is-active">
Volumes
</LinkTo>
</li>
<li data-test-tab="plugins">
<LinkTo @route="csi.plugins.index" @activeClass="is-active">
<LinkTo @route="storage.plugins.index" @activeClass="is-active">
Plugins
</LinkTo>
</li>
Expand Down
4 changes: 2 additions & 2 deletions ui/app/templates/components/task-row.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
</strong>
{{#if volume.isCSI}}
<LinkTo
@route="csi.volumes.volume"
@route="storage.volumes.volume"
@model={{concat
(format-volume-name
source=volume.source
Expand Down Expand Up @@ -130,4 +130,4 @@
</div>
{{/if}}
{{/if}}
</td>
</td>
6 changes: 0 additions & 6 deletions ui/app/templates/csi/plugins.hbs

This file was deleted.

6 changes: 0 additions & 6 deletions ui/app/templates/csi/volumes.hbs

This file was deleted.

4 changes: 2 additions & 2 deletions ui/app/templates/jobs/job/task-group.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -332,10 +332,10 @@
{{#if row.model.isCSI}}
{{!-- if volume is per_alloc=true, there's no one specific volume. So, link to the volumes index with an active query --}}
{{#if row.model.perAlloc}}
<LinkTo @route="csi.volumes.index" @query={{hash search=row.model.source}}>{{row.model.name}}</LinkTo>
<LinkTo @route="storage.volumes.index" @query={{hash search=row.model.source}}>{{row.model.name}}</LinkTo>
{{else}}
<LinkTo
@route="csi.volumes.volume"
@route="storage.volumes.volume"
@model={{concat row.model.source "@" row.model.namespace.id}}
>
{{row.model.name}}
Expand Down
File renamed without changes.
6 changes: 6 additions & 0 deletions ui/app/templates/storage/plugins.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{{!
Copyright (c) HashiCorp, Inc.
SPDX-License-Identifier: BUSL-1.1
~}}

<Breadcrumb @crumb={{hash label="Storage" args=(array "storage.index")}} />{{outlet}}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
action=(action "gotoPlugin" row.model)
}}
>
<LinkTo @route="csi.plugins.plugin" @model={{row.model.plainId}} class="is-primary">{{row.model.plainId}}</LinkTo>
<LinkTo @route="storage.plugins.plugin" @model={{row.model.plainId}} class="is-primary">{{row.model.plainId}}</LinkTo>
</td>
<td data-test-plugin-controller-health>
{{#if row.model.controllerRequired}}
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
<div class="boxed-section-foot">
<p class="pull-right">
<LinkTo
@route="csi.plugins.plugin.allocations"
@route="storage.plugins.plugin.allocations"
@model={{this.model}}
@query={{hash qpType=(qp-serialize (array "controller"))}}
data-test-go-to-controller-allocations>
Expand Down Expand Up @@ -180,7 +180,7 @@
<div class="boxed-section-foot">
<p class="pull-right">
<LinkTo
@route="csi.plugins.plugin.allocations"
@route="storage.plugins.plugin.allocations"
@model={{this.model}}
@query={{hash qpType=(qp-serialize (array "node"))}}
data-test-go-to-node-allocations>
Expand Down
6 changes: 6 additions & 0 deletions ui/app/templates/storage/volumes.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{{!
Copyright (c) HashiCorp, Inc.
SPDX-License-Identifier: BUSL-1.1
~}}

<Breadcrumb @crumb={{hash label="Storage" args=(array "storage.index")}} />{{outlet}}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
>
<Tooltip @text={{row.model.plainId}}>
<LinkTo
@route="csi.volumes.volume"
@route="storage.volumes.volume"
@model={{row.model.idWithNamespace}}
class="is-primary"
>
Expand Down
File renamed without changes.
43 changes: 43 additions & 0 deletions ui/app/utils/route-redirector.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/

import routeRedirects from './route-redirects';

export function handleRouteRedirects(transition, router) {
const currentPath = transition.intent.url || transition.targetName;

for (const redirect of routeRedirects) {
let shouldRedirect = false;
let targetPath =
typeof redirect.to === 'function'
? redirect.to(currentPath)
: redirect.to;

switch (redirect.method) {
case 'startsWith':
shouldRedirect = currentPath.startsWith(redirect.from);
break;
case 'exact':
shouldRedirect = currentPath === redirect.from;
break;
case 'pattern':
if (redirect.pattern && redirect.pattern.test(currentPath)) {
shouldRedirect = true;
}
break;
}

if (shouldRedirect) {
console.warn(
`This URL has changed. Please update your bookmark from ${currentPath} to ${targetPath}`
);

router.replaceWith(targetPath, {
queryParams: transition.to.queryParams,
});
return true;
}
}
}
36 changes: 36 additions & 0 deletions ui/app/utils/route-redirects.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/

// This serves as a lit of routes in the UI that we change over time,
// but still want to respect users' bookmarks and habits.

/**
* @typedef {Object} RouteRedirect
* @property {string} from - The path to match against
* @property {(string|function(string): string)} to - Either a static path or a function to compute the new path
* @property {'startsWith'|'exact'|'pattern'} method - The matching strategy to use
* @property {RegExp} [pattern] - Optional regex pattern if method is 'pattern'
*/
export default [
{
from: '/csi/volumes/',
to: (path) => {
const volumeName = path.split('/csi/volumes/')[1];
return `/storage/volumes/${volumeName}`;
},
method: 'pattern',
pattern: /^\/csi\/volumes\/(.+)$/,
},
{
from: '/csi/volumes',
to: '/storage/volumes',
method: 'exact',
},
{
from: '/csi',
to: '/storage',
method: 'startsWith',
},
];
Loading

0 comments on commit e802bfd

Please sign in to comment.