Skip to content

Commit 30eaf12

Browse files
committed
move details persistence to store
1 parent 4df230b commit 30eaf12

File tree

3 files changed

+10
-14
lines changed

3 files changed

+10
-14
lines changed

packages/compass-components/src/components/modals/error-details-modal.tsx

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect, useMemo, useRef, useState } from 'react';
1+
import React, { useMemo } from 'react';
22

33
import { css, cx } from '@leafygreen-ui/emotion';
44

@@ -29,13 +29,10 @@ function ErrorDetailsModal({
2929
open,
3030
...modalProps
3131
}: ErrorDetailsModalProps) {
32-
const [stringDetails, setStringDetails] = useState<string>('');
33-
34-
useEffect(() => {
35-
if (open) {
36-
setStringDetails(JSON.stringify(details, undefined, 2));
37-
}
38-
}, [details, open]);
32+
const prettyDetails = useMemo(
33+
() => JSON.stringify(details, undefined, 2),
34+
[details]
35+
);
3936

4037
return (
4138
<Modal
@@ -51,7 +48,7 @@ function ErrorDetailsModal({
5148
data-testid="error-details-json"
5249
id="error-details-json"
5350
>
54-
{stringDetails}
51+
{prettyDetails}
5552
</Code>
5653
</ModalBody>
5754
<ModalFooter

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,9 +1489,7 @@ describe('store', function () {
14891489
await openListener;
14901490

14911491
const closeListener = waitForState(store, (state) => {
1492-
expect(state.errorDetails).to.deep.equal({
1493-
isOpen: false,
1494-
});
1492+
expect(state.errorDetails.isOpen).to.be.false;
14951493
});
14961494

14971495
void store.closeErrorDetailsDialog();

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ export type EmittedAppRegistryEvents =
8484
export type ErrorDetailsDialogState =
8585
| {
8686
isOpen: false;
87-
details?: never;
88-
closeAction?: never;
87+
details?: Record<string, unknown>;
88+
closeAction?: 'back' | 'close';
8989
}
9090
| {
9191
isOpen: true;
@@ -987,6 +987,7 @@ class CrudStoreImpl
987987
closeErrorDetailsDialog() {
988988
this.setState({
989989
errorDetails: {
990+
...this.state.errorDetails,
990991
isOpen: false,
991992
},
992993
});

0 commit comments

Comments
 (0)