feat: improve code

This commit is contained in:
chenos 2021-08-27 14:52:58 +08:00
parent 7587e2cdb7
commit 6c779a7e6b
2 changed files with 21 additions and 4 deletions

View File

@ -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 (
<div className={cls('designable-bar', { active: visible })}>
<span
@ -81,8 +84,17 @@ export const CardDesignableBar = observer((props) => {
}
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 });
}
}}
/>
))}

View File

@ -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,