Skip to content
This repository was archived by the owner on Oct 3, 2023. It is now read-only.

Commit cbe4da5

Browse files
Merge pull request #14 from Altroleum/crud-operations
handle join table code generation
2 parents 9c0c009 + c20754a commit cbe4da5

File tree

6 files changed

+57
-61
lines changed

6 files changed

+57
-61
lines changed

app/project/Hook/Hook.tsx

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,36 @@
11
import type { Metadata } from "../Hooks";
22
import Usage from "../Usage";
3-
import RunHookButton from "./RunHookButton";
3+
import RunHook from "./RunHook";
4+
5+
const parseTextClass = (entityType: "TABLE" | "JOIN_TABLE" | "VIEW") => {
6+
if (entityType === "TABLE") {
7+
return "text-brand-green";
8+
}
9+
10+
if (entityType === "JOIN_TABLE") {
11+
return "text-brand-blue";
12+
}
13+
14+
return "text-brand-lavender";
15+
};
16+
17+
const parseBackgroundClass = (entityType: "TABLE" | "JOIN_TABLE" | "VIEW") => {
18+
if (entityType === "TABLE") {
19+
return "bg-brand-green";
20+
}
21+
22+
if (entityType === "JOIN_TABLE") {
23+
return "bg-brand-blue";
24+
}
25+
26+
return "bg-brand-lavender";
27+
};
428

529
export default function Hook({ hookMetadata }: { hookMetadata: Metadata }) {
6-
const { name, entity, location } = hookMetadata;
30+
const { name, entityType, location } = hookMetadata;
731

8-
const textClass =
9-
entity === "TABLE" ? "text-brand-green" : "text-brand-lavender";
10-
const backgroundClass =
11-
entity === "TABLE" ? "bg-brand-green" : "bg-brand-lavender";
32+
const textClass = parseTextClass(entityType);
33+
const backgroundClass = parseBackgroundClass(entityType);
1234

1335
return (
1436
<div className="w-full text-sm rounded-md border py-4 px-4">
@@ -18,13 +40,13 @@ export default function Hook({ hookMetadata }: { hookMetadata: Metadata }) {
1840
</div>
1941
<div className="flex items-center justify-end basis-[150px]">
2042
<span className={`rounded-lg px-2 py-1 text-xs ${backgroundClass}`}>
21-
{entity}
43+
{entityType.replace("_", " ")}
2244
</span>
2345
</div>
2446
</div>
2547
<code className="text-xs font-mono">{location}</code>
2648
<Usage hookMetadata={hookMetadata} />
27-
<RunHookButton hookMetadata={hookMetadata} />
49+
<RunHook hookMetadata={hookMetadata} />
2850
</div>
2951
);
3052
}

app/project/Hook/RunHook.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,30 @@
1+
"use client";
2+
13
import { useState } from "react";
24
import type { Metadata } from "../Hooks";
35

6+
const parseDir = (entityType: "TABLE" | "VIEW" | "JOIN_TABLE") => {
7+
if (entityType === "TABLE") {
8+
return "tables";
9+
}
10+
11+
if (entityType === "JOIN_TABLE") {
12+
return "joinTables";
13+
}
14+
15+
return "views";
16+
};
17+
418
export default function RunHook({ hookMetadata }: { hookMetadata: Metadata }) {
519
const [isError, setIsError] = useState(false);
620

721
let Component = () => null;
822
if (!isError) {
923
try {
1024
const sanitisedName = hookMetadata.name.replace("use", "");
11-
Component =
12-
require(`@/__backengine__/components/${sanitisedName}`).default;
25+
Component = require(`@/__backengine__/components/${parseDir(
26+
hookMetadata.entityType
27+
)}/${sanitisedName}`).default;
1328
} catch {
1429
setIsError(true);
1530
}

app/project/Hook/RunHookButton.tsx

Lines changed: 0 additions & 42 deletions
This file was deleted.

app/project/Hooks.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ export type Metadata = {
66
name: string;
77
location: string;
88
type: string;
9-
entity: "TABLE" | "VIEW";
9+
entityType: "TABLE" | "JOIN_TABLE" | "VIEW";
10+
entityName: string;
1011
usage: string;
1112
};
1213

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"typescript": "5.1.3"
1919
},
2020
"devDependencies": {
21-
"@backengine/codegen": "^1.0.10",
21+
"@backengine/codegen": "^2.0.0",
2222
"@types/node": "20.3.1",
2323
"@types/react": "18.2.12",
2424
"@types/react-dom": "18.2.5",

0 commit comments

Comments
 (0)