mirror of
https://github.com/aykhans/slash-e.git
synced 2025-04-16 12:23:12 +00:00
feat: add title field to workspace
This commit is contained in:
parent
544bd3555b
commit
910e4e1678
@ -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"`
|
||||
}
|
||||
|
||||
|
@ -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 ''
|
||||
);
|
||||
|
||||
|
@ -3,6 +3,7 @@ INSERT INTO
|
||||
`id`,
|
||||
`creator_id`,
|
||||
`name`,
|
||||
`title`,
|
||||
`description`
|
||||
)
|
||||
VALUES
|
||||
@ -10,6 +11,7 @@ VALUES
|
||||
11,
|
||||
101,
|
||||
'minecraft',
|
||||
'minecraft',
|
||||
''
|
||||
);
|
||||
|
||||
@ -18,12 +20,14 @@ INSERT INTO
|
||||
`id`,
|
||||
`creator_id`,
|
||||
`name`,
|
||||
`title`,
|
||||
`description`
|
||||
)
|
||||
VALUES
|
||||
(
|
||||
12,
|
||||
102,
|
||||
'bob',
|
||||
'bob-room',
|
||||
''
|
||||
);
|
@ -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)
|
||||
|
@ -20,6 +20,7 @@ const CreateWorkspaceDialog: React.FC<Props> = (props: Props) => {
|
||||
const [state, setState] = useState<State>({
|
||||
workspaceCreate: {
|
||||
name: "",
|
||||
title: "",
|
||||
description: "",
|
||||
},
|
||||
});
|
||||
@ -33,6 +34,7 @@ const CreateWorkspaceDialog: React.FC<Props> = (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: Props) => {
|
||||
});
|
||||
};
|
||||
|
||||
const handleNameInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
handleInputChange(e, "name");
|
||||
};
|
||||
|
||||
const handleDescriptionInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
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: Props) => {
|
||||
</div>
|
||||
<div>
|
||||
<div className="w-full flex flex-col justify-start items-start mb-3">
|
||||
<span className="mb-2">Name</span>
|
||||
<Input className="w-full" type="text" value={state.workspaceCreate.name} onChange={handleNameInputChange} />
|
||||
<span className="mb-2">
|
||||
ID <span className="text-red-600">*</span>
|
||||
</span>
|
||||
<Input
|
||||
className="w-full"
|
||||
type="text"
|
||||
placeholder="Workspace ID is an unique identifier for your workspace."
|
||||
value={state.workspaceCreate.name}
|
||||
onChange={(e) => handleInputChange(e, "name")}
|
||||
/>
|
||||
</div>
|
||||
<div className="w-full flex flex-col justify-start items-start mb-3">
|
||||
<span className="mb-2">
|
||||
Name <span className="text-red-600">*</span>
|
||||
</span>
|
||||
<Input className="w-full" type="text" value={state.workspaceCreate.title} onChange={(e) => handleInputChange(e, "title")} />
|
||||
</div>
|
||||
<div className="w-full flex flex-col justify-start items-start mb-3">
|
||||
<span className="mb-2">Description</span>
|
||||
<Input className="w-full" type="text" value={state.workspaceCreate.description} onChange={handleDescriptionInputChange} />
|
||||
<Input
|
||||
className="w-full"
|
||||
type="text"
|
||||
value={state.workspaceCreate.description}
|
||||
onChange={(e) => handleInputChange(e, "description")}
|
||||
/>
|
||||
</div>
|
||||
<div className="w-full flex flex-row justify-end items-center">
|
||||
<Button color="primary" disabled={requestState.isLoading} loading={requestState.isLoading} onClick={handleSaveBtnClick}>
|
||||
|
@ -47,7 +47,7 @@ const Header: React.FC = () => {
|
||||
<Dropdown
|
||||
trigger={
|
||||
<button className="flex flex-row justify-end items-center cursor-pointer">
|
||||
<span className="font-mono">{activedWorkspace?.name}</span>
|
||||
<span className="font-mono">{activedWorkspace?.title}</span>
|
||||
<Icon.ChevronDown className="ml-1 w-5 h-auto text-gray-600" />
|
||||
</button>
|
||||
}
|
||||
|
@ -87,7 +87,10 @@ const WorkspaceSetting: React.FC<Props> = (props: Props) => {
|
||||
return (
|
||||
<>
|
||||
<div className="w-full flex flex-col justify-start items-start">
|
||||
<p className="text-3xl mt-4 mb-4">{workspace.name}</p>
|
||||
<p className="text-3xl mt-4 mb-4">
|
||||
{workspace.title}
|
||||
<span className="text-lg ml-1 font-mono text-gray-400">({workspace.name})</span>
|
||||
</p>
|
||||
<p className="mb-4">{workspace.description || "No description."}</p>
|
||||
<div className="border-t pt-4 flex flex-row justify-start items-center">
|
||||
<div className="flex flex-row justify-start items-center space-x-2">
|
||||
|
3
web/src/types/modules/workspace.d.ts
vendored
3
web/src/types/modules/workspace.d.ts
vendored
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user