Skip to content

Commit

Permalink
Merge pull request #365 from liam-hq/add_erd_web
Browse files Browse the repository at this point in the history
feat: Add erd-web package
  • Loading branch information
MH4GF authored Dec 24, 2024
2 parents 4807286 + e3f3f37 commit cf5e8a6
Show file tree
Hide file tree
Showing 17 changed files with 611 additions and 173 deletions.
6 changes: 6 additions & 0 deletions .changeset/eleven-books-camp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@liam-hq/erd-core": patch
"@liam-hq/cli": patch
---

⚒️ Fixing CSS Modules error with toolbar
10 changes: 5 additions & 5 deletions docs/packages-license.md
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,7 @@ LGPL-3.0-or-later permitted


<a name="@next/env"></a>
### @next/env v15.0.3
### @next/env v15.1.2
####

##### Paths
Expand All @@ -908,7 +908,7 @@ LGPL-3.0-or-later permitted


<a name="@next/swc-linux-x64-gnu"></a>
### @next/swc-linux-x64-gnu v15.0.3
### @next/swc-linux-x64-gnu v15.1.2
####

##### Paths
Expand All @@ -919,7 +919,7 @@ LGPL-3.0-or-later permitted


<a name="@next/swc-linux-x64-musl"></a>
### @next/swc-linux-x64-musl v15.0.3
### @next/swc-linux-x64-musl v15.1.2
####

##### Paths
Expand Down Expand Up @@ -1755,7 +1755,7 @@ LGPL-3.0-or-later permitted


<a name="@swc/helpers"></a>
### @swc/helpers v0.5.13
### @swc/helpers v0.5.15
####

##### Paths
Expand Down Expand Up @@ -7868,7 +7868,7 @@ Public Domain manually approved


<a name="next"></a>
### next v15.0.3
### next v15.1.2
####

##### Paths
Expand Down
2 changes: 1 addition & 1 deletion frontend/apps/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"fumadocs-docgen": "1.3.2",
"fumadocs-mdx": "11.1.2",
"fumadocs-ui": "14.5.4",
"next": "15.0.3",
"next": "15.1.2",
"react": "18.3.1",
"react-dom": "18"
},
Expand Down
41 changes: 41 additions & 0 deletions frontend/apps/erd-web/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/versions

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*

# env files (can opt-in for committing if needed)
.env*

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts
39 changes: 39 additions & 0 deletions frontend/apps/erd-web/app/erd/p/[...slug]/erdViewer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
'use client'

import type { DBStructure } from '@liam-hq/db-structure'
import {
CliVersionProvider,
ERDRenderer,
cliVersionSchema,
initDBStructureStore,
} from '@liam-hq/erd-core'
import { useEffect } from 'react'
import * as v from 'valibot'

type ERDViewerProps = {
dbStructure: DBStructure
}

export default function ERDViewer({ dbStructure }: ERDViewerProps) {
useEffect(() => {
initDBStructureStore(dbStructure)
}, [dbStructure])

// TODO: Implement version data
const cliVersionData = {
version: '0.0.0',
gitHash: '0000000',
envName: 'development',
isReleasedGitHash: false,
date: '2021-01-01T00:00:00Z',
}
const cliVersion = v.parse(cliVersionSchema, cliVersionData)

return (
<div style={{ height: '100vh' }}>
<CliVersionProvider cliVersion={cliVersion}>
<ERDRenderer />
</CliVersionProvider>
</div>
)
}
34 changes: 34 additions & 0 deletions frontend/apps/erd-web/app/erd/p/[...slug]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { parse } from '@liam-hq/db-structure/parser'
import { notFound } from 'next/navigation'
import ERDViewer from './erdViewer'

export default async function Page({
params,
}: {
params: Promise<{ slug: string[] }>
}) {
const { slug } = await params
const joinedPath = slug.join('/')
if (!joinedPath) {
notFound()
}

const contentUrl = `https://${joinedPath}`

const res = await fetch(contentUrl, { cache: 'no-store' })
if (!res.ok) {
notFound()
}

const input = await res.text()

// Currently supports Postgres only
const { value: dbStructure, errors } = await parse(input, 'postgres')
if (errors.length > 0) {
for (const error of errors) {
console.error(error)
}
}

return <ERDViewer dbStructure={dbStructure} />
}
Binary file added frontend/apps/erd-web/app/favicon.ico
Binary file not shown.
Empty file.
35 changes: 35 additions & 0 deletions frontend/apps/erd-web/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import type { Metadata } from 'next'
import { Geist, Geist_Mono } from 'next/font/google'
import type React from 'react'
import './globals.css'

const geistSans = Geist({
variable: '--font-geist-sans',
subsets: ['latin'],
})

const geistMono = Geist_Mono({
variable: '--font-geist-mono',
subsets: ['latin'],
})

export const metadata: Metadata = {
title: 'Create Next App',
description: 'Generated by create next app',
}

export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode
}>) {
return (
<html lang="en">
<body
className={`${geistSans.variable} ${geistMono.variable} antialiased`}
>
{children}
</body>
</html>
)
}
3 changes: 3 additions & 0 deletions frontend/apps/erd-web/biome.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": ["../../packages/configs/biome.jsonc"]
}
7 changes: 7 additions & 0 deletions frontend/apps/erd-web/next.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { NextConfig } from 'next'

const nextConfig: NextConfig = {
/* config options here */
}

export default nextConfig
29 changes: 29 additions & 0 deletions frontend/apps/erd-web/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "@liam-hq/erd-web",
"private": true,
"version": "0.1.0",
"dependencies": {
"next": "15.1.2",
"react": "18.3.1",
"react-dom": "18",
"valibot": "^1.0.0-beta.5"
},
"devDependencies": {
"@biomejs/biome": "1.9.3",
"@liam-hq/db-structure": "workspace:*",
"@liam-hq/erd-core": "workspace:*",
"@types/node": "22.9.0",
"@types/react": "18",
"@types/react-dom": "18",
"typescript": "5"
},
"scripts": {
"build": "next build",
"dev": "next dev --turbopack",
"fmt": "pnpm run '/^fmt:.*/'",
"fmt:biome": "biome check --write --unsafe .",
"lint": "pnpm run '/^lint:.*/'",
"lint:biome": "biome check .",
"start": "next start"
}
}
27 changes: 27 additions & 0 deletions frontend/apps/erd-web/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"compilerOptions": {
"target": "ES2017",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"plugins": [
{
"name": "next"
}
],
"paths": {
"@/*": ["./*", "../../packages/erd-core/src/*"]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,3 @@
box-shadow: 0px 10px 38px -10px rgba(22, 23, 24, 0.35), 0px 10px 20px -15px
rgba(22, 23, 24, 0.2);
}

/* https://github.com/radix-ui/primitives/issues/2908 */
:global([data-radix-popper-content-wrapper]) {
font-family: var(--main-font);
}
5 changes: 5 additions & 0 deletions frontend/packages/erd-core/src/styles/globals.css
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
@import url('@liam-hq/ui/src/styles/globals.css');
@import './variables.css';

/* https://github.com/radix-ui/primitives/issues/2908 */
[data-radix-popper-content-wrapper] {
font-family: var(--main-font);
}
4 changes: 4 additions & 0 deletions frontend/packages/ui/src/components/Sidebar/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,10 @@ const SidebarMenuSubButton = forwardRef<
SidebarMenuSubButton.displayName = 'SidebarMenuSubButton'

function getSidebarStateFromCookie(): boolean {
// NOTE: adhoc workaround for SSR
if (typeof document === 'undefined') {
return true
}
const cookies = document.cookie.split('; ').map((cookie) => cookie.split('='))
const cookie = cookies.find(([key]) => key === SIDEBAR_COOKIE_NAME)
return cookie ? cookie[1] === 'true' : false
Expand Down
Loading

0 comments on commit cf5e8a6

Please sign in to comment.