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

[ui] Separate Diffs and Versions from the /versions endpoint as far as Ember is concerned #24145

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 8 additions & 3 deletions ui/app/components/job-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default class JobVersion extends Component {
@service router;

@alias('args.version') version;
@alias('args.diff') diff;
@tracked isOpen = false;
@tracked isEditing = false;
@tracked editableTag;
Expand All @@ -29,7 +30,11 @@ export default class JobVersion extends Component {
constructor() {
super(...arguments);
this.initializeEditableTag();
if (this.args.diffsExpanded && this.version.diff) {
this.versionsDidUpdate();
}

@action versionsDidUpdate() {
if (this.args.diffsExpanded && this.diff) {
this.isOpen = true;
}
}
Expand All @@ -47,9 +52,9 @@ export default class JobVersion extends Component {
this.editableTag.jobName = this.version.get('job.plainId');
}

@computed('version.diff')
@computed('diff')
get changeCount() {
const diff = this.version.diff;
const diff = this.diff;
const taskGroups = diff.TaskGroups || [];

if (!diff) {
Expand Down
7 changes: 5 additions & 2 deletions ui/app/components/job-versions-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ export default class JobVersionsStream extends Component {
// Passes through to the job-diff component
verbose = true;

@computed('versions.[]')
diffs = [];

@computed('versions.[]', 'diffs.[]')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the @computed prefix to this getter indicates something that should trigger an update.

get annotatedVersions() {
const versions = this.versions.sortBy('submitTime').reverse();
return versions.map((version, index) => {
Expand All @@ -38,7 +40,8 @@ export default class JobVersionsStream extends Component {
}
}

return { version, meta };
const diff = this.diffs.objectAt(index);
return { version, meta, diff };
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the component layer where we opt to join the Version and its Diff, which are otherwise same-indexed objects in separate arrays.

});
}
}
15 changes: 15 additions & 0 deletions ui/app/controllers/jobs/job/versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,21 @@ export default class VersionsController extends Controller.extend(
});
}

@tracked diffs = [];

@action async versionsDidUpdate() {
try {
const diffs = await this.job.getVersions(this.diffVersion);
if (diffs.Diffs) {
this.diffs = diffs.Diffs;
} else {
this.diffs = [];
}
} catch (error) {
console.error('error fetching diffs', error);
}
}

get diffsExpanded() {
return this.diffVersion !== '';
}
Expand Down
15 changes: 1 addition & 14 deletions ui/app/routes/jobs/job/versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,8 @@ import { inject as service } from '@ember/service';
export default class VersionsRoute extends Route.extend(WithWatchers) {
@service store;

queryParams = {
diffVersion: {
refreshModel: true,
},
};

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that the route doesn't care about Diff data (the controller does), we don't need to make it concerned with queryParams / it doesn't need to re-fetch the versions when the user switches the comparison version via dropdown

async model(params) {
async model() {
const job = this.modelFor('jobs.job');
const versions = await job.getVersions(params.diffVersion);

job.versions = job.versions.map((v, i) => {
const diff = versions.Diffs[i];
v.set('diff', diff);
return v;
});
return job;
}

Expand Down
4 changes: 3 additions & 1 deletion ui/app/serializers/job.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,9 @@ export default class JobSerializer extends ApplicationSerializer {
},
versions: {
links: {
related: buildURL(`${jobURL}/versions`, { namespace, diffs: true }),
related: buildURL(`${jobURL}/versions`, {
namespace,
}),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We no longer need to get .Diffs[] on initial model load

},
},
deployments: {
Expand Down
5 changes: 3 additions & 2 deletions ui/app/templates/components/job-version.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
SPDX-License-Identifier: BUSL-1.1
~}}

{{did-update this.versionsDidUpdate this.diff}}
<section class="job-version">
<div class="boxed-section {{if this.version.versionTag "tagged"}}" data-test-tagged-version={{if this.version.versionTag "true" "false"}}>
<header class="boxed-section-head is-light inline-definitions">
Expand All @@ -16,7 +17,7 @@
<span data-test-version-submit-time class="submit-date">{{format-ts this.version.submitTime}}</span>
</span>
<div class="pull-right">
{{#if this.version.diff}}
{{#if this.diff}}
<Hds::Button
class="is-light is-small"
@size="small"
Expand All @@ -33,7 +34,7 @@
</header>
{{#if this.isOpen}}
<div class="boxed-section-body is-dark">
<JobDiff @diff={{this.version.diff}} @verbose={{this.verbose}} />
<JobDiff @diff={{this.diff}} @verbose={{this.verbose}} />
</div>
{{/if}}
<footer class="boxed-section-foot {{if this.isEditing "editing"}}">
Expand Down
2 changes: 1 addition & 1 deletion ui/app/templates/components/job-versions-stream.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
</li>
{{/if}}
<li data-test-version class="timeline-object">
<JobVersion @version={{record.version}} @verbose={{this.verbose}} @handleError={{@handleError}} @diffsExpanded={{@diffsExpanded}} />
<JobVersion @version={{record.version}} @diff={{record.diff}} @verbose={{this.verbose}} @handleError={{@handleError}} @diffsExpanded={{@diffsExpanded}} />
</li>
{{/each}}
3 changes: 2 additions & 1 deletion ui/app/templates/jobs/job/versions.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
~}}

{{page-title "Job " this.job.name " versions"}}
{{did-update this.versionsDidUpdate this.job.versions}}
<JobSubnav @job={{this.job}} />
<section class="section">

Expand Down Expand Up @@ -56,5 +57,5 @@
</div>
{{/if}}

<JobVersionsStream @versions={{this.model.versions}} @verbose={{true}} @handleError={{action this.handleError}} @diffsExpanded={{this.diffsExpanded}} />
<JobVersionsStream @versions={{this.model.versions}} @diffs={{this.diffs}} @verbose={{true}} @handleError={{action this.handleError}} @diffsExpanded={{this.diffsExpanded}} />
</section>
Loading