Skip to content

Commit b1ee224

Browse files
committed
fix(tile-manager): apply saved props to tiles already in DOM
1 parent 1e1b5da commit b1ee224

File tree

2 files changed

+70
-50
lines changed

2 files changed

+70
-50
lines changed

src/components/tile-manager/tile-manager.spec.ts

Lines changed: 47 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -673,28 +673,30 @@ describe('Tile Manager component', () => {
673673
const serializedData = JSON.parse(tileManager.saveLayout());
674674
const expectedData = [
675675
{
676-
tileId: 'custom-id1',
676+
// colSpan: 3,
677677
colStart: null,
678-
colSpan: 3,
679678
disableDrag: false,
680679
disableResize: false,
681-
rowStart: null,
682-
rowSpan: 3,
683-
gridColumn: 'span 3',
684-
gridRow: 'span 3',
680+
gridColumn: 'auto',
681+
gridRow: 'auto',
685682
maximized: false,
683+
position: 0,
684+
// rowSpan: 3,
685+
rowStart: null,
686+
tileId: 'custom-id1',
686687
},
687688
{
688-
tileId: 'custom-id2',
689-
colStart: 8,
690689
colSpan: 10,
690+
colStart: 8,
691691
disableDrag: true,
692692
disableResize: true,
693-
rowStart: 7,
694-
rowSpan: 7,
695-
gridColumn: '8 / span 10',
696-
gridRow: '7 / span 7',
693+
gridColumn: 'auto',
694+
gridRow: 'auto',
697695
maximized: false,
696+
position: 1,
697+
rowSpan: 7,
698+
rowStart: 7,
699+
tileId: 'custom-id2',
698700
},
699701
];
700702

@@ -704,28 +706,43 @@ describe('Tile Manager component', () => {
704706
it('should deserialize tiles with proper properties values', async () => {
705707
const tilesData = [
706708
{
707-
tileId: 'id1',
708-
colStart: 1,
709709
colSpan: 5,
710+
colStart: 1,
710711
disableDrag: true,
711712
disableResize: true,
712713
gridColumn: '1 / span 5',
713714
gridRow: '1 / span 5',
714715
maximized: false,
715-
rowStart: 1,
716+
position: 0,
716717
rowSpan: 5,
718+
rowStart: 1,
719+
tileId: 'custom-id1',
717720
},
718721
{
719-
tileId: 'id2',
720-
colStart: null,
721722
colSpan: 3,
723+
colStart: null,
722724
disableDrag: false,
723725
disableResize: false,
724726
gridColumn: 'span 3',
725727
gridRow: 'span 3',
726728
maximized: false,
729+
position: 1,
730+
rowSpan: 3,
727731
rowStart: null,
732+
tileId: 'custom-id2',
733+
},
734+
{
735+
colSpan: 3,
736+
colStart: null,
737+
disableDrag: false,
738+
disableResize: false,
739+
gridColumn: 'span 3',
740+
gridRow: 'span 3',
741+
maximized: false,
742+
position: 2,
728743
rowSpan: 3,
744+
rowStart: null,
745+
tileId: 'no-match-id',
729746
},
730747
];
731748

@@ -735,23 +752,25 @@ describe('Tile Manager component', () => {
735752
const tiles = tileManager.tiles;
736753
expect(tiles.length).to.equal(2);
737754

738-
expect(tiles[0].tileId).to.equal('id1');
739-
expect(tiles[0].colStart).to.equal(1);
740755
expect(tiles[0].colSpan).to.equal(5);
756+
expect(tiles[0].colStart).to.equal(1);
741757
expect(tiles[0].disableDrag).to.equal(true);
742758
expect(tiles[0].disableResize).to.equal(true);
743759
expect(tiles[0].maximized).to.be.false;
744-
expect(tiles[0].rowStart).to.equal(1);
760+
expect(tiles[0].position).to.equal(0);
745761
expect(tiles[0].rowSpan).to.equal(5);
762+
expect(tiles[0].rowStart).to.equal(1);
763+
expect(tiles[0].tileId).to.equal('custom-id1');
746764

747-
expect(tiles[1].tileId).to.equal('id2');
748-
expect(tiles[1].colStart).to.be.null;
749765
expect(tiles[1].colSpan).to.equal(3);
766+
expect(tiles[1].colStart).to.be.null;
750767
expect(tiles[1].disableDrag).to.be.false;
751768
expect(tiles[1].disableResize).to.be.false;
752769
expect(tiles[1].maximized).to.be.false;
753-
expect(tiles[1].rowStart).to.be.null;
770+
expect(tiles[1].position).to.equal(1);
754771
expect(tiles[1].rowSpan).to.equal(3);
772+
expect(tiles[1].rowStart).to.be.null;
773+
expect(tiles[1].tileId).to.equal('custom-id2');
755774

756775
const firstTileStyles = window.getComputedStyle(tiles[0]);
757776
const secondTileStyles = window.getComputedStyle(tiles[1]);
@@ -789,7 +808,11 @@ describe('Tile Manager component', () => {
789808
tileManager.appendChild(tile);
790809
await elementUpdated(tileManager);
791810

792-
expect(tileManager.tiles[5].tileId).to.equal('custom-id');
811+
const matchingTiles = tileManager.tiles.filter(
812+
(tile) => tile.tileId === 'custom-id'
813+
);
814+
815+
expect(matchingTiles.length).to.equal(1);
793816
});
794817
});
795818

src/components/tile-manager/tile-manager.ts

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -208,49 +208,46 @@ export default class IgcTileManagerComponent extends EventEmitterMixin<
208208
const tileStyles = window.getComputedStyle(tile);
209209

210210
return {
211-
tileId: tile.tileId,
212211
colSpan: tile.colSpan,
213212
colStart: tile.colStart,
214-
rowSpan: tile.rowSpan,
215-
rowStart: tile.rowStart,
216-
maximized: tile.maximized,
217213
disableDrag: tile.disableDrag,
218214
disableResize: tile.disableResize,
219-
position: tile.position,
220-
221215
// TODO: Review. We are saving gridColumn and gridRow as they keep the size of the resized tiles.
222216
gridColumn: tileStyles.gridColumn,
223217
gridRow: tileStyles.gridRow,
218+
maximized: tile.maximized,
219+
position: tile.position,
220+
rowSpan: tile.rowSpan,
221+
rowStart: tile.rowStart,
222+
tileId: tile.tileId,
224223
};
225224
});
226225

227-
// console.log("tileData: " + JSON.stringify(tilesData, null, 2));
228226
return JSON.stringify(tilesData);
229227
}
230228

231229
public loadLayout(data: string) {
232230
const tilesData = JSON.parse(data);
233231

234-
this.tiles.forEach((tile) => tile.remove());
235-
236232
tilesData.forEach((tileInfo: any) => {
237-
const tile = document.createElement('igc-tile') as IgcTileComponent;
238-
239-
tile.tileId = tileInfo.tileId;
240-
tile.colSpan = tileInfo.colSpan;
241-
tile.colStart = tileInfo.colStart;
242-
tile.rowSpan = tileInfo.rowSpan;
243-
tile.rowStart = tileInfo.rowStart;
244-
tile.maximized = tileInfo.maximized;
245-
tile.disableDrag = tileInfo.disableDrag;
246-
tile.disableResize = tileInfo.disableResize;
247-
tile.position = tileInfo.position;
248-
249-
// TODO: Review. We are saving gridColumn and gridRow as they keep the size of the resized tiles.
250-
tile.style.gridColumn = tileInfo.gridColumn;
251-
tile.style.gridRow = tileInfo.gridRow;
252-
253-
this.appendChild(tile);
233+
const existingTile = this._tiles.find(
234+
(tile) => tile.tileId === tileInfo.tileId
235+
);
236+
237+
if (existingTile) {
238+
existingTile.colSpan = tileInfo.colSpan;
239+
existingTile.colStart = tileInfo.colStart;
240+
existingTile.disableDrag = tileInfo.disableDrag;
241+
existingTile.disableResize = tileInfo.disableResize;
242+
existingTile.maximized = tileInfo.maximized;
243+
existingTile.position = tileInfo.position;
244+
existingTile.rowSpan = tileInfo.rowSpan;
245+
existingTile.rowStart = tileInfo.rowStart;
246+
247+
// TODO: Review. We are saving gridColumn and gridRow as they keep the size of the resized tiles.
248+
existingTile.style.gridColumn = tileInfo.gridColumn;
249+
existingTile.style.gridRow = tileInfo.gridRow;
250+
}
254251
});
255252
}
256253

0 commit comments

Comments
 (0)