@@ -17,10 +17,11 @@ import { UUID } from 'crypto';
17
17
import { SpreadsheetTabDefinition } from 'components/spreadsheet-view/types/spreadsheet.type' ;
18
18
import ColumnCreationDialog from './column-creation-dialog' ;
19
19
import { AppState } from 'redux/reducer' ;
20
- import { deleteSpreadsheetColumn } from 'services/study/study-config' ;
20
+ import { deleteSpreadsheetColumn , duplicateSpreadsheetColumn } from 'services/study/study-config' ;
21
21
22
22
const UPDATE = 'UPDATE' ;
23
23
const DELETE = 'DELETE' ;
24
+ const DUPLICATE = 'DUPLICATE' ;
24
25
25
26
const CUSTOM_COLUMNS_MENU_DEFINITION = [
26
27
{
@@ -31,6 +32,10 @@ const CUSTOM_COLUMNS_MENU_DEFINITION = [
31
32
id : DELETE ,
32
33
label : 'spreadsheet/custom_column/delete_custom_column' ,
33
34
} ,
35
+ {
36
+ id : DUPLICATE ,
37
+ label : 'spreadsheet/custom_column/duplicate_custom_column' ,
38
+ } ,
34
39
] ;
35
40
36
41
export interface ColumnMenuProps extends DialogMenuProps {
@@ -59,6 +64,19 @@ export const ColumnMenu: FunctionComponent<ColumnMenuProps> = ({
59
64
const [ confirmationDialogOpen , setConfirmationDialogOpen ] = useState ( false ) ;
60
65
const dispatch = useDispatch < AppDispatch > ( ) ;
61
66
67
+ const handleDuplicate = useCallback ( ( ) => {
68
+ if ( studyUuid && columnDefinition ?. id ) {
69
+ duplicateSpreadsheetColumn ( studyUuid , spreadsheetConfigUuid , columnDefinition . uuid )
70
+ . then ( )
71
+ . catch ( ( error ) => {
72
+ snackError ( {
73
+ messageTxt : error . message ,
74
+ headerId : 'spreadsheet/custom_column/duplicate_column_error' ,
75
+ } ) ;
76
+ } ) ;
77
+ }
78
+ } , [ columnDefinition , studyUuid , spreadsheetConfigUuid , snackError ] ) ;
79
+
62
80
const handleMenuItemClick = useCallback (
63
81
( option : { id : string ; label : string } ) => {
64
82
onClose ( ) ;
@@ -69,9 +87,12 @@ export const ColumnMenu: FunctionComponent<ColumnMenuProps> = ({
69
87
case DELETE :
70
88
setConfirmationDialogOpen ( true ) ;
71
89
break ;
90
+ case DUPLICATE :
91
+ handleDuplicate ( ) ;
92
+ break ;
72
93
}
73
94
} ,
74
- [ dialogOpen , onClose ]
95
+ [ dialogOpen , onClose , handleDuplicate ]
75
96
) ;
76
97
77
98
const handleValidate = useCallback ( ( ) => {
@@ -89,7 +110,7 @@ export const ColumnMenu: FunctionComponent<ColumnMenuProps> = ({
89
110
. catch ( ( error ) => {
90
111
snackError ( {
91
112
messageTxt : error . message ,
92
- headerTxt : 'spreadsheet/custom_column/delete_column_error' ,
113
+ headerId : 'spreadsheet/custom_column/delete_column_error' ,
93
114
} ) ;
94
115
} ) ;
95
116
}
0 commit comments