@@ -12,7 +12,11 @@ import SettingsModal from './settings-modal';
1212import FieldList from 'dfv/src/admin/edit-pod/main-tabs/field-list' ;
1313import { GROUP_PROP_TYPE_SHAPE } from 'dfv/src/config/prop-types' ;
1414
15- import { SAVE_STATUSES , DELETE_STATUSES } from 'dfv/src/store/constants' ;
15+ import {
16+ SAVE_STATUSES ,
17+ DUPLICATE_STATUSES ,
18+ DELETE_STATUSES ,
19+ } from 'dfv/src/store/constants' ;
1620
1721import './field-group.scss' ;
1822
@@ -31,8 +35,10 @@ const FieldGroup = ( props ) => {
3135 hasMovedFields,
3236 saveStatus,
3337 saveMessage,
38+ duplicateStatus,
3439 deleteStatus,
3540 resetGroupSaveStatus,
41+ duplicateGroup,
3642 deleteGroup,
3743 removeGroupFromPod,
3844 saveGroup,
@@ -48,6 +54,8 @@ const FieldGroup = ( props ) => {
4854 fields,
4955 } = group ;
5056
57+ const isDuplicating = DUPLICATE_STATUSES . DUPLICATING === duplicateStatus ;
58+ const hasDuplicateFailed = DUPLICATE_STATUSES . DUPLICATE_ERROR === duplicateStatus ;
5159 const isDeleting = DELETE_STATUSES . DELETING === deleteStatus ;
5260 const hasDeleteFailed = DELETE_STATUSES . DELETE_ERROR === deleteStatus ;
5361
@@ -129,6 +137,21 @@ const FieldGroup = ( props ) => {
129137 ) ;
130138 } ;
131139
140+ const onDuplicateGroupClick = ( event ) => {
141+ event . stopPropagation ( ) ;
142+
143+ if ( hasMovedFields ) {
144+ // eslint-disable-next-line no-alert
145+ alert (
146+ __ ( 'You moved fields outside of this group but did not save your changes to the Pod yet. To duplicate this Group, save changes for your Pod first.' , 'pods' ) ,
147+ ) ;
148+
149+ return ;
150+ }
151+
152+ duplicateGroup ( groupID , groupName ) ;
153+ } ;
154+
132155 const onDeleteGroupClick = ( event ) => {
133156 event . stopPropagation ( ) ;
134157
@@ -159,6 +182,8 @@ const FieldGroup = ( props ) => {
159182 classnames (
160183 'pods-field-group-wrapper' ,
161184 hasMoved && 'pods-field-group-wrapper--unsaved' ,
185+ isDuplicating && 'pods-field-group-wrapper--duplicating' ,
186+ hasDuplicateFailed && 'pods-field-group-wrapper--errored' ,
162187 isDeleting && 'pods-field-group-wrapper--deleting' ,
163188 hasDeleteFailed && 'pods-field-group-wrapper--errored' ,
164189 )
@@ -188,6 +213,12 @@ const FieldGroup = ( props ) => {
188213
189214 { groupLabel }
190215
216+ { hasDuplicateFailed ? (
217+ < div className = "pods-field-group_name__error" >
218+ { __ ( 'Duplication failed. Try again?' , 'pods' ) }
219+ </ div >
220+ ) : null }
221+
191222 { hasDeleteFailed ? (
192223 < div className = "pods-field-group_name__error" >
193224 { __ ( 'Delete failed. Try again?' , 'pods' ) }
@@ -223,6 +254,14 @@ const FieldGroup = ( props ) => {
223254 { __ ( 'Edit' , 'pods' ) }
224255 </ button >
225256 |
257+ < button
258+ className = "pods-field-group_button pods-field-group_duplicate"
259+ onClick = { ( event ) => onDuplicateGroupClick ( event ) }
260+ aria-label = { __ ( 'Duplicate this field group for the Pod' , 'pods' ) }
261+ >
262+ { __ ( 'Duplicate' , 'pods' ) }
263+ </ button >
264+ |
226265 < button
227266 className = "pods-field-group_button pods-field-group_delete"
228267 onClick = { onDeleteGroupClick }
@@ -305,9 +344,11 @@ FieldGroup.propTypes = {
305344 hasMovedFields : PropTypes . bool . isRequired ,
306345 saveStatus : PropTypes . string ,
307346 saveMessage : PropTypes . string ,
347+ duplicateStatus : PropTypes . string ,
308348 deleteStatus : PropTypes . string ,
309349
310350 toggleExpanded : PropTypes . func . isRequired ,
351+ duplicateGroup : PropTypes . func . isRequired ,
311352 deleteGroup : PropTypes . func . isRequired ,
312353 removeGroupFromPod : PropTypes . func . isRequired ,
313354 saveGroup : PropTypes . func . isRequired ,
0 commit comments