1- import React , { useMemo , useState } from 'react' ;
1+ import React , { useState } from 'react' ;
22import { connect } from 'react-redux' ;
3- import {
4- Menu ,
5- MenuItem ,
6- css ,
7- IconButton ,
8- Icon ,
9- palette ,
10- spacing ,
11- } from '@mongodb-js/compass-components' ;
3+ import { Menu , IconButton , Icon } from '@mongodb-js/compass-components' ;
124import {
135 addStage ,
146 removeStage ,
@@ -17,12 +9,7 @@ import {
179} from '../../modules/pipeline-builder/stage-editor' ;
1810import type { StoreStage } from '../../modules/pipeline-builder/stage-editor' ;
1911import type { RootState } from '../../modules' ;
20-
21- const menuItemStyles = css ( {
22- display : 'flex' ,
23- alignItems : 'center' ,
24- gap : spacing [ 2 ] ,
25- } ) ;
12+ import { OptionMenuItem } from './option-menu-item' ;
2613
2714export const OptionMenu = ( {
2815 index,
@@ -39,51 +26,6 @@ export const OptionMenu = ({
3926} ) => {
4027 const [ menuOpen , setMenuOpen ] = useState ( false ) ;
4128
42- const menuItems = useMemo ( ( ) => {
43- return [
44- {
45- label : 'Add stage after' ,
46- onClick : ( ) => {
47- onAddStageClick ( index ) ;
48- setMenuOpen ( false ) ;
49- } ,
50- icon : 'PlusWithCircle' ,
51- } ,
52- {
53- label : 'Add stage before' ,
54- onClick : ( ) => {
55- onAddStageClick ( index - 1 ) ;
56- setMenuOpen ( false ) ;
57- } ,
58- icon : 'PlusWithCircle' ,
59- } ,
60- {
61- label : 'Delete stage' ,
62- onClick : ( ) => {
63- onDeleteStageClick ( index ) ;
64- setMenuOpen ( false ) ;
65- } ,
66- icon : 'Trash' ,
67- } ,
68- {
69- label : 'Expand documents' ,
70- onClick : ( ) => {
71- onExpand ( index ) ;
72- setMenuOpen ( false ) ;
73- } ,
74- icon : 'ChevronDown' ,
75- } ,
76- {
77- label : 'Collapse documents' ,
78- onClick : ( ) => {
79- onCollapse ( index ) ;
80- setMenuOpen ( false ) ;
81- } ,
82- icon : 'ChevronUp' ,
83- } ,
84- ] ;
85- } , [ index , onAddStageClick , onDeleteStageClick , onExpand , onCollapse ] ) ;
86-
8729 return (
8830 < Menu
8931 open = { menuOpen }
@@ -105,18 +47,36 @@ export const OptionMenu = ({
10547 ) ;
10648 } }
10749 >
108- { menuItems . map ( ( item ) => (
109- < MenuItem
110- key = { item . label }
111- data-text = { item . label }
112- onClick = { item . onClick }
113- >
114- < div className = { menuItemStyles } >
115- < Icon color = { palette . gray . dark2 } glyph = { item . icon } size = "small" />
116- { item . label }
117- </ div >
118- </ MenuItem >
119- ) ) }
50+ < OptionMenuItem
51+ label = "Add stage after"
52+ icon = "PlusWithCircle"
53+ onClick = { ( ) => onAddStageClick ( index ) }
54+ setMenuOpen = { setMenuOpen }
55+ />
56+ < OptionMenuItem
57+ label = "Add stage before"
58+ icon = "PlusWithCircle"
59+ onClick = { ( ) => onAddStageClick ( index - 1 ) }
60+ setMenuOpen = { setMenuOpen }
61+ />
62+ < OptionMenuItem
63+ label = "Delete stage"
64+ icon = "Trash"
65+ onClick = { ( ) => onDeleteStageClick ( index ) }
66+ setMenuOpen = { setMenuOpen }
67+ />
68+ < OptionMenuItem
69+ label = "Expand documents"
70+ icon = "ChevronDown"
71+ onClick = { ( ) => onExpand ( index ) }
72+ setMenuOpen = { setMenuOpen }
73+ />
74+ < OptionMenuItem
75+ label = "Collapse documents"
76+ icon = "ChevronUp"
77+ onClick = { ( ) => onCollapse ( index ) }
78+ setMenuOpen = { setMenuOpen }
79+ />
12080 </ Menu >
12181 ) ;
12282} ;
0 commit comments