Skip to content

Commit dbe0467

Browse files
committed
chore: make error displays use tailwind for styling
1 parent ae8ec4b commit dbe0467

File tree

3 files changed

+34
-113
lines changed

3 files changed

+34
-113
lines changed

src/components/EditorDisplay.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { useEffect, useMemo, useRef, useState } from "react";
99
import { flushSync } from "react-dom";
1010

1111
import { useMediaQuery } from "@/hooks/use-media-query";
12+
1213
import { ScrollLocation, useCookieService } from "../services/cookieservice";
1314
import { DataStore, DataStoreItem, DataStoreItemKind } from "../services/datastore";
1415
import { LocalParseState } from "../services/localparse";

src/components/panels/errordisplays.tsx

Lines changed: 15 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import "react-reflex/styles.css";
22

3-
import { Theme, createStyles, makeStyles } from "@material-ui/core/styles";
43
import { Link } from "@tanstack/react-router";
54
import { CircleX, MessageCircleWarning } from "lucide-react";
65

@@ -21,64 +20,20 @@ export const ERROR_SOURCE_TO_ITEM = {
2120
[DeveloperError_Source.UNKNOWN_SOURCE]: undefined,
2221
};
2322

24-
const useErrorDisplayStyles = makeStyles((theme: Theme) =>
25-
createStyles({
26-
validationError: {
27-
border: 0,
28-
},
29-
foundVia: {
30-
marginTop: theme.spacing(1),
31-
},
32-
foundViaList: {
33-
margin: 0,
34-
fontFamily: "Roboto Mono, monospace",
35-
listStyleType: "none",
36-
"& li::after": {
37-
content: '" →"',
38-
},
39-
"& li:last-child::after": {
40-
content: '""',
41-
},
42-
},
43-
editorContainer: {
44-
display: "grid",
45-
alignItems: "center",
46-
gridTemplateColumns: "auto 1fr",
47-
},
48-
dot: {
49-
display: "inline-block",
50-
marginRight: theme.spacing(1),
51-
borderRadius: "50%",
52-
width: "8px",
53-
height: "8px",
54-
},
55-
progress: {
56-
color: theme.palette.text.primary,
57-
},
58-
success: {
59-
color: theme.palette.success.main,
60-
},
61-
gray: {
62-
color: theme.palette.grey[500],
63-
},
64-
warning: {
65-
color: theme.palette.warning.main,
66-
},
67-
}),
68-
);
69-
7023
export function DeveloperErrorDisplay({ error }: { error: DeveloperError }) {
71-
const classes = useErrorDisplayStyles();
7224
return (
7325
<Alert variant="destructive">
7426
<CircleX />
7527
<AlertTitle>{error.message}</AlertTitle>
7628
{error.path.length > 0 && (
7729
<AlertDescription>
7830
Found Via:
79-
<ul className={classes.foundViaList}>
31+
<ul className="">
8032
{error.path.map((item) => (
81-
<li key={item}>{item}</li>
33+
// NOTE: the \2192 here is the → character; tailwind needs it as an escape sequence.
34+
<li className="after:content-['\2192'] after:ml-2 last:after:content-none" key={item}>
35+
{item}
36+
</li>
8237
))}
8338
</ul>
8439
</AlertDescription>
@@ -96,72 +51,42 @@ export function DeveloperWarningDisplay({ warning }: { warning: DeveloperWarning
9651
);
9752
}
9853

99-
const useSourceDisplayStyles = makeStyles((theme: Theme) =>
100-
createStyles({
101-
link: {
102-
color: theme.palette.text.primary,
103-
},
104-
validationErrorContext: {
105-
padding: theme.spacing(1),
106-
backgroundColor: theme.palette.background.default,
107-
},
108-
}),
109-
);
110-
11154
export function DeveloperWarningSourceDisplay({ warning }: { warning: DeveloperWarning }) {
112-
const classes = useSourceDisplayStyles();
113-
11455
return (
115-
<div className={classes.validationErrorContext}>
56+
<div className="m-2">
11657
In
117-
<Link className={classes.link} to={DataStorePaths.Schema()}>
118-
Schema
119-
</Link>
58+
<Link to={DataStorePaths.Schema()}>Schema</Link>
12059
{/* NOTE: this is a guess; I think this was an unintentional omission. */}: {warning.message}
12160
</div>
12261
);
12362
}
12463

12564
export function DeveloperSourceDisplay({ error }: { error: DeveloperError }) {
126-
const classes = useSourceDisplayStyles();
127-
12865
// TODO: unify with error source above.
12966
return (
13067
<div>
13168
{error.source === DeveloperError_Source.SCHEMA && (
132-
<div className={classes.validationErrorContext}>
69+
<div className="m-2">
13370
In
134-
<Link className={classes.link} to={DataStorePaths.Schema()}>
135-
Schema
136-
</Link>
137-
:
71+
<Link to={DataStorePaths.Schema()}>Schema</Link>:
13872
</div>
13973
)}
14074
{error.source === DeveloperError_Source.ASSERTION && (
141-
<div className={classes.validationErrorContext}>
75+
<div className="m-2">
14276
In
143-
<Link className={classes.link} to={DataStorePaths.Assertions()}>
144-
Assertions
145-
</Link>
146-
:
77+
<Link to={DataStorePaths.Assertions()}>Assertions</Link>:
14778
</div>
14879
)}
14980
{error.source === DeveloperError_Source.RELATIONSHIP && (
150-
<div className={classes.validationErrorContext}>
81+
<div className="m-2">
15182
In
152-
<Link className={classes.link} to={DataStorePaths.Relationships()}>
153-
Test Data
154-
</Link>
155-
:
83+
<Link to={DataStorePaths.Relationships()}>Test Data</Link>:
15684
</div>
15785
)}
15886
{error.source === DeveloperError_Source.VALIDATION_YAML && (
159-
<div className={classes.validationErrorContext}>
87+
<div className="m-2">
16088
In
161-
<Link className={classes.link} to={DataStorePaths.ExpectedRelations()}>
162-
Expected Relations
163-
</Link>
164-
:
89+
<Link to={DataStorePaths.ExpectedRelations()}>Expected Relations</Link>:
16590
</div>
16691
)}
16792
</div>

src/hooks/use-media-query.ts

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,42 @@
1-
import { useState, useLayoutEffect } from 'react'
1+
import { useState, useLayoutEffect } from "react";
22

33
type UseMediaQueryOptions = {
4-
defaultValue?: boolean
5-
initializeWithValue?: boolean
6-
}
4+
defaultValue?: boolean;
5+
initializeWithValue?: boolean;
6+
};
77

88
const getMatches = (query: string): boolean => {
9-
return window.matchMedia(query).matches
10-
}
9+
return window.matchMedia(query).matches;
10+
};
1111

1212
export function useMediaQuery(
1313
query: string,
14-
{
15-
defaultValue = false,
16-
initializeWithValue = true,
17-
}: UseMediaQueryOptions = {},
14+
{ defaultValue = false, initializeWithValue = true }: UseMediaQueryOptions = {},
1815
): boolean {
1916
const [matches, setMatches] = useState(() => {
2017
if (initializeWithValue) {
21-
return getMatches(query)
18+
return getMatches(query);
2219
}
23-
return defaultValue
24-
})
25-
20+
return defaultValue;
21+
});
2622

2723
useLayoutEffect(() => {
28-
const matchMedia = window.matchMedia(query)
24+
const matchMedia = window.matchMedia(query);
2925

3026
// Handles the change event of the media query.
3127
// Declared inside the layout effect so that we don't need
3228
// to worry about its identity.
33-
const handleChange = () => setMatches(getMatches(query))
29+
const handleChange = () => setMatches(getMatches(query));
3430

3531
// Triggered at the first client-side load and if query changes
36-
handleChange()
32+
handleChange();
3733

38-
matchMedia.addEventListener('change', handleChange)
34+
matchMedia.addEventListener("change", handleChange);
3935

4036
return () => {
41-
matchMedia.removeEventListener('change', handleChange)
42-
}
43-
}, [query])
37+
matchMedia.removeEventListener("change", handleChange);
38+
};
39+
}, [query]);
4440

45-
return matches
41+
return matches;
4642
}
47-

0 commit comments

Comments
 (0)