Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude hidden fields #1734

Merged
merged 12 commits into from
Aug 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions src/components/ColumnsConfiguration/ColumnsConfiguration.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -84,7 +91,19 @@ export default class ColumnsConfiguration extends React.Component {
name,
visible
};
handleColumnsOrder(updatedOrder);
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;
}
if (this.props.className === '_User' && name === 'password') {
shouldReload = false;
}
if (updatedOrder[index].cached) {
shouldReload = false;
}
handleColumnsOrder(updatedOrder, shouldReload);
}}
handleColumnDragDrop={handleColumnDragDrop} />
})}
Expand Down
3 changes: 2 additions & 1 deletion src/dashboard/Data/Browser/Browser.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -675,12 +675,13 @@ 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) {
query.exclude(columns[columnsKey]);
}
ColumnPreferences.updateCachedColumns(this.context.currentApp.applicationId, className);
}
}

Expand Down
1 change: 1 addition & 0 deletions src/dashboard/Data/Browser/BrowserToolbar.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ let BrowserToolbar = ({
handleColumnDragDrop={handleColumnDragDrop}
order={order}
disabled={isPendingEditCloneRows}
className={classNameForEditors}
/>
<div className={styles.toolbarSeparator} />
{onAddRow && (
Expand Down
7 changes: 4 additions & 3 deletions src/dashboard/Data/Browser/DataBrowser.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,15 @@ export default class DataBrowser extends React.Component {
document.body.removeEventListener('keydown', this.handleKey);
}

updatePreferences(order) {
updatePreferences(order, shouldReload) {
if (this.saveOrderTimeout) {
clearTimeout(this.saveOrderTimeout);
}
let appId = this.context.currentApp.applicationId;
let className = this.props.className;
this.saveOrderTimeout = setTimeout(() => {
ColumnPreferences.updatePreferences(order, appId, className)
shouldReload && this.props.onRefresh();
}, 1000);
}

Expand Down Expand Up @@ -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);
});
}

Expand Down
27 changes: 24 additions & 3 deletions src/lib/ColumnPreferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -87,21 +87,30 @@ 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;
}
}
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.
if (typeof visible === 'undefined') {
order[i].visible = true;
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;
Expand All @@ -118,6 +127,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}`;
}