Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: Breadcrumbs Service #11590

Merged
merged 27 commits into from
Jan 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
b14991e
chore: edit mirage scenario to populate csi
ChaiWithJai Nov 30, 2021
67e6cec
feat: create bucket service to register, deregister and store breadc…
ChaiWithJai Nov 30, 2021
dcc9aa1
fix: delete state from routes and move to controllers and add render…
ChaiWithJai Nov 30, 2021
126c4df
fix: delete old breadcrumbs and replace with bucket
ChaiWithJai Nov 30, 2021
b1002d6
feat: create trigger component
ChaiWithJai Dec 8, 2021
b996834
fix: resolve parent on job still issue with alloc job async relation…
ChaiWithJai Dec 9, 2021
db9d62d
fix: handle case for async relationships
ChaiWithJai Dec 13, 2021
972b52a
chore: write tests for trigger component
ChaiWithJai Dec 14, 2021
2cc8a37
test: breadcrumbs functionality
ChaiWithJai Dec 14, 2021
210d0b3
refactor: remove double each in app breadcrumbs
ChaiWithJai Dec 14, 2021
4cadf69
refactor: delete app-breadcrumbs component file
ChaiWithJai Dec 15, 2021
0ea0e69
refactor: delete unit tests for old breadcrumbs service
ChaiWithJai Dec 15, 2021
5ca9ebe
fix: update breadcrumb tests according to new breadcrumb structure
ChaiWithJai Dec 15, 2021
fa5096a
fix: add in for topology route
ChaiWithJai Dec 15, 2021
dd04270
fix: delete jobs route - ember creates this for us
ChaiWithJai Dec 15, 2021
7bf2880
update: add comment to explain loading namespaces in alloc route
ChaiWithJai Dec 15, 2021
0334709
feat: add title to default breadcrumb component
ChaiWithJai Dec 16, 2021
a262979
style: add styling for title on breadcrumbs
ChaiWithJai Dec 16, 2021
e1a5760
refact: add title to breadcrumb generator
ChaiWithJai Dec 16, 2021
10db60e
feat: handle title behavior for job breadcrumb
ChaiWithJai Dec 16, 2021
ed49d59
style: centering and spacing for titled breadcrumbs
ChaiWithJai Dec 16, 2021
1a2914b
fix: test specs should expect to receive breadcrumb titles
ChaiWithJai Dec 16, 2021
92fafca
styling: fix opacity for last child in the list
ChaiWithJai Dec 17, 2021
4d39d88
fix: add ember-a11y-testing-audit-call
ChaiWithJai Dec 17, 2021
c1d2920
chore: clean-up merge conflict after rebase
ChaiWithJai Dec 21, 2021
b25f5ff
fix: remove unecessary breadcrumb
ChaiWithJai Dec 23, 2021
3bdf661
refact: clean-up breadcrumb invocations
ChaiWithJai Dec 17, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/11590.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
ui: Add titles to breadcrumb labels in app navigation bar
```
13 changes: 0 additions & 13 deletions ui/app/components/app-breadcrumbs.js

This file was deleted.

27 changes: 27 additions & 0 deletions ui/app/components/breadcrumb.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { assert } from '@ember/debug';
import { action } from '@ember/object';
import { inject as service } from '@ember/service';
import Component from '@glimmer/component';

export default class Breadcrumb extends Component {
@service breadcrumbs;

constructor() {
super(...arguments);
assert('Provide a valid breadcrumb argument', this.args.crumb);
this.register();
}

@action register() {
this.breadcrumbs.registerBreadcrumb(this);
}

@action deregister() {
this.breadcrumbs.deregisterBreadcrumb(this);
}

willDestroy() {
super.willDestroy();
this.deregister();
}
}
1 change: 1 addition & 0 deletions ui/app/components/breadcrumbs.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{yield this.crumbs}}
10 changes: 10 additions & 0 deletions ui/app/components/breadcrumbs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Component from '@glimmer/component';
import { inject as service } from '@ember/service';

export default class Breadcrumbs extends Component {
@service breadcrumbs;

get crumbs() {
return this.breadcrumbs.crumbs;
}
}
16 changes: 16 additions & 0 deletions ui/app/components/breadcrumbs/default.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<li data-test-breadcrumb-default>
<LinkTo @params={{@crumb.args}} data-test-breadcrumb={{@crumb.args.firstObject}}>
{{#if @crumb.title}}
<dl>
<dt>
{{@crumb.title}}
</dt>
<dd>
{{@crumb.label}}
</dd>
</dl>
{{else}}
{{@crumb.label}}
{{/if}}
</LinkTo>
</li>
49 changes: 49 additions & 0 deletions ui/app/components/breadcrumbs/job.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<Trigger @onError={{action this.onError}} @do={{this.fetchParent}} as |trigger|>
{{did-insert trigger.fns.do}}
{{#if trigger.data.isBusy}}
<li>
<a href="#" aria-label="loading" data-test-breadcrumb="loading">
</a>
</li>
{{/if}}
{{#if trigger.data.isSuccess}}
{{#if trigger.data.result}}
<li>
<LinkTo
@route="jobs.job.index"
@model={{trigger.data.result.plainId}}
@query={{hash namespace=(or trigger.data.result.namespace.name "default")}}
data-test-breadcrumb={{"jobs.job.index"}}
>
<dl>
<dt>
Parent Job
</dt>
<dd>
{{trigger.data.result.trimmedName}}
</dd>
</dl>
</LinkTo>
</li>
{{/if}}
<li>
<LinkTo
@route="jobs.job.index"
@model={{this.job.plainId}}
@query={{hash namespace=(or this.job.namespace.name "default")}}
data-test-breadcrumb={{"jobs.job.index"}}
data-test-job-breadcrumb
>
<dl>
<dt>
{{if this.job.hasChildren "Parent Job" "Job"}}
</dt>
<dd>
{{this.job.trimmedName}}
</dd>
</dl>
</LinkTo>
</li>
{{/if}}
</Trigger>
22 changes: 22 additions & 0 deletions ui/app/components/breadcrumbs/job.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { assert } from '@ember/debug';
import { action } from '@ember/object';
import Component from '@glimmer/component';

export default class BreadcrumbsJob extends Component {
get job() {
return this.args.crumb.job;
}

@action
onError(err) {
assert(`Error: ${err.message}`);
}

@action
fetchParent() {
const hasParent = !!this.job.belongsTo('parent').id();
if (hasParent) {
return this.job.get('parent');
}
}
}
1 change: 1 addition & 0 deletions ui/app/components/trigger.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{yield (hash data=this.data fns=this.fns)}}
68 changes: 68 additions & 0 deletions ui/app/components/trigger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { action } from '@ember/object';
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { task } from 'ember-concurrency';

const noOp = () => undefined;

export default class Trigger extends Component {
@tracked error = null;
@tracked result = null;

get isBusy() {
return this.triggerTask.isRunning;
}

get isIdle() {
return this.triggerTask.isIdle;
}

get isSuccess() {
return this.triggerTask.last?.isSuccessful;
}

get isError() {
return !!this.error;
}

get fns() {
return {
do: this.onTrigger,
};
}

get onError() {
return this.args.onError ?? noOp;
}

get onSuccess() {
return this.args.onSuccess ?? noOp;
}

get data() {
const { isBusy, isIdle, isSuccess, isError, result } = this;
return { isBusy, isIdle, isSuccess, isError, result };
}

_reset() {
this.result = null;
this.error = null;
}

@task(function*() {
this._reset();
try {
this.result = yield this.args.do();
this.onSuccess(this.result);
} catch (e) {
this.error = { Error: e };
this.onError(this.error);
}
})
triggerTask;

@action
onTrigger() {
this.triggerTask.perform();
}
}
47 changes: 47 additions & 0 deletions ui/app/controllers/allocations/allocation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import Controller from '@ember/controller';
import { inject as service } from '@ember/service';
import { qpBuilder } from 'nomad-ui/utils/classes/query-params';

export default class AllocationsAllocationController extends Controller {
@service store;

get allocation() {
return this.model;
}

get job() {
const allocation = this.model;
const jobId = allocation.belongsTo('job').id();
const job = this.store.peekRecord('job', jobId);
return job;
}

get jobNamespace() {
const jobNamespaceId = this.job.belongsTo('namespace').id();

return jobNamespaceId || 'default';
}
// Allocation breadcrumbs extend from job / task group breadcrumbs
// even though the route structure does not.
get breadcrumbs() {
const { allocation, job, jobNamespace } = this;
const jobQueryParams = qpBuilder({
jobNamespace,
});

return [
{ label: 'Jobs', args: ['jobs.index', jobQueryParams] },
{ type: 'job', job: job },
{
title: 'Task Group',
label: allocation.taskGroupName,
args: ['jobs.job.task-group', job.plainId, allocation.taskGroupName, jobQueryParams],
},
{
title: 'Allocation',
label: allocation.shortId,
args: ['allocations.allocation', allocation],
},
];
}
}
15 changes: 15 additions & 0 deletions ui/app/controllers/allocations/allocation/task.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Controller from '@ember/controller';

export default class AllocationsAllocationTaskController extends Controller {
get task() {
return this.model;
}

get breadcrumb() {
return {
title: 'Task',
label: this.task.get('name'),
args: ['allocations.allocation.task', this.task.get('allocation'), this.task],
};
}
}
15 changes: 15 additions & 0 deletions ui/app/controllers/clients/client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Controller from '@ember/controller';

export default class ClientsClientController extends Controller {
get client() {
return this.model;
}

get breadcrumb() {
return {
title: 'Client',
label: this.client.get('shortId'),
args: ['clients.client', this.client.get('id')],
};
}
}
21 changes: 21 additions & 0 deletions ui/app/controllers/csi/plugins/plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import Controller from '@ember/controller';

export default class CsiPluginsPluginController extends Controller {
get plugin() {
return this.model;
}

get breadcrumbs() {
const { plainId } = this.plugin;
return [
{
label: 'Plugins',
args: ['csi.plugins'],
},
{
label: plainId,
args: ['csi.plugins.plugin', plainId],
},
];
}
}
26 changes: 26 additions & 0 deletions ui/app/controllers/csi/volumes/volume.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Controller from '@ember/controller';
import { inject as service } from '@ember/service';
import { action, computed } from '@ember/object';
import { qpBuilder } from 'nomad-ui/utils/classes/query-params';

export default class VolumeController extends Controller {
// Used in the template
Expand All @@ -13,6 +14,31 @@ export default class VolumeController extends Controller {
];
volumeNamespace = 'default';

get volume() {
return this.model;
}

get breadcrumbs() {
const volume = this.volume;
return [
{
label: 'Volumes',
args: [
'csi.volumes',
qpBuilder({ volumeNamespace: volume.get('namespace.name') || 'default' }),
],
},
{
label: volume.name,
args: [
'csi.volumes.volume',
volume.plainId,
qpBuilder({ volumeNamespace: volume.get('namespace.name') || 'default' }),
],
},
];
}

@computed('[email protected]')
get sortedReadAllocations() {
return this.model.readAllocations.sortBy('modifyIndex').reverse();
Expand Down
1 change: 1 addition & 0 deletions ui/app/controllers/jobs.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Controller from '@ember/controller';

// The WithNamespaceResetting Mixin uses Controller Injection and requires us to keep this controller around
export default class JobsController extends Controller {}
4 changes: 4 additions & 0 deletions ui/app/controllers/jobs/job.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@ export default class JobController extends Controller {
},
];
jobNamespace = 'default';

get job() {
return this.model;
}
}
4 changes: 4 additions & 0 deletions ui/app/controllers/jobs/job/dispatch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Controller from '@ember/controller';

// This may be safe to remove but we can't be sure, some route may try access this directly using this.controllerFor
export default class JobsJobDispatchController extends Controller {}
Loading