Skip to content

Commit

Permalink
chore: Bump Primer pin
Browse files Browse the repository at this point in the history
This brings in support for displaying and editing type definitions. We need to make a few changes to accommodate this.

Signed-off-by: George Thomas <[email protected]>
  • Loading branch information
georgefst committed May 31, 2023
1 parent 991295d commit 6011e4e
Show file tree
Hide file tree
Showing 30 changed files with 833 additions and 103 deletions.
2 changes: 1 addition & 1 deletion argocd/base/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ spec:
# Note: use the *dev* version of the package here, so that
# PRs can deploy `primer-service` container images that have
# not yet been merged to `primer` `main`.
image: ghcr.io/hackworthltd/primer-service-dev:git-1145eb89eb85354f67ec3cc5e25f59ef092a6c39
image: ghcr.io/hackworthltd/primer-service-dev:git-f35380015a14db87c5f330a84a5830adc51e1cbb
ports:
- containerPort: 8081
env:
Expand Down
8 changes: 4 additions & 4 deletions flake.lock

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

2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

# Note: don't override any of primer's Nix flake inputs, or else
# we won't hit its binary cache.
primer.url = github:hackworthltd/primer/1145eb89eb85354f67ec3cc5e25f59ef092a6c39;
primer.url = github:hackworthltd/primer/f35380015a14db87c5f330a84a5830adc51e1cbb;

flake-parts.url = "github:hercules-ci/flake-parts";
};
Expand Down
30 changes: 30 additions & 0 deletions src/Actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ export const actionName = (
return prose("r");
case "RenameDef":
return prose("r");
case "RenameType":
return prose("r");
case "AddCon":
return prose("+");
case "RenameCon":
return prose("r");
case "RenameTypeParam":
return prose("r");
case "AddConField":
return prose("+");
}
};

Expand Down Expand Up @@ -171,6 +181,16 @@ export const actionDescription = (
return "Rename this type variable";
case "RenameDef":
return "Rename this definition";
case "RenameType":
return "Rename this type";
case "AddCon":
return "Add a constructor to this type";
case "RenameCon":
return "Rename this constructor";
case "RenameTypeParam":
return "Rename this parameter";
case "AddConField":
return "Add a parameter to this constructor";
}
};

Expand Down Expand Up @@ -246,5 +266,15 @@ export const actionType = (action: NoInputAction | InputAction): ActionType => {
return "Primary";
case "RenameDef":
return "Primary";
case "RenameType":
return "Primary";
case "AddCon":
return "Primary";
case "RenameCon":
return "Primary";
case "RenameTypeParam":
return "Primary";
case "AddConField":
return "Primary";
}
};
81 changes: 70 additions & 11 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -215,16 +215,16 @@ const AppNoError = ({
.sort((a, b) => cmpName(a.name, b.name))
.map((d) => d.name.baseName),
types: p.module.types
.sort((a, b) => cmpName(a, b))
.map((t) => t.baseName),
.sort((a, b) => cmpName(a.name, b.name))
.map((t) => t.name.baseName),
importedDefs: p.imports
.flatMap((m) => m.defs)
.sort((a, b) => cmpName(a.name, b.name))
.map((d) => d.name.baseName),
importedTypes: p.imports
.flatMap((m) => m.types)
.sort((a, b) => cmpName(a, b))
.map((t) => t.baseName),
.sort((a, b) => cmpName(a.name, b.name))
.map((t) => t.name.baseName),
}}
onClickDef={(defName, _event) => {
if (scrollToDefRef.current != undefined) {
Expand Down Expand Up @@ -304,22 +304,79 @@ const AppNoError = ({
{...defaultTreeReactFlowProps}
{...(selection && { selection })}
onNodeClick={(_e, node) => {
if (!("nodeType" in node.data)) {
// TODO move selection conversion in to tree component?
// we could have `onClick` take it as an arg
if (node.type == "primer-typedef-name") {
setSelection({
tag: "SelectionTypeDef",
contents: { def: node.data.def },
});
// console.log("clicked type name");
} else if (node.type == "primer-def-name") {
setSelection({
def: node.data.def,
tag: "SelectionDef",
contents: { def: node.data.def },
});
} else if (node.type == "primer-typedef-param") {
setSelection({
tag: "SelectionTypeDef",
contents: {
def: node.data.def,
node: {
tag: "TypeDefParamNodeSelection",
contents: node.data.name,
},
},
});
} else if (node.type == "primer-typedef-cons") {
setSelection({
tag: "SelectionTypeDef",
contents: {
def: node.data.def,
node: {
tag: "TypeDefConsNodeSelection",
contents: { con: node.data.name },
},
},
});
} else {
console.log(1, node.id);
const id = Number(node.id);
// Non-numeric IDs correspond to non-selectable nodes (those with no ID in backend) e.g. pattern constructors.
if (!isNaN(id)) {
setSelection({
def: node.data.def,
node: { id, nodeType: node.data.nodeType },
});
// if (node.data.nodeType != "typedefFieldNode") {
// if (!("typedefFieldNode" in node.data.nodeType)) {
if (typeof node.data.nodeType == "string") {
setSelection({
tag: "SelectionDef",
contents: {
def: node.data.def,
node: { meta: id, nodeType: node.data.nodeType },
},
});
} else {
setSelection({
tag: "SelectionTypeDef",
contents: {
def: node.data.def,
node: {
tag: "TypeDefConsNodeSelection",
contents: {
con: node.data.nodeType.typedefFieldNode.con,
field: {
index: node.data.nodeType.typedefFieldNode.nChild,
meta: id,
},
},
},
},
});
}
}
}
}}
defs={p.module.defs}
typeDefs={p.module.types}
level={level}
/>
</div>
Expand Down Expand Up @@ -380,7 +437,9 @@ const AppNoError = ({
) : null}
{showCreateTypeDefModal ? (
<CreateTypeDefModal
moduleTypeDefNames={new Set(p.module.types.map((t) => t.baseName))}
moduleTypeDefNames={
new Set(p.module.types.map((t) => t.name.baseName))
}
open={showCreateTypeDefModal}
onClose={() => setShowCreateTypeDefModal(false)}
onCancel={() => setShowCreateTypeDefModal(false)}
Expand Down
36 changes: 29 additions & 7 deletions src/components/TreeReactFlow/TreeReactFlow.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const props: Omit<TreeReactFlowProps, "defs"> = {
...defaultTreeReactFlowProps,
scrollToDefRef: { current: undefined },
forestLayout: "Vertical",
typeDefs: [],
};

const emptyTypeTree = (nodeId: string): Tree => {
Expand Down Expand Up @@ -90,7 +91,10 @@ export const Tree1: ComponentStory<typeof TreeReactFlow> = (
treeSized({
...args,
defs: [def1],
selection: { def: def1.name, node: { nodeType: "BodyNode", id: 100 } },
selection: {
tag: "SelectionDef",
contents: { def: def1.name, node: { nodeType: "BodyNode", meta: 100 } },
},
});
export const Tree2: ComponentStory<typeof TreeReactFlow> = (
args: TreeReactFlowProps
Expand All @@ -105,45 +109,63 @@ export const Tree3: ComponentStory<typeof TreeReactFlow> = (
treeSized({
...args,
defs: [def3],
selection: { def: def3.name, node: { nodeType: "BodyNode", id: 301 } },
selection: {
tag: "SelectionDef",
contents: { def: def3.name, node: { nodeType: "BodyNode", meta: 301 } },
},
});
export const Tree4: ComponentStory<typeof TreeReactFlow> = (
args: TreeReactFlowProps
) =>
treeSized({
...args,
defs: [def4],
selection: { def: def4.name, node: { nodeType: "BodyNode", id: 409 } },
selection: {
tag: "SelectionDef",
contents: { def: def4.name, node: { nodeType: "BodyNode", meta: 409 } },
},
});
export const Tree5: ComponentStory<typeof TreeReactFlow> = (
args: TreeReactFlowProps
) =>
treeSized({
...args,
defs: [def5],
selection: { def: def5.name, node: { nodeType: "BodyNode", id: 503 } },
selection: {
tag: "SelectionDef",
contents: { def: def5.name, node: { nodeType: "BodyNode", meta: 503 } },
},
});
export const AllTrees: ComponentStory<typeof TreeReactFlow> = (
args: TreeReactFlowProps
) =>
treeSized({
...args,
defs: [def1, def2, def3, def4, def5],
selection: { def: def3.name, node: { nodeType: "BodyNode", id: 301 } },
selection: {
tag: "SelectionDef",
contents: { def: def3.name, node: { nodeType: "BodyNode", meta: 301 } },
},
});
export const OddAndEven: ComponentStory<typeof TreeReactFlow> = (
args: TreeReactFlowProps
) =>
treeSized({
...args,
defs: oddEvenDefs,
selection: { def: def5.name, node: { nodeType: "BodyNode", id: 5 } },
selection: {
tag: "SelectionDef",
contents: { def: def5.name, node: { nodeType: "BodyNode", meta: 5 } },
},
});
export const OddAndEvenMiscStyles: ComponentStory<typeof TreeReactFlow> = (
args: TreeReactFlowProps
) =>
treeSized({
...args,
defs: oddEvenDefsMiscStyles,
selection: { def: def5.name, node: { nodeType: "BodyNode", id: 5 } },
selection: {
tag: "SelectionDef",
contents: { def: def5.name, node: { nodeType: "BodyNode", meta: 5 } },
},
});
34 changes: 29 additions & 5 deletions src/components/TreeReactFlow/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
NodeType,
} from "@/primer-api";
import { unzip } from "fp-ts/lib/Array";
import { Position } from "reactflow";
import { NodeFlavor } from "./Flavor";

/** A generic graph. */
Expand Down Expand Up @@ -120,6 +121,10 @@ export type PrimerNode<T = unknown> = {
| { type: "primer-simple"; data: PrimerSimpleNodeProps }
| { type: "primer-box"; data: PrimerBoxNodeProps }
| { type: "primer-def-name"; data: PrimerDefNameNodeProps }
// TODO check all of these are used - some were created while experimenting (if not, there's more to remove below)
| { type: "primer-typedef-name"; data: PrimerTypeDefNameNodeProps }
| { type: "primer-typedef-param"; data: PrimerTypeDefParamNodeProps }
| { type: "primer-typedef-cons"; data: PrimerTypeDefConsNodeProps }
);

export const primerNodeWith = <T>(n: PrimerNode, x: T): PrimerNode<T> =>
Expand All @@ -130,23 +135,30 @@ export const primerNodeWith = <T>(n: PrimerNode, x: T): PrimerNode<T> =>
data: { ...n1.data, ...x },
}))(n);

export type NodeType1 =
| NodeType
| {
// tag: "typedefFieldNode";
typedefFieldNode: { con: GlobalName; nChild: number };
};

/** Node properties. */
export type PrimerNodeProps = {
nodeType: NodeType;
nodeType: NodeType1;
syntax: boolean;
flavor: NodeFlavorTextBody | NodeFlavorPrimBody | NodeFlavorNoBody;
contents: string;
};

/** Properties for a simple node. */
export type PrimerSimpleNodeProps = {
nodeType: NodeType;
nodeType: NodeType1;
flavor: NodeFlavorNoBody;
};

/** Properties for a box node. */
export type PrimerBoxNodeProps = {
nodeType: NodeType;
nodeType: NodeType1;
flavor: NodeFlavorBoxBody;
};

Expand All @@ -155,6 +167,18 @@ export type PrimerDefNameNodeProps = {
def: GlobalName;
};

export type PrimerTypeDefNameNodeProps = {
name: GlobalName;
};

export type PrimerTypeDefParamNodeProps = {
name: string;
};

export type PrimerTypeDefConsNodeProps = {
name: GlobalName;
};

/** Properties common to every type of node. */
export type PrimerCommonNodeProps = {
width: number;
Expand All @@ -168,8 +192,8 @@ export type PrimerEdge = {
id: string;
source: string;
target: string;
sourceHandle: string;
targetHandle: string;
sourceHandle: Position;
targetHandle: Position;
zIndex: number;
} & ({ type: "primer"; data: PrimerEdgeProps } | { type: "primer-def-name" });

Expand Down
Loading

0 comments on commit 6011e4e

Please sign in to comment.