Skip to content

Commit 7435827

Browse files
committed
feat: add autofix request card to show test fix hints
Introduce a new AutofixRequestCard component to display hints generated for test result autofixes. Show placeholder content while generation is in progress and reveal explanations and diffs on success. Add UI controls to unblur the fixed code diff, enhancing user interaction. Also extend tailwind config with purple color and medium spin animation to support new UI styles and animations.
1 parent d209d14 commit 7435827

File tree

4 files changed

+172
-2
lines changed

4 files changed

+172
-2
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<div class="bg-gray-850 rounded-sm border border-white/5 p-4 w-full max-w-xl overflow-hidden" ...attributes data-test-autofix-request-card>
2+
<AnimatedContainer>
3+
{{#animated-value @autofixRequest.status duration=200 use=this.transition as |status|}}
4+
{{#if (eq status "in_progress")}}
5+
<div class="flex items-center gap-2">
6+
<BlinkingDot @color="yellow" class="shrink-0" />
7+
<span class="text-lg font-semibold text-white">Generating custom hint...</span>
8+
</div>
9+
{{else if (eq status "success")}}
10+
<span class="text-lg font-semibold text-white">Hint: {{@autofixRequest.summary}}</span>
11+
{{/if}}
12+
{{/animated-value}}
13+
14+
<BlurredOverlay @isBlurred={{this.explanationIsBlurred}} @overlayClass="bg-gray-900/20" class="-mx-4 -mb-4">
15+
<:content>
16+
<div class="p-4">
17+
<div class="prose prose-sm dark:prose-invert has-prism-highlighting">
18+
{{#if (eq @autofixRequest.status "in_progress")}}
19+
<p>
20+
This is the content of a sample hint. We use this as a
21+
<code>placeholder</code>
22+
for the actual hint. It's blurred out so you shouldn't be seeing this...
23+
</p>
24+
{{else}}
25+
{{markdown-to-html @autofixRequest.explanationMarkdown}}
26+
{{/if}}
27+
</div>
28+
29+
<BlurredOverlay @isBlurred={{and this.diffIsBlurred (not this.explanationIsBlurred)}} @overlayClass="bg-gray-900/20" class="-mx-4 -mb-4">
30+
<:content>
31+
<div class="p-4 flex flex-col gap-6">
32+
{{#each this.changedFilesForRender key="filename" as |changedFile|}}
33+
<FileDiffCard
34+
@code={{changedFile.diff}}
35+
@filename={{changedFile.filename}}
36+
@forceDarkTheme={{true}}
37+
{{! @glint-expect-error language can be nullable }}
38+
@language={{@autofixRequest.submission.repository.language.slug}}
39+
/>
40+
{{/each}}
41+
</div>
42+
</:content>
43+
<:overlay>
44+
{{#if (eq @autofixRequest.status "success")}}
45+
<SecondaryButton class="bg-gray-800 mt-10" {{on "click" (fn (mut this.diffWasUnblurred) true)}}>
46+
<div class="flex items-center gap-2">
47+
<div class="flex">{{svg-jar "eye" class="size-6"}}</div>
48+
Show fixed code
49+
</div>
50+
</SecondaryButton>
51+
{{/if}}
52+
</:overlay>
53+
</BlurredOverlay>
54+
</div>
55+
</:content>
56+
57+
<:overlay>
58+
{{#if (eq @autofixRequest.status "success")}}
59+
<SecondaryButton class="bg-gray-800 mt-10" {{on "click" (fn (mut this.explanationWasUnblurred) true)}}>
60+
<div class="flex items-center gap-2">
61+
<div class="flex">{{svg-jar "eye" class="size-6"}}</div>
62+
Explain more?
63+
</div>
64+
</SecondaryButton>
65+
{{/if}}
66+
</:overlay>
67+
</BlurredOverlay>
68+
</AnimatedContainer>
69+
</div>
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import Component from '@glimmer/component';
2+
import type AutofixRequestModel from 'codecrafters-frontend/models/autofix-request';
3+
import fade from 'ember-animated/transitions/fade';
4+
import { tracked } from '@glimmer/tracking';
5+
6+
interface Signature {
7+
Element: HTMLDivElement;
8+
9+
Args: {
10+
autofixRequest: AutofixRequestModel;
11+
};
12+
}
13+
14+
export default class AutofixRequestCard extends Component<Signature> {
15+
transition = fade;
16+
17+
@tracked diffWasUnblurred = false;
18+
@tracked explanationWasUnblurred = false;
19+
20+
get changedFilesForRender(): AutofixRequestModel['changedFiles'] {
21+
if (this.args.autofixRequest.status === 'in_progress') {
22+
return [
23+
{
24+
filename: 'placeholder.txt', // TODO: This should be the actual filename
25+
diff: `
26+
def main():
27+
- print("Hello, world!")
28+
+ print("Hello, worlds!")
29+
30+
+ foo = calculate(bar)
31+
32+
if __name__ == "__main__":
33+
main()
34+
`,
35+
},
36+
];
37+
} else {
38+
return this.args.autofixRequest.changedFiles;
39+
}
40+
}
41+
42+
get diffIsBlurred() {
43+
// We never show a diff unless the autofix request is successful
44+
if (this.args.autofixRequest.status !== 'success') {
45+
return true;
46+
}
47+
48+
return !this.diffWasUnblurred;
49+
}
50+
51+
get explanationIsBlurred() {
52+
if (this.args.autofixRequest.status !== 'success') {
53+
return true;
54+
}
55+
56+
return !this.explanationWasUnblurred;
57+
}
58+
}
59+
60+
declare module '@glint/environment-ember-loose/registry' {
61+
export default interface Registry {
62+
'CoursePage::TestResultsBar::AutofixRequestCard': typeof AutofixRequestCard;
63+
}
64+
}
Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,38 @@
1-
<div class="pb-3 flex flex-col" ...attributes data-test-autofix-section>
2-
<CoursePage::TestResultsBar::AutofixSection::AutofixResult @autofixRequest={{@autofixRequest}} class="overflow-y-auto grow" />
1+
<div
2+
class="flex flex-col items-center justify-center p-6 mb-3 bg-gray-900 rounded-sm border border-white/10 relative"
3+
...attributes
4+
data-test-autofix-section
5+
>
6+
<div class="absolute inset-0 flex items-stretch justify-stretch">
7+
<div class="w-full relative overflow-hidden rounded-sm">
8+
{{! Left blurred gradient }}
9+
<div class="w-1/2 h-60 absolute -bottom-32 -left-1/4 opacity-50 animate-spin-medium filter blur-[100px]">
10+
<div class="relative">
11+
<div class="rounded-full h-60 w-full bg-purple-800"></div>
12+
<div class="absolute bottom-24 -left-24 rounded-full h-60 w-full bg-red-800"></div>
13+
<div class="absolute top-24 left-24 rounded-full h-60 w-full bg-purple-600"></div>
14+
</div>
15+
</div>
16+
17+
{{! Right blurred gradient }}
18+
<div class="w-1/2 h-60 absolute -bottom-40 -right-1/4 opacity-50 animate-spin-medium filter blur-[100px]">
19+
<div class="relative">
20+
<div class="rounded-full h-60 w-full bg-blue-600"></div>
21+
<div class="absolute bottom-24 -left-24 rounded-full h-60 w-full bg-blue-700"></div>
22+
<div class="absolute top-24 left-24 rounded-full h-60 w-full bg-purple-600"></div>
23+
</div>
24+
</div>
25+
{{! Center blurred gradient }}
26+
27+
<div class="w-1/2 h-60 absolute top-0 left-1/1 right-1/4 opacity-50 animate-spin-medium filter blur-[100px]">
28+
<div class="relative">
29+
<div class="rounded-full h-60 w-full bg-blue-600"></div>
30+
<div class="absolute bottom-24 -left-24 rounded-full h-60 w-full bg-purple-700"></div>
31+
<div class="absolute top-24 left-24 rounded-full h-60 w-full bg-purple-600"></div>
32+
</div>
33+
</div>
34+
</div>
35+
</div>
36+
37+
<CoursePage::TestResultsBar::AutofixRequestCard @autofixRequest={{@autofixRequest}} class="z-10" />
338
</div>

app/tailwind.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ module.exports = {
2525
gray: colors.slate,
2626
green: colors.green,
2727
indigo: colors.indigo,
28+
purple: colors.purple,
2829
pink: colors.pink,
2930
red: colors.red,
3031
sky: colors.sky,
@@ -483,6 +484,7 @@ module.exports = {
483484
'infinite-slide': 'infinite-slide 30s linear infinite',
484485
'blink-fast': 'blink 1s step-start infinite',
485486
'spin-slow': 'spin 16s linear infinite',
487+
'spin-medium': 'spin 4s linear infinite',
486488
},
487489
},
488490
},

0 commit comments

Comments
 (0)