Skip to content

Commit 569db4b

Browse files
authored
feat(preventSort): allow preventSort from columnPreferences props (#1709)
* feat(preventSort): allow preventSort from columnPreferences props * feat(preventSort): add doc section of prevent sorting
1 parent 9d0504b commit 569db4b

File tree

4 files changed

+47
-7
lines changed

4 files changed

+47
-7
lines changed

README.md

+28
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Parse Dashboard is a standalone dashboard for managing your [Parse Server](https
2323
* [App Icon Configuration](#app-icon-configuration)
2424
* [App Background Color Configuration](#app-background-color-configuration)
2525
* [Other Configuration Options](#other-configuration-options)
26+
* [Prevent columns sorting](#prevent-columns-sorting)
2627
* [Running as Express Middleware](#running-as-express-middleware)
2728
* [Deploying Parse Dashboard](#deploying-parse-dashboard)
2829
* [Preparing for Deployment](#preparing-for-deployment)
@@ -241,6 +242,33 @@ You can set `appNameForURL` in the config file for each app to control the url o
241242

242243
To change the app to production, simply set `production` to `true` in your config file. The default value is false if not specified.
243244

245+
### Prevent columns sorting
246+
247+
You can prevent some columns to be sortable by adding `preventSort` to columnPreference options in each app configuration
248+
249+
```json
250+
251+
"apps": [
252+
{
253+
"appId": "local_app_id",
254+
"columnPreference": {
255+
"_User": [
256+
{
257+
"name": "createdAt",
258+
"visible": true,
259+
"preventSort": true
260+
},
261+
{
262+
"name": "updatedAt",
263+
"visible": true,
264+
"preventSort": false
265+
},
266+
]
267+
}
268+
}
269+
]
270+
```
271+
244272
# Running as Express Middleware
245273

246274
Instead of starting Parse Dashboard with the CLI, you can also run it as an [express](https://github.com/expressjs/express) middleware.

src/components/DataBrowserHeaderBar/DataBrowserHeaderBar.react.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export default class DataBrowserHeaderBar extends React.Component {
2727
</div>
2828
];
2929

30-
headers.forEach(({ width, name, type, targetClass, order, visible }, i) => {
30+
headers.forEach(({ width, name, type, targetClass, order, visible, preventSort }, i) => {
3131
if (!visible) return;
3232
let wrapStyle = { width };
3333
if (i % 2) {
@@ -36,15 +36,20 @@ export default class DataBrowserHeaderBar extends React.Component {
3636
wrapStyle.background = '#66637A';
3737
}
3838
let onClick = null;
39-
if (type === 'String' || type === 'Number' || type === 'Date' || type === 'Boolean') {
39+
if (!preventSort && (type === 'String' || type === 'Number' || type === 'Date' || type === 'Boolean')) {
4040
onClick = () => updateOrdering((order === 'descending' ? '' : '-') + name);
4141
}
4242

43+
let className = styles.wrap;
44+
if (preventSort) {
45+
className += ` ${styles.preventSort} `;
46+
}
47+
4348
elements.push(
4449
<div
4550
onClick={onClick}
4651
key={'header' + i}
47-
className={styles.wrap}
52+
className={className}
4853
style={ wrapStyle }>
4954
<DataBrowserHeader
5055
name={name}
@@ -65,7 +70,7 @@ export default class DataBrowserHeaderBar extends React.Component {
6570
if (headers.length % 2) {
6671
finalStyle.background = 'rgba(224,224,234,0.10)';
6772
}
68-
73+
6974
elements.push(
7075
readonly || preventSchemaEdits ? null : (
7176
<div key='add' className={styles.addColumn} style={finalStyle}>

src/components/DataBrowserHeaderBar/DataBrowserHeaderBar.scss

+6
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,9 @@
7272
}
7373
}
7474
}
75+
76+
.preventSort {
77+
:hover {
78+
cursor: not-allowed;
79+
}
80+
}

src/dashboard/Data/Browser/BrowserTable.react.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,15 @@ export default class BrowserTable extends React.Component {
9898
}
9999
}
100100

101-
let headers = this.props.order.map(({ name, width, visible }) => (
101+
let headers = this.props.order.map(({ name, width, visible, preventSort }) => (
102102
{
103103
width: width,
104104
name: name,
105105
type: this.props.columns[name].type,
106106
targetClass: this.props.columns[name].targetClass,
107107
order: ordering.col === name ? ordering.direction : null,
108-
visible
108+
visible,
109+
preventSort
109110
}
110111
));
111112
let editor = null;
@@ -140,7 +141,7 @@ export default class BrowserTable extends React.Component {
140141
setRelation={this.props.setRelation}
141142
setCopyableValue={this.props.setCopyableValue}
142143
setContextMenu={this.props.setContextMenu}
143-
onEditSelectedRow={this.props.onEditSelectedRow}
144+
onEditSelectedRow={this.props.onEditSelectedRow}
144145
/>
145146
<Button
146147
value="Add"

0 commit comments

Comments
 (0)