Skip to content

Commit 8d7f755

Browse files
feat: adds actions support in custom fields (#1041)
Co-authored-by: Hardeep Asrani <[email protected]>
1 parent 4a6071c commit 8d7f755

File tree

6 files changed

+98
-5
lines changed

6 files changed

+98
-5
lines changed

css/settings.css

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2027,7 +2027,8 @@ li.draggable-item .components-panel__body-toggle.components-button{
20272027
.fz-action-control .fz-hide-icon .components-panel__arrow {
20282028
display: none;
20292029
}
2030-
.tagify__filter-icon{
2030+
.tagify__filter-icon,
2031+
.fz-action-icon {
20312032
width: 19px;
20322033
height: 19px;
20332034
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none'%3E%3Cpath d='M14.5 13.8002C13.4 13.8002 12.4 14.5002 12.1 15.6002H4V17.0002H12.1C12.4 18.0002 13.4 18.8002 14.5 18.8002C15.6 18.8002 16.6 18.1002 16.9 17.0002H20V15.5002H16.9C16.6 14.5002 15.6 13.8002 14.5 13.8002ZM11.9 7.0002C11.6 6.0002 10.6 5.2002 9.5 5.2002C8.4 5.2002 7.4 6.0002 7.1 7.0002H4V8.5002H7.1C7.4 9.5002 8.4 10.3002 9.5 10.3002C10.6 10.3002 11.6 9.6002 11.9 8.5002H20V7.0002H11.9Z' fill='%23050505'/%3E%3C/svg%3E");
@@ -2488,6 +2489,25 @@ li.draggable-item .components-panel__body-toggle.components-button{
24882489
.fz-panel-tab .fz-panel-tab__content .components-base-control .components-datetime__timezone {
24892490
display: inline-block;
24902491
}
2492+
2493+
.fz-form-group .custom_fields .fz-form-group {
2494+
position: relative;
2495+
}
2496+
.fz-form-group .custom_fields .fz-form-group .fz-action-icon {
2497+
position: absolute;
2498+
top: 50%;
2499+
right: 2px;
2500+
cursor: pointer;
2501+
transform: translateY(-50%);
2502+
width: 40px;
2503+
height: 40px;
2504+
display: grid;
2505+
place-items: center;
2506+
}
2507+
.fz-form-group .custom_fields .fz-form-group .fz-action-icon.disabled {
2508+
pointer-events: none;
2509+
opacity: 0.5;
2510+
}
24912511
.fz-prompt-button {
24922512
gap: 7px;
24932513
display: flex;

includes/admin/feedzy-rss-feeds-actions.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,5 +597,15 @@ function() {
597597
}
598598
return $dom->saveHTML();
599599
}
600+
601+
/**
602+
* Get custom field value.
603+
*/
604+
private function custom_field() {
605+
if ( ! empty( $this->result ) ) {
606+
return $this->result;
607+
}
608+
return $this->default_value;
609+
}
600610
}
601611
}

includes/admin/feedzy-rss-feeds-import.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -428,8 +428,9 @@ public function feedzy_import_feed_options() {
428428
// maybe more options are required from pro?
429429
$pro_options = apply_filters( 'feedzy_metabox_options', array(), $post->ID );
430430

431-
$import_custom_fields = get_post_meta( $post->ID, 'imports_custom_fields', true );
432-
$import_feed_limit = get_post_meta( $post->ID, 'import_feed_limit', true );
431+
$import_custom_fields = get_post_meta( $post->ID, 'imports_custom_fields', true );
432+
$custom_fields_actions = get_post_meta( $post->ID, 'imports_custom_field_actions', true );
433+
$import_feed_limit = get_post_meta( $post->ID, 'import_feed_limit', true );
433434
if ( empty( $import_feed_limit ) ) {
434435
$import_feed_limit = 10;
435436
}
@@ -1991,7 +1992,11 @@ function( $term ) {
19911992
}
19921993
}
19931994

1994-
do_action( 'feedzy_import_extra', $job, $item_obj, $new_post_id, $import_errors, $import_info );
1995+
do_action( 'feedzy_import_extra', $job, $item_obj, $new_post_id, $import_errors, $import_info, array(
1996+
'translation_lang' => $import_translation_lang,
1997+
'language_code' => $language_code,
1998+
'item' => $item,
1999+
) );
19952000

19962001
if ( ! empty( $import_featured_img ) && 'attachment' !== $import_post_type ) {
19972002
$image_source_url = '';

includes/views/import-metabox-edit.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,8 @@ class="fz-switch-toggle" type="checkbox" value="yes"
572572
</div>
573573
<div class="fz-form-group">
574574
<input type="text" name="custom_vars_value[]" placeholder="<?php esc_html_e( 'Value', 'feedzy-rss-feeds' ); ?>" class="form-control" value="<?php echo esc_attr( $custom_field_value ); ?>" />
575+
<span class="fz-action-icon<?php echo empty( $custom_field_value ) ? ' disabled' : ''; ?>"></span>
576+
<input type="hidden" name="custom_vars_action[]" value="<?php echo isset( $custom_fields_actions[ $custom_field_key ] ) ? esc_attr( $custom_fields_actions[ $custom_field_key ] ) : ''; ?>">
575577
</div>
576578
<div class="remove-group">
577579
<button type="button" class="btn-remove-fields">

includes/views/js/import-metabox-edit.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
$(".custom_fields").append(html_row);
9797
$(".btn.btn-remove-fields").on("click", remove_row);
9898
initCustomFieldAutoComplete();
99+
document.dispatchEvent(new Event('feedzy_new_row_added'));
99100
return false;
100101
}
101102

@@ -659,7 +660,19 @@
659660
tagList.find( 'input:text' ).val( '' );
660661
}
661662
} );
662-
// Append import button.
663+
664+
$(document).on( 'input', 'input[name="custom_vars_value[]"]', function () {
665+
$(this)
666+
.next('.fz-action-icon')
667+
.toggleClass( 'disabled', $(this).val() === '' );
668+
669+
$(this)
670+
.parent( '.fz-form-group' )
671+
.find( 'input:hidden' )
672+
.attr( 'disabled', $(this).val() === '' );
673+
} );
674+
675+
// Append import button.
663676
$( feedzy.i10n.importButton ).insertAfter( $( '.page-title-action', document ) );
664677
$( $( '.page-title-action', document ) ).wrapAll( '<div class="fz-header-action"></div>' );
665678

js/ActionPopup/index.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ const ActionModal = () => {
4141
const [ editModeTag, setEditModeTag ] = useState(null);
4242
const [ isDisabledAddNew, setDisabledAddNew ] = useState(false);
4343
const [ isLoading, setLoading ] = useState(false);
44+
const [ currentCustomRow, setcurrentCustomRow ] = useState(null);
4445

4546
// Close the popup when click on outside the modal.
4647
const exitModalOnOutsideClick = useCallback(( e ) => {
@@ -111,6 +112,7 @@ const ActionModal = () => {
111112
setDisabledAddNew(false);
112113
setAction([]);
113114
setLoading(false);
115+
setcurrentCustomRow(null);
114116
};
115117
const hideIntroMessage = ( status ) => setHideMeg( status );
116118
const removeAction = ( index ) => {
@@ -195,6 +197,13 @@ const ActionModal = () => {
195197
setAction([]);
196198
_action = encodeURIComponent( JSON.stringify( [ { id: '', tag: shortCode, data: {} } ] ) );
197199
}
200+
if ( 'import_custom_field' === fieldName ) {
201+
if ( currentCustomRow ) {
202+
currentCustomRow.value = _action;
203+
}
204+
closeModal();
205+
return;
206+
}
198207

199208
const inputField = jQuery( `[name="feedzy_meta_data[${fieldName}]"]:is(textarea, input)` ).data('tagify');
200209

@@ -241,6 +250,38 @@ const ActionModal = () => {
241250
} );
242251
} );
243252

253+
// Init custom field actions.
254+
const initCustomFieldActions = () => {
255+
const customFieldElement = document.querySelectorAll( '.custom_fields .fz-action-icon' ) || [];
256+
if ( customFieldElement.length === 0 ) {
257+
return;
258+
}
259+
customFieldElement.forEach( actionButton => {
260+
actionButton.addEventListener( 'click', ( event ) => {
261+
event.preventDefault();
262+
if ( userRef.current ) {
263+
if ( ! userRef.current.attributes.meta.feedzy_hide_action_message ) {
264+
hideActionIntroMessage();
265+
} else {
266+
hideIntroMessage(true);
267+
}
268+
}
269+
270+
let editAction = event?.target?.nextElementSibling?.value || '';
271+
if ( editAction ) {
272+
editAction = JSON.parse( decodeURIComponent( editAction ) );
273+
setAction( () => ([...editAction.filter((e)=>{return e.id !== ''})]));
274+
}
275+
setShortCode( 'custom_field' );
276+
setFieldName( 'import_custom_field' );
277+
setcurrentCustomRow( event?.target?.nextElementSibling );
278+
openModal();
279+
} );
280+
} );
281+
};
282+
// Attach click event to the newly added custom field row.
283+
document.addEventListener( 'feedzy_new_row_added', initCustomFieldActions );
284+
244285
const initEditHooks = () => {
245286
if ( isLoading ) {
246287
return;
@@ -249,6 +290,7 @@ const ActionModal = () => {
249290
setTimeout( function() {
250291
const editActionElement = document.querySelectorAll( '.fz-content-action .tagify__filter-icon' ) || [];
251292
if ( editActionElement.length === 0 ) {
293+
initCustomFieldActions();
252294
initEditHooks();
253295
return;
254296
}
@@ -284,6 +326,7 @@ const ActionModal = () => {
284326
} );
285327
} );
286328
}
329+
initCustomFieldActions();
287330
}, 500 );
288331
};
289332
initEditHooks();

0 commit comments

Comments
 (0)