Skip to content

Commit b4b5aab

Browse files
committed
don't close bct when creating a card from the hot edge; deletes placeholder card and reset grid when clicking away after creating from the hot edge - The placeholder is kept around when creating a card from the hot edge since it's used during CollectionCard::API_create
1 parent 40d5428 commit b4b5aab

File tree

6 files changed

+49
-27
lines changed

6 files changed

+49
-27
lines changed

__tests__/stores/UiStore.unit.test.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,14 @@ describe('UiStore', () => {
6262
expect(blankContentToolState.col).toBe(4)
6363
})
6464

65-
describe('with placeholderCard', () => {
65+
describe('with placeholderCard that is placed in a different spot as the bct', () => {
6666
beforeEach(() => {
67-
uiStore.setBctPlaceholderCard({ id: '99' })
67+
const { blankContentToolState } = uiStore
68+
uiStore.setBctPlaceholderCard({
69+
id: '99',
70+
col: blankContentToolState.col + 1,
71+
row: blankContentToolState.row,
72+
})
6873
uiStore.closeBlankContentTool = jest.fn()
6974
})
7075
it('should call closeBlankContentTool to clear the card', () => {

app/javascript/stores/UiStore.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -882,16 +882,35 @@ export default class UiStore {
882882
// --- BCT + GridCard properties
883883
@action
884884
async openBlankContentTool(options = {}) {
885-
const { viewingCollection } = this
886-
if (this.blankContentToolState.placeholderCard) {
885+
const { viewingCollection, blankContentToolState } = this
886+
const { placeholderCard } = blankContentToolState
887+
if (
888+
placeholderCard &&
889+
(placeholderCard.col !== options.col ||
890+
placeholderCard.row !== options.row)
891+
) {
892+
// if we have a placeholder and we're trying to open from the a different spot, close it
887893
await this.closeBlankContentTool()
888894
}
889895
runInAction(() => {
890896
this.deselectCards()
891897
this.closeCardMenu()
892898
this.clearTextEditingCard()
899+
const { placeholderCard, blankType } = this.blankContentToolState
900+
const openingBctFromHotEdge =
901+
placeholderCard &&
902+
blankType === 'hotcell' &&
903+
options &&
904+
options.blankType !== 'hotcell'
905+
const bctState = openingBctFromHotEdge
906+
? {
907+
...this.defaultBCTState,
908+
placeholderCard,
909+
}
910+
: this.defaultBCTState
911+
893912
this.blankContentToolState = {
894-
...this.defaultBCTState,
913+
...bctState,
895914
order: 0,
896915
width: 1,
897916
height: 1,

app/javascript/stores/jsonApi/Collection.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -991,6 +991,10 @@ class Collection extends SharedRecordMixin(BaseRecord) {
991991
const res = await apiStore.fetch('collection_cards', cardId, true)
992992
// make sure it's in our current collection
993993
const card = res.data
994+
if (card.destroyed) {
995+
// don't add the card since it was destroyed while being fetched
996+
return
997+
}
994998
this.addCard(card)
995999
return card
9961000
}

app/javascript/stores/jsonApi/CollectionCard.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,7 @@ class CollectionCard extends TitleAndCoverEditingMixin(BaseRecord) {
380380
return
381381
}
382382
try {
383+
this.destroyed = true
383384
this.destroy()
384385
this.parentCollection.removeCard(this)
385386
return

app/javascript/ui/grid/interactionLayer/FoamcoreInteractionLayer.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -428,13 +428,9 @@ class FoamcoreInteractionLayer extends React.Component {
428428
}
429429

430430
const { blankContentToolState } = uiStore
431-
const { blankType } = blankContentToolState
431+
const { placeholderCard } = blankContentToolState
432432

433-
// BCT is already open as a hotcell, just modify it. But don't do this
434-
// if you're opening a new hotcell.
435-
if (blankType === 'hotcell') {
436-
await uiStore.closeBlankContentTool()
437-
}
433+
const creatingContentAfterHotEdge = !hotEdge && !!placeholderCard
438434

439435
uiStore.openBlankContentTool({
440436
row,
@@ -451,10 +447,12 @@ class FoamcoreInteractionLayer extends React.Component {
451447
}
452448

453449
this.resetHoveringRowCol()
454-
if (!hotEdge && contentType === 'text') {
455-
// don't create placeholders when creating a text card
450+
451+
if (creatingContentAfterHotEdge || contentType === 'text') {
452+
// don't create a placeholder since we already have it or if creating a text card
456453
return
457454
}
455+
458456
const placeholder = new CollectionCard(
459457
{
460458
row,
@@ -463,13 +461,16 @@ class FoamcoreInteractionLayer extends React.Component {
463461
},
464462
apiStore
465463
)
466-
await placeholder.API_createBct()
467464
uiStore.setBctPlaceholderCard(placeholder)
468-
// add placeholder to datx store to trigger warning before unload
469-
collection.addCard(placeholder)
465+
await placeholder.API_createBct()
470466
if (this.creatingHotEdge) {
471467
runInAction(() => (this.creatingHotEdge = false))
472468
}
469+
if (!uiStore.blankContentToolIsOpen) {
470+
// NOTE: the bct was closed during placeholder.API_createBct
471+
placeholder.API_destroy()
472+
return
473+
}
473474
}
474475

475476
onCloseHtc = () => {

cypress/integration/collections/CreateFoamcoreBoard.feature

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,19 @@ Feature: Creating a FoamcoreBoard Collection
1414
And I create a textItem card at 1,1 on the board with "Hello."
1515
# hotspot in between two cards
1616
When I click the "FoamcoreHotEdge-0:1"
17-
And I wait for "@apiCreateCollectionCardBct" to finish
1817
And I wait for "@apiGetCollectionCard" to finish
18+
1919
# should move the card out of the way
2020
Then I should see the text "To my board." in the card at 0,2
21-
22-
# click any quadrant
21+
# closing it should move back
2322
When I wait for 1 second
23+
# click any quadrant
2424
And I click the "HotCellQuadrant-foamcoreBoard"
25-
And I wait for "@apiDeleteCollectionCard" to finish
26-
And I wait for "@apiCreateCollectionCardBct" to finish
27-
And I wait for "@apiGetCollectionCard" to finish
28-
And I wait for 1 second
29-
# closing it should move back
3025
And I click the "BCT-closeButton"
31-
And I wait for "@apiDeleteCollectionCard" to finish
3226
Then I should see the text "To my board." in the card at 0,1
3327

3428
# There should be a hotspot to the left of the 0,0 card
35-
When I wait for 1 second
3629
And I create a text item card "Inserted!" using the first hot edge
37-
And I wait for "@apiDeleteCollectionCard" to finish
3830
# should move both row 0 cards out of the way
3931
Then I should see the text "Inserted!" in the card at 0,0
4032
Then I should see the text "Welcome!" in the card at 0,1

0 commit comments

Comments
 (0)