Skip to content
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
16 changes: 3 additions & 13 deletions src/components/EditorDisplay.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import "react-reflex/styles.css";

import { createStyles, makeStyles } from "@material-ui/core/styles";
import useMediaQuery from "@material-ui/core/useMediaQuery";
import Editor, { DiffEditor, useMonaco } from "@monaco-editor/react";
import { useDebouncedCallback } from "@tanstack/react-pacer/debouncer";
import { useNavigate, useLocation } from "@tanstack/react-router";
Expand All @@ -10,6 +8,8 @@ import monaco from "monaco-editor";
import { useEffect, useMemo, useRef, useState } from "react";
import { flushSync } from "react-dom";

import { useMediaQuery } from "@/hooks/use-media-query";
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The new hook is interchangeable.


import { ScrollLocation, useCookieService } from "../services/cookieservice";
import { DataStore, DataStoreItem, DataStoreItemKind } from "../services/datastore";
import { LocalParseState } from "../services/localparse";
Expand All @@ -33,15 +33,6 @@ import registerTupleLanguage, {
TUPLE_THEME_NAME,
} from "./tuplelang";

const useStyles = makeStyles(() =>
createStyles({
editorContainer: {
height: "100%",
width: "100%",
},
}),
);

export type EditorDisplayProps = {
datastore: DataStore;
services: Services;
Expand Down Expand Up @@ -86,7 +77,6 @@ export function EditorDisplay(props: EditorDisplayProps) {
localParseState.current = props.services.localParseService.state;
}, [props.services.localParseService.state]);

const classes = useStyles();
const navigate = useNavigate();
const location = useLocation();

Expand Down Expand Up @@ -450,7 +440,7 @@ export function EditorDisplay(props: EditorDisplayProps) {
return (
<div>
{monacoReady && currentItem && (
<div className={classes.editorContainer}>
<div className="w-full h-full">
<Component
key={`${currentItem.id}-${props.diff ? "diff" : ""}`}
height={
Expand Down
105 changes: 15 additions & 90 deletions src/components/panels/errordisplays.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import "react-reflex/styles.css";

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

Expand All @@ -12,7 +11,7 @@
} from "../../spicedb-common/protodefs/developer/v1/developer_pb";
import { Alert, AlertDescription, AlertTitle } from "../ui/alert";

export const ERROR_SOURCE_TO_ITEM = {

Check warning on line 14 in src/components/panels/errordisplays.tsx

View workflow job for this annotation

GitHub Actions / Run Linters and Typechecking

Fast refresh only works when a file only exports components. Use a new file to share constants or functions between components
[DeveloperError_Source.SCHEMA]: DataStoreItemKind.SCHEMA,
[DeveloperError_Source.RELATIONSHIP]: DataStoreItemKind.RELATIONSHIPS,
[DeveloperError_Source.ASSERTION]: DataStoreItemKind.ASSERTIONS,
Expand All @@ -21,64 +20,20 @@
[DeveloperError_Source.UNKNOWN_SOURCE]: undefined,
};

const useErrorDisplayStyles = makeStyles((theme: Theme) =>
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Most of these styles were already unused as of the beginning of writing this PR

createStyles({
validationError: {
border: 0,
},
foundVia: {
marginTop: theme.spacing(1),
},
foundViaList: {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This was the only one that I had to recreate in tailwind; I verified by manual inspection that the styling I've come up with is equivalent.

margin: 0,
fontFamily: "Roboto Mono, monospace",
listStyleType: "none",
"& li::after": {
content: '" →"',
},
"& li:last-child::after": {
content: '""',
},
},
editorContainer: {
display: "grid",
alignItems: "center",
gridTemplateColumns: "auto 1fr",
},
dot: {
display: "inline-block",
marginRight: theme.spacing(1),
borderRadius: "50%",
width: "8px",
height: "8px",
},
progress: {
color: theme.palette.text.primary,
},
success: {
color: theme.palette.success.main,
},
gray: {
color: theme.palette.grey[500],
},
warning: {
color: theme.palette.warning.main,
},
}),
);

export function DeveloperErrorDisplay({ error }: { error: DeveloperError }) {
const classes = useErrorDisplayStyles();
return (
<Alert variant="destructive">
<CircleX />
<AlertTitle>{error.message}</AlertTitle>
{error.path.length > 0 && (
<AlertDescription>
Found Via:
<ul className={classes.foundViaList}>
<ul className="">
{error.path.map((item) => (
<li key={item}>{item}</li>
// NOTE: the \2192 here is the → character; tailwind needs it as an escape sequence.
<li className="after:content-['\2192'] after:ml-2 last:after:content-none" key={item}>
{item}
</li>
))}
</ul>
</AlertDescription>
Expand All @@ -96,72 +51,42 @@
);
}

const useSourceDisplayStyles = makeStyles((theme: Theme) =>
createStyles({
link: {
color: theme.palette.text.primary,
},
validationErrorContext: {
padding: theme.spacing(1),
backgroundColor: theme.palette.background.default,
},
}),
);

export function DeveloperWarningSourceDisplay({ warning }: { warning: DeveloperWarning }) {
const classes = useSourceDisplayStyles();

return (
<div className={classes.validationErrorContext}>
<div className="m-2">
In
<Link className={classes.link} to={DataStorePaths.Schema()}>
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't think this styling was doing anything.

Schema
</Link>
<Link to={DataStorePaths.Schema()}>Schema</Link>
{/* NOTE: this is a guess; I think this was an unintentional omission. */}: {warning.message}
</div>
);
}

export function DeveloperSourceDisplay({ error }: { error: DeveloperError }) {
const classes = useSourceDisplayStyles();

// TODO: unify with error source above.
return (
<div>
{error.source === DeveloperError_Source.SCHEMA && (
<div className={classes.validationErrorContext}>
<div className="m-2">
In
<Link className={classes.link} to={DataStorePaths.Schema()}>
Schema
</Link>
:
<Link to={DataStorePaths.Schema()}>Schema</Link>:
</div>
)}
{error.source === DeveloperError_Source.ASSERTION && (
<div className={classes.validationErrorContext}>
<div className="m-2">
In
<Link className={classes.link} to={DataStorePaths.Assertions()}>
Assertions
</Link>
:
<Link to={DataStorePaths.Assertions()}>Assertions</Link>:
</div>
)}
{error.source === DeveloperError_Source.RELATIONSHIP && (
<div className={classes.validationErrorContext}>
<div className="m-2">
In
<Link className={classes.link} to={DataStorePaths.Relationships()}>
Test Data
</Link>
:
<Link to={DataStorePaths.Relationships()}>Test Data</Link>:
</div>
)}
{error.source === DeveloperError_Source.VALIDATION_YAML && (
<div className={classes.validationErrorContext}>
<div className="m-2">
In
<Link className={classes.link} to={DataStorePaths.ExpectedRelations()}>
Expected Relations
</Link>
:
<Link to={DataStorePaths.ExpectedRelations()}>Expected Relations</Link>:
</div>
)}
</div>
Expand Down
42 changes: 42 additions & 0 deletions src/hooks/use-media-query.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { useState, useLayoutEffect } from "react";

type UseMediaQueryOptions = {
defaultValue?: boolean;
initializeWithValue?: boolean;
};

const getMatches = (query: string): boolean => {
return window.matchMedia(query).matches;
};

export function useMediaQuery(
query: string,
{ defaultValue = false, initializeWithValue = true }: UseMediaQueryOptions = {},
): boolean {
const [matches, setMatches] = useState(() => {
if (initializeWithValue) {
return getMatches(query);
}
return defaultValue;
});

useLayoutEffect(() => {
const matchMedia = window.matchMedia(query);

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

// Triggered at the first client-side load and if query changes
handleChange();

matchMedia.addEventListener("change", handleChange);

return () => {
matchMedia.removeEventListener("change", handleChange);
};
}, [query]);

return matches;
}
Loading