-
Notifications
You must be signed in to change notification settings - Fork 139
Expand file tree
/
Copy pathPointCard.jsx
More file actions
177 lines (169 loc) · 5.67 KB
/
PointCard.jsx
File metadata and controls
177 lines (169 loc) · 5.67 KB
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
import React from 'react';
import PropTypes from 'prop-types';
import { Card, CardContent, Grid, CardHeader, LinearProgress, Box } from '@mui/material';
import PointImage from './PointImage';
import { alpha } from '@mui/material';
import { useTheme } from '@mui/material/styles';
import Edit from '@mui/icons-material/Edit';
import IconButton from '@mui/material/IconButton';
import Tooltip from '@mui/material/Tooltip';
import Vectors from './PointVectors';
import { PayloadEditor } from './PayloadEditor';
import { DataGridList } from './DataGridList';
import { CopyButton } from '../Common/CopyButton';
import DeleteIcon from '@mui/icons-material/Delete';
import ConfirmationDialog from '../Common/ConfirmationDialog';
import { bigIntJSON } from '../../common/bigIntJSON';
const PointCard = (props) => {
const theme = useTheme();
const { onConditionChange, conditions } = props;
const [point, setPoint] = React.useState(props.point);
const [openPayloadEditor, setOpenPayloadEditor] = React.useState(false);
const [loading, setLoading] = React.useState(false);
const [openDeleteDialog, setOpenDeleteDialog] = React.useState(false);
const onPayloadEdit = (payload) => {
setPoint({ ...point, payload: structuredClone(payload) });
};
const deletePoint = async () => {
setLoading(true);
props.deletePoint(props.collectionName, [point.id]).then(() => {
setPoint(null);
setLoading(false);
});
};
if (!point) {
return null;
}
return (
<>
<Card
variant="dual"
sx={{
display: 'flex',
flexDirection: 'column',
height: '100%',
position: 'relative',
}}
>
{loading && (
<Box
sx={{
position: 'absolute',
left: 0,
right: 0,
top: 0,
}}
>
<LinearProgress />
</Box>
)}
<CardHeader
title={'Point ' + point.id}
subheader={point.score && `Score: ${point.score}`}
action={
<>
{Object.keys(point.payload).length === 0 && (
<Tooltip title="Add Payload" placement="left">
<IconButton aria-label="add payload" onClick={() => setOpenPayloadEditor(true)}>
<Edit />
</IconButton>
</Tooltip>
)}
<CopyButton
text={bigIntJSON.stringify(point)}
tooltip={'Copy point to clipboard'}
successMessage={'Point JSON copied to clipboard.'}
/>
<Tooltip title={'Delete point'} placement={'left'}>
<IconButton
aria-label={'delete point'}
onClick={() => {
setOpenDeleteDialog(true);
}}
>
<DeleteIcon color={'error'} />
</IconButton>
</Tooltip>
</>
}
/>
{Object.keys(point.payload).length > 0 && (
<>
<CardHeader
subheader={'Payload:'}
sx={{
flexGrow: 1,
background: alpha(theme.palette.primary.main, 0.05),
}}
action={
<>
<Tooltip title="Edit Payload" placement="left">
<IconButton aria-label="edit point payload" onClick={() => setOpenPayloadEditor(true)}>
<Edit />
</IconButton>
</Tooltip>
<CopyButton
text={bigIntJSON.stringify(point.payload)}
tooltip={'Copy payload to clipboard'}
successMessage={'Payload JSON copied to clipboard.'}
/>
</>
}
/>
<CardContent>
<Grid container display={'flex'}>
<Grid item xs my={1}>
<DataGridList
data={point.payload}
onConditionChange={onConditionChange}
conditions={conditions}
payloadSchema={props.payloadSchema}
/>
</Grid>
{point.payload && <PointImage data={point.payload} sx={{ ml: 2 }} />}
</Grid>
</CardContent>
</>
)}
<CardHeader
subheader={'Vectors:'}
sx={{
flexGrow: 1,
background: alpha(theme.palette.primary.main, 0.05),
}}
/>
<CardContent>{point?.vector && <Vectors point={point} onConditionChange={onConditionChange} />}</CardContent>
</Card>
<PayloadEditor
collectionName={props.collectionName}
point={point}
open={openPayloadEditor}
onClose={() => {
setOpenPayloadEditor(false);
}}
onSave={onPayloadEdit}
setLoading={setLoading}
client={props.client}
/>
<ConfirmationDialog
open={openDeleteDialog}
onClose={() => setOpenDeleteDialog(false)}
title={'Delete point ' + point.id}
content={`Are you sure you want to delete point with id ${point.id}?`}
warning={`This action cannot be undone.`}
actionName={'Delete'}
actionHandler={() => deletePoint()}
/>
</>
);
};
PointCard.propTypes = {
point: PropTypes.object.isRequired,
onConditionChange: PropTypes.func.isRequired,
conditions: PropTypes.array.isRequired,
collectionName: PropTypes.string.isRequired, // use params instead?
deletePoint: PropTypes.func.isRequired,
payloadSchema: PropTypes.object.isRequired,
client: PropTypes.object,
};
export default PointCard;