Skip to content

Commit 5db8663

Browse files
committed
wip
1 parent 2690a3f commit 5db8663

File tree

4 files changed

+50
-12
lines changed

4 files changed

+50
-12
lines changed

packages/compass-components/src/components/document-list/document-edit-actions-footer.tsx

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, { useCallback, useEffect, useRef, useState } from 'react';
2+
import type { MongoServerError } from 'mongodb';
23
import type HadronDocument from 'hadron-document';
34
import { Element } from 'hadron-document';
45
import { Button } from '../leafygreen';
@@ -81,13 +82,26 @@ function useHadronDocumentStatus(
8182
? 'Deleting'
8283
: 'Initial';
8384
});
84-
const [errorMessage, setErrorMessage] = useState<string | null>(null);
85+
const [error, setError] = useState<{
86+
message: string;
87+
details?: Record<string, unknown>;
88+
} | null>(null);
8589
const invalidElementsRef = useRef(new Set());
8690

87-
const updateStatus = useCallback((newStatus: Status, errorMessage = null) => {
88-
setStatus(newStatus);
89-
setErrorMessage(errorMessage);
90-
}, []);
91+
const updateStatus = useCallback(
92+
(newStatus: Status, error: Error | MongoServerError | null = null) => {
93+
setStatus(newStatus);
94+
setError(
95+
error
96+
? {
97+
message: error?.message,
98+
details: (error as MongoServerError).errInfo,
99+
}
100+
: null
101+
);
102+
},
103+
[]
104+
);
91105

92106
useEffect(() => {
93107
if (status !== 'Initial') {
@@ -128,7 +142,7 @@ function useHadronDocumentStatus(
128142
const onUpdateSuccess = () => {
129143
updateStatus('UpdateSuccess');
130144
};
131-
const onUpdateError = (err: string) => {
145+
const onUpdateError = (err: Error | MongoServerError) => {
132146
updateStatus('UpdateError', err);
133147
};
134148
const onRemoveStart = () => {
@@ -137,7 +151,7 @@ function useHadronDocumentStatus(
137151
const onRemoveSuccess = () => {
138152
updateStatus('DeleteSuccess');
139153
};
140-
const onRemoveError = (err: string) => {
154+
const onRemoveError = (err: Error | MongoServerError) => {
141155
updateStatus('DeleteError', err);
142156
};
143157

@@ -183,7 +197,7 @@ function useHadronDocumentStatus(
183197
}
184198
}, [status, updateStatus]);
185199

186-
return { status, updateStatus, errorMessage };
200+
return { status, updateStatus, error };
187201
}
188202

189203
const container = css({
@@ -261,6 +275,7 @@ const EditActionsFooter: React.FunctionComponent<{
261275
onUpdate(force: boolean): void;
262276
onDelete(): void;
263277
onCancel?: () => void;
278+
onOpenErrorDetails?: (details: Record<string, unknown>) => void;
264279
}> = ({
265280
doc,
266281
editing,
@@ -271,11 +286,12 @@ const EditActionsFooter: React.FunctionComponent<{
271286
onUpdate,
272287
onDelete,
273288
onCancel,
289+
onOpenErrorDetails,
274290
}) => {
275291
const {
276292
status: _status,
277293
updateStatus,
278-
errorMessage,
294+
error,
279295
} = useHadronDocumentStatus(doc, editing, deleting);
280296

281297
const darkMode = useDarkMode();
@@ -303,7 +319,16 @@ const EditActionsFooter: React.FunctionComponent<{
303319
data-status={status}
304320
>
305321
<div className={message} data-testid="document-footer-message">
306-
{errorMessage ?? statusMessage}
322+
{error?.message ?? statusMessage}
323+
{error?.details && (
324+
<Button
325+
size="xsmall"
326+
onClick={() => onOpenErrorDetails?.(error?.details)}
327+
data-testid="insert-document-error-details-button"
328+
>
329+
VIEW ERROR DETAILS
330+
</Button>
331+
)}
307332
</div>
308333
{!isSuccess(status) && (
309334
<div className={buttonGroup}>

packages/compass-crud/src/components/editable-document.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,12 @@ class EditableDocument extends React.Component<
278278
onCancel={() => {
279279
this.handleCancel();
280280
}}
281+
onOpenErrorDetails={(details: Record<string, unknown>) => {
282+
this.props.openErrorDetailsDialog?.({
283+
details,
284+
closeAction: 'close',
285+
});
286+
}}
281287
/>
282288
);
283289
}
@@ -313,6 +319,7 @@ class EditableDocument extends React.Component<
313319
replaceDocument: PropTypes.func.isRequired,
314320
updateDocument: PropTypes.func.isRequired,
315321
openInsertDocumentDialog: PropTypes.func.isRequired,
322+
openErrorDetailsDialog: PropTypes.func.isRequired,
316323
copyToClipboard: PropTypes.func.isRequired,
317324
showInsights: PropTypes.bool,
318325
};

packages/compass-crud/src/stores/crud-store.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,11 @@ class CrudStoreImpl
705705
const nbsp = '\u00a0';
706706
error.message += ` (Updating fields whose names contain dots or start with $ require MongoDB${nbsp}5.0 or above.)`;
707707
}
708+
console.log(
709+
'updateDocument error',
710+
error,
711+
(error as MongoServerError).errInfo
712+
);
708713
doc.onUpdateError(error as Error);
709714
} else if (d) {
710715
doc.onUpdateSuccess(d);
@@ -803,6 +808,7 @@ class CrudStoreImpl
803808
'replace'
804809
);
805810
if (error) {
811+
console.log('replaceDocument error', error);
806812
doc.onUpdateError(error as Error);
807813
} else {
808814
doc.onUpdateSuccess(d);

packages/hadron-document/src/document.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ export class Document extends EventEmitter {
478478
}
479479

480480
onUpdateError(error: Error) {
481-
this.emit('update-error', error.message);
481+
this.emit('update-error', error);
482482
}
483483

484484
markForDeletion() {
@@ -505,7 +505,7 @@ export class Document extends EventEmitter {
505505
}
506506

507507
onRemoveError(error: Error) {
508-
this.emit('remove-error', error.message);
508+
this.emit('remove-error', error);
509509
}
510510

511511
setModifiedEJSONString(ejson: string | null) {

0 commit comments

Comments
 (0)