-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathBrowserRow.react.js
182 lines (177 loc) · 6.17 KB
/
BrowserRow.react.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
import Parse from 'parse';
import encode from 'parse/lib/browser/encode';
import React, { Component } from 'react';
import { formatDateTime } from 'lib/DateUtils';
import BrowserCell from 'components/BrowserCell/BrowserCell.react';
import styles from 'dashboard/Data/Browser/Browser.scss';
export default class BrowserRow extends Component {
shouldComponentUpdate(nextProps) {
const shallowVerifyProps = [
...new Set(Object.keys(this.props).concat(Object.keys(nextProps))),
].filter(propName => propName !== 'obj');
if (shallowVerifyProps.some(propName => this.props[propName] !== nextProps[propName])) {
return true;
}
const { obj } = this.props;
const { obj: nextObj } = nextProps;
const isRefDifferent = obj !== nextObj;
return isRefDifferent ? JSON.stringify(obj) !== JSON.stringify(nextObj) : isRefDifferent;
}
renderField(name, type, value, targetClass) {
if (!value) {
return '';
}
switch(type) {
case 'Date':
return formatDateTime(value, this.props.useLocalTime);
// ... other cases
}
}
render() {
const {
className,
columns,
currentCol,
isUnique,
obj,
onPointerClick,
onPointerCmdClick,
order,
readOnlyFields,
row,
rowValue,
rowWidth,
selection,
selectRow,
setCopyableValue,
selectedObjectId,
setSelectedObjectId,
callCloudFunction,
isPanelVisible,
setCurrent,
setEditing,
setRelation,
onEditSelectedRow,
setContextMenu,
onFilterChange,
markRequiredFieldRow,
onMouseDownRowCheckBox,
onMouseUpRowCheckBox,
onMouseOverRowCheckBox,
} = this.props;
const attributes = obj.attributes;
let requiredCols = [];
Object.entries(columns).reduce((acc, cur) => {
if (cur[1].required) {
acc.push(cur[0]);
}
return acc;
}, requiredCols);
// for dynamically changing required field on _User class
if (
obj.className === '_User' &&
(obj.get('username') !== undefined || obj.get('password') !== undefined)
) {
requiredCols = ['username', 'password'];
} else if (obj.className === '_User' && obj.get('authData') !== undefined) {
requiredCols = ['authData'];
}
return (
<div className={styles.tableRow} style={{ minWidth: rowWidth }}>
<span
className={styles.checkCell}
onMouseUp={onMouseUpRowCheckBox}
onMouseOver={() => onMouseOverRowCheckBox(obj.id)}
>
<input
type="checkbox"
checked={selection['*'] || selection[obj.id]}
onChange={e => selectRow(obj.id, e.target.checked)}
onMouseDown={(e) => onMouseDownRowCheckBox(e.target.checked)}
/>
</span>
{order.map(({ name, width, visible }, j) => {
if (!visible) {
return null;
}
const type = columns[name].type;
let attr = obj;
if (!isUnique) {
attr = attributes[name];
if (name === 'objectId') {
attr = obj.id;
} else if (name === 'ACL' && className === '_User' && !attr) {
attr = new Parse.ACL({
'*': { read: true },
[obj.id]: { read: true, write: true },
});
} else if (type === 'Relation' && !attr && obj.id) {
attr = new Parse.Relation(obj, name);
attr.targetClassName = columns[name].targetClass;
} else if (type === 'Array' || type === 'Object') {
// This is needed to avoid unwanted conversions of objects to Parse.Objects.
// "Parse._encoding" is responsible to convert Parse data into raw data.
// Since array and object are generic types, we want to render them the way
// they were stored in the database.
attr = encode(obj.get(name), undefined, true);
}
}
let hidden = false;
if (name === 'password' && className === '_User') {
hidden = true;
} else if (name === 'sessionToken') {
if (className === '_User' || className === '_Session') {
hidden = true;
}
}
const isRequired = requiredCols.includes(name);
return (
<BrowserCell
appId={this.props.appId}
key={name}
schema={this.props.schema}
simplifiedSchema={this.props.simplifiedSchema}
filters={this.props.filters}
className={className}
field={name}
row={row}
rowValue={rowValue}
col={j}
type={type}
readonly={isUnique || readOnlyFields.indexOf(name) > -1}
width={width}
current={currentCol === j}
onSelect={setCurrent}
onEditChange={setEditing}
onPointerClick={onPointerClick}
onPointerCmdClick={onPointerCmdClick}
onFilterChange={onFilterChange}
setRelation={setRelation}
objectId={obj.id}
value={attr}
hidden={hidden}
isRequired={isRequired}
markRequiredFieldRow={markRequiredFieldRow}
setCopyableValue={setCopyableValue}
selectedObjectId={selectedObjectId}
setSelectedObjectId={setSelectedObjectId}
isPanelVisible={isPanelVisible}
callCloudFunction={callCloudFunction}
setContextMenu={setContextMenu}
onEditSelectedRow={onEditSelectedRow}
showNote={this.props.showNote}
onRefresh={this.props.onRefresh}
scripts={this.props.scripts}
handleCellClick={this.props.handleCellClick}
selectedCells={this.props.selectedCells}
setShowAggregatedData={this.props.setShowAggregatedData}
setErrorAggregatedData={this.props.setErrorAggregatedData}
firstSelectedCell={this.props.firstSelectedCell}
useLocalTime={this.props.useLocalTime}
/>
);
})}
</div>
);
}
}