Skip to content

Commit 6388b30

Browse files
authored
Merge pull request #3247 from codecrafters-io/add-autofix-request-error-handling
feat(autofix-container): add autofix request creation and error handling
2 parents 7a052fd + 1da7b88 commit 6388b30

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

app/components/course-admin/submissions-page/submission-details/autofix-container.hbs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,17 @@
1010
<div class="bg-gray-800 p-4 text-white font-mono text-xs leading-relaxed rounded-sm mb-4">
1111
This submission doesn't have any autofix requests.
1212
</div>
13+
14+
<PrimaryButtonWithSpinner @shouldShowSpinner={{this.createAutofixRequestTask.isRunning}} {{on "click" this.handleCreateAutofixButtonClick}}>
15+
Create Autofix Request
16+
</PrimaryButtonWithSpinner>
17+
18+
{{#if this.autofixCreationError}}
19+
<AlertWithIcon @type="error" class="mt-3">
20+
<p>
21+
{{this.autofixCreationError}}
22+
</p>
23+
</AlertWithIcon>
24+
{{/if}}
1325
{{/if}}
1426
</div>

app/components/course-admin/submissions-page/submission-details/autofix-container.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import Component from '@glimmer/component';
2+
import type Store from '@ember-data/store';
23
import type SubmissionModel from 'codecrafters-frontend/models/submission';
4+
import { action } from '@ember/object';
5+
import { service } from '@ember/service';
6+
import { task } from 'ember-concurrency';
7+
import { tracked } from '@glimmer/tracking';
38

49
interface Signature {
510
Element: HTMLDivElement;
@@ -9,7 +14,30 @@ interface Signature {
914
};
1015
}
1116

12-
export default class AutofixContainer extends Component<Signature> {}
17+
export default class AutofixContainer extends Component<Signature> {
18+
@service declare store: Store;
19+
20+
@tracked autofixCreationError: string | null = null;
21+
22+
createAutofixRequestTask = task({ drop: true }, async (): Promise<void> => {
23+
this.autofixCreationError = null;
24+
25+
const autofixRequest = this.store.createRecord('autofix-request', {
26+
submission: this.args.submission,
27+
});
28+
29+
try {
30+
await autofixRequest.save();
31+
} catch {
32+
this.autofixCreationError = 'Failed to create autofix request! Try again? Post on #engineering if this persists.';
33+
}
34+
});
35+
36+
@action
37+
handleCreateAutofixButtonClick() {
38+
this.createAutofixRequestTask.perform();
39+
}
40+
}
1341

1442
declare module '@glint/environment-ember-loose/registry' {
1543
export default interface Registry {

0 commit comments

Comments
 (0)