mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 04:18:54 +00:00
fix: The status history in kanban mode cannot be synced to text mode, fixed #43
This commit is contained in:
@@ -1,41 +1,10 @@
|
|||||||
import { removePropertyValueRecord, setPendantHistory } from './utils';
|
import { getPendantController } from './utils';
|
||||||
import { AsyncBlock } from '../editor';
|
import { AsyncBlock } from '../editor';
|
||||||
import {
|
import { useRecastBlock } from '../recast-block';
|
||||||
getRecastItemValue,
|
|
||||||
RecastMetaProperty,
|
|
||||||
useRecastBlock,
|
|
||||||
} from '../recast-block';
|
|
||||||
|
|
||||||
export const usePendant = (block: AsyncBlock) => {
|
export const usePendant = (block: AsyncBlock) => {
|
||||||
// const { getProperties, removeProperty } = useRecastBlockMeta();
|
// const { getProperties, removeProperty } = useRecastBlockMeta();
|
||||||
const recastBlock = useRecastBlock();
|
const recastBlock = useRecastBlock();
|
||||||
const { getValue, setValue, removeValue } = getRecastItemValue(block);
|
|
||||||
// const { updateSelect } = useSelectProperty();
|
|
||||||
|
|
||||||
const setPendant = async (property: RecastMetaProperty, newValue: any) => {
|
return getPendantController(recastBlock, block);
|
||||||
const nv = {
|
|
||||||
id: property.id,
|
|
||||||
type: property.type,
|
|
||||||
value: newValue,
|
|
||||||
};
|
|
||||||
await setValue(nv);
|
|
||||||
setPendantHistory({
|
|
||||||
recastBlockId: recastBlock.id,
|
|
||||||
blockId: block.id,
|
|
||||||
propertyId: property.id,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const removePendant = async (property: RecastMetaProperty) => {
|
|
||||||
await removeValue(property.id);
|
|
||||||
removePropertyValueRecord({
|
|
||||||
recastBlockId: block.id,
|
|
||||||
propertyId: property.id,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
return {
|
|
||||||
setPendant,
|
|
||||||
removePendant,
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,13 +1,16 @@
|
|||||||
import {
|
import {
|
||||||
|
getRecastItemValue,
|
||||||
PropertyType,
|
PropertyType,
|
||||||
RecastBlockValue,
|
RecastBlock,
|
||||||
|
RecastItem,
|
||||||
|
RecastMetaProperty,
|
||||||
RecastPropertyId,
|
RecastPropertyId,
|
||||||
SelectOption,
|
SelectOption,
|
||||||
} from '../recast-block';
|
} from '../recast-block';
|
||||||
import { OptionIdType, OptionType } from './types';
|
import { OptionIdType, OptionType, PendantConfig, PendantTypes } from './types';
|
||||||
import { pendantConfig } from './config';
|
import { pendantConfig } from './config';
|
||||||
import { PendantConfig, PendantTypes } from './types';
|
|
||||||
import { nanoid } from 'nanoid';
|
import { nanoid } from 'nanoid';
|
||||||
|
import { AsyncBlock } from '../editor';
|
||||||
type Props = {
|
type Props = {
|
||||||
recastBlockId: string;
|
recastBlockId: string;
|
||||||
blockId: string;
|
blockId: string;
|
||||||
@@ -81,6 +84,42 @@ export const removePendantHistory = ({
|
|||||||
localStorage.setItem(LOCAL_STORAGE_NAME, JSON.stringify(data));
|
localStorage.setItem(LOCAL_STORAGE_NAME, JSON.stringify(data));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getPendantController = (
|
||||||
|
recastBlock: RecastBlock,
|
||||||
|
block: AsyncBlock | RecastItem
|
||||||
|
) => {
|
||||||
|
const { setValue, removeValue } = getRecastItemValue(block);
|
||||||
|
|
||||||
|
const setPendant = async (property: RecastMetaProperty, newValue: any) => {
|
||||||
|
const nv = {
|
||||||
|
id: property.id,
|
||||||
|
type: property.type,
|
||||||
|
value: newValue,
|
||||||
|
};
|
||||||
|
|
||||||
|
setPendantHistory({
|
||||||
|
recastBlockId: recastBlock.id,
|
||||||
|
blockId: block.id,
|
||||||
|
propertyId: property.id,
|
||||||
|
});
|
||||||
|
|
||||||
|
return await setValue(nv);
|
||||||
|
};
|
||||||
|
|
||||||
|
const removePendant = async (property: RecastMetaProperty) => {
|
||||||
|
removePendantHistory({
|
||||||
|
recastBlockId: block.id,
|
||||||
|
propertyId: property.id,
|
||||||
|
});
|
||||||
|
return await removeValue(property.id);
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
setPendant,
|
||||||
|
removePendant,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* In select pendant panel, use mock options instead of use `createSelect` when add or delete option
|
* In select pendant panel, use mock options instead of use `createSelect` when add or delete option
|
||||||
* so the option`s id is index number, not `SelectOptionId`
|
* so the option`s id is index number, not `SelectOptionId`
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import {
|
|||||||
PropertyType,
|
PropertyType,
|
||||||
RecastBlockValue,
|
RecastBlockValue,
|
||||||
RecastMetaProperty,
|
RecastMetaProperty,
|
||||||
RecastPropertyId,
|
|
||||||
} from '../recast-block/types';
|
} from '../recast-block/types';
|
||||||
import type { DefaultGroup, KanbanGroup } from './types';
|
import type { DefaultGroup, KanbanGroup } from './types';
|
||||||
import { DEFAULT_GROUP_ID } from './types';
|
import { DEFAULT_GROUP_ID } from './types';
|
||||||
@@ -14,6 +13,7 @@ import {
|
|||||||
generateInitialOptions,
|
generateInitialOptions,
|
||||||
generateRandomFieldName,
|
generateRandomFieldName,
|
||||||
getPendantIconsConfigByName,
|
getPendantIconsConfigByName,
|
||||||
|
getPendantController,
|
||||||
} from '../block-pendant/utils';
|
} from '../block-pendant/utils';
|
||||||
import { SelectOption } from '../recast-block';
|
import { SelectOption } from '../recast-block';
|
||||||
|
|
||||||
@@ -106,49 +106,42 @@ export const calcCardGroup = (
|
|||||||
/**
|
/**
|
||||||
* Set group value for the card block
|
* Set group value for the card block
|
||||||
*/
|
*/
|
||||||
export const moveCardToGroup = async (
|
export const moveCardToGroup = async ({
|
||||||
groupById: RecastPropertyId,
|
groupBy,
|
||||||
cardBlock: RecastItem,
|
cardBlock,
|
||||||
group: KanbanGroup
|
group,
|
||||||
) => {
|
recastBlock,
|
||||||
const { setValue, removeValue } = getRecastItemValue(cardBlock);
|
}: {
|
||||||
|
groupBy: RecastMetaProperty;
|
||||||
|
cardBlock: RecastItem;
|
||||||
|
group: KanbanGroup;
|
||||||
|
recastBlock: RecastBlock;
|
||||||
|
}) => {
|
||||||
|
const { setPendant, removePendant } = getPendantController(
|
||||||
|
recastBlock,
|
||||||
|
cardBlock
|
||||||
|
);
|
||||||
let success = false;
|
let success = false;
|
||||||
if (group.id === DEFAULT_GROUP_ID) {
|
if (group.id === DEFAULT_GROUP_ID) {
|
||||||
success = await removeValue(groupById);
|
success = await removePendant(groupBy);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (group.type) {
|
switch (group.type) {
|
||||||
case PropertyType.Select: {
|
case PropertyType.Select: {
|
||||||
success = await setValue({
|
success = await setPendant(groupBy, group.id);
|
||||||
id: groupById,
|
|
||||||
type: group.type,
|
|
||||||
value: group.id,
|
|
||||||
});
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case PropertyType.Status: {
|
case PropertyType.Status: {
|
||||||
success = await setValue({
|
success = await setPendant(groupBy, group.id);
|
||||||
id: groupById,
|
|
||||||
type: group.type,
|
|
||||||
value: group.id,
|
|
||||||
});
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case PropertyType.MultiSelect: {
|
case PropertyType.MultiSelect: {
|
||||||
success = await setValue({
|
success = await setPendant(groupBy, [group.id]);
|
||||||
id: groupById,
|
|
||||||
type: group.type,
|
|
||||||
value: [group.id],
|
|
||||||
});
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case PropertyType.Text: {
|
case PropertyType.Text: {
|
||||||
success = await setValue({
|
success = await setPendant(groupBy, group.id);
|
||||||
id: groupById,
|
|
||||||
type: group.type,
|
|
||||||
value: group.id,
|
|
||||||
});
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -199,7 +199,12 @@ export const useRecastKanban = () => {
|
|||||||
beforeBlock: string | null,
|
beforeBlock: string | null,
|
||||||
afterBlock: string | null
|
afterBlock: string | null
|
||||||
) => {
|
) => {
|
||||||
await moveCardToGroup(groupBy.id, child, kanbanMap[id]);
|
await moveCardToGroup({
|
||||||
|
groupBy,
|
||||||
|
cardBlock: child,
|
||||||
|
group: kanbanMap[id],
|
||||||
|
recastBlock,
|
||||||
|
});
|
||||||
if (beforeBlock) {
|
if (beforeBlock) {
|
||||||
const block = await editor.getBlockById(
|
const block = await editor.getBlockById(
|
||||||
beforeBlock
|
beforeBlock
|
||||||
@@ -288,7 +293,12 @@ export const useKanban = () => {
|
|||||||
);
|
);
|
||||||
if (isChangedGroup) {
|
if (isChangedGroup) {
|
||||||
// 1.2 Move to the target group
|
// 1.2 Move to the target group
|
||||||
await moveCardToGroup(groupBy.id, targetCard, targetGroup);
|
await moveCardToGroup({
|
||||||
|
groupBy,
|
||||||
|
cardBlock: targetCard,
|
||||||
|
group: targetGroup,
|
||||||
|
recastBlock,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. Reorder the card
|
// 2. Reorder the card
|
||||||
@@ -326,7 +336,12 @@ export const useKanban = () => {
|
|||||||
}
|
}
|
||||||
recastBlock.append(newBlock);
|
recastBlock.append(newBlock);
|
||||||
const newCard = newBlock as unknown as RecastItem;
|
const newCard = newBlock as unknown as RecastItem;
|
||||||
await moveCardToGroup(groupBy.id, newCard, group);
|
await moveCardToGroup({
|
||||||
|
groupBy,
|
||||||
|
cardBlock: newCard,
|
||||||
|
group,
|
||||||
|
recastBlock,
|
||||||
|
});
|
||||||
},
|
},
|
||||||
[editor, groupBy.id, recastBlock]
|
[editor, groupBy.id, recastBlock]
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user