Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support views share #WIK-16187 #22

Merged
merged 8 commits into from
Aug 5, 2024
Merged

feat: support views share #WIK-16187 #22

merged 8 commits into from
Aug 5, 2024

Conversation

cmm-va
Copy link
Contributor

@cmm-va cmm-va commented Jul 30, 2024

No description provided.

sort(){
const direction = this.activeView().sortCondition?.conditions[0].direction
const sortCondition = { keepSort:true , conditions:[{sortBy: 'column-4', direction: direction=== Direction.ascending ? Direction.descending: Direction.ascending}]}
this.activeView().sortCondition = sortCondition
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不需要给 sortCondition 赋值,通过 computed 会自动计算

const direction = this.activeView().sortCondition?.conditions[0].direction
const sortCondition = { keepSort:true , conditions:[{sortBy: 'column-4', direction: direction=== Direction.ascending ? Direction.descending: Direction.ascending}]}
this.activeView().sortCondition = sortCondition
CustomActions.setView(this.aiTable as any, this.activeView(), [0]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里只需要传 { sortCondition } 就可以, set_view 的实现和定义也可以参考下 set_field

@@ -10,20 +11,25 @@ export function translateYjsEvent(aiTable: AITable, event: Y.YEvent<any>): AITab
return [];
}

export function applyEvents(aiTable: AITable, events: Y.YEvent<any>[]){
events.forEach((event) =>
translateYjsEvent(aiTable, event).forEach((item: AIViewAction| AITableAction) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的 event 类型应该是 Y.YMapEvent 了,不能在 translateArrayEvent 中处理了,关于 map 的处理可以参考下 https://github.com/worktile/y-slate/blob/main/src/apply-to-slate/map-event.ts

const views = sharedType.get('views');
if (views) {
const index = action.path[0];
views.delete(index);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的修改应该是针对 views 中具体某个属性的修改,

  1. 通过 path 从 views 中取到对应 view
  2. 遍历 action.newView ,执行 set 方法修改对应 key 的数据

修改整个数组理论上虽然可行,但是开销会变大,转换为 action 操作时也无法准确的知道修改的属性都有哪些了,fieldValue 的修改是因为每个值都转换为数组存储了,而这里 view 中的每一项都是对象而非数组。

具体的实现可以参考下 https://github.com/worktile/y-slate/blob/main/src/apply-to-yjs/node/set-node.ts

@huanhuanwa huanhuanwa merged commit 93e28ab into develop Aug 5, 2024
4 checks passed
@huanhuanwa huanhuanwa deleted the #WIK-16187 branch August 5, 2024 02:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants