Skip to content

Commit 146ec5d

Browse files
authored
fix: Handle invalid pointers in Views results (#2891)
1 parent eef72bd commit 146ec5d

File tree

2 files changed

+57
-4
lines changed

2 files changed

+57
-4
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import Field from 'components/Field/Field.react';
2+
import Label from 'components/Label/Label.react';
3+
import Modal from 'components/Modal/Modal.react';
4+
import React from 'react';
5+
import TextInput from 'components/TextInput/TextInput.react';
6+
7+
export default function ViewValueDialog({ value, onClose }) {
8+
let stringValue;
9+
if (typeof value === 'object' && value !== null) {
10+
stringValue = JSON.stringify(value, null, 2);
11+
} else {
12+
stringValue = String(value);
13+
}
14+
return (
15+
<Modal
16+
type={Modal.Types.INFO}
17+
icon="visibility"
18+
title="Value"
19+
confirmText="Close"
20+
showCancel={false}
21+
onConfirm={onClose}
22+
>
23+
<Field label={<Label text="Value" />} input={<TextInput value={stringValue} multiline monospace disabled />} />
24+
</Modal>
25+
);
26+
}

src/dashboard/Data/Views/Views.react.js

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import DragHandle from 'components/DragHandle/DragHandle.react';
1212
import CreateViewDialog from './CreateViewDialog.react';
1313
import EditViewDialog from './EditViewDialog.react';
1414
import DeleteViewDialog from './DeleteViewDialog.react';
15+
import ViewValueDialog from './ViewValueDialog.react';
1516
import BrowserMenu from 'components/BrowserMenu/BrowserMenu.react';
1617
import MenuItem from 'components/BrowserMenu/MenuItem.react';
1718
import Separator from 'components/BrowserMenu/Separator.react';
@@ -48,6 +49,7 @@ class Views extends TableView {
4849
lastError: null,
4950
lastNote: null,
5051
loading: false,
52+
viewValue: null,
5153
};
5254
this.headersRef = React.createRef();
5355
this.noteTimeout = null;
@@ -149,7 +151,11 @@ class Views extends TableView {
149151
if (val.__type === 'Date') {
150152
type = 'Date';
151153
} else if (val.__type === 'Pointer') {
152-
type = 'Pointer';
154+
if (val.className && val.objectId) {
155+
type = 'Pointer';
156+
} else {
157+
type = 'Object';
158+
}
153159
} else if (val.__type === 'File') {
154160
type = 'File';
155161
} else if (val.__type === 'GeoPoint') {
@@ -264,7 +270,11 @@ class Views extends TableView {
264270
if (value.__type === 'Date') {
265271
type = 'Date';
266272
} else if (value.__type === 'Pointer') {
267-
type = 'Pointer';
273+
if (value.className && value.objectId) {
274+
type = 'Pointer';
275+
} else {
276+
type = 'Object';
277+
}
268278
} else if (value.__type === 'File') {
269279
type = 'File';
270280
} else if (value.__type === 'GeoPoint') {
@@ -290,8 +300,14 @@ class Views extends TableView {
290300
} else {
291301
content = String(value);
292302
}
303+
const isViewable = ['String', 'Number', 'Object'].includes(type);
304+
const cellProps = {};
305+
if (isViewable) {
306+
cellProps.onClick = () => this.handleValueClick(value);
307+
cellProps.style = { cursor: 'pointer' };
308+
}
293309
return (
294-
<td key={name} className={styles.cell}>
310+
<td key={name} className={styles.cell} {...cellProps}>
295311
{content}
296312
</td>
297313
);
@@ -435,7 +451,14 @@ class Views extends TableView {
435451

436452
renderExtras() {
437453
let extras = null;
438-
if (this.state.showCreate) {
454+
if (this.state.viewValue !== null) {
455+
extras = (
456+
<ViewValueDialog
457+
value={this.state.viewValue}
458+
onClose={() => this.setState({ viewValue: null })}
459+
/>
460+
);
461+
} else if (this.state.showCreate) {
439462
let classNames = [];
440463
if (this.props.schema?.data) {
441464
const classes = this.props.schema.data.get('classes');
@@ -534,6 +557,10 @@ class Views extends TableView {
534557
this.props.navigate(path);
535558
}
536559

560+
handleValueClick(value) {
561+
this.setState({ viewValue: value });
562+
}
563+
537564
showNote(message, isError) {
538565
if (!message) {
539566
return;

0 commit comments

Comments
 (0)