-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11590 from hashicorp/e-ui/breadcrumbs-service
Refactor: Breadcrumbs Service
- Loading branch information
Showing
73 changed files
with
1,492 additions
and
791 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{{yield this.crumbs}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{{yield (hash data=this.data fns=this.fns)}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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], | ||
}, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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], | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')], | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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], | ||
}, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
@@ -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(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {} |
Oops, something went wrong.