From 6c779a7e6ba963cead5bb35007ada11f177eaac8 Mon Sep 17 00:00:00 2001 From: chenos Date: Fri, 27 Aug 2021 14:52:58 +0800 Subject: [PATCH] feat: improve code --- .../src/schemas/kanban/CardDesignableBar.tsx | 21 +++++++++++++++++-- packages/client/src/schemas/kanban/index.tsx | 4 ++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/packages/client/src/schemas/kanban/CardDesignableBar.tsx b/packages/client/src/schemas/kanban/CardDesignableBar.tsx index 759c04f3f..4a8451cf1 100644 --- a/packages/client/src/schemas/kanban/CardDesignableBar.tsx +++ b/packages/client/src/schemas/kanban/CardDesignableBar.tsx @@ -39,6 +39,8 @@ import { } from '../../constate'; import { useTable } from '../table'; import SwitchMenuItem from '../../components/SwitchMenuItem'; +import { useKanban } from '.'; +import { isAssociation } from '../database-field/interfaces'; export const CardDesignableBar = observer((props) => { const field = useField(); @@ -47,6 +49,7 @@ export const CardDesignableBar = observer((props) => { const { collection, fields } = useCollectionContext(); const displayed = useDisplayedMapContext(); console.log('useDisplayedMapContext', schema); + const { service } = useKanban(); return (
{ } const last = removed.pop(); displayed.remove(field.name); - if (isGridRowOrCol(last)) { - await removeSchema(last); + await removeSchema(last); + if (isAssociation(field)) { + const appends = service.params[0]?.appends || []; + const index = appends.indexOf(field.name); + if (index > -1) { + appends.splice(index, 1); + } + await service.run({ + ...service.params[0], + appends, + }); } return; } @@ -102,6 +114,11 @@ export const CardDesignableBar = observer((props) => { }; const s = appendChild(data); await createSchema(s); + if (isAssociation(field)) { + const appends = service.params[0]?.appends || []; + appends.push(field.name); + await service.run({ ...service.params[0], appends }); + } }} /> ))} diff --git a/packages/client/src/schemas/kanban/index.tsx b/packages/client/src/schemas/kanban/index.tsx index 7da038fc3..c5599c58d 100644 --- a/packages/client/src/schemas/kanban/index.tsx +++ b/packages/client/src/schemas/kanban/index.tsx @@ -175,7 +175,6 @@ const InternalKanban = observer((props: any) => { } return resource.list({ ...params, - appends: fieldFields(schemas.get('Kanban.Card')), perPage: -1, sort: 'sort', }); @@ -191,6 +190,7 @@ const InternalKanban = observer((props: any) => { ); useEffect(() => { service.run({ + appends: fieldFields(schemas.get('Kanban.Card')), defaultFilter: props?.defaultFilter, }); }, [props.defaultFilter]); @@ -517,7 +517,7 @@ Kanban.useSingleResource = ({ onSuccess }) => { const ctx = useContext(KanbanCardContext); const { schema } = useDesignable(); const [visible] = useContext(VisibleContext); - + const resource = Resource.make({ resourceName: collection?.name || props.collectionName, resourceKey: ctx?.record?.id,