-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): add field order & setup web column dnd
- Loading branch information
Chenqin Nee
authored and
Chenqin Nee
committed
Dec 19, 2022
1 parent
6dd9496
commit e8c04e2
Showing
19 changed files
with
179 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
import React from 'react' | ||
import type { THeaderGroup } from './interface' | ||
import { Th } from './th' | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
packages/core/specifications/table-view-fields-order.specification.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { CompositeSpecification } from '@egodb/domain' | ||
import type { Result } from 'oxide.ts' | ||
import { Ok } from 'oxide.ts' | ||
import type { ITableSpecVisitor } from '.' | ||
import type { Table } from '../table' | ||
import type { ViewFieldsOrder } from '../view' | ||
|
||
export class WithViewFieldsOrder extends CompositeSpecification<Table, ITableSpecVisitor> { | ||
constructor(public readonly viewName: string, public readonly viewFieldsOrder: ViewFieldsOrder) { | ||
super() | ||
} | ||
|
||
isSatisfiedBy(t: Table): boolean { | ||
return this.viewFieldsOrder.equals(t.getOrCreateDefaultView(this.viewName).fieldsOrder) | ||
} | ||
|
||
mutate(t: Table): Result<Table, string> { | ||
t.getOrCreateDefaultView(this.viewName).fieldsOrder = this.viewFieldsOrder | ||
return Ok(t) | ||
} | ||
|
||
accept(v: ITableSpecVisitor): Result<void, string> { | ||
v.fieldsOrder(this) | ||
return Ok(undefined) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { ViewFieldsOrder } from '.' | ||
|
||
describe('ViewFieldsOrder', () => { | ||
test('#move()', () => { | ||
const origin = new ViewFieldsOrder(['1', '2', '3']) | ||
const moved = origin.swap('1', '3') | ||
expect(moved.order).toEqual(['3', '2', '1']) | ||
expect(moved === origin).toBe(false) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { ValueObject } from '@egodb/domain' | ||
|
||
export class ViewFieldsOrder extends ValueObject<string[]> { | ||
public get order() { | ||
return this.props | ||
} | ||
|
||
static fromArray(ids: string[]): ViewFieldsOrder { | ||
return new this(ids) | ||
} | ||
|
||
public swap(from: string, to: string): ViewFieldsOrder { | ||
const copied = [...this.order] | ||
const fromIndex = copied.findIndex((v) => v === from) | ||
const toIndex = copied.findIndex((v) => v === to) | ||
|
||
;[copied[toIndex], copied[fromIndex]] = [copied[fromIndex], copied[toIndex]] | ||
return ViewFieldsOrder.fromArray(copied) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,31 @@ | ||
module.exports = { | ||
"env": { | ||
"browser": true, | ||
"amd": true, | ||
"node": true, | ||
env: { | ||
browser: true, | ||
amd: true, | ||
node: true, | ||
}, | ||
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended', "prettier"], | ||
extends: [ | ||
'eslint:recommended', | ||
'plugin:@typescript-eslint/recommended', | ||
'prettier', | ||
'plugin:import/recommended', | ||
'plugin:import/typescript', | ||
], | ||
ignorePatterns: ['node_modules', 'dist'], | ||
parser: '@typescript-eslint/parser', | ||
plugins: ['@typescript-eslint', 'eslint-plugin-tsdoc'], | ||
settings: { | ||
'import/resolver': { | ||
typescript: true, | ||
node: true, | ||
}, | ||
}, | ||
rules: { | ||
"no-console": "warn", | ||
"react/jsx-key": "off", | ||
"tsdoc/syntax": "warn", | ||
"@typescript-eslint/consistent-type-imports": "warn", | ||
"@typescript-eslint/prefer-optional-chain": "warn", | ||
'no-console': 'warn', | ||
'react/jsx-key': 'off', | ||
'tsdoc/syntax': 'warn', | ||
'import/no-cycle': 'warn', | ||
'@typescript-eslint/consistent-type-imports': 'warn', | ||
'@typescript-eslint/prefer-optional-chain': 'warn', | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.