Skip to content

Commit 4eac5f3

Browse files
cyrilchandelierflovilmart
authored andcommitted
Add preventSchemaEdits option to apps and hide or disable buttons to manipulate classes and columns (#960)
1 parent c8f0859 commit 4eac5f3

File tree

6 files changed

+39
-13
lines changed

6 files changed

+39
-13
lines changed

src/components/DataBrowserHeaderBar/DataBrowserHeaderBar.react.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default
1616
@DragDropContext(HTML5Backend)
1717
class DataBrowserHeaderBar extends React.Component {
1818
render() {
19-
let { headers, onResize, selectAll, onAddColumn, updateOrdering, readonly } = this.props;
19+
let { headers, onResize, selectAll, onAddColumn, updateOrdering, readonly, preventSchemaEdits } = this.props;
2020
let elements = [
2121
// Note: bulk checkbox is disabled as all rows are selected (not just visible ones due to current lazy loading implementation)
2222
// TODO: add bulk checking only visible rows
@@ -61,8 +61,9 @@ class DataBrowserHeaderBar extends React.Component {
6161
if (headers.length % 2) {
6262
finalStyle.background = 'rgba(224,224,234,0.10)';
6363
}
64+
6465
elements.push(
65-
readonly ? null : (
66+
readonly || preventSchemaEdits ? null : (
6667
<div key='add' className={styles.addColumn} style={finalStyle}>
6768
<a
6869
href='javascript:;'

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,16 @@ import subscribeTo from 'lib/subscribeTo';
3434
import * as ColumnPreferences from 'lib/ColumnPreferences';
3535
import * as queryString from 'query-string';
3636
import { Helmet } from 'react-helmet';
37+
import PropTypes from 'lib/PropTypes';
38+
import ParseApp from 'lib/ParseApp';
3739

3840
export default
3941
@subscribeTo('Schema', 'schema')
4042
class Browser extends DashboardView {
4143
constructor() {
4244
super();
4345
this.section = 'Core';
44-
this.subsection = 'Browser'
45-
this.action = new SidebarAction('Create a class', this.showCreateClass.bind(this));
46+
this.subsection = 'Browser';
4647
this.noteTimeout = null;
4748

4849
this.state = {
@@ -109,6 +110,11 @@ class Browser extends DashboardView {
109110
}
110111

111112
componentWillMount() {
113+
const { currentApp } = this.context;
114+
if (!currentApp.preventSchemaEdits) {
115+
this.action = new SidebarAction('Create a class', this.showCreateClass.bind(this));
116+
}
117+
112118
this.props.schema.dispatch(ActionTypes.FETCH)
113119
.then(() => this.handleFetchedSchema());
114120
if (!this.props.params.className && this.props.schema.data.get('classes')) {
@@ -1055,3 +1061,7 @@ class Browser extends DashboardView {
10551061
);
10561062
}
10571063
}
1064+
1065+
Browser.contextTypes = {
1066+
currentApp: PropTypes.instanceOf(ParseApp)
1067+
};

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import Parse from 'parse';
1515
import React from 'react';
1616
import styles from 'dashboard/Data/Browser/Browser.scss';
1717
import Button from 'components/Button/Button.react';
18+
import ParseApp from 'lib/ParseApp';
19+
import PropTypes from 'lib/PropTypes';
1820

1921
const MAX_ROWS = 60; // Number of rows to render at any time
2022
const ROW_HEIGHT = 31;
@@ -325,8 +327,14 @@ export default class BrowserTable extends React.Component {
325327
readonly={!!this.props.relation}
326328
handleDragDrop={this.props.handleHeaderDragDrop}
327329
onResize={this.props.handleResize}
328-
onAddColumn={this.props.onAddColumn} />
330+
onAddColumn={this.props.onAddColumn}
331+
preventSchemaEdits={this.context.currentApp.preventSchemaEdits} />
329332
</div>
330333
);
331334
}
332335
}
336+
337+
BrowserTable.contextTypes = {
338+
currentApp: PropTypes.instanceOf(ParseApp)
339+
};
340+

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ let BrowserToolbar = ({
4545
enableDeleteAllRows,
4646
enableExportClass,
4747
enableSecurityDialog,
48+
enableColumnManipulation,
49+
enableClassManipulation
4850
}) => {
4951
let selectionLength = Object.keys(selection).length;
5052
let details = [];
@@ -93,8 +95,8 @@ let BrowserToolbar = ({
9395
menu = (
9496
<BrowserMenu title='Edit' icon='edit-solid'>
9597
<MenuItem text='Add a row' onClick={onAddRow} />
96-
<MenuItem text='Add a column' onClick={onAddColumn} />
97-
<MenuItem text='Add a class' onClick={onAddClass} />
98+
{enableColumnManipulation ? <MenuItem text='Add a column' onClick={onAddColumn} /> : <noscript />}
99+
{enableClassManipulation ? <MenuItem text='Add a class' onClick={onAddClass} /> : <noscript />}
98100
<Separator />
99101
<MenuItem
100102
disabled={!selectionLength}
@@ -112,9 +114,9 @@ let BrowserToolbar = ({
112114
disabled={selectionLength === 0}
113115
text={selectionLength === 1 && !selection['*'] ? 'Delete this row' : 'Delete these rows'}
114116
onClick={() => onDeleteRows(selection)} />
115-
<MenuItem text='Delete a column' onClick={onRemoveColumn} />
117+
{enableColumnManipulation ? <MenuItem text='Delete a column' onClick={onRemoveColumn} /> : <noscript />}
116118
{enableDeleteAllRows ? <MenuItem text='Delete all rows' onClick={() => onDeleteRows({ '*': true })} /> : <noscript />}
117-
<MenuItem text='Delete this class' onClick={onDropClass} />
119+
{enableClassManipulation ? <MenuItem text='Delete this class' onClick={onDropClass} /> : <noscript />}
118120
{enableExportClass ? <Separator /> : <noscript />}
119121
{enableExportClass ? <MenuItem text='Export this data' onClick={onExport} /> : <noscript />}
120122
</BrowserMenu>

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import BrowserToolbar from 'dashboard/Data/Browser/BrowserToolbar.react'
1010
import * as ColumnPreferences from 'lib/ColumnPreferences';
1111
import ParseApp from 'lib/ParseApp';
1212
import React from 'react';
13-
import PropTypes from 'lib/PropTypes';
13+
import PropTypes from 'lib/PropTypes';
1414
import { SpecialClasses } from 'lib/Constants';
1515

1616
/**
@@ -189,6 +189,7 @@ export default class DataBrowser extends React.Component {
189189

190190
render() {
191191
let { className, ...other } = this.props;
192+
const { preventSchemaEdits } = this.context.currentApp;
192193
return (
193194
<div>
194195
<BrowserTable
@@ -206,9 +207,11 @@ export default class DataBrowser extends React.Component {
206207
className={SpecialClasses[className] || className}
207208
classNameForPermissionsEditor={className}
208209
setCurrent={this.setCurrent.bind(this)}
209-
enableDeleteAllRows={this.context.currentApp.serverInfo.features.schemas.clearAllDataFromClass}
210-
enableExportClass={this.context.currentApp.serverInfo.features.schemas.exportClass}
211-
enableSecurityDialog={this.context.currentApp.serverInfo.features.schemas.editClassLevelPermissions}
210+
enableDeleteAllRows={this.context.currentApp.serverInfo.features.schemas.clearAllDataFromClass && !preventSchemaEdits}
211+
enableExportClass={this.context.currentApp.serverInfo.features.schemas.exportClass && !preventSchemaEdits}
212+
enableSecurityDialog={this.context.currentApp.serverInfo.features.schemas.editClassLevelPermissions && !preventSchemaEdits}
213+
enableColumnManipulation={!preventSchemaEdits}
214+
enableClassManipulation={!preventSchemaEdits}
212215
{...other}/>
213216
</div>
214217
);

src/lib/ParseApp.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export default class ParseApp {
4242
primaryBackgroundColor,
4343
secondaryBackgroundColor,
4444
supportedPushLocales,
45+
preventSchemaEdits
4546
}) {
4647
this.name = appName;
4748
this.createdAt = created_at ? new Date(created_at) : new Date();
@@ -65,6 +66,7 @@ export default class ParseApp {
6566
this.primaryBackgroundColor=primaryBackgroundColor;
6667
this.secondaryBackgroundColor=secondaryBackgroundColor;
6768
this.supportedPushLocales = supportedPushLocales ? supportedPushLocales : [];
69+
this.preventSchemaEdits = preventSchemaEdits || false;
6870

6971
if(!supportedPushLocales) {
7072
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`);

0 commit comments

Comments
 (0)