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

merge-queue: embarking main (f012bfa) and #426 together #428

Closed
wants to merge 6 commits into from
Closed
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
50 changes: 43 additions & 7 deletions packages/primer-app/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,56 @@
// TODO this is very much a placeholder
import { TreeReactFlow, tree1, tree4 } from "@hackworthltd/primer-components";
import { TreeReactFlow, Error } from "@hackworthltd/primer-components";
import "@hackworthltd/primer-components/style.css";
import { useParams } from "react-router-dom";
import { useGetApiProgram } from "./primer-api";

const App = (): JSX.Element => {
const params = useParams();
const session = params["sessionId"];

if (!session) {
return (
<Error string={"No session id parameter: " + JSON.stringify(params)} />
);
}
// This hook is *technically* conditional.
// But if the condition above fails, then the app is broken anyway.
// eslint-disable-next-line react-hooks/rules-of-hooks
const queryRes = useGetApiProgram({ session });

if (!queryRes.isSuccess) {
return (
<Error
string={
"Failed to get program from backend: " +
JSON.stringify(queryRes.error)
}
/>
);
}
const prog = queryRes.data;

const editableModules = prog.modules.filter((m) => m.editable);
if (editableModules.length > 1) {
return (
<Error
string={"Multiple editable modules: " + JSON.stringify(editableModules)}
/>
);
}
const module = editableModules[0];
if (!module) {
return <Error string="No editable modules" />;
}
const trees = module.defs.flatMap((def) => def.term || []);

return (
<div>
{"Session: " + params["sessionId"]}
<TreeReactFlow
trees={[tree1, tree4]}
width={1000}
trees={trees}
width={1500}
height={800}
nodeWidth={100}
nodeHeight={40}
nodeWidth={200}
nodeHeight={100}
></TreeReactFlow>
</div>
);
Expand Down
13 changes: 13 additions & 0 deletions packages/primer-components/src/Error/Error.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ComponentStory, ComponentMeta } from "@storybook/react";
import { Error } from "./Error";

export default {
title: "Application/Component Library/Error",
component: Error,
} as ComponentMeta<typeof Error>;

const Template: ComponentStory<typeof Error> = () => (
<Error string="some error message" />
);

export const Default = Template.bind({});
9 changes: 9 additions & 0 deletions packages/primer-components/src/Error/Error.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import "@/index.css";

export type ErrorProps = {
string: string;
};

export const Error = (p: ErrorProps): JSX.Element => (
<p className="mx-4">Error: {p.string}</p>
);
3 changes: 3 additions & 0 deletions packages/primer-components/src/Error/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { Error } from "./Error";

export default Error;
1 change: 1 addition & 0 deletions packages/primer-components/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export { default as ActionButton } from "@/ActionButton";
export { default as ActionButtonList } from "@/ActionButtonList";
export { default as Avatar } from "@/Avatar";
export { default as BinaryTreePlaceholder } from "@/BinaryTreePlaceholder";
export { default as Error } from "@/Error";
export { default as FloatingToolbar } from "@/FloatingToolbar";
export { default as GroupedButtonList } from "@/GroupedButtonList";
export { default as NoMatch } from "@/NoMatch";
Expand Down