Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More checkmate improvements #5728

Merged
merged 5 commits into from
Aug 4, 2023
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
41 changes: 41 additions & 0 deletions crates/compiler/checkmate/www/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/compiler/checkmate/www/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"react-dom": "^18.2.0",
"react-router-dom": "^6.14.2",
"react-router-hash-link": "^2.4.3",
"react-tooltip": "^5.19.0",
"reactflow": "^11.7.4"
},
"scripts": {
Expand Down
7 changes: 1 addition & 6 deletions crates/compiler/checkmate/www/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import React from "react";
import FileInput, { LoadedEvents } from "./components/FileInput";
import Ui from "./components/Ui";
import data from "./checkmate.json";
import { AllEvents } from "./schema";
import { BrowserRouter } from "react-router-dom";

export default function App() {
const [events, setEvents] = React.useState<LoadedEvents | null>({
kind: "ok",
events: data as AllEvents,
});
const [events, setEvents] = React.useState<LoadedEvents | null>(null);

return (
<BrowserRouter>
Expand Down
68 changes: 18 additions & 50 deletions crates/compiler/checkmate/www/src/components/Common/EpochCell.tsx
Original file line number Diff line number Diff line change
@@ -1,60 +1,28 @@
import clsx from "clsx";
import { EventEpoch } from "../../engine/engine";
import { HashLink } from "react-router-hash-link";

export enum EpochCellView {
Events,
Graph,
}

function invert(cell: EpochCellView): EpochCellView {
if (cell === EpochCellView.Events) {
return EpochCellView.Graph;
}
return EpochCellView.Events;
}

function asStr(cell: EpochCellView): string {
switch (cell) {
case EpochCellView.Events:
return "events";
case EpochCellView.Graph:
return "graph";
}
}

interface EpochCellProps {
view: EpochCellView;
epoch: EventEpoch;
className?: string;
children?: React.ReactNode;
focus?: boolean;
}

const EPOCH_STYLES_ARRAY = [
"text-slate-900",
"font-mono",
"bg-slate-200",
"p-1",
"py-0",
"rounded-sm",
"ring-1",
"ring-slate-500",
"text-sm",
];

export const EPOCH_STYLES = clsx(...EPOCH_STYLES_ARRAY);

export default function EpochCell({ epoch, className, view }: EpochCellProps) {
const invertedView = invert(view);
export const EPOCH_STYLES =
"text-slate-900 font-mono bg-slate-200 p-1 py-0 rounded-sm text-sm transition ease-in-out duration-700 mr-2";

export default function EpochCell({
className,
children,
focus,
}: EpochCellProps) {
return (
<HashLink smooth to={`#${asStr(invertedView)}-${epoch}`}>
<div
id={`${asStr(view)}-${epoch}`}
className={clsx(EPOCH_STYLES, className)}
>
{view === EpochCellView.Graph ? "Epoch " : ""}
{epoch}
</div>
</HashLink>
<span
className={clsx(
EPOCH_STYLES,
className,
focus === true ? "ring-2 ring-blue-500" : "ring-1 ring-slate-500"
)}
>
{children}
</span>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import clsx from "clsx";
import { Variable } from "../../schema";
import { VariableName } from "./VariableName";

export interface UnknownVariableProps {
variable: Variable;
}

export function UnknownVariable({
variable,
}: UnknownVariableProps): JSX.Element {
return (
<div className={clsx("rounded-md whitespace-nowrap space-x-1 pr-1")}>
<VariableName className="inline-block" variable={variable} />
<span>???</span>
</div>
);
}
26 changes: 8 additions & 18 deletions crates/compiler/checkmate/www/src/components/Common/Variable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { QuerySubs, TypeDescriptor } from "../../engine/subs";
import { Variable } from "../../schema";
import DrawHeadConstructor from "../Content/HeadConstructor";
import { contentStyles } from "./../Content";
import { VariableName } from "./VariableName";

interface VariableElProps {
variable: Variable;
Expand Down Expand Up @@ -51,23 +52,6 @@ function Helper({
desc: TypeDescriptor | undefined;
}): JSX.Element {
const { bg } = contentStyles(desc);
const varHeader =
!nested || raw ? (
<span
className={clsx(
"ring-1 ring-inset ring-black-100 px-1 bg-white rounded-md cursor",
nested ? "text-md" : "p-0.5"
)}
onClick={(e) => {
e.stopPropagation();
onClick?.(variable);
}}
>
{variable}
</span>
) : (
<></>
);
return (
<span
className={clsx(
Expand All @@ -76,7 +60,13 @@ function Helper({
nested ? "text-sm" : "p-0.5 pl-0 text-base"
)}
>
{varHeader}
{(!nested || raw) && (
<VariableName
variable={variable}
onClick={onClick}
className={nested ? "text-md" : "p-0.5"}
/>
)}
{children ? <span className="px-1">{children}</span> : <></>}
</span>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import clsx from "clsx";
import { QuerySubs } from "../../engine/subs";
import { Variable } from "../../schema";
import { VariableName } from "./VariableName";

export interface VariableLinkProps {
variable: Variable;
subs: QuerySubs;
onClick?: (variable: Variable) => void;
}

export function VariableLink({
variable,
subs,
onClick,
}: VariableLinkProps): JSX.Element {
const root = subs.get_root_key(variable);

if (variable === root) {
throw new Error("VariableLink: variable is root");
}

return (
<div className={clsx("rounded-md whitespace-nowrap space-x-1")}>
<VariableName className="inline-block" variable={variable} />
<span>→</span>
<VariableName
className="inline-block"
variable={root}
onClick={onClick}
/>
</div>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import clsx from "clsx";
import { Variable } from "../../schema";

export interface VariableNameProps {
variable: Variable;
onClick?: (variable: Variable) => void;
className?: string;
}

export function VariableName({
variable,
onClick,
className,
}: VariableNameProps): JSX.Element {
return (
<span
className={clsx(
"ring-1 ring-inset ring-black-100 px-1 bg-white rounded-md",
onClick && "cursor-pointer",
className
)}
onClick={(e) => {
e.stopPropagation();
onClick?.(variable);
}}
>
{variable}
</span>
);
}
2 changes: 2 additions & 0 deletions crates/compiler/checkmate/www/src/components/Content/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,5 @@ export function contentStyles(desc: TypeDescriptor | undefined): ContentStyles {
return { name: "Error", bg: "bg-red-400" };
}
}

export const LinkStyles: ContentStyles = { name: "Link", bg: "bg-slate-500" };
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ interface VariableProps extends CommonProps {

export function VariableEl({
engine,
toggleVariableVis,
epoch,
variable,
graphEe,
}: VariableProps): JSX.Element {
engine.stepTo(epoch);
return (
<VariableElPretty
variable={variable}
subs={engine.subs}
onClick={(variable: Variable) => {
toggleVariableVis(variable);
graphEe.emit("focusVariable", variable);
}}
></VariableElPretty>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { TypedEmitter } from "tiny-typed-emitter";
import type { Engine, EventEpoch } from "../../engine/engine";
import type { Variable } from "../../schema";
import { GraphMessage } from "../../utils/events";

export interface CommonProps {
currentEpoch: EventEpoch;
selectedEpochs: EventEpoch[];
engine: Engine;
toggleVariableVis: (variable: Variable) => void;
graphEe: TypedEmitter<GraphMessage>;
}
Loading
Loading