Skip to content

Commit

Permalink
Bug fixes, start of schematic templates
Browse files Browse the repository at this point in the history
  • Loading branch information
balbatross committed Oct 10, 2023
1 parent be66da0 commit 0e1982f
Show file tree
Hide file tree
Showing 19 changed files with 878 additions and 74 deletions.
54 changes: 54 additions & 0 deletions packages/app/hivecommand-backend/src/schema/schematics/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export default (prisma: PrismaClient) => {
where: { ...filter, organisation: context.jwt.organisation },
include: {
pages: true,
templates: true,
versions: true
}
});
Expand Down Expand Up @@ -176,6 +177,7 @@ export default (prisma: PrismaClient) => {
nodes: args.input.nodes || [],
edges: args.input.edges || [],
rank: newRank.toString(),
templateId: args.input.templateId,
schematic: {
connect: { id: args.schematic }
}
Expand All @@ -192,6 +194,7 @@ export default (prisma: PrismaClient) => {
name: args.input.name,
nodes: args.input.nodes,
edges: args.input.edges,
templateId: args.input.templateId,
schematic: {
connect: { id: args.schematic }
}
Expand Down Expand Up @@ -254,6 +257,36 @@ export default (prisma: PrismaClient) => {
})

return result.rank == newRank.toString();
},
createCommandSchematicPageTemplate: async (root: any, args: { schematic: string, input: any }, context: any) => {
return await prisma.electricalSchematicPageTemplate.create({
data: {
...args.input,
id: nanoid(),
schematic: {
connect: { id: args.schematic }
}
}
});
},
updateCommandSchematicPageTemplate: async (root: any, args: { schematic: string, id: string, input: any }, context: any) => {
return await prisma.electricalSchematicPageTemplate.update({
where: {
id: args.id,
},
data: {
...args.input
}
});

},
deleteCommandSchematicPageTemplate: async (root: any, args: { schematic: string, id: string }, context: any) => {
const res = await prisma.electricalSchematicPageTemplate.delete({
where: {
id: args.id,
}
});
return res != null;
}
}
},
Expand All @@ -278,6 +311,10 @@ export default (prisma: PrismaClient) => {
deleteCommandSchematicPage(schematic: ID, id: ID): Boolean!
createCommandSchematicPageTemplate(schematic: ID, input: CommandSchematicPageTemplateInput): CommandSchematicPageTemplate
updateCommandSchematicPageTemplate(schematic: ID, id: ID, input: CommandSchematicPageTemplateInput): CommandSchematicPageTemplate
deleteCommandSchematicPageTemplate(schematic: ID, id: ID): Boolean!
updateCommandSchematicPageOrder(schematic: ID, id: String, above: String, below: String): Boolean
}
Expand All @@ -299,6 +336,7 @@ export default (prisma: PrismaClient) => {
versions: [CommandSchematicVersion]
pages: [CommandSchematicPage]
templates: [CommandSchematicPageTemplate]
createdAt: DateTime
Expand Down Expand Up @@ -330,6 +368,8 @@ export default (prisma: PrismaClient) => {
nodes: JSON
edges: JSON
templateId: String
}
type CommandSchematicPage {
Expand All @@ -338,10 +378,24 @@ export default (prisma: PrismaClient) => {
rank: String
template: CommandSchematicPageTemplate
nodes: JSON
edges: JSON
}
input CommandSchematicPageTemplateInput {
name: String
nodes: JSON
}
type CommandSchematicPageTemplate {
id: ID!
name: String
nodes: JSON
}
`
return {
Expand Down
1 change: 1 addition & 0 deletions packages/app/hivecommand-frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"webpack-config-single-spa-react": "^3.0.0",
"webpack-config-single-spa-react-ts": "^3.0.0",
"webpack-config-single-spa-ts": "^3.0.0",
"webpack-dev-middleware": "^6.1.1",
"webpack-dev-server": "4.15.1",
"webpack-merge": "^5.8.0"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ export const SchematicEditor = () => {
}
}
templates {
id
name
}
pages {
id
name
Expand Down Expand Up @@ -81,6 +86,39 @@ export const SchematicEditor = () => {
awaitRefetchQueries: true
})


const [createPageTemplate] = useMutation(gql`
mutation CreatePageTemplate($schematic: ID, $name: String) {
createCommandSchematicPageTemplate(schematic: $schematic, input: {name: $name}){
id
}
}
`, {
refetchQueries: ['GetSchematic'],
awaitRefetchQueries: true
})

const [updatePageTemplate] = useMutation(gql`
mutation UpdatePageTemplate($schematic: ID, $id: ID, $input: CommandSchematicPageTemplateInput) {
updateCommandSchematicPageTemplate(schematic: $schematic, id: $id, input: $input){
id
}
}
`, {

// refetchQueries: ['GetSchematic'],
// awaitRefetchQueries: true
})

const [deletePageTemplate] = useMutation(gql`
mutation DeletePageTemplate($schematic: ID, $id: ID) {
deleteCommandSchematicPageTemplate(schematic: $schematic, id: $id)
}
`, {
refetchQueries: ['GetSchematic'],
awaitRefetchQueries: true
})

const [ updatePageOrder ] = useMutation(gql`
mutation UpdatePageOrder($schematic: ID, $id: String, $above: String, $below: String){
updateCommandSchematicPageOrder(schematic: $schematic, id: $id, below: $below, above: $above)
Expand Down Expand Up @@ -150,6 +188,35 @@ export const SchematicEditor = () => {
})
}

const onCreateTemplate = (page: any) => {
createPageTemplate({
variables: {
schematic: id,
name: page.name
}
})
}


const onUpdateTemplate = (page: any) => {
updatePageTemplate({
variables: {
schematic: id,
id: page.id,
input: page
}
})
}

const onDeleteTemplate = (page: any) => {
deletePageTemplate({
variables: {
schematic: id,
id: page.id
}
})
}

const onUpdatePageOrder = (id: string, above: any, below: any) => {
updatePageOrder({
variables: {
Expand Down Expand Up @@ -190,9 +257,14 @@ export const SchematicEditor = () => {
title={schematic?.name}
versions={schematic?.versions || []}
pages={pages || []}
templates={schematic?.templates || []}
onCreatePage={onCreatePage}
onUpdatePage={onUpdatePage}
onDeletePage={onDeletePage}
onCreateTemplate={onCreateTemplate}
onUpdateTemplate={onUpdateTemplate}
onDeleteTemplate={onDeleteTemplate}

onUpdatePageOrder={onUpdatePageOrder}
onExport={() => {
openExportModal(true)
Expand Down
3 changes: 2 additions & 1 deletion packages/core-ui/command-electrical-nodes/src/node.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { CanvasNode, BoxNode, TextNode, ElectricalSymbol, PageNode } from './nodes';
import { CanvasNode, BoxNode, TextNode, ElectricalSymbol, PageNode, WireNode } from './nodes';

export const nodeTypes = {
electricalSymbol: ElectricalSymbol,
page: PageNode,
canvasNode: CanvasNode,
box: BoxNode,
text: TextNode,
wire: WireNode
}

Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ export * from './canvas-node'
export * from './electrical-symbol'
export * from './text-node'
export * from './box-node'
export * from './page-node'
export * from './page-node'
export * from './wire-node';
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ export const PageNode = (props: NodeProps) => {
const ratio = 210 / 297

return (
<Paper style={{width: 1080, height: 1080*ratio}}>
<Paper style={{
width: props.data?.width || 1080,
height: props.data?.height || 1080*ratio,
opacity: 0.4
}}>
{/* <Handle type="target" id={"canvas-target"} position={Position.Left} />
<Handle type="source" id={"canvas-source"} position={Position.Left} /> */}
</Paper>
Expand Down
Loading

0 comments on commit 0e1982f

Please sign in to comment.