From 910e4e1678bc268890627eb8449a482473dcd615 Mon Sep 17 00:00:00 2001 From: Steven Date: Tue, 28 Feb 2023 07:03:37 +0800 Subject: [PATCH] feat: add title field to workspace --- api/workspace.go | 3 ++ store/db/migration/dev/LATEST__SCHEMA.sql | 1 + store/db/seed/10002__workspace.sql | 22 ++++++----- store/workspace.go | 15 ++++++- web/src/components/CreateWorkspaceDialog.tsx | 41 ++++++++++++++------ web/src/components/Header.tsx | 2 +- web/src/components/WorkspaceSetting.tsx | 5 ++- web/src/types/modules/workspace.d.ts | 3 ++ 8 files changed, 67 insertions(+), 25 deletions(-) diff --git a/api/workspace.go b/api/workspace.go index 732a5d3..a1f6602 100644 --- a/api/workspace.go +++ b/api/workspace.go @@ -11,6 +11,7 @@ type Workspace struct { // Domain specific fields Name string `json:"name"` + Title string `json:"title"` Description string `json:"description"` // Related fields @@ -21,6 +22,7 @@ type WorkspaceCreate struct { CreatorID int Name string `json:"name"` + Title string `json:"title"` Description string `json:"description"` } @@ -32,6 +34,7 @@ type WorkspacePatch struct { // Domain specific fields Name *string `json:"name"` + Title *string `json:"title"` Description *string `json:"description"` } diff --git a/store/db/migration/dev/LATEST__SCHEMA.sql b/store/db/migration/dev/LATEST__SCHEMA.sql index 1eb9227..3353a70 100644 --- a/store/db/migration/dev/LATEST__SCHEMA.sql +++ b/store/db/migration/dev/LATEST__SCHEMA.sql @@ -37,6 +37,7 @@ CREATE TABLE workspace ( updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')), row_status TEXT NOT NULL CHECK (row_status IN ('NORMAL', 'ARCHIVED')) DEFAULT 'NORMAL', name TEXT NOT NULL UNIQUE, + title TEXT NOT NULL, description TEXT NOT NULL DEFAULT '' ); diff --git a/store/db/seed/10002__workspace.sql b/store/db/seed/10002__workspace.sql index 1df73a6..3583f0f 100644 --- a/store/db/seed/10002__workspace.sql +++ b/store/db/seed/10002__workspace.sql @@ -1,29 +1,33 @@ -INSERT INTO +INSERT INTO workspace ( - `id`, + `id`, `creator_id`, - `name`, + `name`, + `title`, `description` ) VALUES ( - 11, + 11, 101, 'minecraft', + 'minecraft', '' ); -INSERT INTO +INSERT INTO workspace ( - `id`, + `id`, `creator_id`, - `name`, + `name`, + `title`, `description` ) VALUES ( - 12, + 12, 102, + 'bob', 'bob-room', '' - ); + ); \ No newline at end of file diff --git a/store/workspace.go b/store/workspace.go index b691070..d273723 100644 --- a/store/workspace.go +++ b/store/workspace.go @@ -22,6 +22,7 @@ type workspaceRaw struct { // Domain specific fields Name string + Title string Description string } @@ -35,6 +36,7 @@ func (raw *workspaceRaw) toWorkspace() *api.Workspace { RowStatus: raw.RowStatus, Name: raw.Name, + Title: raw.Title, Description: raw.Description, WorkspaceUserList: []*api.WorkspaceUser{}, } @@ -174,15 +176,17 @@ func createWorkspace(ctx context.Context, tx *sql.Tx, create *api.WorkspaceCreat INSERT INTO workspace ( creator_id, name, + title, description ) VALUES (?, ?, ?) - RETURNING id, creator_id, created_ts, updated_ts, row_status, name, description + RETURNING id, creator_id, created_ts, updated_ts, row_status, name, title, description ` var workspaceRaw workspaceRaw if err := tx.QueryRowContext(ctx, query, create.CreatorID, create.Name, + create.Title, create.Description, ).Scan( &workspaceRaw.ID, @@ -191,6 +195,7 @@ func createWorkspace(ctx context.Context, tx *sql.Tx, create *api.WorkspaceCreat &workspaceRaw.UpdatedTs, &workspaceRaw.RowStatus, &workspaceRaw.Name, + &workspaceRaw.Title, &workspaceRaw.Description, ); err != nil { return nil, FormatError(err) @@ -208,6 +213,9 @@ func patchWorkspace(ctx context.Context, tx *sql.Tx, patch *api.WorkspacePatch) if v := patch.Name; v != nil { set, args = append(set, "name = ?"), append(args, *v) } + if v := patch.Title; v != nil { + set, args = append(set, "title = ?"), append(args, *v) + } if v := patch.Description; v != nil { set, args = append(set, "description = ?"), append(args, *v) } @@ -218,7 +226,7 @@ func patchWorkspace(ctx context.Context, tx *sql.Tx, patch *api.WorkspacePatch) UPDATE workspace SET ` + strings.Join(set, ", ") + ` WHERE id = ? - RETURNING id, creator_id, created_ts, updated_ts, row_status, name, description + RETURNING id, creator_id, created_ts, updated_ts, row_status, name, title, description ` row, err := tx.QueryContext(ctx, query, args...) if err != nil { @@ -235,6 +243,7 @@ func patchWorkspace(ctx context.Context, tx *sql.Tx, patch *api.WorkspacePatch) &workspaceRaw.UpdatedTs, &workspaceRaw.RowStatus, &workspaceRaw.Name, + &workspaceRaw.Title, &workspaceRaw.Description, ); err != nil { return nil, FormatError(err) @@ -274,6 +283,7 @@ func findWorkspaceList(ctx context.Context, tx *sql.Tx, find *api.WorkspaceFind) updated_ts, row_status, name, + title, description FROM workspace WHERE ` + strings.Join(where, " AND ") + ` @@ -295,6 +305,7 @@ func findWorkspaceList(ctx context.Context, tx *sql.Tx, find *api.WorkspaceFind) &workspaceRaw.UpdatedTs, &workspaceRaw.RowStatus, &workspaceRaw.Name, + &workspaceRaw.Title, &workspaceRaw.Description, ); err != nil { return nil, FormatError(err) diff --git a/web/src/components/CreateWorkspaceDialog.tsx b/web/src/components/CreateWorkspaceDialog.tsx index d275674..25b0d11 100644 --- a/web/src/components/CreateWorkspaceDialog.tsx +++ b/web/src/components/CreateWorkspaceDialog.tsx @@ -20,6 +20,7 @@ const CreateWorkspaceDialog: React.FC = (props: Props) => { const [state, setState] = useState({ workspaceCreate: { name: "", + title: "", description: "", }, }); @@ -33,6 +34,7 @@ const CreateWorkspaceDialog: React.FC = (props: Props) => { ...state, workspaceCreate: Object.assign(state.workspaceCreate, { name: workspaceTemp.name, + title: workspaceTemp.title, description: workspaceTemp.description, }), }); @@ -51,17 +53,13 @@ const CreateWorkspaceDialog: React.FC = (props: Props) => { }); }; - const handleNameInputChange = (e: React.ChangeEvent) => { - handleInputChange(e, "name"); - }; - - const handleDescriptionInputChange = (e: React.ChangeEvent) => { - handleInputChange(e, "description"); - }; - const handleSaveBtnClick = async () => { if (!state.workspaceCreate.name) { - toastHelper.error("Name is required"); + toastHelper.error("ID is required"); + return; + } + if (!state.workspaceCreate.title) { + toastHelper.error("Title is required"); return; } @@ -102,12 +100,31 @@ const CreateWorkspaceDialog: React.FC = (props: Props) => {
- Name - + + ID * + + handleInputChange(e, "name")} + /> +
+
+ + Name * + + handleInputChange(e, "title")} />
Description - + handleInputChange(e, "description")} + />
} diff --git a/web/src/components/WorkspaceSetting.tsx b/web/src/components/WorkspaceSetting.tsx index 6e1075b..c76c3fa 100644 --- a/web/src/components/WorkspaceSetting.tsx +++ b/web/src/components/WorkspaceSetting.tsx @@ -87,7 +87,10 @@ const WorkspaceSetting: React.FC = (props: Props) => { return ( <>
-

{workspace.name}

+

+ {workspace.title} + ({workspace.name}) +

{workspace.description || "No description."}

diff --git a/web/src/types/modules/workspace.d.ts b/web/src/types/modules/workspace.d.ts index 4adf4a3..5712969 100644 --- a/web/src/types/modules/workspace.d.ts +++ b/web/src/types/modules/workspace.d.ts @@ -9,6 +9,7 @@ interface Workspace { rowStatus: RowStatus; name: string; + title: string; description: string; workspaceUserList: WorkspaceUser[]; @@ -16,6 +17,7 @@ interface Workspace { interface WorkspaceCreate { name: string; + title: string; description: string; } @@ -23,6 +25,7 @@ interface WorkspacePatch { id: WorkspaceId; rowStatus?: RowStatus; name?: string; + title?: string; description?: string; }