This commit is contained in:
Chen-I Lim 2020-10-13 21:26:48 -07:00
parent 20883bb900
commit 4db40c310e
3 changed files with 5 additions and 29 deletions

View file

@ -41,7 +41,6 @@ class Block implements IBlock {
this.updateAt = block.updateAt || now
this.deleteAt = block.deleteAt || 0
// this.properties = block.properties ? block.properties.map((o: IProperty) => ({ ...o })) : [] // Deep clone
if (Array.isArray(block.properties)) {
// HACKHACK: Port from old schema
this.properties = {}
@ -54,29 +53,6 @@ class Block implements IBlock {
this.properties = { ...block.properties || {} }
}
}
static getPropertyValue(block: IBlock, id: string): string | undefined {
if (!block.properties) { return undefined }
return block.properties[id]
}
static setProperty(block: IBlock, id: string, value?: string) {
block.properties[id] = value
// if (!block.properties) { block.properties = [] }
// if (!value) {
// // Remove property
// block.properties = block.properties.filter(o => o.id !== id)
// return
// }
// const property = block.properties.find(o => o.id === id)
// if (property) {
// property.value = value
// } else {
// const newProperty: IProperty = { id, value }
// block.properties.push(newProperty)
// }
}
}
export { Block }

View file

@ -233,7 +233,7 @@ class BoardComponent extends React.Component<Props, State> {
const properties = CardFilter.propertiesThatMeetFilterGroup(activeView.filter, board.cardProperties)
const card = new Block({ type: "card", parentId: boardTree.board.id, properties })
if (boardTree.groupByProperty) {
Block.setProperty(card, boardTree.groupByProperty.id, groupByValue)
card.properties[boardTree.groupByProperty.id] = groupByValue
}
await mutator.insertBlock(card, "add card", async () => { await this.showCard(card) }, async () => { await this.showCard(undefined) })
}
@ -354,7 +354,7 @@ class BoardComponent extends React.Component<Props, State> {
if (draggedCard) {
Utils.log(`ondrop. Card: ${draggedCard.title}, column: ${propertyValue}`)
const oldValue = Block.getPropertyValue(draggedCard, boardTree.groupByProperty.id)
const oldValue = draggedCard.properties[boardTree.groupByProperty.id]
if (propertyValue !== oldValue) {
await mutator.changePropertyValue(draggedCard, boardTree.groupByProperty.id, propertyValue, "drag card")
}

View file

@ -408,14 +408,14 @@ class Mutator {
async changePropertyValue(block: IBlock, propertyId: string, value?: string, description: string = "change property") {
const { octo, undoManager } = this
const oldValue = Block.getPropertyValue(block, propertyId)
const oldValue = block.properties[propertyId]
await undoManager.perform(
async () => {
Block.setProperty(block, propertyId, value)
block.properties[propertyId] = value
await octo.updateBlock(block)
},
async () => {
Block.setProperty(block, propertyId, oldValue)
block.properties[propertyId] = oldValue
await octo.updateBlock(block)
},
description