Skip to content

Commit a8317f0

Browse files
committed
refactor: improve code clarity and maintainability
- Replace !! operator with Boolean() for type coercion in build-instruqt-url - Move sandbox error boundary styles to CSS module - Create sandbox-error-boundary.module.css - Update components to use CSS module classes - Maintain existing functionality and visual styles These changes improve code quality by: - Using explicit Boolean() constructor instead of double negation - Following project conventions for CSS modules - Removing inline styles for better maintainability
1 parent 4314f49 commit a8317f0

File tree

3 files changed

+45
-30
lines changed

3 files changed

+45
-30
lines changed

src/components/sandbox-error-boundary/index.tsx

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import React, { ReactNode } from 'react'
77
import { ErrorBoundary } from 'react-error-boundary'
88
import { trackSandboxEvent, SANDBOX_EVENT } from 'lib/posthog-events'
9+
import s from './sandbox-error-boundary.module.css'
910

1011
interface SandboxErrorBoundaryProps {
1112
children: ReactNode
@@ -30,44 +31,22 @@ const SandboxErrorFallback = ({
3031
We encountered an unexpected error while loading your sandbox environment.
3132
This issue has been reported and we’re working to fix it.
3233
</p>
33-
<details style={{ marginTop: '1rem', fontSize: '0.875rem' }}>
34+
<details className={s.details}>
3435
<summary>Technical Details</summary>
35-
<pre style={{
36-
marginTop: '0.5rem',
37-
padding: '0.5rem',
38-
backgroundColor: '#f5f5f5',
39-
borderRadius: '4px',
40-
overflow: 'auto',
41-
fontSize: '0.75rem'
42-
}}>
36+
<pre className={s.detailsContent}>
4337
{error.message}
4438
</pre>
4539
</details>
46-
<div style={{ marginTop: '1rem' }}>
40+
<div className={s.buttonContainer}>
4741
<button
4842
onClick={resetErrorBoundary}
49-
style={{
50-
backgroundColor: '#1f2937',
51-
color: 'white',
52-
border: 'none',
53-
borderRadius: '4px',
54-
padding: '0.75rem 1.5rem',
55-
marginRight: '0.5rem',
56-
cursor: 'pointer'
57-
}}
43+
className={s.primaryButton}
5844
>
5945
Try Again
6046
</button>
6147
<button
6248
onClick={() => window.location.reload()}
63-
style={{
64-
backgroundColor: 'transparent',
65-
color: '#1f2937',
66-
border: '1px solid #d1d5db',
67-
borderRadius: '4px',
68-
padding: '0.75rem 1.5rem',
69-
cursor: 'pointer'
70-
}}
49+
className={s.secondaryButton}
7150
>
7251
Refresh Page
7352
</button>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
.details {
2+
margin-top: 1rem;
3+
font-size: 0.875rem;
4+
}
5+
6+
.detailsContent {
7+
margin-top: 0.5rem;
8+
padding: 0.5rem;
9+
background-color: #f5f5f5;
10+
border-radius: 4px;
11+
overflow: auto;
12+
font-size: 0.75rem;
13+
}
14+
15+
.buttonContainer {
16+
margin-top: 1rem;
17+
}
18+
19+
.primaryButton {
20+
background-color: #1f2937;
21+
color: white;
22+
border: none;
23+
border-radius: 4px;
24+
padding: 0.75rem 1.5rem;
25+
margin-right: 0.5rem;
26+
cursor: pointer;
27+
}
28+
29+
.secondaryButton {
30+
background-color: transparent;
31+
color: #1f2937;
32+
border: 1px solid #d1d5db;
33+
border-radius: 4px;
34+
padding: 0.75rem 1.5rem;
35+
cursor: pointer;
36+
}

src/lib/build-instruqt-url.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export function buildLabId(
5454
trackInstruqtUrlError(
5555
'null_lab_config',
5656
'Lab configuration is null or undefined',
57-
{ custom_tokens_provided: !!customTokens }
57+
{ custom_tokens_provided: Boolean(customTokens) }
5858
)
5959
return ''
6060
}
@@ -65,7 +65,7 @@ export function buildLabId(
6565
'Lab instruqtTrack is missing',
6666
{
6767
lab_id: lab.labId,
68-
lab_has_scenario: !!lab.scenario,
68+
lab_has_scenario: Boolean(lab.scenario),
6969
}
7070
)
7171
return lab.labId || ''
@@ -89,7 +89,7 @@ export function buildLabId(
8989
error_stack: error instanceof Error ? error.stack : undefined,
9090
lab_id: lab?.labId,
9191
instruqt_track: lab?.instruqtTrack,
92-
has_scenario: !!lab?.scenario,
92+
has_scenario: Boolean(lab?.scenario),
9393
}
9494
)
9595
return lab?.labId || ''

0 commit comments

Comments
 (0)