From 062808840ac8dc82424f7df7701baeed6d30e97e Mon Sep 17 00:00:00 2001 From: Ricardo Costa Date: Fri, 24 May 2024 15:22:12 +0100 Subject: [PATCH] Fixed Document Management, Added Features --- code/client/src/domain/workspaces/utils.ts | 52 ++++++++++++ .../ui/components/data-table/DataTable.tsx | 40 --------- .../components/data-table/useSortableData.tsx | 35 -------- .../src/ui/components/sidebar/Sidebar.scss | 2 +- .../src/ui/components/table/DataTable.scss | 60 ++++++++++++++ .../src/ui/components/table/DataTable.tsx | 57 +++++++++++++ .../contexts/workspace/WorkspaceContext.tsx | 4 +- .../src/ui/pages/workspace/Workspace.scss | 61 -------------- .../src/ui/pages/workspace/Workspace.tsx | 72 +++++++++++------ .../workspace/components/DocumentView.tsx | 31 ++++--- .../src/ui/pages/workspaces/Workspaces.scss | 81 ------------------- .../src/ui/pages/workspaces/Workspaces.tsx | 69 +++++++++------- .../workspaces/components/WorkspaceView.tsx | 7 +- .../pages/workspaces/hooks/useWorkspaces.ts | 8 +- .../ts/databases/memory/MemoryWorkspacesDB.ts | 4 +- code/server/test/utils/workspaceRequests.ts | 4 +- code/server/test/workspaces/resources.test.ts | 10 +-- code/server/test/workspaces/tree.test.ts | 8 +- .../server/test/workspaces/workspaces.test.ts | 10 +-- 19 files changed, 298 insertions(+), 317 deletions(-) create mode 100644 code/client/src/domain/workspaces/utils.ts delete mode 100644 code/client/src/ui/components/data-table/DataTable.tsx delete mode 100644 code/client/src/ui/components/data-table/useSortableData.tsx create mode 100644 code/client/src/ui/components/table/DataTable.scss create mode 100644 code/client/src/ui/components/table/DataTable.tsx diff --git a/code/client/src/domain/workspaces/utils.ts b/code/client/src/domain/workspaces/utils.ts new file mode 100644 index 00000000..6a87a10f --- /dev/null +++ b/code/client/src/domain/workspaces/utils.ts @@ -0,0 +1,52 @@ +import { WorkspaceMeta } from '@notespace/shared/src/workspace/types/workspace'; +import { DocumentResource, ResourceType } from '@notespace/shared/src/workspace/types/resource'; +import { Resources } from '@ui/contexts/workspace/WorkspaceContext'; + +export function sortWorkspaces(workspaces: WorkspaceMeta[], column: string, ascending: boolean): WorkspaceMeta[] { + return workspaces.sort((a, b) => { + let comparison = 0; + switch (column) { + case 'Name': + comparison = a.name.localeCompare(b.name); + break; + case 'Visibility': + comparison = a.isPrivate === b.isPrivate ? 0 : a.isPrivate ? 1 : -1; + break; + case 'Members': + comparison = a.members.length - b.members.length; + break; + case 'Created': + comparison = new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime(); + break; + default: + break; + } + return ascending ? comparison : -comparison; + }); +} + +export function sortDocuments(documents: DocumentResource[], column: string, ascending: boolean): DocumentResource[] { + return documents.sort((a, b) => { + let comparison = 0; + switch (column) { + case 'Name': + comparison = a.name.localeCompare(b.name); + break; + case 'Created': + comparison = new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime(); + break; + case 'Modified': + comparison = new Date(a.updatedAt).getTime() - new Date(b.updatedAt).getTime(); + break; + default: + break; + } + return ascending ? comparison : -comparison; + }); +} + +export function getDocuments(resources?: Resources): DocumentResource[] { + return Object.values(resources || []).filter( + resource => resource.type === ResourceType.DOCUMENT + ) as DocumentResource[]; +} diff --git a/code/client/src/ui/components/data-table/DataTable.tsx b/code/client/src/ui/components/data-table/DataTable.tsx deleted file mode 100644 index 8e5a2c6a..00000000 --- a/code/client/src/ui/components/data-table/DataTable.tsx +++ /dev/null @@ -1,40 +0,0 @@ -import useSortableData from '@ui/components/data-table/useSortableData'; - -type DataTableProps = { - columns: string[]; - data: string[]; -}; - -function DataTable({ columns, data }: DataTableProps) { - if (!data.length) throw new Error('No data provided'); - - const { items, sort, sortConfig } = useSortableData(data); - return ( - - - - {columns.map(column => ( - - ))} - - - - {items.map((item, index) => ( - - {columns.map(column => ( - - ))} - - ))} - -
sort(column)} - className={sortConfig && sortConfig.key === column ? sortConfig.direction : undefined} - > - {column} -
{item}
- ); -} - -export default DataTable; diff --git a/code/client/src/ui/components/data-table/useSortableData.tsx b/code/client/src/ui/components/data-table/useSortableData.tsx deleted file mode 100644 index c9542b05..00000000 --- a/code/client/src/ui/components/data-table/useSortableData.tsx +++ /dev/null @@ -1,35 +0,0 @@ -import { useState, useMemo } from 'react'; - -type SortConfig = { - key: string; - direction: 'asc' | 'desc'; -}; - -function useSortableData(items: any[], config: SortConfig | null = null) { - const [sortConfig, setSortConfig] = useState(config); - - const sortedItems = useMemo(() => { - const sortableItems = [...items]; - if (sortConfig !== null) { - sortableItems.sort((a, b) => { - if (a[sortConfig.key] < b[sortConfig.key]) { - return sortConfig.direction === 'asc' ? -1 : 1; - } - if (a[sortConfig.key] > b[sortConfig.key]) { - return sortConfig.direction === 'asc' ? 1 : -1; - } - return 0; - }); - } - return sortableItems; - }, [items, sortConfig]); - - const sort = (key: string) => { - const direction = sortConfig && sortConfig.key === key && sortConfig.direction === 'asc' ? 'desc' : 'asc'; - setSortConfig({ key, direction }); - }; - - return { items: sortedItems, sort, sortConfig }; -} - -export default useSortableData; diff --git a/code/client/src/ui/components/sidebar/Sidebar.scss b/code/client/src/ui/components/sidebar/Sidebar.scss index 583b1ae2..776f2af0 100644 --- a/code/client/src/ui/components/sidebar/Sidebar.scss +++ b/code/client/src/ui/components/sidebar/Sidebar.scss @@ -41,7 +41,7 @@ } a { - padding: 0 0 2vh 1vh; + padding-left: 2vh; } } diff --git a/code/client/src/ui/components/table/DataTable.scss b/code/client/src/ui/components/table/DataTable.scss new file mode 100644 index 00000000..7f586b11 --- /dev/null +++ b/code/client/src/ui/components/table/DataTable.scss @@ -0,0 +1,60 @@ +.table { + width: 100%; + display: flex; + flex-direction: row; + justify-content: center; + align-items: start; + + button { + margin: 1vh 0 1vh 1vh; + } + + .table-content { + width: 50%; + position: relative; + + > div:first-child { + background-color: black; + color: white; + } + + .table-header button { + padding: 0; + margin: 0; + } + + .table-row, + .table-header { + display: grid; + grid-template-columns: 50px repeat(4, 1fr); + grid-template-rows: 5vh; + row-gap: 10vh; + grid-gap: 1vh; + margin: 5px; + align-items: center; + justify-content: space-between; + gap: 4vh; + padding: 1vh; + background-color: lightgray; + border-radius: 5px; + transition: background-color 0.2s; + + span { + width: min-content; + } + } + + .table-row:hover { + background-color: rgb(180, 180, 180); + cursor: pointer; + } + + a { + text-decoration: none !important; + } + + svg { + color: white; + } + } +} diff --git a/code/client/src/ui/components/table/DataTable.tsx b/code/client/src/ui/components/table/DataTable.tsx new file mode 100644 index 00000000..cbca30eb --- /dev/null +++ b/code/client/src/ui/components/table/DataTable.tsx @@ -0,0 +1,57 @@ +import { ReactNode, useState } from 'react'; +import { Checkbox } from '@mui/material'; +import { FaSortDown, FaSortUp } from 'react-icons/fa6'; + +type DataTableProps = { + columns: string[]; + selectedAll: boolean; + setSelectedAll: (selected: boolean) => void; + createButton: ReactNode; + deleteButton: ReactNode; + sortRows: (column: string, ascending: boolean) => void; + children: ReactNode; +}; + +function DataTable({ + columns, + createButton, + deleteButton, + setSelectedAll, + selectedAll, + sortRows, + children, +}: DataTableProps) { + const [sortColumn, setSortColumn] = useState(''); + const [ascending, setAscending] = useState(true); + return ( +
+ {selectedAll ? deleteButton : createButton} +
+
+ setSelectedAll(!selectedAll)} /> + {columns.map(column => ( +
+ +
+ ))} +
+ {children} +
+
+ ); +} + +export default DataTable; diff --git a/code/client/src/ui/contexts/workspace/WorkspaceContext.tsx b/code/client/src/ui/contexts/workspace/WorkspaceContext.tsx index ba03ed1a..fee2d34e 100644 --- a/code/client/src/ui/contexts/workspace/WorkspaceContext.tsx +++ b/code/client/src/ui/contexts/workspace/WorkspaceContext.tsx @@ -38,8 +38,8 @@ export function WorkspaceProvider({ children }: { children: React.ReactNode }) { if (!wid) return; async function fetchWorkspace() { - const { id, name, resources } = await services.getWorkspace(wid!); - setWorkspace({ id, name }); + const { resources, ...workspace } = await services.getWorkspace(wid!); + setWorkspace(workspace); setResources(resources); } socket.emit('joinWorkspace', wid); diff --git a/code/client/src/ui/pages/workspace/Workspace.scss b/code/client/src/ui/pages/workspace/Workspace.scss index 6967622c..856214dc 100644 --- a/code/client/src/ui/pages/workspace/Workspace.scss +++ b/code/client/src/ui/pages/workspace/Workspace.scss @@ -1,63 +1,2 @@ .workspace { - display: flex; - flex-direction: column; - align-items: center; - justify-content: center; - padding: 2vh; - - .table { - padding: 1vh; - width: 50%; - position: relative; - - > div:first-child { - background-color: black; - color: white; - } - - .table-row { - display: grid; - grid-template-columns: repeat(3, 1fr); - grid-template-rows: 5vh; - row-gap: 10vh; - grid-gap: 1vh; - margin: 5px; - - align-items: center; - justify-content: space-between; - gap: 4vh; - padding: 1vh; - background-color: lightgray; - border-radius: 5px; - transition: background-color 0.2s; - - div { - display: flex; - align-items: center; - justify-content: center; - } - - :first-child { - text-align: left; - display: flex; - align-items: center; - justify-content: start; - gap: 1vh; - padding-left: 2vh; - } - } - - .document:hover { - background-color: rgb(180, 180, 180); - cursor: pointer; - } - - .document-checkbox { - position: absolute; - } - - a { - text-decoration: none !important; - } - } } diff --git a/code/client/src/ui/pages/workspace/Workspace.tsx b/code/client/src/ui/pages/workspace/Workspace.tsx index 483d0257..7de46f72 100644 --- a/code/client/src/ui/pages/workspace/Workspace.tsx +++ b/code/client/src/ui/pages/workspace/Workspace.tsx @@ -1,37 +1,63 @@ -import { DocumentResource, ResourceType } from '@notespace/shared/src/workspace/types/resource'; +import { ResourceType } from '@notespace/shared/src/workspace/types/resource'; import DocumentView from '@ui/pages/workspace/components/DocumentView'; import useError from '@ui/contexts/error/useError'; import useWorkspace from '@ui/contexts/workspace/useWorkspace'; import './Workspace.scss'; +import { useEffect, useState } from 'react'; +import DataTable from '@ui/components/table/DataTable'; +import { FaPlus } from 'react-icons/fa'; +import { MdDelete } from 'react-icons/md'; +import { getDocuments, sortDocuments } from '@domain/workspaces/utils'; +import '../../components/table/DataTable.scss'; function Workspace() { const { workspace, resources, operations } = useWorkspace(); const { publishError } = useError(); + const [selectedAll, setSelectedAll] = useState(false); + const [rows, setRows] = useState(getDocuments(resources)); + + useEffect(() => { + setRows(getDocuments(resources)); + }, [resources]); return (
-

{workspace?.name}

- -
-
-

Name

-

Created

-

Modified

-
- {Object.values(resources || []) - .filter(resource => resource.type === ResourceType.DOCUMENT) - .map(resource => ( - operations?.deleteResource(resource.id).catch(publishError)} - onDuplicate={() => - operations?.createResource(resource.name + '-copy', ResourceType.DOCUMENT).catch(publishError) - } - onRename={name => operations?.updateResource(resource.id, { name }).catch(publishError)} - /> - ))} -
+

Documents in {workspace?.name}

+ operations?.createResource('Untitled', ResourceType.DOCUMENT).catch(publishError)}> + + + } + deleteButton={ + + } + sortRows={(column, ascending) => { + setRows(() => sortDocuments([...rows], column, ascending)); + }} + > + {rows.map(document => ( + operations?.deleteResource(document.id).catch(publishError)} + onDuplicate={() => + operations?.createResource(document.name + '-copy', ResourceType.DOCUMENT).catch(publishError) + } + onRename={name => operations?.updateResource(document.id, { name }).catch(publishError)} + /> + ))} +
); } diff --git a/code/client/src/ui/pages/workspace/components/DocumentView.tsx b/code/client/src/ui/pages/workspace/components/DocumentView.tsx index aff8b8a5..1e712190 100644 --- a/code/client/src/ui/pages/workspace/components/DocumentView.tsx +++ b/code/client/src/ui/pages/workspace/components/DocumentView.tsx @@ -1,40 +1,39 @@ import { Link, useParams } from 'react-router-dom'; -import { FaFile } from 'react-icons/fa6'; import DocumentContextMenu from '@ui/pages/workspace/components/DocumentContextMenu'; import useEditing from '@ui/hooks/useEditing'; import { DocumentResource } from '@notespace/shared/src/workspace/types/resource'; import { Checkbox } from '@mui/material'; -import React from 'react'; +import '../../../components/table/DataTable.scss'; +import { formatDate } from '@/utils/utils'; +import { useEffect, useState } from 'react'; type DocumentViewProps = { document: DocumentResource; + selected: boolean; onDelete: () => void; onDuplicate: () => void; onRename: (title: string) => void; }; -function DocumentView({ document, onDelete, onRename, onDuplicate }: DocumentViewProps) { +function DocumentView({ document, onDelete, onRename, onDuplicate, selected }: DocumentViewProps) { const { wid } = useParams(); const { component, isEditing, setIsEditing } = useEditing(document.name || 'Untitled', onRename); + const [isSelected, setSelected] = useState(selected); + + useEffect(() => { + setSelected(selected); + }, [selected]); + const DocumentComponent = (
-
- - {component} -
-

{document.createdAt}

-

{document.updatedAt}

+ setSelected(!isSelected)} onClick={e => e.stopPropagation()} /> + {component} +

{formatDate(document.createdAt)}

+

{formatDate(document.updatedAt)}

); return ( setIsEditing(true)} onDuplicate={onDuplicate} onDelete={onDelete}> - { - e.stopPropagation(); - }} - /> {isEditing ? DocumentComponent : {DocumentComponent}} ); diff --git a/code/client/src/ui/pages/workspaces/Workspaces.scss b/code/client/src/ui/pages/workspaces/Workspaces.scss index 52e1f1dc..eb9072e7 100644 --- a/code/client/src/ui/pages/workspaces/Workspaces.scss +++ b/code/client/src/ui/pages/workspaces/Workspaces.scss @@ -1,83 +1,2 @@ .workspaces { - .container { - width: 100%; - display: flex; - flex-direction: row; - justify-content: center; - align-items: start; - - .actions { - display: flex; - flex-direction: row; - justify-content: left; - align-items: center; - gap: 2vh; - width: 100%; - border-radius: 5px; - padding: 1vh; - } - - button { - margin: 1vh 0 1vh 1vh; - } - } - - .table { - width: 50%; - position: relative; - - svg { - color: white; - } - - > div:first-child { - background-color: black; - color: white; - } - - .table-row { - display: grid; - grid-template-columns: 50px repeat(4, 1fr); - grid-template-rows: 5vh; - row-gap: 10vh; - grid-gap: 1vh; - margin: 5px; - - align-items: center; - justify-content: space-between; - gap: 4vh; - padding: 1vh; - background-color: lightgray; - border-radius: 5px; - transition: background-color 0.2s; - - div { - display: flex; - align-items: center; - justify-content: center; - } - - :first-child { - text-align: left; - display: flex; - align-items: center; - justify-content: start; - gap: 1vh; - padding-left: 2vh; - } - - span { - width: min-content; - } - } - - .workspace:hover { - background-color: rgb(180, 180, 180); - cursor: pointer; - } - - a { - text-decoration: none !important; - } - } } diff --git a/code/client/src/ui/pages/workspaces/Workspaces.tsx b/code/client/src/ui/pages/workspaces/Workspaces.tsx index a4de814f..ae02b2c9 100644 --- a/code/client/src/ui/pages/workspaces/Workspaces.tsx +++ b/code/client/src/ui/pages/workspaces/Workspaces.tsx @@ -2,49 +2,56 @@ import useWorkspaces from '@ui/pages/workspaces/hooks/useWorkspaces'; import WorkspaceView from '@ui/pages/workspaces/components/WorkspaceView'; import CreateWorkspaceDialog from '@ui/pages/workspaces/components/CreateWorkspaceDialog'; import useError from '@ui/contexts/error/useError'; +import DataTable from '@ui/components/table/DataTable'; import { MdDelete } from 'react-icons/md'; -import { useState } from 'react'; -import { Checkbox } from '@mui/material'; +import { useEffect, useState } from 'react'; +import { sortWorkspaces } from '@domain/workspaces/utils'; import './Workspaces.scss'; function Workspaces() { - const { workspaces, createWorkspace, updateWorkspace, deleteWorkspace } = useWorkspaces(); + const { workspaces, operations } = useWorkspaces(); const { publishError } = useError(); const [selectedAll, setSelectedAll] = useState(false); + const [rows, setRows] = useState(workspaces); + + useEffect(() => { + setRows(workspaces); + }, [workspaces]); return (

Workspaces

- -
- {selectedAll ? ( - - ) : ( - createWorkspace(workspace).catch(publishError)} /> - )} -
-
- setSelectedAll(!selectedAll)} /> -

Name

-

Members

-

Created

-

Visibility

-
- - {workspaces.map(workspace => ( - deleteWorkspace(workspace.id).catch(publishError)} - onRename={name => updateWorkspace(workspace.id, { ...workspace, name }).catch(publishError)} - onInvite={() => {}} - /> - ))} -
-
+ } + selectedAll={selectedAll} + setSelectedAll={setSelectedAll} + sortRows={(column, ascending) => { + setRows(() => sortWorkspaces([...rows], column, ascending)); + }} + > + {rows.map(workspace => ( + operations.deleteWorkspace(workspace.id).catch(publishError)} + onRename={name => operations.updateWorkspace(workspace.id, { ...workspace, name }).catch(publishError)} + onInvite={() => {}} + /> + ))} +
); } diff --git a/code/client/src/ui/pages/workspaces/components/WorkspaceView.tsx b/code/client/src/ui/pages/workspaces/components/WorkspaceView.tsx index 36fe5a5e..7ac22757 100644 --- a/code/client/src/ui/pages/workspaces/components/WorkspaceView.tsx +++ b/code/client/src/ui/pages/workspaces/components/WorkspaceView.tsx @@ -24,12 +24,7 @@ function WorkspaceView({ workspace, selected, onDelete, onRename, onInvite }: Wo const WorkspaceComponent = (
- setSelected(!isSelected)} - onClick={e => e.stopPropagation()} - /> + setSelected(!isSelected)} onClick={e => e.stopPropagation()} /> {component}

{workspace.members.length}

{formatDate(workspace.createdAt)}

diff --git a/code/client/src/ui/pages/workspaces/hooks/useWorkspaces.ts b/code/client/src/ui/pages/workspaces/hooks/useWorkspaces.ts index 351ff4e0..0bcae923 100644 --- a/code/client/src/ui/pages/workspaces/hooks/useWorkspaces.ts +++ b/code/client/src/ui/pages/workspaces/hooks/useWorkspaces.ts @@ -51,9 +51,11 @@ function useWorkspaces() { return { workspaces, - createWorkspace, - deleteWorkspace, - updateWorkspace, + operations: { + createWorkspace, + deleteWorkspace, + updateWorkspace, + }, }; } diff --git a/code/server/src/ts/databases/memory/MemoryWorkspacesDB.ts b/code/server/src/ts/databases/memory/MemoryWorkspacesDB.ts index 29a51c26..9c91d8f4 100644 --- a/code/server/src/ts/databases/memory/MemoryWorkspacesDB.ts +++ b/code/server/src/ts/databases/memory/MemoryWorkspacesDB.ts @@ -7,8 +7,8 @@ export class MemoryWorkspacesDB implements WorkspacesRepository { memoryDB.reset(); } - async createWorkspace(name: string): Promise { - return memoryDB.createWorkspace(name); + async createWorkspace(name: string, isPrivate: boolean): Promise { + return memoryDB.createWorkspace(name, isPrivate); } async getWorkspaces(): Promise { return memoryDB.getWorkspaces(); diff --git a/code/server/test/utils/workspaceRequests.ts b/code/server/test/utils/workspaceRequests.ts index e007fa3e..011961be 100644 --- a/code/server/test/utils/workspaceRequests.ts +++ b/code/server/test/utils/workspaceRequests.ts @@ -3,8 +3,8 @@ import request = require('supertest'); import { WorkspaceMeta } from '@notespace/shared/src/workspace/types/workspace'; export function workspaceRequests(app: Express) { - async function createWorkspace(name: string): Promise { - const response = await request(app).post('/workspaces').send({ name }); + async function createWorkspace(name: string, isPrivate: boolean = false): Promise { + const response = await request(app).post('/workspaces').send({ name, isPrivate }); expect(response.status).toBe(201); return response.body.id; } diff --git a/code/server/test/workspaces/resources.test.ts b/code/server/test/workspaces/resources.test.ts index 7dd638d5..a787a9f4 100644 --- a/code/server/test/workspaces/resources.test.ts +++ b/code/server/test/workspaces/resources.test.ts @@ -10,7 +10,7 @@ beforeEach(() => { describe('Resource operations', () => { test('should create a resource', async () => { - const wid = await services.workspace.createWorkspace('test'); + const wid = await services.workspace.createWorkspace('test', false); const id = await services.resources.createResource(wid, 'testDoc', ResourceType.DOCUMENT); const resource = await services.resources.getResource(wid, id); expect(resource.name).toEqual('testDoc'); @@ -18,7 +18,7 @@ describe('Resource operations', () => { }); test('should delete a resource', async () => { - const wid = await services.workspace.createWorkspace('test'); + const wid = await services.workspace.createWorkspace('test', false); const id = await services.resources.createResource(wid, 'testDoc', ResourceType.DOCUMENT); await services.resources.deleteResource(id); const resources = (await services.resources.getResources(wid)) as Resource[]; @@ -26,7 +26,7 @@ describe('Resource operations', () => { }); test('should update a resource', async () => { - const wid = await services.workspace.createWorkspace('test'); + const wid = await services.workspace.createWorkspace('test', false); const id = await services.resources.createResource(wid, 'testDoc', ResourceType.DOCUMENT); await services.resources.updateResource(id, { name: 'testDoc2' }); const resource = await services.resources.getResource(wid, id); @@ -34,7 +34,7 @@ describe('Resource operations', () => { }); test('should get all resources', async () => { - const wid = await services.workspace.createWorkspace('test'); + const wid = await services.workspace.createWorkspace('test', false); await services.resources.createResource(wid, 'testDoc', ResourceType.DOCUMENT); await services.resources.createResource(wid, 'testDoc2', ResourceType.DOCUMENT); const resources = (await services.resources.getResources(wid)) as Resource[]; @@ -42,7 +42,7 @@ describe('Resource operations', () => { }); test('should get all resources of a type', async () => { - const wid = await services.workspace.createWorkspace('test'); + const wid = await services.workspace.createWorkspace('test', false); await services.resources.createResource(wid, 'testDoc', ResourceType.DOCUMENT); await services.resources.createResource(wid, 'testFolder', ResourceType.FOLDER); const resources = (await services.resources.getResources(wid, ResourceType.DOCUMENT)) as Resource[]; diff --git a/code/server/test/workspaces/tree.test.ts b/code/server/test/workspaces/tree.test.ts index 921d0fb0..d99a70a6 100644 --- a/code/server/test/workspaces/tree.test.ts +++ b/code/server/test/workspaces/tree.test.ts @@ -10,13 +10,13 @@ beforeEach(() => { describe('Workspace tree operations', () => { test('should return an empty tree', async () => { - const id = await services.workspace.createWorkspace('test'); + const id = await services.workspace.createWorkspace('test', false); const resources = await services.resources.getResources(id); expect(resources.length).toBe(1); }); test('should return a tree with one document', async () => { - const id = await services.workspace.createWorkspace('test'); + const id = await services.workspace.createWorkspace('test', false); const docId = await services.resources.createResource(id, 'testDoc', ResourceType.DOCUMENT); const resources = (await services.resources.getResources(id)).filter(r => r.id != id); expect(resources.length).toBe(1); @@ -25,7 +25,7 @@ describe('Workspace tree operations', () => { }); test('should return a tree with one document inside a folder', async () => { - const id = await services.workspace.createWorkspace('test'); + const id = await services.workspace.createWorkspace('test', false); const folderId = await services.resources.createResource(id, 'testFolder', ResourceType.FOLDER); const docId = await services.resources.createResource(id, 'testDoc', ResourceType.DOCUMENT, folderId); const resources = (await services.resources.getResources(id)).filter(r => r.id != id); @@ -40,7 +40,7 @@ describe('Workspace tree operations', () => { }); test('should return a tree with one document inside a folder inside a folder', async () => { - const id = await services.workspace.createWorkspace('test'); + const id = await services.workspace.createWorkspace('test', false); const folderId1 = await services.resources.createResource(id, 'testFolder1', ResourceType.FOLDER); const folderId2 = await services.resources.createResource(id, 'testFolder2', ResourceType.FOLDER, folderId1); const docId = await services.resources.createResource(id, 'testDoc', ResourceType.DOCUMENT, folderId2); diff --git a/code/server/test/workspaces/workspaces.test.ts b/code/server/test/workspaces/workspaces.test.ts index 8ebe21c7..bf3b7cfc 100644 --- a/code/server/test/workspaces/workspaces.test.ts +++ b/code/server/test/workspaces/workspaces.test.ts @@ -9,29 +9,29 @@ beforeEach(() => { describe('Workspace operations', () => { test('should create a workspace', async () => { - const id = await services.workspace.createWorkspace('test'); + const id = await services.workspace.createWorkspace('test', false); const workspace = await services.workspace.getWorkspace(id); expect(workspace.name).toEqual('test'); expect(workspace.id).toEqual(id); }); test('should delete a workspace', async () => { - const id = await services.workspace.createWorkspace('test'); + const id = await services.workspace.createWorkspace('test', false); await services.workspace.deleteWorkspace(id); const workspaces = await services.workspace.getWorkspaces(); expect(workspaces).toEqual([]); }); test('should update a workspace', async () => { - const id = await services.workspace.createWorkspace('test'); + const id = await services.workspace.createWorkspace('test', false); await services.workspace.updateWorkspace(id, 'test2'); const workspace = await services.workspace.getWorkspace(id); expect(workspace.name).toEqual('test2'); }); test('should get all workspaces', async () => { - await services.workspace.createWorkspace('test'); - await services.workspace.createWorkspace('test2'); + await services.workspace.createWorkspace('test', false); + await services.workspace.createWorkspace('test2', false); const workspaces = await services.workspace.getWorkspaces(); expect(workspaces.length).toEqual(2); });