From cfed36f0bc036235ec16c175ff6105196564442f Mon Sep 17 00:00:00 2001 From: sadakchap Date: Tue, 15 Jun 2021 21:14:14 +0530 Subject: [PATCH 1/7] get column preference correctly from localstorage --- src/dashboard/Data/Browser/Browser.react.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dashboard/Data/Browser/Browser.react.js b/src/dashboard/Data/Browser/Browser.react.js index 74422f9a41..2e31692619 100644 --- a/src/dashboard/Data/Browser/Browser.react.js +++ b/src/dashboard/Data/Browser/Browser.react.js @@ -455,7 +455,7 @@ class Browser extends DashboardView { } excludeFields(query, className) { - let columns = ColumnPreferences.getPreferences(this.props.params.appId, className); + let columns = ColumnPreferences.getPreferences(this.context.currentApp.applicationId, className); if (columns) { columns = columns.filter(clmn => !clmn.visible).map(clmn => clmn.name); for (let columnsKey in columns) { From 72ad884853ebbd08b2dacafefada2f7a7dddad38 Mon Sep 17 00:00:00 2001 From: sadakchap Date: Wed, 21 Jul 2021 07:54:18 +0530 Subject: [PATCH 2/7] refreshing after a column is marked visible --- .../ColumnsConfiguration/ColumnsConfiguration.react.js | 2 +- src/dashboard/Data/Browser/DataBrowser.react.js | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/components/ColumnsConfiguration/ColumnsConfiguration.react.js b/src/components/ColumnsConfiguration/ColumnsConfiguration.react.js index b4e6df4280..1f7aeb9deb 100644 --- a/src/components/ColumnsConfiguration/ColumnsConfiguration.react.js +++ b/src/components/ColumnsConfiguration/ColumnsConfiguration.react.js @@ -78,7 +78,7 @@ export default class ColumnsConfiguration extends React.Component { name, visible }; - handleColumnsOrder(updatedOrder); + handleColumnsOrder(updatedOrder, visible); }} handleColumnDragDrop={handleColumnDragDrop} /> })} diff --git a/src/dashboard/Data/Browser/DataBrowser.react.js b/src/dashboard/Data/Browser/DataBrowser.react.js index fb8431d23f..ea4784c658 100644 --- a/src/dashboard/Data/Browser/DataBrowser.react.js +++ b/src/dashboard/Data/Browser/DataBrowser.react.js @@ -87,7 +87,7 @@ export default class DataBrowser extends React.Component { document.body.removeEventListener('keydown', this.handleKey); } - updatePreferences(order) { + updatePreferences(order, shouldReload) { if (this.saveOrderTimeout) { clearTimeout(this.saveOrderTimeout); } @@ -95,6 +95,7 @@ export default class DataBrowser extends React.Component { let className = this.props.className; this.saveOrderTimeout = setTimeout(() => { ColumnPreferences.updatePreferences(order, appId, className) + shouldReload && this.props.onRefresh(); }, 1000); } @@ -262,9 +263,9 @@ export default class DataBrowser extends React.Component { this.setState({ contextMenuX, contextMenuY, contextMenuItems }); } - handleColumnsOrder(order) { + handleColumnsOrder(order, shouldReload) { this.setState({ order: [ ...order ] }, () => { - this.updatePreferences(order); + this.updatePreferences(order, shouldReload); }); } From 95f298fb614ea45abff0ec48dfe47fbbcdafc53b Mon Sep 17 00:00:00 2001 From: sadakchap Date: Wed, 18 Aug 2021 07:47:10 +0530 Subject: [PATCH 3/7] prevent request for always cached fields --- .../ColumnsConfiguration/ColumnsConfiguration.react.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/components/ColumnsConfiguration/ColumnsConfiguration.react.js b/src/components/ColumnsConfiguration/ColumnsConfiguration.react.js index f214a91d53..4d0d4ef243 100644 --- a/src/components/ColumnsConfiguration/ColumnsConfiguration.react.js +++ b/src/components/ColumnsConfiguration/ColumnsConfiguration.react.js @@ -84,7 +84,13 @@ export default class ColumnsConfiguration extends React.Component { name, visible }; - handleColumnsOrder(updatedOrder, visible); + let shouldReload = visible; + // these fields are always cached as they are never excluded from server + // therefore no need to make another request. + if (name === 'objectId' || name === 'createdAt' || name === 'updatedAt' || name === 'ACL') { + shouldReload = false; + } + handleColumnsOrder(updatedOrder, shouldReload); }} handleColumnDragDrop={handleColumnDragDrop} /> })} From 690e369400b957d40b90f294a2784ae8d770a9f3 Mon Sep 17 00:00:00 2001 From: sadakchap Date: Wed, 18 Aug 2021 07:55:30 +0530 Subject: [PATCH 4/7] prevent request for password at _User --- .../ColumnsConfiguration/ColumnsConfiguration.react.js | 3 +++ src/dashboard/Data/Browser/BrowserToolbar.react.js | 1 + 2 files changed, 4 insertions(+) diff --git a/src/components/ColumnsConfiguration/ColumnsConfiguration.react.js b/src/components/ColumnsConfiguration/ColumnsConfiguration.react.js index 4d0d4ef243..d53519b27f 100644 --- a/src/components/ColumnsConfiguration/ColumnsConfiguration.react.js +++ b/src/components/ColumnsConfiguration/ColumnsConfiguration.react.js @@ -90,6 +90,9 @@ export default class ColumnsConfiguration extends React.Component { if (name === 'objectId' || name === 'createdAt' || name === 'updatedAt' || name === 'ACL') { shouldReload = false; } + if (this.props.className === '_User' && name === 'password') { + shouldReload = false; + } handleColumnsOrder(updatedOrder, shouldReload); }} handleColumnDragDrop={handleColumnDragDrop} /> diff --git a/src/dashboard/Data/Browser/BrowserToolbar.react.js b/src/dashboard/Data/Browser/BrowserToolbar.react.js index 3cfe11679b..d200c01fb1 100644 --- a/src/dashboard/Data/Browser/BrowserToolbar.react.js +++ b/src/dashboard/Data/Browser/BrowserToolbar.react.js @@ -219,6 +219,7 @@ let BrowserToolbar = ({ handleColumnDragDrop={handleColumnDragDrop} order={order} disabled={isPendingEditCloneRows} + className={classNameForEditors} />
{onAddRow && ( From 3330ac958234275bf74055a2989b275bb8409fee Mon Sep 17 00:00:00 2001 From: sadakchap Date: Wed, 18 Aug 2021 11:50:08 +0530 Subject: [PATCH 5/7] set flag cached & making request if not cached --- .../ColumnsConfiguration.react.js | 3 +++ src/dashboard/Data/Browser/Browser.react.js | 1 + src/lib/ColumnPreferences.js | 17 +++++++++++++++-- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/components/ColumnsConfiguration/ColumnsConfiguration.react.js b/src/components/ColumnsConfiguration/ColumnsConfiguration.react.js index d53519b27f..cf500e7172 100644 --- a/src/components/ColumnsConfiguration/ColumnsConfiguration.react.js +++ b/src/components/ColumnsConfiguration/ColumnsConfiguration.react.js @@ -93,6 +93,9 @@ export default class ColumnsConfiguration extends React.Component { if (this.props.className === '_User' && name === 'password') { shouldReload = false; } + if (updatedOrder[index].cached) { + shouldReload = false; + } handleColumnsOrder(updatedOrder, shouldReload); }} handleColumnDragDrop={handleColumnDragDrop} /> diff --git a/src/dashboard/Data/Browser/Browser.react.js b/src/dashboard/Data/Browser/Browser.react.js index a1e58930b0..e365672f3e 100644 --- a/src/dashboard/Data/Browser/Browser.react.js +++ b/src/dashboard/Data/Browser/Browser.react.js @@ -681,6 +681,7 @@ class Browser extends DashboardView { for (let columnsKey in columns) { query.exclude(columns[columnsKey]); } + ColumnPreferences.updateCachedColumns(this.context.currentApp.applicationId, className); } } diff --git a/src/lib/ColumnPreferences.js b/src/lib/ColumnPreferences.js index 86324a6dc6..d994bde983 100644 --- a/src/lib/ColumnPreferences.js +++ b/src/lib/ColumnPreferences.js @@ -73,7 +73,7 @@ export function getColumnSort(sortBy, appId, className) { export function getOrder(cols, appId, className, defaultPrefs) { - let prefs = getPreferences(appId, className) || [ { name: 'objectId', width: DEFAULT_WIDTH, visible: true } ]; + let prefs = getPreferences(appId, className) || [ { name: 'objectId', width: DEFAULT_WIDTH, visible: true, cached: true } ]; if (defaultPrefs) { prefs = defaultPrefs; } @@ -87,7 +87,7 @@ export function getOrder(cols, appId, className, defaultPrefs) { for (let name in cols) { requested[name] = true; if (!seen[name]) { - order.push({ name: name, width: DEFAULT_WIDTH, visible: !defaultPrefs, required: cols[name]['required'] }); + order.push({ name: name, width: DEFAULT_WIDTH, visible: !defaultPrefs, required: cols[name]['required'], cached: !defaultPrefs }); seen[name] = true; updated = true; } @@ -100,6 +100,7 @@ export function getOrder(cols, appId, className, defaultPrefs) { // and updates the cached preferences. if (typeof visible === 'undefined') { order[i].visible = true; + order[i].cached = visible; updated = true; } // If "required" attribute is not defined, set it to false @@ -118,6 +119,18 @@ export function getOrder(cols, appId, className, defaultPrefs) { return filtered; } +export function updateCachedColumns(appId, className) { + let prefs = getPreferences(appId, className); + let order = [].concat(prefs); + + for (let col of order) { + let { visible } = col; + col.cached = visible; + } + updatePreferences(order, appId, className); + return order; +} + function path(appId, className) { return `ParseDashboard:${VERSION}:${appId}:${className}`; } From be940be2dc126eed2d917b9860ad121872dfea22 Mon Sep 17 00:00:00 2001 From: sadakchap Date: Wed, 18 Aug 2021 11:54:05 +0530 Subject: [PATCH 6/7] add cache flag for cached preferences --- src/lib/ColumnPreferences.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/lib/ColumnPreferences.js b/src/lib/ColumnPreferences.js index d994bde983..13bc46381b 100644 --- a/src/lib/ColumnPreferences.js +++ b/src/lib/ColumnPreferences.js @@ -94,7 +94,7 @@ export function getOrder(cols, appId, className, defaultPrefs) { } let filtered = []; for (let i = 0; i < order.length; i++) { - const { name, visible, required } = order[i]; + const { name, visible, required, cached } = order[i]; // If "visible" attribute is not defined, sets to true // and updates the cached preferences. @@ -103,6 +103,14 @@ export function getOrder(cols, appId, className, defaultPrefs) { order[i].cached = visible; updated = true; } + + // If "cached" attribute is not defined, set it to visible attr + // and updates the cached preferences. + if (typeof cached === 'undefined') { + order[i].cached = order[i].visible; + updated = true; + } + // If "required" attribute is not defined, set it to false if (typeof required === 'undefined') { order[i].required = false; From 95b02e7b8c362edbaec70b90f3d0155e75566656 Mon Sep 17 00:00:00 2001 From: sadakchap Date: Mon, 23 Aug 2021 08:25:28 +0530 Subject: [PATCH 7/7] refetch data on showAll columns --- .../ColumnsConfiguration/ColumnsConfiguration.react.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/components/ColumnsConfiguration/ColumnsConfiguration.react.js b/src/components/ColumnsConfiguration/ColumnsConfiguration.react.js index cf500e7172..f190d098fa 100644 --- a/src/components/ColumnsConfiguration/ColumnsConfiguration.react.js +++ b/src/components/ColumnsConfiguration/ColumnsConfiguration.react.js @@ -40,7 +40,14 @@ export default class ColumnsConfiguration extends React.Component { } showAll() { - this.props.handleColumnsOrder(this.props.order.map(order => ({ ...order, visible: true }))); + let shouldReload = false; + let updatedOrder = this.props.order.map(field => { + if (!shouldReload && !field.cached) { + shouldReload = true; + } + return { ...field, visible: true } + }); + this.props.handleColumnsOrder(updatedOrder, shouldReload); } hideAll() {