There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.
TypeScript appcrdteditorelectronknowledge-basemarkdownmironotesnotionnotion-alternativerustrust-langrust-languagetabletableviewwhiteboardwikiworkspace
refactor(view): migrate group by
lawvs2846e464d908
diff --git a/libs/components/editor-core/src/kanban/kanban.ts b/libs/components/editor-core/src/kanban/kanban.tsindex d47e0ce75d..675e75db3e 100644--- a/libs/components/editor-core/src/kanban/kanban.ts+++ b/libs/components/editor-core/src/kanban/kanban.ts@@ -2,17 +2,18 @@ import { Protocol } from '@toeverything/datasource/db-service';import { useCallback, useContext, useEffect, useState } from 'react';import { useEditor } from '../contexts';import { AsyncBlock } from '../editor';+import { useRecastView } from '../recast-block';import { useRecastBlock } from '../recast-block/Context';import {useRecastBlockMeta,useSelectProperty,} from '../recast-block/property';-import type { RecastItem } from '../recast-block/types';import {- KANBAN_PROPERTIES_KEY,PropertyType,+ RecastItem,RecastMetaProperty,RecastPropertyId,+ RecastScene,} from '../recast-block/types';import { supportChildren } from '../utils';import {@@ -39,9 +40,9 @@ import { KanbanCard, KanbanGroup } from './types';* @public*/export const useRecastKanbanGroupBy = () => {- const recastBlock = useRecastBlock();const { getProperty, getProperties } = useRecastBlockMeta();- const kanbanProperties = recastBlock.getProperty(KANBAN_PROPERTIES_KEY);+ const { currentView, withKanbanView } = useRecastView();+ const isKanbanView = currentView.type === RecastScene.Kanban;// TODO: remove filter// Add other type groupBy support@@ -53,18 +54,19 @@ export const useRecastKanbanGroupBy = () => {const setGroupBy = useCallback(async (id: RecastPropertyId) => {- const ok = await recastBlock.setProperty(KANBAN_PROPERTIES_KEY, {- ...kanbanProperties,- groupBy: id,- });- if (!ok) {- throw new Error('Failed to set groupBy');+ if (!isKanbanView) {+ console.error('current view:', currentView);+ throw new Error(+ 'Failed to set groupBy! Current view is not kanban view!'+ );}+ const { setGroupBy } = withKanbanView(currentView);+ await setGroupBy(id);},- [recastBlock, kanbanProperties]+ [currentView, isKanbanView, withKanbanView]);- const groupById = kanbanProperties?.groupBy;+ const groupById = isKanbanView ? currentView.groupBy : null;// 1. groupBy is not setif (!groupById) {return {diff --git a/libs/components/editor-core/src/recast-block/view.ts b/libs/components/editor-core/src/recast-block/view.tsindex 27a4ce79be..de505f9607 100644--- a/libs/components/editor-core/src/recast-block/view.ts+++ b/libs/components/editor-core/src/recast-block/view.ts@@ -20,7 +20,7 @@ const genViewId = () => nanoid(16) as RecastViewId; // This is a safe type castconst DEFAULT_VIEWS: RecastView[] = [{id: genViewId(),- name: 'List',+ name: 'Text View',type: RecastScene.Page,},{@@ -137,6 +137,23 @@ export const useRecastView = () => {[getView, recastViews, setViews]);+ /**+ * Get kanban ability+ */+ const withKanbanView = useCallback(+ (view: KanbanView) => {+ const groupBy = view.groupBy ?? null;+ const setGroupBy = (groupBy: RecastPropertyId) => {+ updateView({ ...view, groupBy });+ };+ return {+ groupBy,+ setGroupBy,+ };+ },+ [updateView]+ );+return {currentView,recastViews,@@ -145,5 +162,8 @@ export const useRecastView = () => {updateView,renameView,removeView,++ withKanbanView,+ // TODO reorder API};};