Skip to content

Commit 1ac104e

Browse files
committed
cleanup hook
1 parent b0944f7 commit 1ac104e

File tree

6 files changed

+34
-45
lines changed

6 files changed

+34
-45
lines changed

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { css } from '@leafygreen-ui/emotion';
66
import { palette } from '@leafygreen-ui/palette';
77
import { spacing } from '@leafygreen-ui/tokens';
88
import { useDarkMode } from '../../hooks/use-theme';
9-
import { useErrorDetailsModal } from '../../hooks/use-error-details';
9+
import { showErrorDetails } from '../../hooks/use-error-details';
1010

1111
type Status =
1212
| 'Initial'
@@ -304,8 +304,6 @@ const EditActionsFooter: React.FunctionComponent<{
304304

305305
const darkMode = useDarkMode();
306306

307-
const { showErrorDetails } = useErrorDetailsModal();
308-
309307
// Allow props to override event based status of the document (helpful for
310308
// JSON editor where changing the document text doesn't really generate any
311309
// changes of the HadronDocument)

packages/compass-components/src/hooks/use-confirmation.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { useContext, useEffect, useRef, useState } from 'react';
22
import { Variant as ConfirmationModalVariant } from '@leafygreen-ui/confirmation-modal';
33
import ConfirmationModal from '../components/modals/confirmation-modal';
44
import { css } from '@leafygreen-ui/emotion';
5+
import type { ButtonProps } from '@leafygreen-ui/button';
56

67
export { ConfirmationModalVariant };
78

@@ -11,6 +12,7 @@ type ConfirmationProperties = Partial<
1112
Pick<ConfirmationModalProps, 'title' | 'variant' | 'requiredInputText'>
1213
> & {
1314
buttonText?: React.ReactNode;
15+
confirmButtonProps?: Omit<ButtonProps, 'onClick'>;
1416
hideConfirmButton?: boolean;
1517
hideCancelButton?: boolean;
1618
description?: React.ReactNode;
@@ -191,6 +193,7 @@ export const ConfirmationModalArea: React.FC = ({ children }) => {
191193
: undefined,
192194
children: confirmationProps.buttonText ?? 'Confirm',
193195
onClick: handleConfirm,
196+
...confirmationProps.confirmButtonProps,
194197
}}
195198
cancelButtonProps={{
196199
className: confirmationProps.hideCancelButton

packages/compass-components/src/hooks/use-error-details.tsx

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import {
22
type showConfirmation as originalShowConfirmation,
33
showConfirmation,
4-
useConfirmationModal,
54
} from './use-confirmation';
65
import { Code } from '../components/leafygreen';
76
import React from 'react';
7+
import { ButtonVariant } from '..';
88

99
const getShowErrorDetails = (
1010
showConfirmation: typeof originalShowConfirmation
@@ -29,15 +29,10 @@ const getShowErrorDetails = (
2929
),
3030
hideCancelButton: true,
3131
buttonText: closeAction.replace(/\b\w/g, (c) => c.toUpperCase()),
32-
// modalProps
33-
// buttonProps
32+
confirmButtonProps: {
33+
variant: ButtonVariant.Default,
34+
},
3435
});
3536
};
3637

37-
export function useErrorDetailsModal() {
38-
const { showConfirmation } = useConfirmationModal();
39-
40-
return { showErrorDetails: getShowErrorDetails(showConfirmation) };
41-
}
42-
4338
export const showErrorDetails = getShowErrorDetails(showConfirmation);

packages/compass-components/src/index.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,7 @@ export {
182182
ConfirmationModalArea,
183183
showConfirmation,
184184
} from './hooks/use-confirmation';
185-
export {
186-
useErrorDetailsModal,
187-
showErrorDetails,
188-
} from './hooks/use-error-details';
185+
export { showErrorDetails } from './hooks/use-error-details';
189186
export {
190187
useHotkeys,
191188
formatHotkey,

packages/compass-crud/src/components/insert-document-dialog.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
SegmentedControl,
1212
SegmentedControlOption,
1313
spacing,
14-
useErrorDetailsModal,
14+
showErrorDetails,
1515
} from '@mongodb-js/compass-components';
1616

1717
import type { InsertCSFLEWarningBannerProps } from './insert-csfle-warning-banner';
@@ -141,8 +141,6 @@ const InsertDocumentDialog: React.FC<InsertDocumentDialogProps> = ({
141141
);
142142
const [insertInProgress, setInsertInProgress] = useState(false);
143143

144-
const { showErrorDetails } = useErrorDetailsModal();
145-
146144
const hasManyDocuments = useCallback(() => {
147145
let parsed: unknown;
148146
try {

packages/compass-crud/src/components/table-view/full-width-cell-renderer.tsx

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -129,32 +129,30 @@ class FullWidthCellRenderer extends React.Component<
129129
// this is needed cause ag-grid renders this component outside
130130
// of the context chain
131131
<LeafyGreenProvider darkMode={this.props.darkMode}>
132-
<ConfirmationModalArea>
133-
<DocumentList.DocumentEditActionsFooter
134-
doc={this.doc}
135-
editing={this.state.mode === 'editing'}
136-
deleting={this.state.mode === 'deleting'}
137-
onUpdate={(force) => {
138-
this.props.api.stopEditing();
139-
if (force) {
140-
this.props.replaceDocument(this.doc);
141-
} else {
142-
this.props.updateDocument(this.doc);
143-
}
144-
}}
145-
onDelete={() => {
146-
this.props.api.stopEditing();
147-
this.props.removeDocument(this.doc);
148-
}}
149-
onCancel={() => {
150-
if (this.state.mode === 'editing') {
151-
this.handleCancelUpdate();
152-
} else {
153-
this.handleCancelRemove();
154-
}
155-
}}
156-
/>
157-
</ConfirmationModalArea>
132+
<DocumentList.DocumentEditActionsFooter
133+
doc={this.doc}
134+
editing={this.state.mode === 'editing'}
135+
deleting={this.state.mode === 'deleting'}
136+
onUpdate={(force) => {
137+
this.props.api.stopEditing();
138+
if (force) {
139+
this.props.replaceDocument(this.doc);
140+
} else {
141+
this.props.updateDocument(this.doc);
142+
}
143+
}}
144+
onDelete={() => {
145+
this.props.api.stopEditing();
146+
this.props.removeDocument(this.doc);
147+
}}
148+
onCancel={() => {
149+
if (this.state.mode === 'editing') {
150+
this.handleCancelUpdate();
151+
} else {
152+
this.handleCancelRemove();
153+
}
154+
}}
155+
/>
158156
</LeafyGreenProvider>
159157
);
160158
}

0 commit comments

Comments
 (0)