Skip to content

Commit e78d1b0

Browse files
[OGUI-1813] Save objectTree separator position in local storage (#3188)
* Add local storage for panel separation distribution
1 parent 2e43b32 commit e78d1b0

File tree

3 files changed

+85
-2
lines changed

3 files changed

+85
-2
lines changed

QualityControl/public/common/enums/storageKeys.enum.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@
1818
* @readonly
1919
*/
2020
export const StorageKeysEnum = Object.freeze({
21+
OBJECT_VIEW_LEFT_PANEL_WIDTH: 'object-view-left-panel-width',
2122
OBJECT_VIEW_INFO_VISIBILITY_SETTING: 'object-view-info-visibility-setting',
2223
});

QualityControl/public/object/QCObject.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@
1212
* or submit itself to any jurisdiction.
1313
*/
1414

15-
import { RemoteData, iconArrowTop } from '/js/src/index.js';
15+
import { RemoteData, iconArrowTop, BrowserStorage } from '/js/src/index.js';
1616
import ObjectTree from './ObjectTree.class.js';
1717
import { prettyFormatDate, setBrowserTabTitle } from './../common/utils.js';
1818
import { isObjectOfTypeChecker } from './../library/qcObject/utils.js';
1919
import { BaseViewModel } from '../common/abstracts/BaseViewModel.js';
20+
import { StorageKeysEnum } from '../common/enums/storageKeys.enum.js';
2021

2122
/**
2223
* Model namespace for all about QC's objects (not javascript objects)
@@ -56,7 +57,18 @@ export default class QCObject extends BaseViewModel {
5657
this.scrollTop = 0;
5758
this.scrollHeight = 0;
5859

59-
this.leftPanelWidthPercent = 50;
60+
this._initializeLeftPanelWidth();
61+
}
62+
63+
/**
64+
* Initialize left panel width from local storage or set to default
65+
* @returns {undefined}
66+
*/
67+
_initializeLeftPanelWidth() {
68+
const DEFAULT_PANEL_WIDTH = 50;
69+
this.leftPanelWidthStorage = new BrowserStorage(StorageKeysEnum.OBJECT_VIEW_LEFT_PANEL_WIDTH);
70+
const storedWidth = this.leftPanelWidthStorage.getLocalItem(this.model.session.personid.toString());
71+
this.leftPanelWidthPercent = storedWidth ?? DEFAULT_PANEL_WIDTH;
6072
}
6173

6274
/**
@@ -65,6 +77,7 @@ export default class QCObject extends BaseViewModel {
6577
* @returns {undefined}
6678
*/
6779
setLeftPanelWidthPercent(widthPercent) {
80+
this.leftPanelWidthStorage.setLocalItem(this.model.session.personid.toString(), widthPercent);
6881
this.leftPanelWidthPercent = widthPercent;
6982
this.notify();
7083
}

QualityControl/test/public/pages/object-tree.test.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
import { strictEqual, ok, deepStrictEqual } from 'node:assert';
1515
import { delay } from '../../testUtils/delay.js';
16+
import { getLocalStorage } from '../../testUtils/localStorage.js';
17+
import { StorageKeysEnum } from '../../../public/common/enums/storageKeys.enum.js';
1618

1719
const OBJECT_TREE_PAGE_PARAM = '?page=objectTree';
1820
const SORTING_BUTTON_PATH = 'header > div > div > div:nth-child(3) > div > button';
@@ -79,6 +81,73 @@ export const objectTreePageTests = async (url, page, timeout = 5000, testParent)
7981
},
8082
);
8183

84+
await testParent.test(
85+
'should have default panel width of 50% when width is null in localStorage',
86+
{ timeout },
87+
async () => {
88+
const defaultValue = '50%';
89+
const panelWidth = await page.evaluate(() =>
90+
document.querySelector('section > div > div > div:nth-child(1)').style.width);
91+
const personId = await page.evaluate(() => window.model.session.personid);
92+
const storedPanelWidth = await getLocalStorage(
93+
page,
94+
`${StorageKeysEnum.OBJECT_VIEW_LEFT_PANEL_WIDTH}-${personId}`,
95+
);
96+
strictEqual(storedPanelWidth, null);
97+
strictEqual(panelWidth, defaultValue);
98+
},
99+
);
100+
101+
await testParent.test(
102+
'should change and store panel width when dragging the divider',
103+
{ timeout },
104+
async () => {
105+
const dragAmount = 35;
106+
const [container, divider] = await Promise.all([
107+
page.$('body > div.absolute-fill.flex-column > div > section'),
108+
page.$('section > div > div > div:nth-child(2)'),
109+
]);
110+
const [containerBB, dividerBB] = await Promise.all([container.boundingBox(), divider.boundingBox()]);
111+
112+
const centerX = dividerBB.x + dividerBB.width / 2;
113+
const centerY = dividerBB.y + dividerBB.height / 2;
114+
const targetX = containerBB.x + containerBB.width * (dragAmount / 100);
115+
116+
await page.mouse.move(centerX, centerY);
117+
await page.mouse.down();
118+
await page.mouse.move(targetX, centerY, { steps: 5 });
119+
await page.mouse.up();
120+
await delay(300);
121+
122+
const [personId, panelWidth] = await page.evaluate(() => [
123+
window.model.session.personid,
124+
document.querySelector('section > div > div > div:nth-child(1)').style.width,
125+
]);
126+
const storedWidth = await getLocalStorage(page, `${StorageKeysEnum.OBJECT_VIEW_LEFT_PANEL_WIDTH}-${personId}`);
127+
128+
strictEqual(panelWidth, `${dragAmount}%`);
129+
strictEqual(storedWidth, dragAmount.toString());
130+
},
131+
);
132+
133+
await testParent.test(
134+
'should maintain panel width from localStorage on page reload',
135+
{ timeout },
136+
async () => {
137+
const dragAmount = 35;
138+
await page.reload({ waitUntil: 'networkidle0' });
139+
await page.evaluate(() => document.querySelector('tr.object-selectable:nth-child(2)').click());
140+
await delay(500);
141+
await page.evaluate(() => document.querySelector('tr.object-selectable:nth-child(3)').click());
142+
await delay(500);
143+
await page.evaluate(() => document.querySelector('tr.object-selectable:nth-child(4)').click());
144+
await delay(1000);
145+
const panelWidth = await page.evaluate(() =>
146+
document.querySelector('section > div > div > div:nth-child(1)').style.width);
147+
strictEqual(panelWidth, `${dragAmount}%`);
148+
},
149+
);
150+
82151
await testParent.test(
83152
'should correctly render the path as first in the object info panel',
84153
{ timeout },

0 commit comments

Comments
 (0)