Skip to content

Commit

Permalink
--wip-- [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
nichenqin committed Sep 13, 2024
1 parent d55b792 commit 075bc69
Show file tree
Hide file tree
Showing 18 changed files with 168 additions and 2 deletions.
5 changes: 5 additions & 0 deletions apps/frontend/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ type GalleryOption {
field: String
}

type GridOption {
widths: JSON
}

type Invitation {
email: String!
id: ID!
Expand Down Expand Up @@ -204,6 +208,7 @@ type View {
fields: JSON
filter: JSON
gallery: GalleryOption
grid: GridOption
id: ID!
isDefault: Boolean
kanban: KanbanOption
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ query GetTableQuery($tableId: ID!, $viewId: ID) {
aggregate
fields

grid {
widths
}

kanban {
field
}
Expand Down
3 changes: 3 additions & 0 deletions apps/frontend/src/routes/(share)/s/b/[shareId]/+layout.gql
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ query GetShareBaseData($shareId: ID!) {
name
type
isDefault
grid {
widths
}
kanban {
field
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ query GetBaseTableShareData($shareId: ID!, $tableId: ID!) {
isDefault
fields
type
grid {
widths
}
kanban {
field
}
Expand Down
3 changes: 3 additions & 0 deletions apps/frontend/src/routes/(share)/s/v/[shareId]/+layout.gql
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ query GetViewShareData($shareId: ID!) {
option {
showSystemFields
}
grid {
widths
}
kanban {
field
}
Expand Down
6 changes: 6 additions & 0 deletions packages/authz/src/space-member/space-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ export const spaceActions = z.enum([
"table:list",
"table:delete",

"view:create",
"view:update",
"view:read",
"view:list",
"view:delete",

"form:create",
"form:update",
"form:list",
Expand Down
24 changes: 24 additions & 0 deletions packages/authz/src/space-member/space-permission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ export const spacePermission: Record<ISpaceMemberRole, Record<ISpaceAction, bool
"base:read": true,
"base:update": true,

"view:create": true,
"view:update": true,
"view:read": true,
"view:list": true,
"view:delete": true,

"table:create": true,
"table:update": true,
"table:list": true,
Expand Down Expand Up @@ -70,6 +76,12 @@ export const spacePermission: Record<ISpaceMemberRole, Record<ISpaceAction, bool
"table:delete": true,
"table:read": true,

"view:create": true,
"view:update": true,
"view:read": true,
"view:list": true,
"view:delete": true,

"form:create": true,
"form:update": true,
"form:list": true,
Expand Down Expand Up @@ -120,6 +132,12 @@ export const spacePermission: Record<ISpaceMemberRole, Record<ISpaceAction, bool
"form:delete": true,
"form:read": true,

"view:create": false,
"view:update": false,
"view:read": true,
"view:list": true,
"view:delete": false,

"table:create": true,
"table:update": true,
"table:list": true,
Expand Down Expand Up @@ -170,6 +188,12 @@ export const spacePermission: Record<ISpaceMemberRole, Record<ISpaceAction, bool
"table:delete": false,
"table:read": true,

"view:create": false,
"view:update": false,
"view:read": true,
"view:list": true,
"view:delete": false,

"form:create": false,
"form:update": false,
"form:list": true,
Expand Down
2 changes: 2 additions & 0 deletions packages/command-handlers/src/handlers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { DuplicateViewCommandHandler } from "./duplicate-view.command-handler"
import { EnableShareCommandHandler } from "./enable-share.command-handler"
import { ExportViewCommandHandler } from "./export-view.command-handler"
import { InviteCommandHandler } from "./invite.command-handler"
import { SetFieldWidthCommandHandler } from "./set-field-width.command-handler"
import { SetTableFormCommandHandler } from "./set-table-form.command-handler"
import { SetTableRLSCommandHandler } from "./set-table-rls.command-handler"
import { SetViewAggregateCommandHandler } from "./set-view-aggregate.command-handler"
Expand Down Expand Up @@ -102,4 +103,5 @@ export const commandHandlers = [
TriggerRecordButtonCommandHandler,
DeleteFormCommandHandler,
SubmitFormCommandHandler,
SetFieldWidthCommandHandler,
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { SetFieldWidthCommand } from "@undb/commands"
import { commandHandler } from "@undb/cqrs"
import { singleton } from "@undb/di"
import type { ICommandHandler } from "@undb/domain"
import { createLogger } from "@undb/logger"
import { TableIdVo, injectTableRepository, type ITableRepository } from "@undb/table"

@commandHandler(SetFieldWidthCommand)
@singleton()
export class SetFieldWidthCommandHandler implements ICommandHandler<SetFieldWidthCommand, any> {
public readonly logger = createLogger(SetFieldWidthCommandHandler.name)
constructor(
@injectTableRepository()
private readonly repo: ITableRepository,
) {}

async execute(command: SetFieldWidthCommand): Promise<any> {
const table = (await this.repo.findOneById(new TableIdVo(command.tableId))).unwrap()

const spec = table.$setFieldWidth(command)

await this.repo.updateOneById(table, spec)
}
}
1 change: 1 addition & 0 deletions packages/commands/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export * from "./duplicate-view.command"
export * from "./enable-share.command"
export * from "./export-view.command"
export * from "./invite.command"
export * from "./set-field-width.command"
export * from "./set-table-form.command"
export * from "./set-table-rls.command"
export * from "./set-view-aggregate.command"
Expand Down
22 changes: 22 additions & 0 deletions packages/commands/src/set-field-width.command.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Command, type CommandProps } from "@undb/domain"
import { setFieldWidthDTO } from "@undb/table"
import { z } from "@undb/zod"

export const setFieldWidthCommand = setFieldWidthDTO

export type ISetFieldWidthCommand = z.infer<typeof setFieldWidthCommand>

export class SetFieldWidthCommand extends Command {
public readonly tableId: string
public readonly viewId?: string
public readonly field: string
public readonly width: number

constructor(props: CommandProps<ISetFieldWidthCommand>) {
super(props)
this.tableId = props.tableId
this.viewId = props.viewId
this.field = props.field
this.width = props.width
}
}
5 changes: 5 additions & 0 deletions packages/graphql/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ export class Graphql {
showSystemFields: Boolean
}
type GridOption {
widths: JSON
}
type KanbanOption {
field: String
}
Expand All @@ -151,6 +155,7 @@ export class Graphql {
aggregate: JSON
fields: JSON
grid: GridOption
kanban: KanbanOption
gallery: GalleryOption
Expand Down
1 change: 1 addition & 0 deletions packages/table/src/dto/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export * from "./delete-view.dto"
export * from "./duplicate-table-field.dto"
export * from "./duplicate-table.dto"
export * from "./duplicate-view.dto"
export * from "./set-field-width.dto"
export * from "./set-table-form.dto"
export * from "./set-table-rls.dto"
export * from "./set-view-aggregate.dto"
Expand Down
13 changes: 13 additions & 0 deletions packages/table/src/dto/set-field-width.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { z } from "@undb/zod"
import { viewId } from "../modules"
import { fieldId } from "../modules/schema/fields/field-id.vo"
import { tableId } from "../table-id.vo"

export const setFieldWidthDTO = z.object({
tableId: tableId,
viewId: viewId.optional(),
field: fieldId,
width: z.number(),
})

export type ISetFieldWidthDTO = z.infer<typeof setFieldWidthDTO>
14 changes: 14 additions & 0 deletions packages/table/src/methods/set-field-width.method.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { type Option } from "@undb/domain"
import type { ISetFieldWidthDTO } from "../dto"
import type { TableComositeSpecification } from "../specifications"
import type { TableDo } from "../table.do"

export function setFieldWidth(this: TableDo, dto: ISetFieldWidthDTO): Option<TableComositeSpecification> {
const view = this.views.getViewById(dto.viewId)

if (view.type !== "grid") {
throw new Error("View type is not grid")
}

throw new Error("Not implemented")
}
22 changes: 20 additions & 2 deletions packages/table/src/modules/views/view/variants/grid-view.vo.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Option, Some } from "@undb/domain"
import { None, Option, Some } from "@undb/domain"
import { z } from "@undb/zod"
import type { IDuplicateViewDTO } from "../../../../dto"
import { WithNewView, WithView } from "../../../../specifications/table-view.specification"
Expand All @@ -7,29 +7,40 @@ import { AbstractView, baseViewDTO, createBaseViewDTO, updateBaseViewDTO } from

export const GRID_TYPE = "grid" as const

export const gridOption = z.object({
widths: z.record(z.number().positive()),
})

export type IGridOption = z.infer<typeof gridOption>

export const createGridViewDTO = createBaseViewDTO.extend({
type: z.literal(GRID_TYPE),
grid: gridOption.optional(),
})

export type ICreateGridViewDTO = z.infer<typeof createGridViewDTO>

export const gridViewDTO = baseViewDTO.extend({
type: z.literal(GRID_TYPE),
grid: gridOption.optional(),
})

export type IGridViewDTO = z.infer<typeof gridViewDTO>

export const updateGridViewDTO = updateBaseViewDTO.merge(
z.object({
type: z.literal(GRID_TYPE),
grid: gridOption.optional(),
}),
)

export type IUpdateGridViewDTO = z.infer<typeof updateGridViewDTO>

export class GridView extends AbstractView {
grid: Option<IGridOption> = None
constructor(dto: IGridViewDTO) {
super(dto)
this.grid = Option(dto.grid)
}

static create(dto: ICreateGridViewDTO) {
Expand All @@ -40,7 +51,13 @@ export class GridView extends AbstractView {

override $update(input: IUpdateGridViewDTO): Option<WithView> {
const json = this.toJSON()
const view = new GridView({ ...json, name: input.name, id: this.id.value, type: GRID_TYPE })
const view = new GridView({
...json,
name: input.name,
id: this.id.value,
type: GRID_TYPE,
grid: input.grid ?? this.grid.into(undefined),
})

return Some(new WithView(this, view))
}
Expand All @@ -56,6 +73,7 @@ export class GridView extends AbstractView {
isDefault: false,
id: ViewIdVo.create().value,
type: GRID_TYPE,
grid: this.grid.into(undefined),
}),
),
)
Expand Down
2 changes: 2 additions & 0 deletions packages/table/src/table.do.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { deleteViewMethod } from "./methods/delete-view.method"
import { duplicateFieldMethod } from "./methods/duplicate-field.method"
import { duplicateTableMethod } from "./methods/duplicate-table.method"
import { duplicateViewMethod } from "./methods/duplicate-view.method"
import { setFieldWidth } from "./methods/set-field-width.method"
import { setTableForm } from "./methods/set-table-form.method"
import { setTableRLS } from "./methods/set-table-rls.method"
import { setViewAggregate } from "./methods/set-view-aggregate.method"
Expand Down Expand Up @@ -55,6 +56,7 @@ export class TableDo extends AggregateRoot<ITableEvents> {
$update = updateTable
$duplicate = duplicateTableMethod
$updateView = updateView
$setFieldWidth = setFieldWidth
$setViewFilter = setViewFilter
$setViewOption = setViewOption
$setViewColor = setViewColor
Expand Down
Loading

0 comments on commit 075bc69

Please sign in to comment.