Skip to content

Commit

Permalink
(feat) column preference for data browser (parse-community#1625)
Browse files Browse the repository at this point in the history
  • Loading branch information
dblythy authored Nov 18, 2020
1 parent 2394ea9 commit 8c5155b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/dashboard/Data/Browser/Browser.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -1124,10 +1124,12 @@ class Browser extends DashboardView {
columnsObject[column.name] = column
});
// get ordered list of class columns
const columnPreferences = this.context.currentApp.columnPreference || {}
const columns = ColumnPreferences.getOrder(
columnsObject,
this.context.currentApp.applicationId,
className
className,
columnPreferences[className]
);
// extend columns with their type and targetClass properties
columns.forEach(column => {
Expand Down
13 changes: 9 additions & 4 deletions src/dashboard/Data/Browser/DataBrowser.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ export default class DataBrowser extends React.Component {
constructor(props, context) {
super(props, context);

const columnPreferences = context.currentApp.columnPreference || {}
let order = ColumnPreferences.getOrder(
props.columns,
context.currentApp.applicationId,
props.className
props.className,
columnPreferences[props.className]
);

this.state = {
order: order,
current: null,
Expand All @@ -52,10 +53,12 @@ export default class DataBrowser extends React.Component {

componentWillReceiveProps(props, context) {
if (props.className !== this.props.className) {
const columnPreferences = context.currentApp.columnPreference || {}
let order = ColumnPreferences.getOrder(
props.columns,
context.currentApp.applicationId,
props.className
props.className,
columnPreferences[props.className]
);
this.setState({
order: order,
Expand All @@ -65,10 +68,12 @@ export default class DataBrowser extends React.Component {
});
} else if (Object.keys(props.columns).length !== Object.keys(this.props.columns).length
|| (props.isUnique && props.uniqueField !== this.props.uniqueField)) {
const columnPreferences = context.currentApp.columnPreference || {}
let order = ColumnPreferences.getOrder(
props.columns,
context.currentApp.applicationId,
props.className
props.className,
columnPreferences[props.className]
);
this.setState({ order });
}
Expand Down
8 changes: 6 additions & 2 deletions src/lib/ColumnPreferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,12 @@ export function getColumnSort(sortBy, appId, className) {
return currentSort;
}

export function getOrder(cols, appId, className) {
export function getOrder(cols, appId, className, defaultPrefs) {

let prefs = getPreferences(appId, className) || [ { name: 'objectId', width: DEFAULT_WIDTH, visible: true } ];
if (defaultPrefs) {
prefs = defaultPrefs;
}
let order = [].concat(prefs);
let seen = {};
for (let i = 0; i < order.length; i++) {
Expand All @@ -83,7 +87,7 @@ export function getOrder(cols, appId, className) {
for (let name in cols) {
requested[name] = true;
if (!seen[name]) {
order.push({ name: name, width: DEFAULT_WIDTH, visible: true });
order.push({ name: name, width: DEFAULT_WIDTH, visible: !defaultPrefs });
seen[name] = true;
updated = true;
}
Expand Down
4 changes: 3 additions & 1 deletion src/lib/ParseApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ export default class ParseApp {
secondaryBackgroundColor,
supportedPushLocales,
preventSchemaEdits,
graphQLServerURL
graphQLServerURL,
columnPreference
}) {
this.name = appName;
this.createdAt = created_at ? new Date(created_at) : new Date();
Expand All @@ -69,6 +70,7 @@ export default class ParseApp {
this.supportedPushLocales = supportedPushLocales ? supportedPushLocales : [];
this.preventSchemaEdits = preventSchemaEdits || false;
this.graphQLServerURL = graphQLServerURL;
this.columnPreference = columnPreference;

if(!supportedPushLocales) {
console.warn('Missing push locales for \'' + appName + '\', see this link for details on setting localizations up. https://github.com/parse-community/parse-dashboard#configuring-localized-push-notifications');
Expand Down

0 comments on commit 8c5155b

Please sign in to comment.