From 87b1b8cd9b9e961b8edf86c4549ee01e87f8e336 Mon Sep 17 00:00:00 2001 From: efuller Date: Tue, 19 Nov 2024 10:53:17 -0500 Subject: [PATCH] Add in ability to hide columns --- assets/js/admin-settings/index.jsx | 4 +- assets/js/admin-settings/rule.jsx | 239 ++++++++++++++++------------- 2 files changed, 135 insertions(+), 108 deletions(-) diff --git a/assets/js/admin-settings/index.jsx b/assets/js/admin-settings/index.jsx index 148cf90b..dcb463a4 100644 --- a/assets/js/admin-settings/index.jsx +++ b/assets/js/admin-settings/index.jsx @@ -92,6 +92,7 @@ function AdminSettings() { */ const generateRule = (item, index) => { const hideFieldTypes = item.field === LINK_SECTIONS ? allFieldsButSections : sectionsOnly; + const hideColumns = item.field === LINK_SECTIONS ? ['field'] : []; return ( ); }; @@ -150,7 +152,7 @@ function AdminSettings() { {__('Taxonomy', 'apple-news')} {__('Term', 'apple-news')} - {__('Value', 'apple-news')} + {__('Section', 'apple-news')} {__('Delete?', 'apple-news')} diff --git a/assets/js/admin-settings/rule.jsx b/assets/js/admin-settings/rule.jsx index f03c6d62..e06b0a54 100644 --- a/assets/js/admin-settings/rule.jsx +++ b/assets/js/admin-settings/rule.jsx @@ -23,6 +23,7 @@ function Rule({ value, index, hideFieldTypes, + hideColumns, }) { const { fields, @@ -73,124 +74,148 @@ function Rule({ draggable onDragEnd={onDragEnd} > - - onUpdate('taxonomy', next)} - options={[ - { value: '', label: __('Select Taxonomy', 'apple-news') }, - ...Object.keys(taxonomies).map((tax) => ({ value: tax, label: tax })), - ]} - value={taxonomy} - /> - - - onUpdate('term_id', next)} - taxonomy={taxonomy} - termId={termId} - /> - - - onUpdate('field', next)} - options={getFieldTypes()} - value={field} - /> - - - {fieldType === 'contentGenerationType' ? ( - onUpdate('value', next)} - options={[ - { value: '', label: __('None', 'apple-news') }, - { value: 'AI', label: __('AI', 'apple-news') }, - ]} - value={value} - /> - ) : null} - {fieldType === 'sections' ? ( - onUpdate('value', next)} - options={[ - { value: '', label: __('Select Section', 'apple-news') }, - ...sections.map((sect) => ({ value: sect.id, label: sect.name })), - ]} - value={value} - /> - ) : null} - {fieldType === 'boolean-select' ? ( - onUpdate('value', next)} - options={[ - { value: '', label: __('Channel Default', 'apple-news') }, - { value: 'true', label: __('True', 'apple-news') }, - { value: 'false', label: __('False', 'apple-news') }, - ]} - value={value} - /> - ) : null} - {fieldType === 'boolean' ? ( - onUpdate('value', next.toString())} - /> - ) : null} - {fieldType === 'string' ? ( - onUpdate('value', next)} - value={value} - /> - ) : null} - {fieldType === 'themes' ? ( - onUpdate('value', next)} - options={[ - { value: '', label: __('Select Theme', 'apple-news') }, - ...themes.map((name) => ({ value: name, label: name })), - ]} - value={value} - /> - ) : null} - - - - + { + hideColumns.includes('taxonomy') + ? null + : ( + + onUpdate('taxonomy', next)} + options={[ + { value: '', label: __('Select Taxonomy', 'apple-news') }, + ...Object.keys(taxonomies).map((tax) => ({ value: tax, label: tax })), + ]} + value={taxonomy} + /> + + ) + } + { + hideColumns.includes('term') ? null : ( + + onUpdate('term_id', next)} + taxonomy={taxonomy} + termId={termId} + /> + + ) + } + { + hideColumns.includes('field') ? null : ( + + onUpdate('field', next)} + options={getFieldTypes()} + value={field} + /> + + ) + } + { + hideColumns.includes('value') ? null : ( + + {fieldType === 'contentGenerationType' ? ( + onUpdate('value', next)} + options={[ + { value: '', label: __('None', 'apple-news') }, + { value: 'AI', label: __('AI', 'apple-news') }, + ]} + value={value} + /> + ) : null} + {fieldType === 'sections' ? ( + onUpdate('value', next)} + options={[ + { value: '', label: __('Select Section', 'apple-news') }, + ...sections.map((sect) => ({ value: sect.id, label: sect.name })), + ]} + value={value} + /> + ) : null} + {fieldType === 'boolean-select' ? ( + onUpdate('value', next)} + options={[ + { value: '', label: __('Channel Default', 'apple-news') }, + { value: 'true', label: __('True', 'apple-news') }, + { value: 'false', label: __('False', 'apple-news') }, + ]} + value={value} + /> + ) : null} + {fieldType === 'boolean' ? ( + onUpdate('value', next.toString())} + /> + ) : null} + {fieldType === 'string' ? ( + onUpdate('value', next)} + value={value} + /> + ) : null} + {fieldType === 'themes' ? ( + onUpdate('value', next)} + options={[ + { value: '', label: __('Select Theme', 'apple-news') }, + ...themes.map((name) => ({ value: name, label: name })), + ]} + value={value} + /> + ) : null} + + ) + } + { + hideColumns.includes('delete') ? null : ( + + + + ) + } ); } Rule.defaultProps = { + hideColumns: [], hideFieldTypes: [], }; Rule.propTypes = { busy: PropTypes.bool.isRequired, field: PropTypes.string.isRequired, + hideColumns: PropTypes.arrayOf(PropTypes.string), hideFieldTypes: PropTypes.arrayOf(PropTypes.string), index: PropTypes.number.isRequired, onDelete: PropTypes.func.isRequired,