Fix card insertion order (#1030)
Co-authored-by: Scott Bishel <scott.bishel@mattermost.com>
This commit is contained in:
parent
171164ec6d
commit
964cc1a0b8
1 changed files with 40 additions and 29 deletions
|
@ -15,6 +15,7 @@ import mutator from '../mutator'
|
|||
import {Utils} from '../utils'
|
||||
import {UserSettings} from '../userSettings'
|
||||
import {addCard, addTemplate} from '../store/cards'
|
||||
import {updateView} from '../store/views'
|
||||
|
||||
import './centerPanel.scss'
|
||||
|
||||
|
@ -36,6 +37,7 @@ type Props = {
|
|||
intl: IntlShape
|
||||
readonly: boolean
|
||||
addCard: (card: Card) => void
|
||||
updateView: (view: BoardView) => void
|
||||
addTemplate: (template: Card) => void
|
||||
shownCardId?: string
|
||||
showCard: (cardId?: string) => void
|
||||
|
@ -196,17 +198,22 @@ class CenterPanel extends React.Component<Props, State> {
|
|||
}
|
||||
|
||||
private addCardFromTemplate = async (cardTemplateId: string) => {
|
||||
await mutator.duplicateCard(
|
||||
cardTemplateId,
|
||||
this.props.intl.formatMessage({id: 'Mutator.new-card-from-template', defaultMessage: 'new card from template'}),
|
||||
false,
|
||||
async (newCardId) => {
|
||||
this.showCard(newCardId)
|
||||
},
|
||||
async () => {
|
||||
this.showCard(undefined)
|
||||
},
|
||||
)
|
||||
const {activeView} = this.props
|
||||
mutator.performAsUndoGroup(async () => {
|
||||
const [, newCardId] = await mutator.duplicateCard(
|
||||
cardTemplateId,
|
||||
this.props.intl.formatMessage({id: 'Mutator.new-card-from-template', defaultMessage: 'new card from template'}),
|
||||
false,
|
||||
async (cardId) => {
|
||||
this.props.updateView({...activeView, fields: {...activeView.fields, cardOrder: [...activeView.fields.cardOrder, cardId]}})
|
||||
this.showCard(cardId)
|
||||
},
|
||||
async () => {
|
||||
this.showCard(undefined)
|
||||
},
|
||||
)
|
||||
await mutator.changeViewCardOrder(activeView, [...activeView.fields.cardOrder, newCardId], 'add-card')
|
||||
})
|
||||
}
|
||||
|
||||
addCard = async (groupByOptionId?: string, show = false): Promise<void> => {
|
||||
|
@ -228,23 +235,27 @@ class CenterPanel extends React.Component<Props, State> {
|
|||
if (!card.fields.icon && UserSettings.prefillRandomIcons) {
|
||||
card.fields.icon = BlockIcons.shared.randomIcon()
|
||||
}
|
||||
await mutator.insertBlock(
|
||||
card,
|
||||
'add card',
|
||||
async () => {
|
||||
if (show) {
|
||||
this.props.addCard(card)
|
||||
this.showCard(card.id)
|
||||
} else {
|
||||
// Focus on this card's title inline on next render
|
||||
this.setState({cardIdToFocusOnRender: card.id})
|
||||
setTimeout(() => this.setState({cardIdToFocusOnRender: ''}), 100)
|
||||
}
|
||||
},
|
||||
async () => {
|
||||
this.showCard(undefined)
|
||||
},
|
||||
)
|
||||
mutator.performAsUndoGroup(async () => {
|
||||
await mutator.insertBlock(
|
||||
card,
|
||||
'add card',
|
||||
async () => {
|
||||
if (show) {
|
||||
this.props.addCard(card)
|
||||
this.props.updateView({...activeView, fields: {...activeView.fields, cardOrder: [...activeView.fields.cardOrder, card.id]}})
|
||||
this.showCard(card.id)
|
||||
} else {
|
||||
// Focus on this card's title inline on next render
|
||||
this.setState({cardIdToFocusOnRender: card.id})
|
||||
setTimeout(() => this.setState({cardIdToFocusOnRender: ''}), 100)
|
||||
}
|
||||
},
|
||||
async () => {
|
||||
this.showCard(undefined)
|
||||
},
|
||||
)
|
||||
await mutator.changeViewCardOrder(activeView, [...activeView.fields.cardOrder, card.id], 'add-card')
|
||||
})
|
||||
}
|
||||
|
||||
private addCardTemplate = async () => {
|
||||
|
@ -399,4 +410,4 @@ class CenterPanel extends React.Component<Props, State> {
|
|||
}
|
||||
}
|
||||
|
||||
export default connect(undefined, {addCard, addTemplate})(injectIntl(CenterPanel))
|
||||
export default connect(undefined, {addCard, addTemplate, updateView})(injectIntl(CenterPanel))
|
||||
|
|
Loading…
Reference in a new issue