Skip to content

Open-source and local-first Slack and Notion alternative that puts you in control of your data

Implement initial version of databases

Hakan Shehu8d872a9553d6
diff --git a/desktop/package-lock.json b/desktop/package-lock.json
index dd5958ef..7a84e488 100644
--- a/desktop/package-lock.json
+++ b/desktop/package-lock.json
@@ -11,17 +11,19 @@
"dependencies": {
"@hookform/resolvers": "^3.9.0",
"@radix-ui/react-alert-dialog": "^1.1.1",
+ "@radix-ui/react-checkbox": "^1.1.1",
"@radix-ui/react-dialog": "^1.1.1",
"@radix-ui/react-dropdown-menu": "^2.1.1",
"@radix-ui/react-icons": "^1.3.0",
"@radix-ui/react-label": "^2.1.0",
"@radix-ui/react-popover": "^1.1.1",
"@radix-ui/react-scroll-area": "^1.1.0",
+ "@radix-ui/react-separator": "^1.1.0",
"@radix-ui/react-slot": "^1.1.0",
"@radix-ui/react-toast": "^1.2.1",
"@radix-ui/react-tooltip": "^1.1.2",
"@react-oauth/google": "^0.12.1",
- "@tanstack/react-query": "^5.52.2",
+ "@tanstack/react-query": "^5.53.1",
"@tiptap/core": "^2.6.6",
"@tiptap/extension-blockquote": "^2.6.6",
"@tiptap/extension-bold": "^2.6.6",
@@ -52,7 +54,7 @@
"@tiptap/pm": "^2.5.8",
"@tiptap/react": "^2.6.6",
"@tiptap/suggestion": "^2.6.6",
- "axios": "^1.7.5",
+ "axios": "^1.7.6",
"better-sqlite3": "^11.2.1",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
@@ -66,6 +68,8 @@
"node-sql-parser": "^5.3.1",
"re-resizable": "^6.9.17",
"react": "^18.3.1",
+ "react-dnd": "^16.0.1",
+ "react-dnd-html5-backend": "^16.0.1",
"react-dom": "^18.3.1",
"react-hook-form": "^7.53.0",
"react-intersection-observer": "^9.13.0",
@@ -90,7 +94,7 @@
"@types/better-sqlite3": "^7.6.11",
"@types/is-hotkey": "^0.1.10",
"@types/lodash": "^4.17.7",
- "@types/react": "^18.3.4",
+ "@types/react": "^18.3.5",
"@types/react-dom": "^18.3.0",
"@types/ws": "^8.5.12",
"@typescript-eslint/eslint-plugin": "^5.62.0",
@@ -1715,6 +1719,36 @@
}
}
},
+ "node_modules/@radix-ui/react-checkbox": {
+ "version": "1.1.1",
+ "resolved": "https://registry.npmjs.org/@radix-ui/react-checkbox/-/react-checkbox-1.1.1.tgz",
+ "integrity": "sha512-0i/EKJ222Afa1FE0C6pNJxDq1itzcl3HChE9DwskA4th4KRse8ojx8a1nVcOjwJdbpDLcz7uol77yYnQNMHdKw==",
+ "license": "MIT",
+ "dependencies": {
+ "@radix-ui/primitive": "1.1.0",
+ "@radix-ui/react-compose-refs": "1.1.0",
+ "@radix-ui/react-context": "1.1.0",
+ "@radix-ui/react-presence": "1.1.0",
+ "@radix-ui/react-primitive": "2.0.0",
+ "@radix-ui/react-use-controllable-state": "1.1.0",
+ "@radix-ui/react-use-previous": "1.1.0",
+ "@radix-ui/react-use-size": "1.1.0"
+ },
+ "peerDependencies": {
+ "@types/react": "*",
+ "@types/react-dom": "*",
+ "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc",
+ "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
+ },
+ "peerDependenciesMeta": {
+ "@types/react": {
+ "optional": true
+ },
+ "@types/react-dom": {
+ "optional": true
+ }
+ }
+ },
"node_modules/@radix-ui/react-collection": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/@radix-ui/react-collection/-/react-collection-1.1.0.tgz",
@@ -2210,6 +2244,29 @@
}
}
},
+ "node_modules/@radix-ui/react-separator": {
+ "version": "1.1.0",
+ "resolved": "https://registry.npmjs.org/@radix-ui/react-separator/-/react-separator-1.1.0.tgz",
+ "integrity": "sha512-3uBAs+egzvJBDZAzvb/n4NxxOYpnspmWxO2u5NbZ8Y6FM/NdrGSF9bop3Cf6F6C71z1rTSn8KV0Fo2ZVd79lGA==",
+ "license": "MIT",
+ "dependencies": {
+ "@radix-ui/react-primitive": "2.0.0"
+ },
+ "peerDependencies": {
+ "@types/react": "*",
+ "@types/react-dom": "*",
+ "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc",
+ "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
+ },
+ "peerDependenciesMeta": {
+ "@types/react": {
+ "optional": true
+ },
+ "@types/react-dom": {
+ "optional": true
+ }
+ }
+ },
"node_modules/@radix-ui/react-slot": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/@radix-ui/react-slot/-/react-slot-1.1.0.tgz",
@@ -2362,6 +2419,21 @@
}
}
},
+ "node_modules/@radix-ui/react-use-previous": {
+ "version": "1.1.0",
+ "resolved": "https://registry.npmjs.org/@radix-ui/react-use-previous/-/react-use-previous-1.1.0.tgz",
+ "integrity": "sha512-Z/e78qg2YFnnXcW88A4JmTtm4ADckLno6F7OXotmkQfeuCVaKuYzqAATPhVzl3delXE7CxIV8shofPn3jPc5Og==",
+ "license": "MIT",
+ "peerDependencies": {
+ "@types/react": "*",
+ "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
+ },
+ "peerDependenciesMeta": {
+ "@types/react": {
+ "optional": true
+ }
+ }
+ },
"node_modules/@radix-ui/react-use-rect": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/@radix-ui/react-use-rect/-/react-use-rect-1.1.0.tgz",
@@ -2427,6 +2499,24 @@
"integrity": "sha512-A9+lCBZoaMJlVKcRBz2YByCG+Cp2t6nAnMnNba+XiWxnj6r4JUFqfsgwocMBZU9LPtdxC6wB56ySYpc7LQIoJg==",
"license": "MIT"
},
+ "node_modules/@react-dnd/asap": {
+ "version": "5.0.2",
+ "resolved": "https://registry.npmjs.org/@react-dnd/asap/-/asap-5.0.2.tgz",
+ "integrity": "sha512-WLyfoHvxhs0V9U+GTsGilGgf2QsPl6ZZ44fnv0/b8T3nQyvzxidxsg/ZltbWssbsRDlYW8UKSQMTGotuTotZ6A==",
+ "license": "MIT"
+ },
+ "node_modules/@react-dnd/invariant": {
+ "version": "4.0.2",
+ "resolved": "https://registry.npmjs.org/@react-dnd/invariant/-/invariant-4.0.2.tgz",
+ "integrity": "sha512-xKCTqAK/FFauOM9Ta2pswIyT3D8AQlfrYdOi/toTPEhqCuAs1v5tcJ3Y08Izh1cJ5Jchwy9SeAXmMg6zrKs2iw==",
+ "license": "MIT"
+ },
+ "node_modules/@react-dnd/shallowequal": {
+ "version": "4.0.2",
+ "resolved": "https://registry.npmjs.org/@react-dnd/shallowequal/-/shallowequal-4.0.2.tgz",
+ "integrity": "sha512-/RVXdLvJxLg4QKvMoM5WlwNR9ViO9z8B/qPcc+C0Sa/teJY7QG7kJ441DwzOjMYEY7GmU4dj5EcGHIkKZiQZCA==",
+ "license": "MIT"
+ },
"node_modules/@react-oauth/google": {
"version": "0.12.1",
"resolved": "https://registry.npmjs.org/@react-oauth/google/-/google-0.12.1.tgz",
@@ -2703,9 +2793,9 @@
}
},
"node_modules/@tanstack/query-core": {
- "version": "5.52.2",
- "resolved": "https://registry.npmjs.org/@tanstack/query-core/-/query-core-5.52.2.tgz",
- "integrity": "sha512-9vvbFecK4A0nDnrc/ks41e3UHONF1DAnGz8Tgbxkl59QcvKWmc0ewhYuIKRh8NC4ja5LTHT9EH16KHbn2AIYWA==",
+ "version": "5.53.1",
+ "resolved": "https://registry.npmjs.org/@tanstack/query-core/-/query-core-5.53.1.tgz",
+ "integrity": "sha512-mvLG7s4Zy3Yvc2LsKm8BVafbmPrsReKgqwhmp4XKVmRW9us3KbWRqu3qBBfhVavcUUEHfNK7PvpTchvQpVdFpw==",
"license": "MIT",
"funding": {
"type": "github",
@@ -2713,12 +2803,12 @@
}
},
"node_modules/@tanstack/react-query": {
- "version": "5.52.2",
- "resolved": "https://registry.npmjs.org/@tanstack/react-query/-/react-query-5.52.2.tgz",
- "integrity": "sha512-d4OwmobpP+6+SvuAxW1RzAY95Pv87Gu+0GjtErzFOUXo+n0FGcwxKvzhswCsXKxsgnAr3bU2eJ2u+GXQAutkCQ==",
+ "version": "5.53.1",
+ "resolved": "https://registry.npmjs.org/@tanstack/react-query/-/react-query-5.53.1.tgz",
+ "integrity": "sha512-35HU4836Ey1/W74BxmS8p9KHXcDRGPdkw6w3VX0Tc5S9v5acFl80oi/yc6nsmoLhu68wQkWMyX0h7y7cOtY5OA==",
"license": "MIT",
"dependencies": {
- "@tanstack/query-core": "5.52.2"
+ "@tanstack/query-core": "5.53.1"
},
"funding": {
"type": "github",
@@ -3383,9 +3473,9 @@
"license": "MIT"
},
"node_modules/@types/react": {
- "version": "18.3.4",
- "resolved": "https://registry.npmjs.org/@types/react/-/react-18.3.4.tgz",
- "integrity": "sha512-J7W30FTdfCxDDjmfRM+/JqLHBIyl7xUIp9kwK637FGmY7+mkSFSe6L4jpZzhj5QMfLssSDP4/i75AKkrdC7/Jw==",
+ "version": "18.3.5",
+ "resolved": "https://registry.npmjs.org/@types/react/-/react-18.3.5.tgz",
+ "integrity": "sha512-WeqMfGJLGuLCqHGYRGHxnKrXcTitc6L/nBUWfWPcTarG3t9PsquqUMuVeXZeca+mglY4Vo5GZjCi0A3Or2lnxA==",
"devOptional": true,
"license": "MIT",
"dependencies": {
@@ -4147,9 +4237,9 @@
}
},
"node_modules/axios": {
- "version": "1.7.5",
- "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.5.tgz",
- "integrity": "sha512-fZu86yCo+svH3uqJ/yTdQ0QHpQu5oL+/QE+QPSv6BZSkDAoky9vytxp7u5qk83OJFS3kEBcesWni9WTZAv3tSw==",
+ "version": "1.7.6",
+ "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.6.tgz",
+ "integrity": "sha512-Ekur6XDwhnJ5RgOCaxFnXyqlPALI3rVeukZMwOdfghW7/wGz784BYKiQq+QD8NPcr91KRo30KfHOchyijwWw7g==",
"license": "MIT",
"dependencies": {
"follow-redirects": "^1.15.6",
@@ -5701,6 +5791,17 @@
"integrity": "sha512-+HlytyjlPKnIG8XuRG8WvmBP8xs8P71y+SKKS6ZXWoEgLuePxtDoUEiH7WkdePWrQ5JBpE6aoVqfZfJUQkjXwA==",
"license": "MIT"
},
+ "node_modules/dnd-core": {
+ "version": "16.0.1",
+ "resolved": "https://registry.npmjs.org/dnd-core/-/dnd-core-16.0.1.tgz",
+ "integrity": "sha512-HK294sl7tbw6F6IeuK16YSBUoorvHpY8RHO+9yFfaJyCDVb6n7PRcezrOEOa2SBCqiYpemh5Jx20ZcjKdFAVng==",
+ "license": "MIT",
+ "dependencies": {
+ "@react-dnd/asap": "^5.0.1",
+ "@react-dnd/invariant": "^4.0.1",
+ "redux": "^4.2.0"
+ }
+ },
"node_modules/doctrine": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/doctrine/-/doctrine-3.0.0.tgz",
@@ -7211,7 +7312,6 @@
"version": "3.1.3",
"resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz",
"integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==",
- "dev": true,
"license": "MIT"
},
"node_modules/fast-glob": {
@@ -8150,6 +8250,15 @@
"node": ">=12.0.0"
}
},
+ "node_modules/hoist-non-react-statics": {
+ "version": "3.3.2",
+ "resolved": "https://registry.npmjs.org/hoist-non-react-statics/-/hoist-non-react-statics-3.3.2.tgz",
+ "integrity": "sha512-/gGivxi8JPKWNm/W0jSmzcMPpfpPLc3dY/6GxhX2hQ9iGj3aDfklV4ET7NjKpSinLpJ5vafa9iiGIEZg10SfBw==",
+ "license": "BSD-3-Clause",
+ "dependencies": {
+ "react-is": "^16.7.0"
+ }
+ },
"node_modules/homedir-polyfill": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/homedir-polyfill/-/homedir-polyfill-1.0.3.tgz",
@@ -9298,9 +9407,9 @@
}
},
"node_modules/micromatch": {
- "version": "4.0.7",
- "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.7.tgz",
- "integrity": "sha512-LPP/3KorzCwBxfeUuZmaR6bG2kdeHSbe0P2tY3FLRU4vYrjYz5hI4QZwV0njUx3jeuKe67YukQ1LSPZBKDqO/Q==",
+ "version": "4.0.8",
+ "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.8.tgz",
+ "integrity": "sha512-PXwfBhYu0hBCPw8Dn0E+WDYb7af3dSLVWKi3HGv84IdF4TyFoC0ysxFd0Goxw7nSv4T/PzEJQxsYsEiFCKo2BA==",
"license": "MIT",
"dependencies": {
"braces": "^3.0.3",
@@ -11105,6 +11214,45 @@
"node": ">=0.10.0"
}
},
+ "node_modules/react-dnd": {
+ "version": "16.0.1",
+ "resolved": "https://registry.npmjs.org/react-dnd/-/react-dnd-16.0.1.tgz",
+ "integrity": "sha512-QeoM/i73HHu2XF9aKksIUuamHPDvRglEwdHL4jsp784BgUuWcg6mzfxT0QDdQz8Wj0qyRKx2eMg8iZtWvU4E2Q==",
+ "license": "MIT",
+ "dependencies": {
+ "@react-dnd/invariant": "^4.0.1",
+ "@react-dnd/shallowequal": "^4.0.1",
+ "dnd-core": "^16.0.1",
+ "fast-deep-equal": "^3.1.3",
+ "hoist-non-react-statics": "^3.3.2"
+ },
+ "peerDependencies": {
+ "@types/hoist-non-react-statics": ">= 3.3.1",
+ "@types/node": ">= 12",
+ "@types/react": ">= 16",
+ "react": ">= 16.14"
+ },
+ "peerDependenciesMeta": {
+ "@types/hoist-non-react-statics": {
+ "optional": true
+ },
+ "@types/node": {
+ "optional": true
+ },
+ "@types/react": {
+ "optional": true
+ }
+ }
+ },
+ "node_modules/react-dnd-html5-backend": {
+ "version": "16.0.1",
+ "resolved": "https://registry.npmjs.org/react-dnd-html5-backend/-/react-dnd-html5-backend-16.0.1.tgz",
+ "integrity": "sha512-Wu3dw5aDJmOGw8WjH1I1/yTH+vlXEL4vmjk5p+MHxP8HuHJS1lAGeIdG/hze1AvNeXWo/JgULV87LyQOr+r5jw==",
+ "license": "MIT",
+ "dependencies": {
+ "dnd-core": "^16.0.1"
+ }
+ },
"node_modules/react-dom": {
"version": "18.3.1",
"resolved": "https://registry.npmjs.org/react-dom/-/react-dom-18.3.1.tgz",
@@ -11149,6 +11297,12 @@
}
}
},
+ "node_modules/react-is": {
+ "version": "16.13.1",
+ "resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz",
+ "integrity": "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==",
+ "license": "MIT"
+ },
"node_modules/react-remove-scroll": {
"version": "2.5.7",
"resolved": "https://registry.npmjs.org/react-remove-scroll/-/react-remove-scroll-2.5.7.tgz",
@@ -11445,6 +11599,15 @@
"node": ">= 10.13.0"
}
},
+ "node_modules/redux": {
+ "version": "4.2.1",
+ "resolved": "https://registry.npmjs.org/redux/-/redux-4.2.1.tgz",
+ "integrity": "sha512-LAUYz4lc+Do8/g7aeRa8JkyDErK6ekstQaqWQrNRW//MY1TvCEpMtpTWvlQ+FPbWCx+Xixu/6SHt5N0HR+SB4w==",
+ "license": "MIT",
+ "dependencies": {
+ "@babel/runtime": "^7.9.2"
+ }
+ },
"node_modules/regenerator-runtime": {
"version": "0.14.1",
"resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.14.1.tgz",
diff --git a/desktop/package.json b/desktop/package.json
index b850bfe6..2d7cb3ff 100644
--- a/desktop/package.json
+++ b/desktop/package.json
@@ -25,7 +25,7 @@
"@types/better-sqlite3": "^7.6.11",
"@types/is-hotkey": "^0.1.10",
"@types/lodash": "^4.17.7",
- "@types/react": "^18.3.4",
+ "@types/react": "^18.3.5",
"@types/react-dom": "^18.3.0",
"@types/ws": "^8.5.12",
"@typescript-eslint/eslint-plugin": "^5.62.0",
@@ -51,17 +51,19 @@
"dependencies": {
"@hookform/resolvers": "^3.9.0",
"@radix-ui/react-alert-dialog": "^1.1.1",
+ "@radix-ui/react-checkbox": "^1.1.1",
"@radix-ui/react-dialog": "^1.1.1",
"@radix-ui/react-dropdown-menu": "^2.1.1",
"@radix-ui/react-icons": "^1.3.0",
"@radix-ui/react-label": "^2.1.0",
"@radix-ui/react-popover": "^1.1.1",
"@radix-ui/react-scroll-area": "^1.1.0",
+ "@radix-ui/react-separator": "^1.1.0",
"@radix-ui/react-slot": "^1.1.0",
"@radix-ui/react-toast": "^1.2.1",
"@radix-ui/react-tooltip": "^1.1.2",
"@react-oauth/google": "^0.12.1",
- "@tanstack/react-query": "^5.52.2",
+ "@tanstack/react-query": "^5.53.1",
"@tiptap/core": "^2.6.6",
"@tiptap/extension-blockquote": "^2.6.6",
"@tiptap/extension-bold": "^2.6.6",
@@ -92,7 +94,7 @@
"@tiptap/pm": "^2.5.8",
"@tiptap/react": "^2.6.6",
"@tiptap/suggestion": "^2.6.6",
- "axios": "^1.7.5",
+ "axios": "^1.7.6",
"better-sqlite3": "^11.2.1",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
@@ -106,6 +108,8 @@
"node-sql-parser": "^5.3.1",
"re-resizable": "^6.9.17",
"react": "^18.3.1",
+ "react-dnd": "^16.0.1",
+ "react-dnd-html5-backend": "^16.0.1",
"react-dom": "^18.3.1",
"react-hook-form": "^7.53.0",
"react-intersection-observer": "^9.13.0",
diff --git a/desktop/src/components/databases/boards/board-view.tsx b/desktop/src/components/databases/boards/board-view.tsx
new file mode 100644
index 00000000..098d8631
--- /dev/null
+++ b/desktop/src/components/databases/boards/board-view.tsx
@@ -0,0 +1,10 @@
+import React from 'react';
+import { LocalNode } from '@/types/nodes';
+
+interface BoardViewProps {
+ node: LocalNode;
+}
+
+export const BoardView = ({ node }: BoardViewProps) => {
+ return <div>BoardView</div>;
+};
diff --git a/desktop/src/components/databases/calendars/calendar-view.tsx b/desktop/src/components/databases/calendars/calendar-view.tsx
new file mode 100644
index 00000000..93e55452
--- /dev/null
+++ b/desktop/src/components/databases/calendars/calendar-view.tsx
@@ -0,0 +1,10 @@
+import React from 'react';
+import { LocalNode } from '@/types/nodes';
+
+interface CalendarViewProps {
+ node: LocalNode;
+}
+
+export const CalendarView = ({ node }: CalendarViewProps) => {
+ return <div>CalendarView</div>;
+};
diff --git a/desktop/src/components/databases/database-container-node.tsx b/desktop/src/components/databases/database-container-node.tsx
new file mode 100644
index 00000000..e2581b02
--- /dev/null
+++ b/desktop/src/components/databases/database-container-node.tsx
@@ -0,0 +1,65 @@
+import React from 'react';
+import { LocalNode } from '@/types/nodes';
+import { useQuery } from '@tanstack/react-query';
+import { useWorkspace } from '@/contexts/workspace';
+import { sql } from 'kysely';
+import { SelectNode } from '@/data/schemas/workspace';
+import { NodeTypes, ViewNodeTypes } from '@/lib/constants';
+import { mapNode } from '@/lib/nodes';
+import { DatabaseContext } from '@/contexts/database';
+import { DatabaseViews } from './database-views';
+import { ScrollArea } from '@/components/ui/scroll-area';
+
+interface DatabaseContainerNodeProps {
+ node: LocalNode;
+}
+
+export const DatabaseContainerNode = ({ node }: DatabaseContainerNodeProps) => {
+ const workspace = useWorkspace();
+ const { data, isPending } = useQuery({
+ queryKey: ['database', node.id],
+ queryFn: async ({ queryKey }) => {
+ const query = sql<SelectNode>`
+ WITH field_nodes AS (
+ SELECT *
+ FROM nodes
+ WHERE parent_id = ${node.id} AND type = ${NodeTypes.Field}
+ ),
+ view_nodes AS (
+ SELECT *
+ FROM nodes
+ WHERE parent_id = ${node.id} AND type IN (${sql.join(ViewNodeTypes)})
+ )
+ SELECT * FROM field_nodes
+ UNION ALL
+ SELECT * FROM view_nodes;
+ `.compile(workspace.schema);
+
+ return await workspace.queryAndSubscribe({
+ key: queryKey,
+ query,
+ });
+ },
+ });
+
+ if (isPending) {
+ return null;
+ }
+
+ const rows = data?.rows ?? [];
+ const fieldNodes = rows
+ .filter((row) => row.type === NodeTypes.Field)
+ .map((row) => mapNode(row));
+
+ const viewNodes = rows
+ .filter((row) => ViewNodeTypes.includes(row.type))
+ .map((row) => mapNode(row));
+
+ return (
+ <DatabaseContext.Provider value={{ id: node.id, fields: fieldNodes }}>
+ <ScrollArea className="h-full max-h-full w-full overflow-y-auto px-10 pb-12">
+ <DatabaseViews key={node.id} views={viewNodes} />
+ </ScrollArea>
+ </DatabaseContext.Provider>
+ );
+};
diff --git a/desktop/src/components/databases/database-create-dialog.tsx b/desktop/src/components/databases/database-create-dialog.tsx
new file mode 100644
index 00000000..b822e225
--- /dev/null
+++ b/desktop/src/components/databases/database-create-dialog.tsx
@@ -0,0 +1,180 @@
+import React from 'react';
+import { useWorkspace } from '@/contexts/workspace';
+import {
+ Dialog,
+ DialogContent,
+ DialogDescription,
+ DialogFooter,
+ DialogHeader,
+ DialogTitle,
+} from '@/components/ui/dialog';
+import { z } from 'zod';
+import {
+ Form,
+ FormControl,
+ FormField,
+ FormItem,
+ FormLabel,
+ FormMessage,
+} from '@/components/ui/form';
+import { Input } from '@/components/ui/input';
+import { Button } from '@/components/ui/button';
+import { Spinner } from '@/components/ui/spinner';
+import { useForm } from 'react-hook-form';
+import { zodResolver } from '@hookform/resolvers/zod';
+import { NeuronId } from '@/lib/id';
+import { NodeTypes } from '@/lib/constants';
+import { generateNodeIndex } from '@/lib/nodes';
+import { useMutation } from '@tanstack/react-query';
+import { compareString } from '@/lib/utils';
+
+const formSchema = z.object({
+ name: z.string().min(3, 'Name must be at least 3 characters long.'),
+});
+
+interface DatabaseCreateDialogProps {
+ spaceId: string;
+ open: boolean;
+ onOpenChange: (open: boolean) => void;
+}
+
+export const DatabaseCreateDialog = ({
+ spaceId,
+ open,
+ onOpenChange,
+}: DatabaseCreateDialogProps) => {
+ const workspace = useWorkspace();
+ const form = useForm<z.infer<typeof formSchema>>({
+ resolver: zodResolver(formSchema),
+ defaultValues: {
+ name: '',
+ },
+ });
+
+ const { mutate, isPending } = useMutation({
+ mutationFn: async (values: z.infer<typeof formSchema>) => {
+ const siblingsQuery = workspace.schema
+ .selectFrom('nodes')
+ .where('parent_id', '=', spaceId)
+ .selectAll()
+ .compile();
+
+ const result = await workspace.query(siblingsQuery);
+ const siblings = result.rows;
+ const maxIndex =
+ siblings.length > 0
+ ? siblings.sort((a, b) => compareString(a.index, b.index))[
+ siblings.length - 1
+ ].index
+ : null;
+
+ const index = generateNodeIndex(maxIndex, null);
+ const databaseId = NeuronId.generate(NeuronId.Type.Database);
+ const query = workspace.schema
+ .insertInto('nodes')
+ .values([
+ {
+ id: databaseId,
+ type: NodeTypes.Database,
+ parent_id: spaceId,
+ index,
+ attrs: JSON.stringify({
+ name: values.name,
+ }),
+ content: null,
+ created_at: new Date().toISOString(),
+ created_by: workspace.userId,
+ version_id: NeuronId.generate(NeuronId.Type.Version),
+ },
+ {
+ id: NeuronId.generate(NeuronId.Type.TableView),
+ type: NodeTypes.TableView,
+ parent_id: databaseId,
+ index: generateNodeIndex(null, null),
+ attrs: JSON.stringify({
+ name: 'Default',
+ }),
+ content: null,
+ created_at: new Date().toISOString(),
+ created_by: workspace.userId,
+ version_id: NeuronId.generate(NeuronId.Type.Version),
+ },
+ {
+ id: NeuronId.generate(NeuronId.Type.Field),
+ type: NodeTypes.Field,
+ parent_id: databaseId,
+ index: generateNodeIndex(null, null),
+ attrs: JSON.stringify({
+ name: 'Title',
+ type: 'text',
+ }),
+ content: null,
+ created_at: new Date().toISOString(),
+ created_by: workspace.userId,
+ version_id: NeuronId.generate(NeuronId.Type.Version),
+ },
+ ])
+ .compile();
+
+ await workspace.mutate(query);
+ },
+ });
+
+ const handleCancel = () => {
+ form.reset();
+ onOpenChange(false);
+ };
+
+ const handleSubmit = async (values: z.infer<typeof formSchema>) => {
+ mutate(values, {
+ onSuccess: () => {
+ onOpenChange(false);
+ form.reset();
+ },
+ });
+ };
+
+ return (
+ <Dialog open={open} onOpenChange={onOpenChange}>
+ <DialogContent>
+ <DialogHeader>
+ <DialogTitle>Create database</DialogTitle>
+ <DialogDescription>
+ Create a new database to store your data
+ </DialogDescription>
+ </DialogHeader>
+ <Form {...form}>
+ <form
+ className="flex flex-col"
+ onSubmit={form.handleSubmit(handleSubmit)}
+ >
+ <div className="flex-grow space-y-4 py-2 pb-4">
+ <FormField
+ control={form.control}
+ name="name"
+ render={({ field }) => (
+ <FormItem className="flex-1">
+ <FormLabel>Name *</FormLabel>
+ <FormControl>
+ <Input placeholder="Name" {...field} />
+ </FormControl>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ </div>
+ <DialogFooter>
+ <Button variant="outline" onClick={handleCancel}>
+ Cancel
+ </Button>
+ <Button type="submit" disabled={isPending}>
+ {isPending && <Spinner className="mr-1" />}
+ Create
+ </Button>
+ </DialogFooter>
+ </form>
+ </Form>
+ </DialogContent>
+ </Dialog>
+ );
+};
diff --git a/desktop/src/components/databases/database-sidebar-node.tsx b/desktop/src/components/databases/database-sidebar-node.tsx
new file mode 100644
index 00000000..c5d707f1
--- /dev/null
+++ b/desktop/src/components/databases/database-sidebar-node.tsx
@@ -0,0 +1,47 @@
+import React from 'react';
+import { LocalNode } from '@/types/nodes';
+import { cn } from '@/lib/utils';
+import { Avatar } from '@/components/ui/avatar';
+import { Icon } from '@/components/ui/icon';
+import { useWorkspace } from '@/contexts/workspace';
+
+interface DatabaseSidebarNodeProps {
+ node: LocalNode;
+}
+
+export const DatabaseSidebarNode = ({ node }: DatabaseSidebarNodeProps) => {
+ const workspace = useWorkspace();
+ const isActive = false;
+ const isUnread = false;
+
+ const avatar = node.attrs.avatar;
+ const name = node.attrs.name ?? 'Unnamed';
+ return (
+ <div
+ key={node.id}
+ className={cn(
+ 'flex cursor-pointer items-center rounded-md p-1 text-sm text-foreground/80 hover:bg-gray-100',
+ isActive && 'bg-gray-100',
+ )}
+ onClick={() => {
+ workspace.navigateToNode(node.id);
+ }}
+ >
+ <Avatar id={node.id} avatar={avatar} name={name} size="small" />
+ <span
+ className={cn(
+ 'line-clamp-1 w-full flex-grow pl-2 text-left',
+ isUnread && 'font-bold',
+ )}
+ >
+ {name}
+ </span>
+ {isUnread && (
+ <Icon
+ name="checkbox-blank-circle-fill"
+ className="mr-2 h-3 w-3 p-0.5 text-red-500"
+ />
+ )}
+ </div>
+ );
+};
diff --git a/desktop/src/components/databases/database-views.tsx b/desktop/src/components/databases/database-views.tsx
new file mode 100644
index 00000000..bf942a42
--- /dev/null
+++ b/desktop/src/components/databases/database-views.tsx
@@ -0,0 +1,44 @@
+import React from 'react';
+import { LocalNode } from '@/types/nodes';
+import { ViewTab } from '@/components/databases/view-tab';
+import { ViewActions } from '@/components/databases/view-actions';
+import { match } from 'ts-pattern';
+import { NodeTypes } from '@/lib/constants';
+import { TableView } from '@/components/databases/tables/table-view';
+import { BoardView } from '@/components/databases/boards/board-view';
+import { CalendarView } from '@/components/databases/calendars/calendar-view';
+
+interface DatabaseViewsProps {
+ views: LocalNode[];
+}
+
+export const DatabaseViews = ({ views }: DatabaseViewsProps) => {
+ const [selectedView, setSelectedView] = React.useState<LocalNode | null>(
+ views.length > 0 ? views[0] : null,
+ );
+
+ return (
+ <div className="group/database">
+ <div className="mt-2 flex flex-row justify-between border-b">
+ <div className="flex flex-row gap-3">
+ {views.map((view) => (
+ <ViewTab
+ key={view.id}
+ view={view}
+ isActive={view.id === selectedView?.id}
+ onClick={() => setSelectedView(view)}
+ />
+ ))}
+ </div>
+ <ViewActions />
+ </div>
+ {match(selectedView?.type)
+ .with(NodeTypes.TableView, () => <TableView node={selectedView} />)
+ .with(NodeTypes.BoardView, () => <BoardView node={selectedView} />)
+ .with(NodeTypes.CalendarView, () => (
+ <CalendarView node={selectedView} />
+ ))
+ .otherwise(() => null)}
+ </div>
+ );
+};
diff --git a/desktop/src/components/databases/fields/field-attrs.tsx b/desktop/src/components/databases/fields/field-attrs.tsx
new file mode 100644
index 00000000..e5a14fd9
--- /dev/null
+++ b/desktop/src/components/databases/fields/field-attrs.tsx
@@ -0,0 +1,5 @@
+import React from 'react';
+
+export const FieldAttrs = () => {
+ return <div>FieldAttrs</div>;
+};
diff --git a/desktop/src/components/databases/fields/field-create-popover.tsx b/desktop/src/components/databases/fields/field-create-popover.tsx
new file mode 100644
index 00000000..29fa0668
--- /dev/null
+++ b/desktop/src/components/databases/fields/field-create-popover.tsx
@@ -0,0 +1,182 @@
+import React from 'react';
+import { zodResolver } from '@hookform/resolvers/zod';
+import { useForm } from 'react-hook-form';
+import * as z from 'zod';
+
+import { Button } from '@/components/ui/button';
+import {
+ Form,
+ FormControl,
+ FormField,
+ FormItem,
+ FormLabel,
+ FormMessage,
+} from '@/components/ui/form';
+import { Input } from '@/components/ui/input';
+import {
+ Popover,
+ PopoverContent,
+ PopoverTrigger,
+} from '@/components/ui/popover';
+import { useDatabase } from '@/contexts/database';
+import { FieldTypeSelect } from './field-type-select';
+import { FieldAttrs } from './field-attrs';
+import { useMutation } from '@tanstack/react-query';
+import { useWorkspace } from '@/contexts/workspace';
+import { compareString } from '@/lib/utils';
+import { generateNodeIndex } from '@/lib/nodes';
+import { NeuronId } from '@/lib/id';
+import { NodeTypes } from '@/lib/constants';
+import { Spinner } from '@/components/ui/spinner';
+import { Icon } from '@/components/ui/icon';
+
+const formSchema = z.object({
+ name: z.string(),
+ type: z.union([
+ z.literal('autonumber'),
+ z.literal('boolean'),
+ z.literal('button'),
+ z.literal('collaborator'),
+ z.literal('created_at'),
+ z.literal('created_by'),
+ z.literal('date'),
+ z.literal('email'),
+ z.literal('file'),
+ z.literal('formula'),
+ z.literal('multi_select'),
+ z.literal('number'),
+ z.literal('phone'),
+ z.literal('relation'),
+ z.literal('rollup'),
+ z.literal('select'),
+ z.literal('text'),
+ z.literal('updated_at'),
+ z.literal('updated_by'),
+ z.literal('url'),
+ ]),
+});
+
+export const FieldCreatePopover = () => {
+ const [open, setOpen] = React.useState(false);
+ const workspace = useWorkspace();
+ const database = useDatabase();
+
+ const form = useForm<z.infer<typeof formSchema>>({
+ resolver: zodResolver(formSchema),
+ defaultValues: {
+ name: '',
+ type: 'text',
+ },
+ });
+
+ const { mutate, isPending } = useMutation({
+ mutationFn: async (values: z.infer<typeof formSchema>) => {
+ const siblingsQuery = workspace.schema
+ .selectFrom('nodes')
+ .where('parent_id', '=', database.id)
+ .selectAll()
+ .compile();
+
+ const result = await workspace.query(siblingsQuery);
+ const siblings = result.rows;
+ const maxIndex =
+ siblings.length > 0
+ ? siblings.sort((a, b) => compareString(a.index, b.index))[
+ siblings.length - 1
+ ].index
+ : null;
+
+ const index = generateNodeIndex(maxIndex, null);
+ const query = workspace.schema
+ .insertInto('nodes')
+ .values({
+ id: NeuronId.generate(NeuronId.Type.Field),
+ type: NodeTypes.Field,
+ parent_id: database.id,
+ index,
+ attrs: JSON.stringify({
+ name: values.name,
+ type: values.type,
+ }),
+ content: null,
+ created_at: new Date().toISOString(),
+ created_by: workspace.userId,
+ version_id: NeuronId.generate(NeuronId.Type.Version),
+ })
+ .compile();
+
+ await workspace.mutate(query);
+ },
+ });
+
+ const handleCancelClick = () => {
+ setOpen(false);
+ form.reset();
+ };
+
+ const handleSubmit = (values: z.infer<typeof formSchema>) => {
+ mutate(values, {
+ onSuccess: () => {
+ setOpen(false);
+ form.reset();
+ },
+ });
+ };
+
+ return (
+ <Popover open={open} onOpenChange={setOpen} modal={true}>
+ <PopoverTrigger asChild>
+ <Icon name="add-line" className="mr-2 h-3 w-3 cursor-pointer" />
+ </PopoverTrigger>
+ <PopoverContent className="w-128 mr-5" side="bottom">
+ <Form {...form}>
+ <form
+ className="flex flex-col gap-2"
+ onSubmit={form.handleSubmit(handleSubmit)}
+ >
+ <div className="flex-grow space-y-4 py-2 pb-4">
+ <FormField
+ control={form.control}
+ name="name"
+ render={({ field, formState }) => (
+ <FormItem>
+ <FormLabel>Name</FormLabel>
+ <FormControl>
+ <Input id="name" placeholder="Field name" {...field} />
+ </FormControl>
+ <FormMessage>{formState.errors.name?.message}</FormMessage>
+ </FormItem>
+ )}
+ />
+ <FormField
+ control={form.control}
+ name="type"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>Field type</FormLabel>
+ <FormControl>
+ <FieldTypeSelect
+ type={field.value}
+ onChange={field.onChange}
+ />
+ </FormControl>
+ </FormItem>
+ )}
+ />
+ <FieldAttrs />
+ </div>
+ <div className="mt-2 flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2">
+ <Button variant="outline" size="sm" onClick={handleCancelClick}>
+ Cancel
+ </Button>
+ <Button type="submit" size="sm" disabled={isPending}>
+ {isPending && <Spinner className="mr-1" />}
+ Create
+ </Button>
+ </div>
+ </form>
+ </Form>
+ </PopoverContent>
+ </Popover>
+ );
+};
diff --git a/desktop/src/components/databases/fields/field-delete-dialog.tsx b/desktop/src/components/databases/fields/field-delete-dialog.tsx
new file mode 100644
index 00000000..998f8e28
--- /dev/null
+++ b/desktop/src/components/databases/fields/field-delete-dialog.tsx
@@ -0,0 +1,68 @@
+import React from 'react';
+import {
+ AlertDialog,
+ AlertDialogCancel,
+ AlertDialogContent,
+ AlertDialogDescription,
+ AlertDialogFooter,
+ AlertDialogHeader,
+ AlertDialogTitle,
+} from '@/components/ui/alert-dialog';
+import { Button } from '@/components/ui/button';
+import { useWorkspace } from '@/contexts/workspace';
+import { useMutation } from '@tanstack/react-query';
+
+interface FieldDeleteDialogProps {
+ id: string;
+ open: boolean;
+ onOpenChange: (open: boolean) => void;
+}
+
+export const FieldDeleteDialog = ({
+ id,
+ open,
+ onOpenChange,
+}: FieldDeleteDialogProps) => {
+ const { mutate, isPending } = useMutation({
+ mutationFn: async (fieldId: string) => {
+ const mutation = workspace.schema
+ .deleteFrom('nodes')
+ .where('id', '=', fieldId)
+ .compile();
+ await workspace.mutate(mutation);
+ },
+ });
+ const workspace = useWorkspace();
+
+ return (
+ <AlertDialog open={open} onOpenChange={onOpenChange}>
+ <AlertDialogContent>
+ <AlertDialogHeader>
+ <AlertDialogTitle>
+ Are you sure you want delete this field?
+ </AlertDialogTitle>
+ <AlertDialogDescription>
+ This action cannot be undone. This field will no longer be
+ accessible and all data in the field will be lost.
+ </AlertDialogDescription>
+ </AlertDialogHeader>
+ <AlertDialogFooter>
+ <AlertDialogCancel>Cancel</AlertDialogCancel>
+ <Button
+ variant="destructive"
+ disabled={isPending}
+ onClick={async () => {
+ mutate(id, {
+ onSuccess: () => {
+ onOpenChange(false);
+ },
+ });
+ }}
+ >
+ Delete
+ </Button>
+ </AlertDialogFooter>
+ </AlertDialogContent>
+ </AlertDialog>
+ );
+};
diff --git a/desktop/src/components/databases/fields/field-type-select.tsx b/desktop/src/components/databases/fields/field-type-select.tsx
new file mode 100644
index 00000000..6d7a188b
--- /dev/null
+++ b/desktop/src/components/databases/fields/field-type-select.tsx
@@ -0,0 +1,167 @@
+import React from 'react';
+import {
+ Popover,
+ PopoverContent,
+ PopoverTrigger,
+} from '@/components/ui/popover';
+import { Button } from '@/components/ui/button';
+import {
+ Command,
+ CommandEmpty,
+ CommandGroup,
+ CommandInput,
+ CommandItem,
+ CommandList,
+} from '@/components/ui/command';
+import { Icon } from '@/components/ui/icon';
+import { getFieldIcon } from '@/lib/databases';
+import { FieldType } from '@/types/databases';
+import { cn } from '@/lib/utils';
+
+interface FieldTypeOption {
+ name: string;
+ type: FieldType;
+}
+
+const fieldTypes: FieldTypeOption[] = [
+ {
+ name: 'Autonumber',
+ type: 'autonumber',
+ },
+ {
+ name: 'Boolean',
+ type: 'boolean',
+ },
+ {
+ name: 'Collaborator',
+ type: 'collaborator',
+ },
+ {
+ name: 'Created Date & Time',
+ type: 'created_at',
+ },
+ {
+ name: 'Created by user',
+ type: 'created_by',
+ },
+ {
+ name: 'Date',
+ type: 'date',
+ },
+ {
+ name: 'Email',
+ type: 'email',
+ },
+ {
+ name: 'File',
+ type: 'file',
+ },
+ {
+ name: 'Formula',
+ type: 'formula',
+ },
+ {
+ name: 'Multi Select',
+ type: 'multi_select',
+ },
+ {
+ name: 'Number',
+ type: 'number',
+ },
+ {
+ name: 'Phone',
+ type: 'phone',
+ },
+ {
+ name: 'Relation',
+ type: 'relation',
+ },
+ {
+ name: 'Rollup',
+ type: 'rollup',
+ },
+ {
+ name: 'Select',
+ type: 'select',
+ },
+ {
+ name: 'Text',
+ type: 'text',
+ },
+ {
+ name: 'Last modified Date & Time',
+ type: 'updated_at',
+ },
+ {
+ name: 'Last modified by user',
+ type: 'updated_by',
+ },
+ {
+ name: 'Url',
+ type: 'url',
+ },
+];
+
+interface FieldTypeSelectProps {
+ type: string | null;
+ onChange: (type: FieldType) => void;
+}
+
+export const FieldTypeSelect = ({ type, onChange }: FieldTypeSelectProps) => {
+ const [open, setOpen] = React.useState(false);
+
+ return (
+ <Popover open={open} onOpenChange={setOpen} modal={true}>
+ <PopoverTrigger asChild>
+ <Button
+ variant="outline"
+ role="combobox"
+ aria-expanded={open}
+ className="w-full justify-between p-2"
+ >
+ <span className="flex flex-row items-center gap-1">
+ <Icon name={getFieldIcon(type as FieldType)} />
+ {type
+ ? fieldTypes.find((fieldType) => fieldType.type === type)?.name
+ : 'Select field type...'}
+ </span>
+ <Icon
+ name="expand-up-down-line"
+ className="ml-2 h-4 w-4 shrink-0 opacity-50"
+ />
+ </Button>
+ </PopoverTrigger>
+ <PopoverContent className="w-96 p-1">
+ <Command className="min-h-min">
+ <CommandInput placeholder="Search field types..." className="h-9" />
+ <CommandEmpty>No field type found.</CommandEmpty>
+ <CommandList>
+ <CommandGroup className="h-min max-h-96">
+ {fieldTypes.map((fieldType) => (
+ <CommandItem
+ key={fieldType.type}
+ onSelect={() => {
+ onChange(fieldType.type);
+ setOpen(false);
+ }}
+ >
+ <div className="flex w-full flex-row items-center gap-2">
+ <Icon name={getFieldIcon(fieldType.type)} />
+ <p>{fieldType.name}</p>
+ <Icon
+ name="check-line"
+ className={cn(
+ 'ml-auto h-4 w-4',
+ type === fieldType.type ? 'opacity-100' : 'opacity-0',
+ )}
+ />
+ </div>
+ </CommandItem>
+ ))}
+ </CommandGroup>
+ </CommandList>
+ </Command>
+ </PopoverContent>
+ </Popover>
+ );
+};
diff --git a/desktop/src/components/databases/tables/cells/table-view-boolean-cell.tsx b/desktop/src/components/databases/tables/cells/table-view-boolean-cell.tsx
new file mode 100644
index 00000000..9856ce59
--- /dev/null
+++ b/desktop/src/components/databases/tables/cells/table-view-boolean-cell.tsx
@@ -0,0 +1,81 @@
+import React from 'react';
+
+import { Checkbox } from '@/components/ui/checkbox';
+import { LocalNode } from '@/types/nodes';
+import { useMutation } from '@tanstack/react-query';
+import { useWorkspace } from '@/contexts/workspace';
+import { NeuronId } from '@/lib/id';
+
+const getBooleanValue = (record: LocalNode, field: LocalNode): boolean => {
+ const attrs = record.attrs;
+
+ if (!attrs) {
+ return false;
+ }
+
+ const fieldValue = attrs[field.id];
+
+ if (typeof fieldValue === 'boolean') {
+ return fieldValue;
+ }
+
+ return false;
+};
+
+export const TableViewBooleanCell = ({
+ record,
+ field,
+}: {
+ record: LocalNode;
+ field: LocalNode;
+}) => {
+ const workspace = useWorkspace();
+ const { mutate, isPending } = useMutation({
+ mutationFn: async (newValue: boolean) => {
+ const newAttrs = {
+ ...record.attrs,
+ [field.id]: newValue,
+ };
+ const query = workspace.schema
+ .updateTable('nodes')
+ .set({
+ attrs: newAttrs ? JSON.stringify(newAttrs) : null,
+ updated_at: new Date().toISOString(),
+ updated_by: workspace.userId,
+ version_id: NeuronId.generate(NeuronId.Type.Version),
+ })
+ .where('id', '=', record.id)
+ .compile();
+
+ await workspace.mutate(query);
+ },
+ });
+
+ const canEdit = true;
+
+ const [input, setInput] = React.useState<boolean>(
+ getBooleanValue(record, field),
+ );
+
+ React.useEffect(() => {
+ setInput(getBooleanValue(record, field));
+ }, [record.versionId]);
+
+ return (
+ <div className="flex h-full w-full flex-row items-center justify-center p-1">
+ <Checkbox
+ checked={input}
+ disabled={isPending || !canEdit}
+ onCheckedChange={(e) => {
+ if (isPending) return;
+ if (!canEdit) return;
+
+ if (typeof e === 'boolean') {
+ setInput(e.valueOf());
+ mutate(e.valueOf());
+ }
+ }}
+ />
+ </div>
+ );
+};
diff --git a/desktop/src/components/databases/tables/cells/table-view-number-cell.tsx b/desktop/src/components/databases/tables/cells/table-view-number-cell.tsx
new file mode 100644
index 00000000..111c55fd
--- /dev/null
+++ b/desktop/src/components/databases/tables/cells/table-view-number-cell.tsx
@@ -0,0 +1,100 @@
+import React from 'react';
+import isHotkey from 'is-hotkey';
+import { useEffect, useRef, useState } from 'react';
+
+import { useMutation } from '@tanstack/react-query';
+import { useWorkspace } from '@/contexts/workspace';
+import { LocalNode } from '@/types/nodes';
+import { NeuronId } from '@/lib/id';
+
+const getNumberValue = (record: LocalNode, field: LocalNode): number | null => {
+ const attrs = record.attrs;
+
+ if (!attrs) {
+ return null;
+ }
+
+ const fieldValue = attrs[field.id];
+
+ if (typeof fieldValue === 'number') {
+ return fieldValue;
+ }
+
+ return null;
+};
+
+interface TableViewNumberCellProps {
+ record: LocalNode;
+ field: LocalNode;
+}
+
+export const TableViewNumberCell = ({
+ record,
+ field,
+}: TableViewNumberCellProps) => {
+ const workspace = useWorkspace();
+ const { mutate, isPending } = useMutation({
+ mutationFn: async (newValue: number) => {
+ const newAttrs = {
+ ...record.attrs,
+ [field.id]: newValue,
+ };
+ const query = workspace.schema
+ .updateTable('nodes')
+ .set({
+ attrs: newAttrs ? JSON.stringify(newAttrs) : null,
+ updated_at: new Date().toISOString(),
+ updated_by: workspace.userId,
+ version_id: NeuronId.generate(NeuronId.Type.Version),
+ })
+ .where('id', '=', record.id)
+ .compile();
+
+ await workspace.mutate(query);
+ },
+ });
+
+ const canEdit = true;
+
+ const [input, setInput] = React.useState<string>(
+ getNumberValue(record, field)?.toString() ?? '',
+ );
+
+ useEffect(() => {
+ setInput(getNumberValue(record, field)?.toString() ?? '');
+ }, [record.versionId]);
+
+ const saveIfChanged = (current: number | null, previous: number | null) => {
+ if (current !== null && current !== previous) {
+ mutate(current);
+ }
+ };
+
+ return (
+ <input
+ className="flex h-full w-full cursor-pointer flex-row items-center gap-1 p-1 text-sm focus-visible:cursor-text"
+ readOnly={!canEdit || isPending}
+ value={input ?? ''}
+ onChange={(e) => setInput(e.target.value)}
+ onBlur={() => {
+ const number = Number(input);
+ if (Number.isNaN(number)) {
+ setInput('');
+ } else {
+ saveIfChanged(number, getNumberValue(record, field));
+ }
+ }}
+ onKeyDown={(e) => {
+ if (isHotkey('enter', e)) {
+ const number = Number(input);
+ if (Number.isNaN(number)) {
+ setInput('');
+ } else {
+ saveIfChanged(number, getNumberValue(record, field));
+ }
+ e.preventDefault();
+ }
+ }}
+ />
+ );
+};
diff --git a/desktop/src/components/databases/tables/cells/table-view-text-cell.tsx b/desktop/src/components/databases/tables/cells/table-view-text-cell.tsx
new file mode 100644
index 00000000..d679f77d
--- /dev/null
+++ b/desktop/src/components/databases/tables/cells/table-view-text-cell.tsx
@@ -0,0 +1,89 @@
+import React from 'react';
+import isHotkey from 'is-hotkey';
+
+import { useMutation } from '@tanstack/react-query';
+import { useWorkspace } from '@/contexts/workspace';
+import { LocalNode } from '@/types/nodes';
+import { NeuronId } from '@/lib/id';
+
+const getTextValue = (record: LocalNode, field: LocalNode): string => {
+ const attrs = record.attrs;
+
+ if (!attrs) {
+ return '';
+ }
+
+ const fieldValue = attrs[field.id];
+
+ if (typeof fieldValue === 'string') {
+ return fieldValue;
+ }
+
+ return '';
+};
+
+interface TableViewTextCellProps {
+ record: LocalNode;
+ field: LocalNode;
+ className?: string;
+}
+
+export const TableViewTextCell = ({
+ record,
+ field,
+ className,
+}: TableViewTextCellProps) => {
+ const workspace = useWorkspace();
+ const { mutate, isPending } = useMutation({
+ mutationFn: async (newValue: string) => {
+ const newAttrs = {
+ ...record.attrs,
+ [field.id]: newValue,
+ };
+ const query = workspace.schema
+ .updateTable('nodes')
+ .set({
+ attrs: newAttrs ? JSON.stringify(newAttrs) : null,
+ updated_at: new Date().toISOString(),
+ updated_by: workspace.userId,
+ version_id: NeuronId.generate(NeuronId.Type.Version),
+ })
+ .where('id', '=', record.id)
+ .compile();
+
+ await workspace.mutate(query);
+ },
+ });
+
+ const canEdit = true;
+
+ const [text, setText] = React.useState<string>(
+ getTextValue(record, field) ?? '',
+ );
+
+ React.useEffect(() => {
+ setText(getTextValue(record, field) ?? '');
+ }, [record.versionId]);
+
+ const saveIfChanged = (current: string, previous: string | null) => {
+ if (current.length && current !== previous) {
+ mutate(current);
+ }
+ };
+
+ return (
+ <input
+ readOnly={!canEdit || isPending}
+ value={text}
+ onChange={(e) => setText(e.target.value)}
+ onBlur={() => saveIfChanged(text, getTextValue(record, field))}
+ onKeyDown={(e) => {
+ if (isHotkey('enter', e)) {
+ saveIfChanged(text, getTextValue(record, field));
+ e.preventDefault();
+ }
+ }}
+ className="flex h-full w-full cursor-pointer flex-row items-center gap-1 p-1 text-sm focus-visible:cursor-text"
+ />
+ );
+};
diff --git a/desktop/src/components/databases/tables/table-view-add-record-row.tsx b/desktop/src/components/databases/tables/table-view-add-record-row.tsx
new file mode 100644
index 00000000..f22d4a75
--- /dev/null
+++ b/desktop/src/components/databases/tables/table-view-add-record-row.tsx
@@ -0,0 +1,62 @@
+import React from 'react';
+import { Icon } from '@/components/ui/icon';
+import { useMutation } from '@tanstack/react-query';
+import { useWorkspace } from '@/contexts/workspace';
+import { useDatabase } from '@/contexts/database';
+import { generateNodeIndex } from '@/lib/nodes';
+import { NeuronId } from '@/lib/id';
+import { NodeTypes } from '@/lib/constants';
+
+export const TableViewAddRecordRow = () => {
+ const workspace = useWorkspace();
+ const database = useDatabase();
+
+ const { mutate, isPending } = useMutation({
+ mutationFn: async () => {
+ const lastChildQuery = workspace.schema
+ .selectFrom('nodes')
+ .where('parent_id', '=', database.id)
+ .selectAll()
+ .orderBy('index', 'desc')
+ .limit(1)
+ .compile();
+
+ const result = await workspace.query(lastChildQuery);
+ const lastChild =
+ result.rows && result.rows.length > 0 ? result.rows[0] : null;
+ const maxIndex = lastChild?.index ? lastChild.index : null;
+
+ const index = generateNodeIndex(maxIndex, null);
+ const query = workspace.schema
+ .insertInto('nodes')
+ .values({
+ id: NeuronId.generate(NeuronId.Type.Record),
+ type: NodeTypes.Record,
+ parent_id: database.id,
+ index,
+ attrs: null,
+ content: null,
+ created_at: new Date().toISOString(),
+ created_by: workspace.userId,
+ version_id: NeuronId.generate(NeuronId.Type.Version),
+ })
+ .compile();
+
+ await workspace.mutate(query);
+ },
+ });
+
+ return (
+ <button
+ type="button"
+ disabled={isPending}
+ className="animate-fade-in flex h-8 w-full cursor-pointer flex-row items-center gap-1 border-b pl-2 text-muted-foreground hover:bg-gray-50"
+ onClick={() => {
+ mutate();
+ }}
+ >
+ <Icon name="add-line" />
+ <span className="text-sm">Add record</span>
+ </button>
+ );
+};
diff --git a/desktop/src/components/databases/tables/table-view-body.tsx b/desktop/src/components/databases/tables/table-view-body.tsx
new file mode 100644
index 00000000..331ca56d
--- /dev/null
+++ b/desktop/src/components/databases/tables/table-view-body.tsx
@@ -0,0 +1,44 @@
+import React from 'react';
+import { useDatabase } from '@/contexts/database';
+import { useWorkspace } from '@/contexts/workspace';
+import { useQuery } from '@tanstack/react-query';
+import { NodeTypes } from '@/lib/constants';
+import { mapNode } from '@/lib/nodes';
+import { TableViewRow } from '@/components/databases/tables/table-view-row';
+import { TableViewEmptyPlaceholder } from '@/components/databases/tables/table-view-empty-placeholder';
+
+export const TableViewBody = () => {
+ const workspace = useWorkspace();
+ const database = useDatabase();
+
+ const { data, isPending } = useQuery({
+ queryKey: ['view', 'records', database.id],
+ queryFn: async ({ queryKey }) => {
+ const query = workspace.schema
+ .selectFrom('nodes')
+ .selectAll()
+ .where('parent_id', '=', database.id)
+ .where('type', '=', NodeTypes.Record)
+ .compile();
+
+ return await workspace.queryAndSubscribe({
+ key: queryKey,
+ query,
+ });
+ },
+ });
+
+ if (isPending) {
+ return null;
+ }
+
+ const recordNodes = data?.rows.map((row) => mapNode(row)) ?? [];
+ return (
+ <div className="border-t">
+ {recordNodes.length === 0 && <TableViewEmptyPlaceholder />}
+ {recordNodes.map((node, index) => (
+ <TableViewRow key={node.id} index={index} node={node} />
+ ))}
+ </div>
+ );
+};
diff --git a/desktop/src/components/databases/tables/table-view-empty-placeholder.tsx b/desktop/src/components/databases/tables/table-view-empty-placeholder.tsx
new file mode 100644
index 00000000..c8573953
--- /dev/null
+++ b/desktop/src/components/databases/tables/table-view-empty-placeholder.tsx
@@ -0,0 +1,9 @@
+import React from 'react';
+
+export const TableViewEmptyPlaceholder = () => {
+ return (
+ <div className="flex w-full flex-col items-center justify-center border-b p-10 text-sm text-muted-foreground">
+ <p>No records</p>
+ </div>
+ );
+};
diff --git a/desktop/src/components/databases/tables/table-view-field-cell.tsx b/desktop/src/components/databases/tables/table-view-field-cell.tsx
new file mode 100644
index 00000000..acf87222
--- /dev/null
+++ b/desktop/src/components/databases/tables/table-view-field-cell.tsx
@@ -0,0 +1,26 @@
+import React from 'react';
+import { LocalNode } from '@/types/nodes';
+import { match } from 'ts-pattern';
+import { FieldType } from '@/types/databases';
+import { TableViewTextCell } from '@/components/databases/tables/cells/table-view-text-cell';
+import { TableViewNumberCell } from '@/components/databases/tables/cells/table-view-number-cell';
+import { TableViewBooleanCell } from '@/components/databases/tables/cells/table-view-boolean-cell';
+
+interface TableViewFieldCellProps {
+ record: LocalNode;
+ field: LocalNode;
+}
+
+export const TableViewFieldCell = ({
+ record,
+ field,
+}: TableViewFieldCellProps) => {
+ const type = field.attrs?.type as FieldType;
+ return match(type)
+ .with('text', () => <TableViewTextCell record={record} field={field} />)
+ .with('number', () => <TableViewNumberCell record={record} field={field} />)
+ .with('boolean', () => (
+ <TableViewBooleanCell record={record} field={field} />
+ ))
+ .otherwise(() => null);
+};
diff --git a/desktop/src/components/databases/tables/table-view-field-header.tsx b/desktop/src/components/databases/tables/table-view-field-header.tsx
new file mode 100644
index 00000000..5b490b9a
--- /dev/null
+++ b/desktop/src/components/databases/tables/table-view-field-header.tsx
@@ -0,0 +1,205 @@
+import React from 'react';
+import { LocalNode } from '@/types/nodes';
+import { Icon } from '@/components/ui/icon';
+import { cn } from '@/lib/utils';
+import { getDefaultFieldWidth, getFieldIcon } from '@/lib/databases';
+import { useDrag, useDrop } from 'react-dnd';
+import { Resizable } from 're-resizable';
+import {
+ Popover,
+ PopoverContent,
+ PopoverTrigger,
+} from '@/components/ui/popover';
+import { Separator } from '@/components/ui/separator';
+import { Input } from '@/components/ui/input';
+import { FieldDeleteDialog } from '@/components/databases/fields/field-delete-dialog';
+
+interface TableViewFieldHeaderProps {
+ field: LocalNode;
+ index: number;
+}
+
+export const TableViewFieldHeader = ({
+ field,
+ index,
+}: TableViewFieldHeaderProps) => {
+ const name = field.attrs.name ?? 'Untitled';
+ const canEditDatabase = true;
+ const canEditView = true;
+
+ const [showDeleteDialog, setShowDeleteDialog] = React.useState(false);
+
+ const [, dragRef] = useDrag<LocalNode>({
+ type: 'table-field-header',
+ item: field,
+ canDrag: () => canEditView,
+ end: (item, monitor) => {
+ const dropResult = monitor.getDropResult<{ index: number }>();
+ if (!dropResult?.index) return;
+
+ // view.updateFieldAttrs({
+ // ...item.attrs,
+ // order: dropResult.index,
+ // });
+ },
+ collect: (monitor) => ({
+ isDragging: monitor.isDragging(),
+ }),
+ });
+
+ const [dropMonitor, dropRef] = useDrop({
+ accept: 'table-field-header',
+ drop: () => ({
+ index,
+ }),
+ collect: (monitor) => ({
+ isOver: monitor.isOver(),
+ canDrop: monitor.canDrop(),
+ }),
+ });
+
+ const divRef = React.useRef<HTMLDivElement>(null);
+ const dragDropRef = dragRef(dropRef(divRef));
+
+ const defaultWidth = getDefaultFieldWidth(field.attrs.type);
+
+ return (
+ <React.Fragment>
+ <Resizable
+ defaultSize={{
+ width: defaultWidth,
+ height: '2rem',
+ }}
+ minWidth={100}
+ maxWidth={500}
+ size={{ width: field.attrs.width ?? defaultWidth, height: '2rem' }}
+ enable={{
+ bottom: false,
+ bottomLeft: false,
+ bottomRight: false,
+ left: false,
+ right: canEditView,
+ top: false,
+ topLeft: false,
+ topRight: false,
+ }}
+ handleClasses={{
+ right: 'opacity-0 hover:opacity-100 bg-blue-300',
+ }}
+ handleStyles={{
+ right: {
+ width: '3px',
+ right: '-3px',
+ },
+ }}
+ onResizeStop={(e, direction, ref) => {
+ // const newWidth = ref.offsetWidth;
+ // view.updateFieldAttrs({
+ // ...viewField.attrs,
+ // width: newWidth,
+ // });
+ }}
+ >
+ <Popover modal={true}>
+ <PopoverTrigger asChild>
+ <div
+ className={cn(
+ 'flex h-8 w-full cursor-pointer flex-row items-center gap-1 p-1 text-sm hover:bg-gray-50',
+ {
+ 'border-l-2 border-blue-300':
+ dropMonitor.isOver && dropMonitor.canDrop,
+ },
+ )}
+ ref={dragDropRef as any}
+ >
+ <Icon name={getFieldIcon(field.attrs.type)} />
+ <p>{name}</p>
+ </div>
+ </PopoverTrigger>
+ <PopoverContent className="ml-1 flex w-72 flex-col gap-1 p-2 text-sm">
+ <div className="p-1">
+ <Input
+ value={name}
+ onChange={(e) => {
+ // setName(e.target.value);
+ // updateName(e.target.value);
+ }}
+ />
+ </div>
+ <Separator />
+ {true && (
+ <>
+ <div
+ className="flex cursor-pointer flex-row items-center gap-2 p-1 hover:bg-gray-100"
+ onClick={() => {
+ // eventBus.publish({
+ // __typename: 'AddSortEvent',
+ // field: viewField.field,
+ // viewId: view.id,
+ // direction: 'ASC',
+ // });
+ }}
+ >
+ <Icon name="sort-asc" />
+ <span>Sort ascending</span>
+ </div>
+
+ <div
+ className="flex cursor-pointer flex-row items-center gap-2 p-1 hover:bg-gray-100"
+ onClick={() => {
+ // eventBus.publish({
+ // __typename: 'AddSortEvent',
+ // field: viewField.field,
+ // viewId: view.id,
+ // direction: 'DESC',
+ // });
+ }}
+ >
+ <Icon name="sort-desc" />
+ <span>Sort descending</span>
+ </div>
+ </>
+ )}
+ <div className="flex cursor-pointer flex-row items-center gap-2 p-1 hover:bg-gray-100">
+ <Icon name="filter-line" />
+ <span>Filter</span>
+ </div>
+ <Separator />
+ {canEditView && (
+ <div
+ className="flex cursor-pointer flex-row items-center gap-2 p-1 hover:bg-gray-100"
+ onClick={() => {
+ // view.updateFieldAttrs({
+ // ...viewField.attrs,
+ // visible: false,
+ // });
+ }}
+ >
+ <Icon name="eye-off-line" />
+ <span>Hide in view</span>
+ </div>
+ )}
+ {canEditDatabase && (
+ <div
+ className="flex cursor-pointer flex-row items-center gap-2 p-1 hover:bg-gray-100"
+ onClick={() => {
+ setShowDeleteDialog(true);
+ }}
+ >
+ <Icon name="delete-bin-line" />
+ <span>Delete field</span>
+ </div>
+ )}
+ </PopoverContent>
+ </Popover>
+ </Resizable>
+ {showDeleteDialog && (
+ <FieldDeleteDialog
+ id={field.id}
+ open={showDeleteDialog}
+ onOpenChange={setShowDeleteDialog}
+ />
+ )}
+ </React.Fragment>
+ );
+};
diff --git a/desktop/src/components/databases/tables/table-view-header.tsx b/desktop/src/components/databases/tables/table-view-header.tsx
new file mode 100644
index 00000000..1992fcb0
--- /dev/null
+++ b/desktop/src/components/databases/tables/table-view-header.tsx
@@ -0,0 +1,25 @@
+import React from 'react';
+import { useDatabase } from '@/contexts/database';
+import { TableViewNameHeader } from '@/components/databases/tables/table-view-name-header';
+import { TableViewFieldHeader } from '@/components/databases/tables/table-view-field-header';
+import { FieldCreatePopover } from '@/components/databases/fields/field-create-popover';
+
+export const TableViewHeader = () => {
+ const database = useDatabase();
+ return (
+ <div className="flex flex-row items-center gap-0.5">
+ <div style={{ width: '30px', minWidth: '30px' }} />
+ <TableViewNameHeader />
+ {database.fields.map((field, index) => {
+ // const isVisible =
+ // viewField.attrs.visible ?? getDefaultFieldVisibility(view.layout);
+ // if (!isVisible) return null;
+
+ return (
+ <TableViewFieldHeader field={field} key={field.id} index={index} />
+ );
+ })}
+ <FieldCreatePopover />
+ </div>
+ );
+};
diff --git a/desktop/src/components/databases/tables/table-view-name-cell.tsx b/desktop/src/components/databases/tables/table-view-name-cell.tsx
new file mode 100644
index 00000000..54bae629
--- /dev/null
+++ b/desktop/src/components/databases/tables/table-view-name-cell.tsx
@@ -0,0 +1,133 @@
+import React from 'react';
+import isHotkey from 'is-hotkey';
+
+import { Icon } from '@/components/ui/icon';
+import { useWorkspace } from '@/contexts/workspace';
+import { LocalNode } from '@/types/nodes';
+import { useMutation } from '@tanstack/react-query';
+import { NeuronId } from '@/lib/id';
+import { Spinner } from '@/components/ui/spinner';
+
+interface NameEditorProps {
+ initialValue: string;
+ onSave: (value: string) => void;
+ onCancel: () => void;
+}
+
+const NameEditor = ({ initialValue, onSave, onCancel }: NameEditorProps) => {
+ const [value, setValue] = React.useState(initialValue);
+ const inputRef = React.useRef<HTMLInputElement>(null);
+
+ React.useEffect(() => {
+ inputRef.current?.focus();
+ }, []);
+
+ const handleBlur = () => {
+ onSave(value);
+ };
+
+ const handleKeyDown = (e: React.KeyboardEvent) => {
+ if (isHotkey('enter', e)) {
+ e.preventDefault();
+ onSave(value);
+ } else if (isHotkey('esc', e)) {
+ e.preventDefault();
+ onCancel();
+ }
+ };
+
+ return (
+ <input
+ ref={inputRef}
+ value={value}
+ onChange={(e) => setValue(e.target.value)}
+ onBlur={handleBlur}
+ onKeyDown={handleKeyDown}
+ className="flex h-full w-full cursor-text flex-row items-center gap-1 p-1 text-sm"
+ />
+ );
+};
+
+interface TableViewNameCellProps {
+ node: LocalNode;
+}
+
+export const TableViewNameCell = ({ node }: TableViewNameCellProps) => {
+ const workspace = useWorkspace();
+ const [isEditing, setIsEditing] = React.useState(false);
+ const [name, setName] = React.useState(node.attrs?.name);
+
+ const { mutate, isPending } = useMutation({
+ mutationFn: async (newName: string) => {
+ const newAttrs = {
+ ...node.attrs,
+ name: newName,
+ };
+ const query = workspace.schema
+ .updateTable('nodes')
+ .set({
+ attrs: newAttrs ? JSON.stringify(newAttrs) : null,
+ updated_at: new Date().toISOString(),
+ updated_by: workspace.userId,
+ version_id: NeuronId.generate(NeuronId.Type.Version),
+ })
+ .where('id', '=', node.id)
+ .compile();
+
+ await workspace.mutate(query);
+ },
+ });
+
+ React.useEffect(() => {
+ setName(node.attrs?.name);
+ }, [node.versionId]);
+
+ const canEdit = true;
+ const hasName = name && name.length > 0;
+
+ const handleSave = (newName: string) => {
+ setName(newName);
+ mutate(newName, {
+ onSuccess: () => {
+ setIsEditing(false);
+ },
+ });
+ };
+
+ return (
+ <div className="group relative flex h-full w-full items-center">
+ {isEditing ? (
+ <NameEditor
+ initialValue={name}
+ onSave={handleSave}
+ onCancel={() => setIsEditing(false)}
+ />
+ ) : (
+ <>
+ <div
+ onClick={() => canEdit && setIsEditing(true)}
+ className="flex h-full w-full cursor-pointer flex-row items-center gap-1 p-1 text-sm"
+ >
+ {hasName ? (
+ name
+ ) : (
+ <span className="text-muted-foreground">Untitled</span>
+ )}
+ </div>
+ <button
+ type="button"
+ className="absolute right-2 flex h-6 cursor-pointer flex-row items-center gap-1 rounded-md border bg-white p-1 text-sm text-muted-foreground opacity-0 hover:bg-gray-50 group-hover:opacity-100"
+ onClick={() => workspace.openModal(node.id)}
+ >
+ <Icon name="edit-box-line" /> <p>Open</p>
+ </button>
+ {isPending && (
+ <span className="absolute right-2 text-muted-foreground">
+ <Spinner size="small" />
+ </span>
+ )}
+ </>
+ )}
+ </div>
+ );
+};
diff --git a/desktop/src/components/databases/tables/table-view-name-header.tsx b/desktop/src/components/databases/tables/table-view-name-header.tsx
new file mode 100644
index 00000000..202c637e
--- /dev/null
+++ b/desktop/src/components/databases/tables/table-view-name-header.tsx
@@ -0,0 +1,113 @@
+import React from 'react';
+import { Icon } from '@/components/ui/icon';
+import { getDefaultFieldWidth, getFieldIcon } from '@/lib/databases';
+import { Resizable } from 're-resizable';
+import {
+ Popover,
+ PopoverContent,
+ PopoverTrigger,
+} from '@/components/ui/popover';
+import { Separator } from '@/components/ui/separator';
+import { Input } from '@/components/ui/input';
+
+export const TableViewNameHeader = () => {
+ const defaultWidth = getDefaultFieldWidth('name');
+
+ const canEditView = true;
+
+ return (
+ <Resizable
+ defaultSize={{
+ width: defaultWidth,
+ height: '2rem',
+ }}
+ minWidth={100}
+ maxWidth={500}
+ size={{ width: defaultWidth, height: '2rem' }}
+ enable={{
+ bottom: false,
+ bottomLeft: false,
+ bottomRight: false,
+ left: false,
+ right: canEditView,
+ top: false,
+ topLeft: false,
+ topRight: false,
+ }}
+ handleClasses={{
+ right: 'opacity-0 hover:opacity-100 bg-blue-300',
+ }}
+ handleStyles={{
+ right: {
+ width: '3px',
+ right: '-3px',
+ },
+ }}
+ onResizeStop={(e, direction, ref) => {
+ // const newWidth = ref.offsetWidth;
+ // view.updateFieldAttrs({
+ // ...viewField.attrs,
+ // width: newWidth,
+ // });
+ }}
+ >
+ <Popover modal={true}>
+ <PopoverTrigger asChild>
+ <div className="flex h-8 w-full cursor-pointer flex-row items-center gap-1 p-1 text-sm hover:bg-gray-50">
+ <Icon name={getFieldIcon('name')} />
+ <p>Name</p>
+ </div>
+ </PopoverTrigger>
+ <PopoverContent className="ml-1 flex w-72 flex-col gap-1 p-2 text-sm">
+ <div className="p-1">
+ <Input
+ value={'Name'}
+ onChange={(e) => {
+ // setName(e.target.value);
+ // updateName(e.target.value);
+ }}
+ />
+ </div>
+ <Separator />
+ {true && (
+ <>
+ <div
+ className="flex cursor-pointer flex-row items-center gap-2 p-1 hover:bg-gray-100"
+ onClick={() => {
+ // eventBus.publish({
+ // __typename: 'AddSortEvent',
+ // field: viewField.field,
+ // viewId: view.id,
+ // direction: 'ASC',
+ // });
+ }}
+ >
+ <Icon name="sort-asc" />
+ <span>Sort ascending</span>
+ </div>
+
+ <div
+ className="flex cursor-pointer flex-row items-center gap-2 p-1 hover:bg-gray-100"
+ onClick={() => {
+ // eventBus.publish({
+ // __typename: 'AddSortEvent',
+ // field: viewField.field,
+ // viewId: view.id,
+ // direction: 'DESC',
+ // });
+ }}
+ >
+ <Icon name="sort-desc" />
+ <span>Sort descending</span>
+ </div>
+ </>
+ )}
+ <div className="flex cursor-pointer flex-row items-center gap-2 p-1 hover:bg-gray-100">
+ <Icon name="filter-line" />
+ <span>Filter</span>
+ </div>
+ </PopoverContent>
+ </Popover>
+ </Resizable>
+ );
+};
diff --git a/desktop/src/components/databases/tables/table-view-row.tsx b/desktop/src/components/databases/tables/table-view-row.tsx
new file mode 100644
index 00000000..efc1ef33
--- /dev/null
+++ b/desktop/src/components/databases/tables/table-view-row.tsx
@@ -0,0 +1,46 @@
+import { LocalNode } from '@/types/nodes';
+import React from 'react';
+import { TableViewNameCell } from '@/components/databases/tables/table-view-name-cell';
+import { getDefaultFieldWidth } from '@/lib/databases';
+import { useDatabase } from '@/contexts/database';
+import { TableViewFieldCell } from './table-view-field-cell';
+import { FieldType } from '@/types/databases';
+
+interface TableViewRowProps {
+ index: number;
+ node: LocalNode;
+}
+
+export const TableViewRow = ({ index, node }: TableViewRowProps) => {
+ const database = useDatabase();
+ const nameCellWidth = getDefaultFieldWidth('name') + 'px';
+ return (
+ <div className="animate-fade-in flex flex-row items-center gap-0.5 border-b">
+ <span
+ className="flex cursor-pointer items-center justify-center text-sm text-muted-foreground"
+ style={{ width: '30px', minWidth: '30px' }}
+ >
+ {index + 1}
+ </span>
+ <div
+ className="h-8 border-r"
+ style={{ width: nameCellWidth, minWidth: nameCellWidth }}
+ >
+ <TableViewNameCell node={node} />
+ </div>
+ {database.fields.map((field) => {
+ const width = getDefaultFieldWidth(field.attrs?.type as FieldType);
+ return (
+ <div
+ key={`row-${node.id}-${field.id}`}
+ className="h-8 border-r"
+ style={{ width: width }}
+ >
+ <TableViewFieldCell record={node} field={field} />
+ </div>
+ );
+ })}
+ <div className="w-8" />
+ </div>
+ );
+};
diff --git a/desktop/src/components/databases/tables/table-view.tsx b/desktop/src/components/databases/tables/table-view.tsx
new file mode 100644
index 00000000..c5596bd7
--- /dev/null
+++ b/desktop/src/components/databases/tables/table-view.tsx
@@ -0,0 +1,19 @@
+import React from 'react';
+import { LocalNode } from '@/types/nodes';
+import { TableViewHeader } from '@/components/databases/tables/table-view-header';
+import { TableViewBody } from '@/components/databases/tables/table-view-body';
+import { TableViewAddRecordRow } from '@/components/databases/tables/table-view-add-record-row';
+
+interface TableViewProps {
+ node: LocalNode;
+}
+
+export const TableView = ({ node }: TableViewProps) => {
+ return (
+ <div className="mt-2 w-full min-w-full max-w-full overflow-auto pr-5">
+ <TableViewHeader />
+ <TableViewBody />
+ <TableViewAddRecordRow />
+ </div>
+ );
+};
diff --git a/desktop/src/components/databases/view-actions.tsx b/desktop/src/components/databases/view-actions.tsx
new file mode 100644
index 00000000..1bfeeaf1
--- /dev/null
+++ b/desktop/src/components/databases/view-actions.tsx
@@ -0,0 +1,14 @@
+import React from 'react';
+import { ViewSettingsButton } from '@/components/databases/view-settings-button';
+import { ViewSortButton } from '@/components/databases/view-sort-button';
+import { ViewFilterButton } from '@/components/databases/view-filter-button';
+
+export const ViewActions = () => {
+ return (
+ <div className="invisible flex flex-row items-center justify-end group-hover/database:visible">
+ <ViewSettingsButton />
+ <ViewSortButton />
+ <ViewFilterButton />
+ </div>
+ );
+};
diff --git a/desktop/src/components/databases/view-create-dialog.tsx b/desktop/src/components/databases/view-create-dialog.tsx
new file mode 100644
index 00000000..b7b2c904
--- /dev/null
+++ b/desktop/src/components/databases/view-create-dialog.tsx
@@ -0,0 +1,5 @@
+import React from 'react';
+
+export const ViewCreateDialog = () => {
+ return <div>ViewCreateDialog</div>;
+};
diff --git a/desktop/src/components/databases/view-filter-button.tsx b/desktop/src/components/databases/view-filter-button.tsx
new file mode 100644
index 00000000..27582ad2
--- /dev/null
+++ b/desktop/src/components/databases/view-filter-button.tsx
@@ -0,0 +1,10 @@
+import React from 'react';
+import { Icon } from '@/components/ui/icon';
+
+export const ViewFilterButton = () => {
+ return (
+ <div className="flex cursor-pointer items-center rounded-md p-1.5 hover:bg-gray-50">
+ <Icon name="filter-line" />
+ </div>
+ );
+};
diff --git a/desktop/src/components/databases/view-settings-button.tsx b/desktop/src/components/databases/view-settings-button.tsx
new file mode 100644
index 00000000..6631dc5c
--- /dev/null
+++ b/desktop/src/components/databases/view-settings-button.tsx
@@ -0,0 +1,10 @@
+import React from 'react';
+import { Icon } from '@/components/ui/icon';
+
+export const ViewSettingsButton = () => {
+ return (
+ <div className="flex cursor-pointer items-center rounded-md p-1.5 hover:bg-gray-50">
+ <Icon name="settings-3-line" />
+ </div>
+ );
+};
diff --git a/desktop/src/components/databases/view-sort-button.tsx b/desktop/src/components/databases/view-sort-button.tsx
new file mode 100644
index 00000000..4b675802
--- /dev/null
+++ b/desktop/src/components/databases/view-sort-button.tsx
@@ -0,0 +1,10 @@
+import React from 'react';
+import { Icon } from '@/components/ui/icon';
+
+export const ViewSortButton = () => {
+ return (
+ <div className="flex cursor-pointer items-center rounded-md p-1.5 hover:bg-gray-50">
+ <Icon name="sort-desc" />
+ </div>
+ );
+};
diff --git a/desktop/src/components/databases/view-tab.tsx b/desktop/src/components/databases/view-tab.tsx
new file mode 100644
index 00000000..b7a80a8c
--- /dev/null
+++ b/desktop/src/components/databases/view-tab.tsx
@@ -0,0 +1,28 @@
+import React from 'react';
+import { cn } from '@/lib/utils';
+import { LocalNode } from '@/types/nodes';
+import { Avatar } from '@/components/ui/avatar';
+
+interface ViewTabProps {
+ view: LocalNode;
+ isActive: boolean;
+ onClick: () => void;
+}
+
+export const ViewTab = ({ view, isActive, onClick }: ViewTabProps) => {
+ const name = view.attrs?.name ?? 'Unnamed View';
+ return (
+ <div
+ role="presentation"
+ className={cn(
+ 'inline-flex cursor-pointer flex-row items-center gap-1 border-b-2 p-1 pl-0 text-sm',
+ isActive ? 'border-gray-500' : 'border-transparent',
+ )}
+ onClick={() => onClick()}
+ onKeyDown={() => onClick()}
+ >
+ <Avatar id={view.id} name={name} size="small" />
+ {name}
+ </div>
+ );
+};
diff --git a/desktop/src/components/messages/message-delete-button.tsx b/desktop/src/components/messages/message-delete-button.tsx
index cafe1163..c089be45 100644
--- a/desktop/src/components/messages/message-delete-button.tsx
+++ b/desktop/src/components/messages/message-delete-button.tsx
@@ -25,7 +25,7 @@ export const MessageDeleteButton = ({ id }: MessageDeleteButtonProps) => {
.deleteFrom('nodes')
.where('id', '=', messageId)
.compile();
-
+
await workspace.mutate(mutation);
},
});
diff --git a/desktop/src/components/messages/message-list.tsx b/desktop/src/components/messages/message-list.tsx
index abc394ab..b18f0260 100644
--- a/desktop/src/components/messages/message-list.tsx
+++ b/desktop/src/components/messages/message-list.tsx
@@ -36,8 +36,6 @@ export const MessageList = ({
if (messageCount >= MESSAGES_PER_PAGE) {
return pages.length;
}
-
- return undefined;
}
return undefined;
},
diff --git a/desktop/src/components/root.tsx b/desktop/src/components/root.tsx
index c5a1c4b5..8b1bbbe5 100644
--- a/desktop/src/components/root.tsx
+++ b/desktop/src/components/root.tsx
@@ -10,6 +10,8 @@ import { createBrowserRouter, RouterProvider } from 'react-router-dom';
import { Container } from '@/components/workspaces/container';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { eventBus } from '@/lib/event-bus';
+import { DndProvider } from 'react-dnd';
+import { HTML5Backend } from 'react-dnd-html5-backend';
const router = createBrowserRouter([
{
@@ -112,10 +114,12 @@ export const Root = () => {
return (
<QueryClientProvider client={queryClient}>
- <TooltipProvider>
- <RouterProvider router={router} />
- </TooltipProvider>
- <Toaster />
+ <DndProvider backend={HTML5Backend}>
+ <TooltipProvider>
+ <RouterProvider router={router} />
+ </TooltipProvider>
+ <Toaster />
+ </DndProvider>
</QueryClientProvider>
);
};
diff --git a/desktop/src/components/spaces/space-create-button.tsx b/desktop/src/components/spaces/space-create-button.tsx
index 7407cebd..0ba098d7 100644
--- a/desktop/src/components/spaces/space-create-button.tsx
+++ b/desktop/src/components/spaces/space-create-button.tsx
@@ -1,6 +1,6 @@
-import React from "react";
-import {SpaceCreateDialog} from "@/components/spaces/space-create-dialog";
-import {Icon} from "@/components/ui/icon";
+import React from 'react';
+import { SpaceCreateDialog } from '@/components/spaces/space-create-dialog';
+import { Icon } from '@/components/ui/icon';
export const SpaceCreateButton = () => {
const [open, setOpen] = React.useState(false);
@@ -13,5 +13,5 @@ export const SpaceCreateButton = () => {
/>
<SpaceCreateDialog open={open} onOpenChange={setOpen} />
</React.Fragment>
- )
-}
\ No newline at end of file
+ );
+};
diff --git a/desktop/src/components/spaces/space-sidebar-node.tsx b/desktop/src/components/spaces/space-sidebar-node.tsx
index 5bdaf025..b20815f8 100644
--- a/desktop/src/components/spaces/space-sidebar-node.tsx
+++ b/desktop/src/components/spaces/space-sidebar-node.tsx
@@ -16,6 +16,7 @@ import { getDefaultNodeIcon } from '@/lib/nodes';
import { NodeTypes } from '@/lib/constants';
import { ChannelCreateDialog } from '@/components/channels/channel-create-dialog';
import { PageCreateDialog } from '@/components/pages/page-create-dialog';
+import { DatabaseCreateDialog } from '@/components/databases/database-create-dialog';
interface SettingsState {
open: boolean;
@@ -130,6 +131,13 @@ export const SpaceSidebarNode = ({ node }: SpaceSidebarNodeProps) => {
onOpenChange={setOpenCreatePage}
/>
)}
+ {openCreateDatabase && (
+ <DatabaseCreateDialog
+ spaceId={node.id}
+ open={openCreateDatabase}
+ onOpenChange={setOpenCreateDatabase}
+ />
+ )}
</React.Fragment>
);
};
diff --git a/desktop/src/components/ui/checkbox.tsx b/desktop/src/components/ui/checkbox.tsx
new file mode 100644
index 00000000..f8315322
--- /dev/null
+++ b/desktop/src/components/ui/checkbox.tsx
@@ -0,0 +1,28 @@
+import * as React from "react"
+import * as CheckboxPrimitive from "@radix-ui/react-checkbox"
+import { CheckIcon } from "@radix-ui/react-icons"
+
+import { cn } from "@/lib/utils"
+
+const Checkbox = React.forwardRef<
+ React.ElementRef<typeof CheckboxPrimitive.Root>,
+ React.ComponentPropsWithoutRef<typeof CheckboxPrimitive.Root>
+>(({ className, ...props }, ref) => (
+ <CheckboxPrimitive.Root
+ ref={ref}
+ className={cn(
+ "peer h-4 w-4 shrink-0 rounded-sm border border-primary shadow focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",
+ className
+ )}
+ {...props}
+ >
+ <CheckboxPrimitive.Indicator
+ className={cn("flex items-center justify-center text-current")}
+ >
+ <CheckIcon className="h-4 w-4" />
+ </CheckboxPrimitive.Indicator>
+ </CheckboxPrimitive.Root>
+))
+Checkbox.displayName = CheckboxPrimitive.Root.displayName
+
+export { Checkbox }
diff --git a/desktop/src/components/ui/command.tsx b/desktop/src/components/ui/command.tsx
index 326c03fc..47098e43 100644
--- a/desktop/src/components/ui/command.tsx
+++ b/desktop/src/components/ui/command.tsx
@@ -1,10 +1,10 @@
-import * as React from "react"
-import { type DialogProps } from "@radix-ui/react-dialog"
-import { MagnifyingGlassIcon } from "@radix-ui/react-icons"
-import { Command as CommandPrimitive } from "cmdk"
+import * as React from 'react';
+import { type DialogProps } from '@radix-ui/react-dialog';
+import { MagnifyingGlassIcon } from '@radix-ui/react-icons';
+import { Command as CommandPrimitive } from 'cmdk';
-import { cn } from "@/lib/utils"
-import { Dialog, DialogContent } from "@/components/ui/dialog"
+import { cn } from '@/lib/utils';
+import { Dialog, DialogContent } from '@/components/ui/dialog';
const Command = React.forwardRef<
React.ElementRef<typeof CommandPrimitive>,
@@ -13,13 +13,13 @@ const Command = React.forwardRef<
<CommandPrimitive
ref={ref}
className={cn(
- "flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",
- className
+ 'flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground',
+ className,
)}
{...props}
/>
-))
-Command.displayName = CommandPrimitive.displayName
+));
+Command.displayName = CommandPrimitive.displayName;
interface CommandDialogProps extends DialogProps {}
@@ -32,8 +32,8 @@ const CommandDialog = ({ children, ...props }: CommandDialogProps) => {
</Command>
</DialogContent>
</Dialog>
- )
-}
+ );
+};
const CommandInput = React.forwardRef<
React.ElementRef<typeof CommandPrimitive.Input>,
@@ -44,15 +44,15 @@ const CommandInput = React.forwardRef<
<CommandPrimitive.Input
ref={ref}
className={cn(
- "flex h-10 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",
- className
+ 'flex h-10 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50',
+ className,
)}
{...props}
/>
</div>
-))
+));
-CommandInput.displayName = CommandPrimitive.Input.displayName
+CommandInput.displayName = CommandPrimitive.Input.displayName;
const CommandList = React.forwardRef<
React.ElementRef<typeof CommandPrimitive.List>,
@@ -60,12 +60,12 @@ const CommandList = React.forwardRef<
>(({ className, ...props }, ref) => (
<CommandPrimitive.List
ref={ref}
- className={cn("max-h-[300px] overflow-y-auto overflow-x-hidden", className)}
+ className={cn('max-h-[300px] overflow-y-auto overflow-x-hidden', className)}
{...props}
/>
-))
+));
-CommandList.displayName = CommandPrimitive.List.displayName
+CommandList.displayName = CommandPrimitive.List.displayName;
const CommandEmpty = React.forwardRef<
React.ElementRef<typeof CommandPrimitive.Empty>,
@@ -76,9 +76,9 @@ const CommandEmpty = React.forwardRef<
className="py-6 text-center text-sm"
{...props}
/>
-))
+));
-CommandEmpty.displayName = CommandPrimitive.Empty.displayName
+CommandEmpty.displayName = CommandPrimitive.Empty.displayName;
const CommandGroup = React.forwardRef<
React.ElementRef<typeof CommandPrimitive.Group>,
@@ -87,14 +87,14 @@ const CommandGroup = React.forwardRef<
<CommandPrimitive.Group
ref={ref}
className={cn(
- "overflow-hidden p-1 text-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",
- className
+ 'overflow-hidden p-1 text-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground',
+ className,
)}
{...props}
/>
-))
+));
-CommandGroup.displayName = CommandPrimitive.Group.displayName
+CommandGroup.displayName = CommandPrimitive.Group.displayName;
const CommandSeparator = React.forwardRef<
React.ElementRef<typeof CommandPrimitive.Separator>,
@@ -102,11 +102,11 @@ const CommandSeparator = React.forwardRef<
>(({ className, ...props }, ref) => (
<CommandPrimitive.Separator
ref={ref}
- className={cn("-mx-1 h-px bg-border", className)}
+ className={cn('-mx-1 h-px bg-border', className)}
{...props}
/>
-))
-CommandSeparator.displayName = CommandPrimitive.Separator.displayName
+));
+CommandSeparator.displayName = CommandPrimitive.Separator.displayName;
const CommandItem = React.forwardRef<
React.ElementRef<typeof CommandPrimitive.Item>,
@@ -115,14 +115,14 @@ const CommandItem = React.forwardRef<
<CommandPrimitive.Item
ref={ref}
className={cn(
- "relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none aria-selected:bg-accent aria-selected:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
- className
+ 'relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none aria-selected:bg-accent aria-selected:text-accent-foreground data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50',
+ className,
)}
{...props}
/>
-))
+));
-CommandItem.displayName = CommandPrimitive.Item.displayName
+CommandItem.displayName = CommandPrimitive.Item.displayName;
const CommandShortcut = ({
className,
@@ -131,14 +131,14 @@ const CommandShortcut = ({
return (
<span
className={cn(
- "ml-auto text-xs tracking-widest text-muted-foreground",
- className
+ 'ml-auto text-xs tracking-widest text-muted-foreground',
+ className,
)}
{...props}
/>
- )
-}
-CommandShortcut.displayName = "CommandShortcut"
+ );
+};
+CommandShortcut.displayName = 'CommandShortcut';
export {
Command,
@@ -150,4 +150,4 @@ export {
CommandItem,
CommandShortcut,
CommandSeparator,
-}
+};
diff --git a/desktop/src/components/ui/separator.tsx b/desktop/src/components/ui/separator.tsx
new file mode 100644
index 00000000..6d7f1226
--- /dev/null
+++ b/desktop/src/components/ui/separator.tsx
@@ -0,0 +1,29 @@
+import * as React from "react"
+import * as SeparatorPrimitive from "@radix-ui/react-separator"
+
+import { cn } from "@/lib/utils"
+
+const Separator = React.forwardRef<
+ React.ElementRef<typeof SeparatorPrimitive.Root>,
+ React.ComponentPropsWithoutRef<typeof SeparatorPrimitive.Root>
+>(
+ (
+ { className, orientation = "horizontal", decorative = true, ...props },
+ ref
+ ) => (
+ <SeparatorPrimitive.Root
+ ref={ref}
+ decorative={decorative}
+ orientation={orientation}
+ className={cn(
+ "shrink-0 bg-border",
+ orientation === "horizontal" ? "h-[1px] w-full" : "h-full w-[1px]",
+ className
+ )}
+ {...props}
+ />
+ )
+)
+Separator.displayName = SeparatorPrimitive.Root.displayName
+
+export { Separator }
diff --git a/desktop/src/components/workspaces/container.tsx b/desktop/src/components/workspaces/container.tsx
index a7e2acbd..e8add563 100644
--- a/desktop/src/components/workspaces/container.tsx
+++ b/desktop/src/components/workspaces/container.tsx
@@ -9,6 +9,7 @@ import { Spinner } from '@/components/ui/spinner';
import { mapNode } from '@/lib/nodes';
import { useQuery } from '@tanstack/react-query';
import { useWorkspace } from '@/contexts/workspace';
+import { DatabaseContainerNode } from '@/components/databases/database-container-node';
export const Container = () => {
const { nodeId } = useParams<{ nodeId: string }>();
@@ -45,7 +46,8 @@ export const Container = () => {
{match(node.type)
.with(NodeTypes.Channel, () => <ChannelContainerNode node={node} />)
.with(NodeTypes.Page, () => <PageContainerNode node={node} />)
- .otherwise(null)}
+ .with(NodeTypes.Database, () => <DatabaseContainerNode node={node} />)
+ .otherwise(() => null)}
</div>
);
};
diff --git a/desktop/src/components/workspaces/sidebar-node.tsx b/desktop/src/components/workspaces/sidebar-node.tsx
index d77e63e6..f369578c 100644
--- a/desktop/src/components/workspaces/sidebar-node.tsx
+++ b/desktop/src/components/workspaces/sidebar-node.tsx
@@ -5,6 +5,7 @@ import { SpaceSidebarNode } from '@/components/spaces/space-sidebar-node';
import { NodeTypes } from '@/lib/constants';
import { ChannelSidebarNode } from '@/components/channels/channel-sidebar-node';
import { PageSidebarNode } from '@/components/pages/page-sidebar-node';
+import { DatabaseSidebarNode } from '@/components/databases/database-sidebar-node';
interface SidebarNodeProps {
node: LocalNode;
@@ -15,5 +16,6 @@ export const SidebarNode = ({ node }: SidebarNodeProps): React.ReactNode => {
.with(NodeTypes.Space, () => <SpaceSidebarNode node={node} />)
.with(NodeTypes.Channel, () => <ChannelSidebarNode node={node} />)
.with(NodeTypes.Page, () => <PageSidebarNode node={node} />)
+ .with(NodeTypes.Database, () => <DatabaseSidebarNode node={node} />)
.otherwise(null);
};
diff --git a/desktop/src/components/workspaces/workspace.tsx b/desktop/src/components/workspaces/workspace.tsx
index d6eb0862..62f0beef 100644
--- a/desktop/src/components/workspaces/workspace.tsx
+++ b/desktop/src/components/workspaces/workspace.tsx
@@ -144,6 +144,9 @@ export const Workspace = () => {
navigateToNode(nodeId) {
navigate(`/${workspaceId}/${nodeId}`);
},
+ openModal(modal) {
+ // setModal(modal);
+ },
}}
>
<div className="flex h-screen max-h-screen flex-row">
diff --git a/desktop/src/contexts/app-database.ts b/desktop/src/contexts/app-database.ts
index 47e0ea73..d9a7cc52 100644
--- a/desktop/src/contexts/app-database.ts
+++ b/desktop/src/contexts/app-database.ts
@@ -1,7 +1,7 @@
import React from 'react';
import { CompiledQuery, Kysely, QueryResult } from 'kysely';
import { AppDatabaseSchema } from '@/data/schemas/app';
-import { SubscribedQueryContext } from '@/types/databases';
+import { SubscribedQueryContext } from '@/types/queries';
interface AppDatabaseContext {
database: Kysely<AppDatabaseSchema>;
diff --git a/desktop/src/contexts/database.ts b/desktop/src/contexts/database.ts
new file mode 100644
index 00000000..16cfe6cf
--- /dev/null
+++ b/desktop/src/contexts/database.ts
@@ -0,0 +1,13 @@
+import { LocalNode } from '@/types/nodes';
+import { createContext, useContext } from 'react';
+
+interface DatabaseContext {
+ id: string;
+ fields: LocalNode[];
+}
+
+export const DatabaseContext = createContext<DatabaseContext>(
+ {} as DatabaseContext,
+);
+
+export const useDatabase = () => useContext(DatabaseContext);
diff --git a/desktop/src/contexts/workspace.ts b/desktop/src/contexts/workspace.ts
index 38c513af..8046da7a 100644
--- a/desktop/src/contexts/workspace.ts
+++ b/desktop/src/contexts/workspace.ts
@@ -2,7 +2,7 @@ import { createContext, useContext } from 'react';
import { Workspace } from '@/types/workspaces';
import { CompiledQuery, Kysely, QueryResult } from 'kysely';
import { WorkspaceDatabaseSchema } from '@/data/schemas/workspace';
-import { SubscribedQueryContext } from '@/types/databases';
+import { SubscribedQueryContext } from '@/types/queries';
interface WorkspaceContext extends Workspace {
schema: Kysely<WorkspaceDatabaseSchema>;
@@ -12,6 +12,7 @@ interface WorkspaceContext extends Workspace {
context: SubscribedQueryContext<R>,
) => Promise<QueryResult<R>>;
navigateToNode: (nodeId: string) => void;
+ openModal: (nodeId: string) => void;
}
export const WorkspaceContext = createContext<WorkspaceContext>(
diff --git a/desktop/src/data/app-manager.ts b/desktop/src/data/app-manager.ts
index 54661e08..4b174b71 100644
--- a/desktop/src/data/app-manager.ts
+++ b/desktop/src/data/app-manager.ts
@@ -17,10 +17,7 @@ import {
resultHasChanged,
} from '@/data/utils';
import { Workspace } from '@/types/workspaces';
-import {
- SubscribedQueryContext,
- SubscribedQueryResult,
-} from '@/types/databases';
+import { SubscribedQueryContext, SubscribedQueryResult } from '@/types/queries';
import { eventBus } from '@/lib/event-bus';
import { isEqual } from 'lodash';
@@ -245,7 +242,6 @@ class AppManager {
} catch (error) {
console.error('Error in event loop:', error);
}
-
setTimeout(this.executeEventLoop, EVENT_LOOP_INTERVAL);
}
diff --git a/desktop/src/data/migrations/workspace.ts b/desktop/src/data/migrations/workspace.ts
index 2590d77f..a9f58deb 100644
--- a/desktop/src/data/migrations/workspace.ts
+++ b/desktop/src/data/migrations/workspace.ts
@@ -50,7 +50,7 @@ const createNodesInsertTrigger: Migration = {
CREATE TRIGGER after_insert_nodes
AFTER INSERT ON nodes
FOR EACH ROW
- WHEN NEW.server_version_id is null
+ WHEN NEW.server_version_id IS NULL
BEGIN
INSERT INTO mutations ('action', 'table', 'after', 'created_at')
VALUES (
@@ -88,7 +88,7 @@ const createNodesUpdateTrigger: Migration = {
CREATE TRIGGER after_update_nodes
AFTER UPDATE ON nodes
FOR EACH ROW
- WHEN NEW.version_id != NEW.server_version_id
+ WHEN NEW.server_version_id IS NULL OR NEW.version_id != NEW.server_version_id
BEGIN
INSERT INTO mutations ('action', 'table', 'before', 'after', 'created_at')
VALUES (
diff --git a/desktop/src/data/workspace-manager.ts b/desktop/src/data/workspace-manager.ts
index 03415c77..6942651c 100644
--- a/desktop/src/data/workspace-manager.ts
+++ b/desktop/src/data/workspace-manager.ts
@@ -15,10 +15,7 @@ import {
extractTablesFromSql,
resultHasChanged,
} from '@/data/utils';
-import {
- SubscribedQueryContext,
- SubscribedQueryResult,
-} from '@/types/databases';
+import { SubscribedQueryContext, SubscribedQueryResult } from '@/types/queries';
import { ServerMutation } from '@/types/mutations';
import { eventBus } from '@/lib/event-bus';
import { AxiosInstance } from 'axios';
diff --git a/desktop/src/lib/constants.ts b/desktop/src/lib/constants.ts
index 5f24a363..8aef929a 100644
--- a/desktop/src/lib/constants.ts
+++ b/desktop/src/lib/constants.ts
@@ -15,8 +15,13 @@ export const NodeTypes = {
TaskItem: 'taskItem',
HorizontalRule: 'horizontalRule',
Database: 'database',
+ DatabaseReplica: 'database_replica',
Record: 'record',
Folder: 'folder',
+ TableView: 'table_view',
+ BoardView: 'board_view',
+ CalendarView: 'calendar_view',
+ Field: 'field',
};
export const LeafNodeTypes: string[] = [
@@ -32,3 +37,9 @@ export const RootNodeTypes: string[] = [
NodeTypes.Page,
NodeTypes.Channel,
];
+
+export const ViewNodeTypes: string[] = [
+ NodeTypes.TableView,
+ NodeTypes.BoardView,
+ NodeTypes.CalendarView,
+];
diff --git a/desktop/src/lib/databases.ts b/desktop/src/lib/databases.ts
new file mode 100644
index 00000000..9953df9e
--- /dev/null
+++ b/desktop/src/lib/databases.ts
@@ -0,0 +1,103 @@
+import { FieldType } from '@/types/databases';
+
+export const getFieldIcon = (type?: FieldType): string => {
+ if (!type) return '';
+
+ switch (type) {
+ case 'name':
+ return 'text';
+ case 'autonumber':
+ return 'hashtag';
+ case 'boolean':
+ return 'checkbox-line';
+ case 'button':
+ return 'focus-line';
+ case 'collaborator':
+ return 'user-line';
+ case 'created_at':
+ return 'calendar-event-line';
+ case 'created_by':
+ return 'user-received-line';
+ case 'date':
+ return 'calendar-event-line';
+ case 'email':
+ return 'mail-line';
+ case 'file':
+ return 'file-line';
+ case 'formula':
+ return 'functions';
+ case 'multi_select':
+ return 'list-check';
+ case 'number':
+ return 'hashtag';
+ case 'phone':
+ return 'smartphone-line';
+ case 'relation':
+ return 'mind-map';
+ case 'rollup':
+ return 'magic-line';
+ case 'select':
+ return 'radio-button-line';
+ case 'text':
+ return 'text';
+ case 'updated_at':
+ return 'calendar-event-line';
+ case 'updated_by':
+ return 'user-received-line';
+ case 'url':
+ return 'link';
+ default:
+ return 'close-line';
+ }
+};
+
+export const getDefaultFieldWidth = (type: FieldType): number => {
+ if (!type) return 0;
+
+ switch (type.toLowerCase()) {
+ case 'name':
+ return 200;
+ case 'autonumber':
+ return 150;
+ case 'boolean':
+ return 100;
+ case 'button':
+ return 100;
+ case 'collaborator':
+ return 200;
+ case 'created_at':
+ return 200;
+ case 'created_by':
+ return 200;
+ case 'date':
+ return 200;
+ case 'email':
+ return 200;
+ case 'file':
+ return 200;
+ case 'formula':
+ return 200;
+ case 'multi_select':
+ return 200;
+ case 'number':
+ return 150;
+ case 'phone':
+ return 200;
+ case 'relation':
+ return 200;
+ case 'rollup':
+ return 200;
+ case 'select':
+ return 200;
+ case 'text':
+ return 200;
+ case 'updated_at':
+ return 200;
+ case 'updated_by':
+ return 200;
+ case 'url':
+ return 200;
+ default:
+ return 200;
+ }
+};
diff --git a/desktop/src/lib/id.ts b/desktop/src/lib/id.ts
index 23770e9c..1a4ed121 100644
--- a/desktop/src/lib/id.ts
+++ b/desktop/src/lib/id.ts
@@ -25,6 +25,14 @@ enum IdType {
TaskList = 'tl',
TaskItem = 'ti',
HorizontalRule = 'hr',
+ Database = 'db',
+ DatabaseReplica = 'dr',
+ Record = 'rc',
+ Folder = 'fl',
+ TableView = 'tv',
+ BoardView = 'bv',
+ CalendarView = 'cv',
+ Field = 'fi',
}
export class NeuronId {
@@ -72,6 +80,22 @@ export class NeuronId {
return IdType.TaskItem;
case NodeTypes.HorizontalRule:
return IdType.HorizontalRule;
+ case NodeTypes.Database:
+ return IdType.Database;
+ case NodeTypes.DatabaseReplica:
+ return IdType.DatabaseReplica;
+ case NodeTypes.Record:
+ return IdType.Record;
+ case NodeTypes.Folder:
+ return IdType.Folder;
+ case NodeTypes.TableView:
+ return IdType.TableView;
+ case NodeTypes.BoardView:
+ return IdType.BoardView;
+ case NodeTypes.CalendarView:
+ return IdType.CalendarView;
+ case NodeTypes.Field:
+ return IdType.Field;
default:
return IdType.Node;
}
diff --git a/desktop/src/lib/utils.ts b/desktop/src/lib/utils.ts
index bedc7bef..a0edcb3f 100644
--- a/desktop/src/lib/utils.ts
+++ b/desktop/src/lib/utils.ts
@@ -119,5 +119,9 @@ export const compareString = (a?: string | null, b?: string | null): number => {
return 1;
}
- return a.localeCompare(b);
+ if (a > b) {
+ return 1;
+ }
+
+ return -1;
};
diff --git a/desktop/src/main.ts b/desktop/src/main.ts
index f37ea84b..9f4e02e9 100644
--- a/desktop/src/main.ts
+++ b/desktop/src/main.ts
@@ -3,8 +3,7 @@ import path from 'path';
import { eventBus } from '@/lib/event-bus';
import { appManager } from '@/data/app-manager';
import { CompiledQuery, QueryResult } from 'kysely';
-import { SubscribedQueryContext } from './types/databases';
-
+import { SubscribedQueryContext } from '@/types/queries';
let subscriptionId: string | null = null;
// Handle creating/removing shortcuts on Windows when installing/uninstalling.
diff --git a/desktop/src/types/databases.ts b/desktop/src/types/databases.ts
index b5a13c0a..74e1dae3 100644
--- a/desktop/src/types/databases.ts
+++ b/desktop/src/types/databases.ts
@@ -1,13 +1,22 @@
-import { CompiledQuery, QueryResult } from 'kysely';
-
-export type SubscribedQueryContext<T> = {
- key: string[];
- page?: number;
- query: CompiledQuery<T>;
-};
-
-export type SubscribedQueryResult<T> = {
- context: SubscribedQueryContext<T>;
- tables: string[];
- result: QueryResult<T>;
-};
+export type FieldType =
+ | 'name'
+ | 'autonumber'
+ | 'boolean'
+ | 'button'
+ | 'collaborator'
+ | 'created_at'
+ | 'created_by'
+ | 'date'
+ | 'email'
+ | 'file'
+ | 'formula'
+ | 'multi_select'
+ | 'number'
+ | 'phone'
+ | 'relation'
+ | 'rollup'
+ | 'select'
+ | 'text'
+ | 'updated_at'
+ | 'updated_by'
+ | 'url';
diff --git a/desktop/src/types/queries.ts b/desktop/src/types/queries.ts
new file mode 100644
index 00000000..b5a13c0a
--- /dev/null
+++ b/desktop/src/types/queries.ts
@@ -0,0 +1,13 @@
+import { CompiledQuery, QueryResult } from 'kysely';
+
+export type SubscribedQueryContext<T> = {
+ key: string[];
+ page?: number;
+ query: CompiledQuery<T>;
+};
+
+export type SubscribedQueryResult<T> = {
+ context: SubscribedQueryContext<T>;
+ tables: string[];
+ result: QueryResult<T>;
+};
diff --git a/desktop/src/types/updates.ts b/desktop/src/types/updates.ts
deleted file mode 100644
index 5795f05a..00000000
--- a/desktop/src/types/updates.ts
+++ /dev/null
@@ -1,8 +0,0 @@
-export type Update = {
- id: string;
- workspaceId: string;
- deviceId: string;
- type: string;
- content: string;
- createdAt: string;
-};
diff --git a/desktop/src/types/window.d.ts b/desktop/src/types/window.d.ts
index 46107f0f..a66f3867 100644
--- a/desktop/src/types/window.d.ts
+++ b/desktop/src/types/window.d.ts
@@ -1,7 +1,7 @@
import { EventBus } from '@/lib/event-bus';
import { CompiledQuery, QueryResult } from 'kysely';
import { LocalMutationInput } from '@/types/mutations';
-import { SubscribedQueryContext } from './databases';
+import { SubscribedQueryContext } from '@/types/queries';
interface NeuronApi {
init: () => Promise<void>;
diff --git a/desktop/tailwind.config.js b/desktop/tailwind.config.js
index 7cb7e37a..ceda62b3 100644
--- a/desktop/tailwind.config.js
+++ b/desktop/tailwind.config.js
@@ -1,77 +1,86 @@
/** @type {import('tailwindcss').Config} */
module.exports = {
- darkMode: ["class"],
+ darkMode: ['class'],
content: [
'./pages/**/*.{ts,tsx}',
'./components/**/*.{ts,tsx}',
'./app/**/*.{ts,tsx}',
'./src/**/*.{ts,tsx}',
],
- prefix: "",
+ prefix: '',
theme: {
container: {
center: true,
- padding: "2rem",
+ padding: '2rem',
screens: {
- "2xl": "1400px",
+ '2xl': '1400px',
},
},
extend: {
colors: {
- border: "hsl(var(--border))",
- input: "hsl(var(--input))",
- ring: "hsl(var(--ring))",
- background: "hsl(var(--background))",
- foreground: "hsl(var(--foreground))",
+ border: 'hsl(var(--border))',
+ input: 'hsl(var(--input))',
+ ring: 'hsl(var(--ring))',
+ background: 'hsl(var(--background))',
+ foreground: 'hsl(var(--foreground))',
primary: {
- DEFAULT: "hsl(var(--primary))",
- foreground: "hsl(var(--primary-foreground))",
+ DEFAULT: 'hsl(var(--primary))',
+ foreground: 'hsl(var(--primary-foreground))',
},
secondary: {
- DEFAULT: "hsl(var(--secondary))",
- foreground: "hsl(var(--secondary-foreground))",
+ DEFAULT: 'hsl(var(--secondary))',
+ foreground: 'hsl(var(--secondary-foreground))',
},
destructive: {
- DEFAULT: "hsl(var(--destructive))",
- foreground: "hsl(var(--destructive-foreground))",
+ DEFAULT: 'hsl(var(--destructive))',
+ foreground: 'hsl(var(--destructive-foreground))',
},
muted: {
- DEFAULT: "hsl(var(--muted))",
- foreground: "hsl(var(--muted-foreground))",
+ DEFAULT: 'hsl(var(--muted))',
+ foreground: 'hsl(var(--muted-foreground))',
},
accent: {
- DEFAULT: "hsl(var(--accent))",
- foreground: "hsl(var(--accent-foreground))",
+ DEFAULT: 'hsl(var(--accent))',
+ foreground: 'hsl(var(--accent-foreground))',
},
popover: {
- DEFAULT: "hsl(var(--popover))",
- foreground: "hsl(var(--popover-foreground))",
+ DEFAULT: 'hsl(var(--popover))',
+ foreground: 'hsl(var(--popover-foreground))',
},
card: {
- DEFAULT: "hsl(var(--card))",
- foreground: "hsl(var(--card-foreground))",
+ DEFAULT: 'hsl(var(--card))',
+ foreground: 'hsl(var(--card-foreground))',
},
},
borderRadius: {
- lg: "var(--radius)",
- md: "calc(var(--radius) - 2px)",
- sm: "calc(var(--radius) - 4px)",
+ lg: 'var(--radius)',
+ md: 'calc(var(--radius) - 2px)',
+ sm: 'calc(var(--radius) - 4px)',
},
keyframes: {
- "accordion-down": {
- from: { height: "0" },
- to: { height: "var(--radix-accordion-content-height)" },
+ 'accordion-down': {
+ from: { height: '0' },
+ to: { height: 'var(--radix-accordion-content-height)' },
},
- "accordion-up": {
- from: { height: "var(--radix-accordion-content-height)" },
- to: { height: "0" },
+ 'accordion-up': {
+ from: { height: 'var(--radix-accordion-content-height)' },
+ to: { height: '0' },
},
},
animation: {
- "accordion-down": "accordion-down 0.2s ease-out",
- "accordion-up": "accordion-up 0.2s ease-out",
+ 'accordion-down': 'accordion-down 0.2s ease-out',
+ 'accordion-up': 'accordion-up 0.2s ease-out',
+ },
+ spacing: {
+ 128: '32rem',
+ },
+ width: {
+ 128: '32rem',
+ },
+ height: {
+ 128: '32rem',
},
},
},
- plugins: [require("tailwindcss-animate")],
-}
\ No newline at end of file
+ plugins: [require('tailwindcss-animate')],
+};