-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create Trigger Component and deprecate Breadcrumb-Utils pattern.
- Loading branch information
1 parent
5f9fc61
commit 5a1df04
Showing
16 changed files
with
171 additions
and
48 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,5 @@ | ||
<li> | ||
<LinkTo @params={{@crumb.args}} data-test-breadcrumb={{@crumb.args.firstObject}}> | ||
{{@crumb.label}} | ||
</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,19 @@ | ||
<Trigger @do={{this.fetchParent}} as |trigger|> | ||
{{did-insert trigger.fns.do}} | ||
{{#if trigger.data.result}} | ||
<li> | ||
<LinkTo @params={{trigger.data.result.args}} data-test-breadcrumb={{@crumb.args.firstObject}}> | ||
{{trigger.data.result.label}} | ||
</LinkTo> | ||
</li> | ||
{{/if}} | ||
<li> | ||
<LinkTo | ||
@route={{@crumbs.args}} | ||
data-test-breadcrumb={{@crumb.args.firstObject}} | ||
{{!-- @model={{trigger.data.result}} FIX THIS PARAMETER --}} | ||
> | ||
{{this.crumb.label}} | ||
</LinkTo> | ||
</li> | ||
</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,36 @@ | ||
import { action } from '@ember/object'; | ||
import Component from '@glimmer/component'; | ||
import { tracked } from '@glimmer/tracking'; | ||
import { qpBuilder } from 'nomad-ui/utils/classes/query-params'; | ||
|
||
export default class BreadcrumbsJob extends Component { | ||
get job() { | ||
return this.args.crumb.job; | ||
} | ||
|
||
@tracked parent = null; | ||
|
||
generateCrumb(job) { | ||
return { | ||
label: job.get('trimmedName') || job.trimmedName, | ||
args: [ | ||
'jobs.job.index', | ||
job.get('plainId') || job.plainId, | ||
qpBuilder({ | ||
jobNamespace: job.get('namespace.name') || 'default', | ||
}), | ||
], | ||
}; | ||
} | ||
|
||
get crumb() { | ||
if (!this.job) return null; | ||
return this.generateCrumb(this.job); | ||
} | ||
|
||
@action | ||
fetchParent() { | ||
this.parent = this.job.parent || this.job.get('parent'); | ||
return this.generateCrumb(this.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,62 @@ | ||
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.triggerTask.lastErrored; | ||
} | ||
|
||
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 }; | ||
} | ||
|
||
@task(function*() { | ||
try { | ||
this.result = yield this.args.do(); | ||
this.onSuccess(this.result); | ||
} catch (e) { | ||
this.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
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
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,17 +1,15 @@ | ||
<Breadcrumbs as |bb|> | ||
{{#each bb as |breadcrumb index|}} | ||
{{#each breadcrumb.args.crumb as |b|}} | ||
<li class="{{if (eq (inc index) this.b.length) "is-active"}}"> | ||
{{#if b.isPending}} | ||
{{#if b.isPending}} | ||
<li class="{{if (eq (inc index) this.b.length) "is-active"}}"> | ||
<a href="#" aria-label="loading" data-test-breadcrumb="loading"> | ||
… | ||
</a> | ||
{{else}} | ||
<LinkTo @params={{b.args}} data-test-breadcrumb={{b.args.firstObject}}> | ||
{{b.label}} | ||
</LinkTo> | ||
{{/if}} | ||
</li> | ||
</li> | ||
{{else}} | ||
{{component (concat "breadcrumbs/" (or b.type "default")) crumb=b}} | ||
{{/if}} | ||
{{/each}} | ||
{{/each}} | ||
</Breadcrumbs> |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
<Breadcrumb @bucket="navigation" @crumb={{this.breadcrumbs}} /> | ||
<PageLayout> | ||
{{outlet}} | ||
</PageLayout> | ||
<Breadcrumb @bucket="navigation" @crumb={{this.breadcrumbs}} /> | ||
</PageLayout> |
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 +1 @@ | ||
{{outlet}} | ||
{{outlet}}<Breadcrumb bucket="navigation" crumb={{this.metadata.breadcrumb}} /> |
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
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