Skip to content

Commit 0236593

Browse files
committed
fix: use the shared hook
1 parent 458276b commit 0236593

File tree

2 files changed

+14
-96
lines changed

2 files changed

+14
-96
lines changed

packages/compass-crud/src/components/document-json-view-item.tsx

Lines changed: 7 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type HadronDocument from 'hadron-document';
33
import { css, KeylineCard } from '@mongodb-js/compass-components';
44

55
import JSONEditor, { type JSONEditorProps } from './json-editor';
6-
import { useContextMenuItems } from '@mongodb-js/compass-components';
6+
import { useDocumentItemContextMenu } from './use-document-item-context-menu';
77

88
const keylineCardStyles = css({
99
overflow: 'hidden',
@@ -41,53 +41,12 @@ const DocumentJsonViewItem: React.FC<DocumentJsonViewItemProps> = ({
4141
updateDocument,
4242
openInsertDocumentDialog,
4343
}) => {
44-
const ref = useContextMenuItems([
45-
{
46-
label: doc.expanded ? 'Collapse all fields' : 'Expand all fields',
47-
onAction: () => {
48-
if (doc.expanded) {
49-
doc.collapse();
50-
} else {
51-
doc.expand();
52-
}
53-
},
54-
},
55-
...(isEditable && !doc.editing
56-
? [
57-
{
58-
label: 'Edit document',
59-
onAction: () => {
60-
doc.startEditing();
61-
},
62-
},
63-
]
64-
: []),
65-
{
66-
label: 'Copy document',
67-
onAction: () => {
68-
copyToClipboard?.(doc);
69-
},
70-
},
71-
...(isEditable
72-
? [
73-
{
74-
label: 'Clone document...',
75-
onAction: () => {
76-
const clonedDoc = doc.generateObject({
77-
excludeInternalFields: true,
78-
});
79-
openInsertDocumentDialog?.(clonedDoc, true);
80-
},
81-
},
82-
{
83-
label: 'Delete document',
84-
onAction: () => {
85-
doc.markForDeletion();
86-
},
87-
},
88-
]
89-
: []),
90-
]);
44+
const ref = useDocumentItemContextMenu({
45+
doc,
46+
isEditable,
47+
copyToClipboard,
48+
openInsertDocumentDialog,
49+
});
9150

9251
return (
9352
<div ref={ref}>

packages/compass-crud/src/components/document-list-view-item.tsx

Lines changed: 7 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import type HadronDocument from 'hadron-document';
33
import { KeylineCard } from '@mongodb-js/compass-components';
44
import Document, { type DocumentProps } from './document';
5-
import { useContextMenuItems } from '@mongodb-js/compass-components';
5+
import { useDocumentItemContextMenu } from './use-document-item-context-menu';
66

77
export type DocumentListViewItemProps = {
88
doc: HadronDocument;
@@ -33,53 +33,12 @@ const DocumentListViewItem: React.FC<DocumentListViewItemProps> = ({
3333
updateDocument,
3434
openInsertDocumentDialog,
3535
}) => {
36-
const ref = useContextMenuItems([
37-
{
38-
label: doc.expanded ? 'Collapse all fields' : 'Expand all fields',
39-
onAction: () => {
40-
if (doc.expanded) {
41-
doc.collapse();
42-
} else {
43-
doc.expand();
44-
}
45-
},
46-
},
47-
...(isEditable && !doc.editing
48-
? [
49-
{
50-
label: 'Edit document',
51-
onAction: () => {
52-
doc.startEditing();
53-
},
54-
},
55-
]
56-
: []),
57-
{
58-
label: 'Copy document',
59-
onAction: () => {
60-
copyToClipboard?.(doc);
61-
},
62-
},
63-
...(isEditable
64-
? [
65-
{
66-
label: 'Clone document...',
67-
onAction: () => {
68-
const clonedDoc = doc.generateObject({
69-
excludeInternalFields: true,
70-
});
71-
openInsertDocumentDialog?.(clonedDoc, true);
72-
},
73-
},
74-
{
75-
label: 'Delete document',
76-
onAction: () => {
77-
doc.markForDeletion();
78-
},
79-
},
80-
]
81-
: []),
82-
]);
36+
const ref = useDocumentItemContextMenu({
37+
doc,
38+
isEditable,
39+
copyToClipboard,
40+
openInsertDocumentDialog,
41+
});
8342

8443
return (
8544
<div ref={ref}>

0 commit comments

Comments
 (0)