-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3324 from quantified-uncertainty/project2
SqProject rewrite
- Loading branch information
Showing
143 changed files
with
4,942 additions
and
2,602 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
packages/components/src/components/ProjectStateViewer/ActionLog.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { FC, useEffect, useRef, useState } from "react"; | ||
|
||
import { | ||
ProjectAction, | ||
ProjectEventListener, | ||
SqProject, | ||
} from "@quri/squiggle-lang"; | ||
import { Tooltip } from "@quri/ui"; | ||
|
||
const ActionDetails: FC<{ action: ProjectAction }> = ({ action }) => { | ||
switch (action.type) { | ||
case "loadImports": | ||
return <div>{action.payload}</div>; | ||
case "buildOutputIfPossible": | ||
return <div>{action.payload.hash}</div>; | ||
case "loadModule": | ||
return <div>{action.payload.name}</div>; | ||
default: | ||
return null; | ||
} | ||
}; | ||
|
||
export const ActionLog: FC<{ project: SqProject }> = ({ project }) => { | ||
const [actionLog, setActionLog] = useState<ProjectAction[]>([]); | ||
|
||
useEffect(() => { | ||
const listener: ProjectEventListener<"action"> = (event) => { | ||
setActionLog((log) => [...log, event.data]); | ||
}; | ||
project.addEventListener("action", listener); | ||
return () => project.removeEventListener("action", listener); | ||
}); | ||
|
||
const ref = useRef<HTMLDivElement>(null); | ||
useEffect(() => { | ||
ref.current?.scrollTo(0, ref.current.scrollHeight); | ||
}, [actionLog]); | ||
|
||
return ( | ||
<details> | ||
<summary className="cursor-pointer text-sm font-medium text-slate-700"> | ||
Action log | ||
</summary> | ||
<div className="max-h-24 overflow-y-auto p-2 text-xs" ref={ref}> | ||
{actionLog.map((action, index) => ( | ||
<div key={index} className="flex"> | ||
<div className="cursor-pointer px-1 hover:bg-slate-100"> | ||
<Tooltip | ||
render={() => ( | ||
<div className="max-w-64 whitespace-pre-wrap break-all rounded border bg-white px-2 py-1 text-xs shadow-md"> | ||
{JSON.stringify(action, null, 2)} | ||
</div> | ||
)} | ||
> | ||
<div className="flex gap-1"> | ||
<div className="text-slate-500">{action.type}</div> | ||
<ActionDetails action={action} /> | ||
</div> | ||
</Tooltip> | ||
</div> | ||
</div> | ||
))} | ||
</div> | ||
</details> | ||
); | ||
}; |
Oops, something went wrong.