Open-source and local-first Slack and Notion alternative that puts you in control of your data
TypeScript chatchat-applicationcrdteditorelectronknowledge-baselocal-firstnotionnotion-alternativerealtime-collaborationself-hostedslacksqliteteam-collaborationwikiyjs
Implement workspace update
Hakan Shehuf4a6e51ea5d7
diff --git a/desktop/package-lock.json b/desktop/package-lock.jsonindex 567c436f..5702f26b 100644--- a/desktop/package-lock.json+++ b/desktop/package-lock.json@@ -21,6 +21,7 @@"@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-tabs": "^1.1.0","@radix-ui/react-toast": "^1.2.1","@radix-ui/react-tooltip": "^1.1.2","@react-oauth/google": "^0.12.1",@@ -2324,6 +2325,36 @@}}},+ "node_modules/@radix-ui/react-tabs": {+ "version": "1.1.0",+ "resolved": "https://registry.npmjs.org/@radix-ui/react-tabs/-/react-tabs-1.1.0.tgz",+ "integrity": "sha512-bZgOKB/LtZIij75FSuPzyEti/XBhJH52ExgtdVqjCIh+Nx/FW+LhnbXtbCzIi34ccyMsyOja8T0thCzoHFXNKA==",+ "license": "MIT",+ "dependencies": {+ "@radix-ui/primitive": "1.1.0",+ "@radix-ui/react-context": "1.1.0",+ "@radix-ui/react-direction": "1.1.0",+ "@radix-ui/react-id": "1.1.0",+ "@radix-ui/react-presence": "1.1.0",+ "@radix-ui/react-primitive": "2.0.0",+ "@radix-ui/react-roving-focus": "1.1.0",+ "@radix-ui/react-use-controllable-state": "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-toast": {"version": "1.2.1","resolved": "https://registry.npmjs.org/@radix-ui/react-toast/-/react-toast-1.2.1.tgz",diff --git a/desktop/package.json b/desktop/package.jsonindex cd0773a9..c93eb5ad 100644--- a/desktop/package.json+++ b/desktop/package.json@@ -62,6 +62,7 @@"@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-tabs": "^1.1.0","@radix-ui/react-toast": "^1.2.1","@radix-ui/react-tooltip": "^1.1.2","@react-oauth/google": "^0.12.1",diff --git a/desktop/src/components/permissions/node-permissions-popover.tsx b/desktop/src/components/permissions/node-permissions-popover.tsxnew file mode 100644index 00000000..86758646--- /dev/null+++ b/desktop/src/components/permissions/node-permissions-popover.tsx@@ -0,0 +1,29 @@+import React from 'react';+import {+ Popover,+ PopoverTrigger,+ PopoverContent,+} from '@/components/ui/popover';+import { Icon } from '@/components/ui/icon';++interface NodePermissionsPopoverProps {+ id: string;+}++export const NodePermissionsPopover = ({ id }: NodePermissionsPopoverProps) => {+ return (+ <Popover>+ <PopoverTrigger asChild>+ <span>+ <Icon+ name="user-add-line"+ className="h-5 w-5 cursor-pointer text-muted-foreground"+ />+ </span>+ </PopoverTrigger>+ <PopoverContent className="mr-2 max-h-128 w-128 overflow-auto">+ <div>Permissions listed here.</div>+ </PopoverContent>+ </Popover>+ );+};diff --git a/desktop/src/components/ui/tabs.tsx b/desktop/src/components/ui/tabs.tsxnew file mode 100644index 00000000..85d83bea--- /dev/null+++ b/desktop/src/components/ui/tabs.tsx@@ -0,0 +1,53 @@+import * as React from "react"+import * as TabsPrimitive from "@radix-ui/react-tabs"++import { cn } from "@/lib/utils"++const Tabs = TabsPrimitive.Root++const TabsList = React.forwardRef<+ React.ElementRef<typeof TabsPrimitive.List>,+ React.ComponentPropsWithoutRef<typeof TabsPrimitive.List>+>(({ className, ...props }, ref) => (+ <TabsPrimitive.List+ ref={ref}+ className={cn(+ "inline-flex h-9 items-center justify-center rounded-lg bg-muted p-1 text-muted-foreground",+ className+ )}+ {...props}+ />+))+TabsList.displayName = TabsPrimitive.List.displayName++const TabsTrigger = React.forwardRef<+ React.ElementRef<typeof TabsPrimitive.Trigger>,+ React.ComponentPropsWithoutRef<typeof TabsPrimitive.Trigger>+>(({ className, ...props }, ref) => (+ <TabsPrimitive.Trigger+ ref={ref}+ className={cn(+ "inline-flex items-center justify-center whitespace-nowrap rounded-md px-3 py-1 text-sm font-medium ring-offset-background transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow",+ className+ )}+ {...props}+ />+))+TabsTrigger.displayName = TabsPrimitive.Trigger.displayName++const TabsContent = React.forwardRef<+ React.ElementRef<typeof TabsPrimitive.Content>,+ React.ComponentPropsWithoutRef<typeof TabsPrimitive.Content>+>(({ className, ...props }, ref) => (+ <TabsPrimitive.Content+ ref={ref}+ className={cn(+ "mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",+ className+ )}+ {...props}+ />+))+TabsContent.displayName = TabsPrimitive.Content.displayName++export { Tabs, TabsList, TabsTrigger, TabsContent }diff --git a/desktop/src/components/workspaces/containers/breadcrumb.tsx b/desktop/src/components/workspaces/containers/breadcrumb.tsxindex 74d793ba..dbe616b3 100644--- a/desktop/src/components/workspaces/containers/breadcrumb.tsx+++ b/desktop/src/components/workspaces/containers/breadcrumb.tsx@@ -43,7 +43,7 @@ export const Breadcrumb = ({ node }: BreadcrumbProps) => {const isClickable = (type: string) => type !== NodeTypes.Space;return (- <BreadcrumbWrapper className="mx-1 flex h-12 justify-between p-2 text-foreground/80">+ <BreadcrumbWrapper><BreadcrumbList>{visibleNodes.map((breadcrumbNode, index) => (<React.Fragment key={breadcrumbNode.id}>diff --git a/desktop/src/components/workspaces/containers/container-header.tsx b/desktop/src/components/workspaces/containers/container-header.tsxindex 3c99870f..6b37b12b 100644--- a/desktop/src/components/workspaces/containers/container-header.tsx+++ b/desktop/src/components/workspaces/containers/container-header.tsx@@ -1,11 +1,17 @@import React from 'react';import { LocalNode } from '@/types/nodes';import { Breadcrumb } from '@/components/workspaces/containers/breadcrumb';+import { NodePermissionsPopover } from '@/components/permissions/node-permissions-popover';interface ContainerHeaderProps {node: LocalNode;}export const ContainerHeader = ({ node }: ContainerHeaderProps) => {- return <Breadcrumb node={node} />;+ return (+ <div className="mx-1 flex h-12 items-center justify-between p-2 pr-4 text-foreground/80">+ <Breadcrumb node={node} />+ <NodePermissionsPopover id={node.id} />+ </div>+ );};diff --git a/desktop/src/components/workspaces/sidebars/sidebar-header.tsx b/desktop/src/components/workspaces/sidebars/sidebar-header.tsxindex 1cf2af01..c532ce4c 100644--- a/desktop/src/components/workspaces/sidebars/sidebar-header.tsx+++ b/desktop/src/components/workspaces/sidebars/sidebar-header.tsx@@ -75,7 +75,12 @@ export const SidebarHeader = () => {<Icon name="add-line" /><span>Create workspace</span></button>- <button className="flex flex-row items-center gap-2 rounded-md p-1 pl-0 text-sm outline-none hover:cursor-pointer hover:bg-gray-100">+ <button+ className="flex flex-row items-center gap-2 rounded-md p-1 pl-0 text-sm outline-none hover:cursor-pointer hover:bg-gray-100"+ onClick={() => {+ workspace.openSettings();+ }}+ ><Icon name="settings-4-line" /><span>Settings</span></button>diff --git a/desktop/src/components/workspaces/workspace-create.tsx b/desktop/src/components/workspaces/workspace-create.tsxindex 3da6fda4..fa90f304 100644--- a/desktop/src/components/workspaces/workspace-create.tsx+++ b/desktop/src/components/workspaces/workspace-create.tsx@@ -17,6 +17,8 @@ import { Textarea } from '@/components/ui/textarea';import { toast } from '@/components/ui/use-toast';import { parseApiError } from '@/lib/axios';import { useWorkspaceCreateMutation } from '@/mutations/use-workspace-create-mutation';+import { useAccount } from '@/contexts/account';+import { useNavigate } from 'react-router-dom';const formSchema = z.object({name: z.string().min(3, 'Name must be at least 3 characters long.'),@@ -26,6 +28,9 @@ const formSchema = z.object({type formSchemaType = z.infer<typeof formSchema>;export const WorkspaceCreate = () => {+ const account = useAccount();+ const navigate = useNavigate();+const { mutate, isPending } = useWorkspaceCreateMutation();const form = useForm<formSchemaType>({resolver: zodResolver(formSchema),@@ -102,6 +107,19 @@ export const WorkspaceCreate = () => {/></div><div className="flex flex-row justify-end gap-2">+ {account.workspaces?.length > 0 && (+ <Button+ type="button"+ disabled={isPending}+ variant="outline"+ onClick={() => {+ navigate('/');+ }}+ >+ Cancel+ </Button>+ )}+<Button type="submit" disabled={isPending}>{isPending && <Spinner className="mr-1" />}Creatediff --git a/desktop/src/components/workspaces/workspace-settings-dialog.tsx b/desktop/src/components/workspaces/workspace-settings-dialog.tsxnew file mode 100644index 00000000..02763251--- /dev/null+++ b/desktop/src/components/workspaces/workspace-settings-dialog.tsx@@ -0,0 +1,91 @@+import React from 'react';+import { Dialog, DialogContent } from '@/components/ui/dialog';+import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs';+import { Icon } from '@/components/ui/icon';+import { Avatar } from '@/components/ui/avatar';+import { useWorkspace } from '@/contexts/workspace';+import { WorkspaceUpdate } from './workspace-update';++interface WorkspaceSettingsDialogProps {+ open: boolean;+ onOpenChange: (open: boolean) => void;+}++export const WorkspaceSettingsDialog = ({+ open,+ onOpenChange,+}: WorkspaceSettingsDialogProps) => {+ const workspace = useWorkspace();++ return (+ <Dialog open={open} onOpenChange={onOpenChange}>+ <DialogContent className="md:min-h-3/4 md:max-h-3/4 p-3 md:h-3/4 md:w-3/4 md:max-w-full">+ <Tabs+ defaultValue="info"+ className="grid h-full max-h-full grid-cols-[240px_minmax(0,1fr)] overflow-hidden"+ >+ <TabsList className="flex h-full max-h-full flex-col items-start justify-start gap-1 rounded-none border-r border-r-gray-100 bg-white pr-3">+ <div className="mb-1 flex h-10 w-full items-center justify-between bg-gray-50 p-1 text-foreground/80">+ <div className="flex items-center gap-2">+ <Avatar+ id={workspace.id}+ name={workspace.name}+ avatar={workspace.avatar}+ size="small"+ />+ <span>{workspace.name}</span>+ </div>+ </div>+ <TabsTrigger+ key={`tab-trigger-info`}+ className="w-full justify-start p-2 hover:bg-gray-50"+ value="info"+ >+ <Icon name="information-line" className="mr-2" />+ Info+ </TabsTrigger>+ <TabsTrigger+ key={`tab-trigger-collaborators`}+ className="w-full justify-start p-2 hover:bg-gray-50"+ value="collaborators"+ >+ <Icon name="group-line" className="mr-2" />+ Collaborators+ </TabsTrigger>+ <TabsTrigger+ key={`tab-trigger-delete`}+ className="w-full justify-start p-2 hover:bg-gray-50"+ value="delete"+ >+ <Icon name="delete-bin-line" className="mr-2" />+ Delete+ </TabsTrigger>+ </TabsList>+ <div className="overflow-auto p-4">+ <TabsContent+ key="tab-content-info"+ className="focus-visible:ring-0 focus-visible:ring-offset-0"+ value="info"+ >+ <WorkspaceUpdate />+ </TabsContent>+ <TabsContent+ key="tab-content-collaborators"+ className="focus-visible:ring-0 focus-visible:ring-offset-0"+ value="collaborators"+ >+ <p>Coming soon.</p>+ </TabsContent>+ <TabsContent+ key="tab-content-delete"+ className="focus-visible:ring-0 focus-visible:ring-offset-0"+ value="delete"+ >+ <p>Coming soon.</p>+ </TabsContent>+ </div>+ </Tabs>+ </DialogContent>+ </Dialog>+ );+};diff --git a/desktop/src/components/workspaces/workspace-update.tsx b/desktop/src/components/workspaces/workspace-update.tsxnew file mode 100644index 00000000..fcad8cb8--- /dev/null+++ b/desktop/src/components/workspaces/workspace-update.tsx@@ -0,0 +1,118 @@+import React from 'react';+import { z } from 'zod';+import {+ Form,+ FormControl,+ FormField,+ FormItem,+ FormMessage,+ FormLabel,+} from '@/components/ui/form';+import { useForm } from 'react-hook-form';+import { zodResolver } from '@hookform/resolvers/zod';+import { Button } from '@/components/ui/button';+import { Spinner } from '@/components/ui/spinner';+import { Input } from '@/components/ui/input';+import { Textarea } from '@/components/ui/textarea';+import { toast } from '@/components/ui/use-toast';+import { parseApiError } from '@/lib/axios';+import { useWorkspaceUpdateMutation } from '@/mutations/use-workspace-update-mutation';+import { useWorkspace } from '@/contexts/workspace';++const formSchema = z.object({+ name: z.string().min(3, 'Name must be at least 3 characters long.'),+ description: z.string(),+});++type formSchemaType = z.infer<typeof formSchema>;++export const WorkspaceUpdate = () => {+ const workspace = useWorkspace();+ const { mutate, isPending } = useWorkspaceUpdateMutation();++ const form = useForm<formSchemaType>({+ resolver: zodResolver(formSchema),+ defaultValues: {+ name: workspace.name,+ description: workspace.description,+ },+ });++ const handleSubmit = async (values: formSchemaType) => {+ mutate(+ {+ id: workspace.id,+ name: values.name,+ description: values.description,+ },+ {+ onSuccess: () => {+ toast({+ title: 'Workspace updated',+ description: 'Workspace was updated successfully',+ variant: 'default',+ });+ },+ onError: (error) => {+ const apiError = parseApiError(error);+ toast({+ title: 'Failed to update workspace',+ description: apiError.message,+ variant: 'destructive',+ });+ },+ },+ );+ };++ return (+ <div className="container flex flex-row justify-center">+ <div className="w-full max-w-[700px]">+ <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>+ )}+ />+ <FormField+ control={form.control}+ name="description"+ render={({ field }) => (+ <FormItem>+ <FormLabel>Description</FormLabel>+ <FormControl>+ <Textarea+ placeholder="Write a short description about the workspace"+ {...field}+ />+ </FormControl>+ <FormMessage />+ </FormItem>+ )}+ />+ </div>+ <div className="flex flex-row justify-end gap-2">+ <Button type="submit" disabled={isPending}>+ {isPending && <Spinner className="mr-1" />}+ Save+ </Button>+ </div>+ </form>+ </Form>+ </div>+ </div>+ );+};diff --git a/desktop/src/components/workspaces/workspace.tsx b/desktop/src/components/workspaces/workspace.tsxindex 14f85290..2daeb3c8 100644--- a/desktop/src/components/workspaces/workspace.tsx+++ b/desktop/src/components/workspaces/workspace.tsx@@ -19,6 +19,7 @@ import { useAccount } from '@/contexts/account';import { QueryClient, QueryClientProvider } from '@tanstack/react-query';import { useEventBus } from '@/hooks/use-event-bus';import { Modal } from '@/components/workspaces/modals/modal';+import { WorkspaceSettingsDialog } from '@/components/workspaces/workspace-settings-dialog';const workspaceDatabase = new Kysely<WorkspaceDatabaseSchema>({dialect: {@@ -31,9 +32,11 @@ const workspaceDatabase = new Kysely<WorkspaceDatabaseSchema>({export const Workspace = () => {const { workspaceId } = useParams<{ workspaceId: string }>();+const account = useAccount();const navigate = useNavigate();const [searchParams, setSearchParams] = useSearchParams();+ const [openSettings, setOpenSettings] = React.useState(false);const eventBus = useEventBus();const workspace = account.workspaces.find((w) => w.id === workspaceId);@@ -161,6 +164,9 @@ export const Workspace = () => {};});},+ openSettings() {+ setOpenSettings(true);+ },}}><div className="flex h-screen max-h-screen flex-row">@@ -183,6 +189,12 @@ export const Workspace = () => {/>)}</div>+ {openSettings && (+ <WorkspaceSettingsDialog+ open={openSettings}+ onOpenChange={setOpenSettings}+ />+ )}</WorkspaceContext.Provider></QueryClientProvider>);diff --git a/desktop/src/contexts/workspace.ts b/desktop/src/contexts/workspace.tsindex 91c5fcce..3f84bc9b 100644--- a/desktop/src/contexts/workspace.ts+++ b/desktop/src/contexts/workspace.ts@@ -13,6 +13,7 @@ interface WorkspaceContext extends Workspace {) => Promise<QueryResult<R>>;navigateToNode: (nodeId: string) => void;openModal: (nodeId: string) => void;+ openSettings: () => void;}export const WorkspaceContext = createContext<WorkspaceContext>(diff --git a/desktop/src/electron/account-manager.ts b/desktop/src/electron/account-manager.tsindex bd926e34..93e628c6 100644--- a/desktop/src/electron/account-manager.ts+++ b/desktop/src/electron/account-manager.ts@@ -68,8 +68,6 @@ export class AccountManager {for (const workspace of this.workspaces.values()) {await workspace.init();}-- this.socket.init();}public getWorkspace(workspaceId: string): WorkspaceManager | undefined {diff --git a/desktop/src/mutations/use-workspace-update-mutation.tsx b/desktop/src/mutations/use-workspace-update-mutation.tsxnew file mode 100644index 00000000..af120032--- /dev/null+++ b/desktop/src/mutations/use-workspace-update-mutation.tsx@@ -0,0 +1,36 @@+import { useAppDatabase } from '@/contexts/app-database';+import { useAxios } from '@/contexts/axios';+import { Workspace } from '@/types/workspaces';+import { useMutation } from '@tanstack/react-query';++interface UpdateWorkspaceInput {+ id: string;+ name: string;+ description: string;+}++export const useWorkspaceUpdateMutation = () => {+ const appDatabase = useAppDatabase();+ const axios = useAxios();++ return useMutation({+ mutationFn: async (input: UpdateWorkspaceInput) => {+ const { data } = await axios.put<Workspace>(`v1/workspaces/${input.id}`, {+ name: input.name,+ description: input.description,+ });+ const updateWorkspaceQuery = appDatabase.database+ .updateTable('workspaces')+ .set({+ name: data.name,+ description: data.description,+ avatar: data.avatar,+ role: data.role,+ version_id: data.versionId,+ })+ .compile();++ await appDatabase.mutate(updateWorkspaceQuery);+ },+ });+};diff --git a/server/src/routes/workspaces.ts b/server/src/routes/workspaces.tsindex 8b85547f..9f31cd27 100644--- a/server/src/routes/workspaces.ts+++ b/server/src/routes/workspaces.ts@@ -207,6 +207,8 @@ workspacesRouter.put(.updateTable('workspaces').set({name: input.name,+ description: input.description,+ avatar: input.avatar,updated_at: new Date(),updated_by: req.accountId,})