Skip to content

Commit 49cd9fc

Browse files
committed
feat: link pointers in views
1 parent 8825239 commit 49cd9fc

File tree

1 file changed

+41
-3
lines changed

1 file changed

+41
-3
lines changed

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

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ import Toolbar from 'components/Toolbar/Toolbar.react';
66
import Parse from 'parse';
77
import React from 'react';
88
import Notification from 'dashboard/Data/Browser/Notification.react';
9+
import Pill from 'components/Pill/Pill.react';
910
import CreateViewDialog from './CreateViewDialog.react';
1011
import * as ViewPreferences from 'lib/ViewPreferences';
12+
import generatePath from 'lib/generatePath';
1113
import { withRouter } from 'lib/withRouter';
1214
import subscribeTo from 'lib/subscribeTo';
1315
import { ActionTypes as SchemaActionTypes } from 'lib/stores/SchemaStore';
@@ -139,9 +141,33 @@ class Views extends TableView {
139141
renderRow(row) {
140142
return (
141143
<tr key={JSON.stringify(row)}>
142-
{this.state.order.map(({ name, width }) => (
143-
<td key={name} style={{ width: width + '%' }}>{String(row[name])}</td>
144-
))}
144+
{this.state.order.map(({ name, width }) => {
145+
const value = row[name];
146+
const type = this.state.columns[name]?.type;
147+
let content = '';
148+
if (type === 'Pointer' && value && value.className && value.objectId) {
149+
const id = value.objectId;
150+
const className = value.className;
151+
content = (
152+
<Pill
153+
value={id}
154+
followClick={true}
155+
onClick={() =>
156+
this.handlePointerClick({ className, id })
157+
}
158+
/>
159+
);
160+
} else if (type === 'Object') {
161+
content = JSON.stringify(value);
162+
} else {
163+
content = String(value);
164+
}
165+
return (
166+
<td key={name} style={{ width: width + '%' }}>
167+
{content}
168+
</td>
169+
);
170+
})}
145171
</tr>
146172
);
147173
}
@@ -222,6 +248,18 @@ class Views extends TableView {
222248
);
223249
}
224250

251+
handlePointerClick({ className, id, field = 'objectId' }) {
252+
const filters = JSON.stringify([
253+
{ field, constraint: 'eq', compareTo: id },
254+
]);
255+
this.props.navigate(
256+
generatePath(
257+
this.context,
258+
`browser/${className}?filters=${encodeURIComponent(filters)}`
259+
)
260+
);
261+
}
262+
225263
showNote(message, isError) {
226264
if (!message) {
227265
return;

0 commit comments

Comments
 (0)