From 643aa8bb5d12e6b8cc2cda9e780c58c4849be1fa Mon Sep 17 00:00:00 2001 From: asizemore Date: Wed, 9 Oct 2024 18:03:19 -0400 Subject: [PATCH 01/11] remove defaultProps for CheckboxTree --- .../inputs/SelectTree/SelectTree.tsx | 2 +- .../checkboxes/CheckboxTree/CheckboxTree.tsx | 62 +++++++------------ 2 files changed, 25 insertions(+), 39 deletions(-) diff --git a/packages/libs/coreui/src/components/inputs/SelectTree/SelectTree.tsx b/packages/libs/coreui/src/components/inputs/SelectTree/SelectTree.tsx index 19cc9c7d6e..5c0286e98e 100644 --- a/packages/libs/coreui/src/components/inputs/SelectTree/SelectTree.tsx +++ b/packages/libs/coreui/src/components/inputs/SelectTree/SelectTree.tsx @@ -18,7 +18,7 @@ function SelectTree(props: SelectTreeProps) { ? props.currentList.join(', ') : props.buttonDisplayContent ); - const { selectedList, shouldCloseOnSelection, wrapPopover } = props; + const { selectedList = [], shouldCloseOnSelection, wrapPopover } = props; /** Used as a hack to "auto close" the popover when shouldCloseOnSelection is true */ const [key, setKey] = useState(''); diff --git a/packages/libs/coreui/src/components/inputs/checkboxes/CheckboxTree/CheckboxTree.tsx b/packages/libs/coreui/src/components/inputs/checkboxes/CheckboxTree/CheckboxTree.tsx index 0de3be1cef..97e3ab4c31 100644 --- a/packages/libs/coreui/src/components/inputs/checkboxes/CheckboxTree/CheckboxTree.tsx +++ b/packages/libs/coreui/src/components/inputs/checkboxes/CheckboxTree/CheckboxTree.tsx @@ -163,7 +163,7 @@ export type CheckboxTreeProps = { isSelectable?: boolean; /** List of selected nodes as represented by their ids, defaults to [ ] */ - selectedList: string[]; + selectedList?: string[]; /** * List of filtered nodes as represented by their ids used to determine isLeafVisible node status. @@ -183,7 +183,7 @@ export type CheckboxTreeProps = { /** Takes array of ids, thus encapsulates: selectAll, clearAll, selectDefault, selectCurrent (i.e. reset) */ - onSelectionChange: ChangeHandler; + onSelectionChange?: ChangeHandler; /** List of “current” ids, if omitted (undefined or null), then don’t display link */ currentList?: string[]; @@ -470,6 +470,9 @@ function applyPropsToStatefulTree( isLeafVisible: (id: string) => boolean, stateExpandedList?: string[] ) { + // set default vaule of selectedList to [] + selectedList = selectedList || []; + // if single-pick then trim selected list so at most 1 item present if (!isMultiPick && selectedList.length > 1) { console.warn( @@ -696,32 +699,38 @@ function CheckboxTree(props: CheckboxTreeProps) { tree, getNodeId, getNodeChildren, - searchTerm, - selectedList, + searchTerm = '', + selectedList = [], currentList, defaultList, - isSearchable, + expandedList = null, + isSearchable = false, isAdditionalFilterApplied, name, shouldExpandDescendantsWithOneChild, onExpansionChange, - isSelectable, - isMultiPick, - onSelectionChange, - showRoot, + onSelectionChange = () => { + // + }, + isSelectable = false, + isMultiPick = true, + showRoot = false, additionalActions, linksPosition = LinksPosition.Both, - showSearchBox, + showSearchBox = true, autoFocusSearchBox, - onSearchTermChange, - searchBoxPlaceholder, + onSearchTermChange = () => { + // + }, + searchBoxPlaceholder = 'Search...', searchIconName, searchIconPosition, - searchBoxHelp, + searchBoxHelp = '', + searchPredicate = () => true, additionalFilters, wrapTreeSection, shouldExpandOnClick = true, - customCheckboxes, + customCheckboxes = {}, renderNoResults, styleOverrides = {}, customTreeNodeCssSelectors = {}, @@ -765,7 +774,7 @@ function CheckboxTree(props: CheckboxTreeProps) { * Creates a function that will handle selection-related tree link clicks */ function createSelector(listFetcher: ListFetcher) { - return createLinkHandler(listFetcher, props.onSelectionChange); + return createLinkHandler(listFetcher, onSelectionChange); } // define event handlers related to expansion @@ -1071,29 +1080,6 @@ function defaultRenderNoResults() { ); } -const defaultProps = { - showRoot: false, - expandedList: null, - isSelectable: false, - selectedList: [], - customCheckboxes: {}, - isMultiPick: true, - onSelectionChange: () => { - /* */ - }, - isSearchable: false, - showSearchBox: true, - searchBoxPlaceholder: 'Search...', - searchBoxHelp: '', - searchTerm: '', - onSearchTermChange: () => { - /* */ - }, - searchPredicate: () => true, - linksPosition: LinksPosition.Both, -}; - -CheckboxTree.defaultProps = defaultProps; CheckboxTree.LinkPlacement = LinksPosition; export default CheckboxTree; From 424d980c0d5858cc1282dd480ffe6fc7b3508a34 Mon Sep 17 00:00:00 2001 From: asizemore Date: Fri, 11 Oct 2024 08:45:34 -0400 Subject: [PATCH 02/11] remove defaultProps from SelectTree --- .../inputs/SelectTree/SelectTree.tsx | 74 +++---------------- 1 file changed, 10 insertions(+), 64 deletions(-) diff --git a/packages/libs/coreui/src/components/inputs/SelectTree/SelectTree.tsx b/packages/libs/coreui/src/components/inputs/SelectTree/SelectTree.tsx index 5c0286e98e..410d57356b 100644 --- a/packages/libs/coreui/src/components/inputs/SelectTree/SelectTree.tsx +++ b/packages/libs/coreui/src/components/inputs/SelectTree/SelectTree.tsx @@ -13,12 +13,18 @@ export interface SelectTreeProps extends CheckboxTreeProps { } function SelectTree(props: SelectTreeProps) { + const { + shouldCloseOnSelection, + wrapPopover, + currentList, + selectedList = [], + } = props; + const [buttonDisplayContent, setButtonDisplayContent] = useState( - props.currentList && props.currentList.length - ? props.currentList.join(', ') + currentList && currentList.length + ? currentList.join(', ') : props.buttonDisplayContent ); - const { selectedList = [], shouldCloseOnSelection, wrapPopover } = props; /** Used as a hack to "auto close" the popover when shouldCloseOnSelection is true */ const [key, setKey] = useState(''); @@ -35,47 +41,7 @@ function SelectTree(props: SelectTreeProps) { ); }; - const checkboxTree = ( - - ); + const checkboxTree = ; return ( (props: SelectTreeProps) { ); } -const defaultProps = { - showRoot: false, - expandedList: null, - isSelectable: false, - selectedList: [], - customCheckboxes: {}, - isMultiPick: true, - onSelectionChange: () => {}, - isSearchable: false, - showSearchBox: true, - searchBoxPlaceholder: 'Search...', - searchBoxHelp: '', - searchTerm: '', - onSearchTermChange: () => {}, - searchPredicate: () => true, - linksPosition: LinksPosition.Both, - isDisabled: false, -}; - -SelectTree.defaultProps = defaultProps; SelectTree.LinkPlacement = LinksPosition; export default SelectTree; From 081fb80d212dcecbef29dfb851854d0000199380 Mon Sep 17 00:00:00 2001 From: asizemore Date: Fri, 11 Oct 2024 10:30:11 -0400 Subject: [PATCH 03/11] remove defaultProps from FieldFilter --- .../src/Components/AttributeFilter/FieldFilter.jsx | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/packages/libs/wdk-client/src/Components/AttributeFilter/FieldFilter.jsx b/packages/libs/wdk-client/src/Components/AttributeFilter/FieldFilter.jsx index 419eb09954..36a0b7e514 100644 --- a/packages/libs/wdk-client/src/Components/AttributeFilter/FieldFilter.jsx +++ b/packages/libs/wdk-client/src/Components/AttributeFilter/FieldFilter.jsx @@ -12,12 +12,14 @@ const cx = makeClassNameHelper('field-detail'); * Main interactive filtering interface for a particular field. */ function FieldFilter(props) { + const { displayName = 'Items' } = props; + let className = cx('', props.hideFieldPanel && 'fullWidth'); return (
{!props.activeField ? ( - + ) : (

@@ -48,9 +50,9 @@ function FieldFilter(props) { props.activeFieldState.summary == null && props.activeFieldState.leafSummaries == null) || props.dataCount == null ? null : isMulti(props.activeField) ? ( - + ) : ( - + )} )} @@ -95,8 +97,4 @@ FieldFilter.propTypes = { selectByDefault: PropTypes.bool.isRequired, }; -FieldFilter.defaultProps = { - displayName: 'Items', -}; - export default FieldFilter; From 1fe8bc7413dd2ac839a497a9256f2b07cc25a05e Mon Sep 17 00:00:00 2001 From: asizemore Date: Fri, 11 Oct 2024 10:30:43 -0400 Subject: [PATCH 04/11] create a shared defaultCheckboxTreeProps --- .../checkboxes/CheckboxTree/CheckboxTree.tsx | 48 +++++++++++++------ 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/packages/libs/coreui/src/components/inputs/checkboxes/CheckboxTree/CheckboxTree.tsx b/packages/libs/coreui/src/components/inputs/checkboxes/CheckboxTree/CheckboxTree.tsx index 97e3ab4c31..c8a93a7232 100644 --- a/packages/libs/coreui/src/components/inputs/checkboxes/CheckboxTree/CheckboxTree.tsx +++ b/packages/libs/coreui/src/components/inputs/checkboxes/CheckboxTree/CheckboxTree.tsx @@ -194,7 +194,7 @@ export type CheckboxTreeProps = { //%%%%%%%%%%% Properties associated with search %%%%%%%%%%% /** Indicates whether this is a searchable CBT. If so, then show boxes and respect the optional parameters below, also turn off expansion; default to false */ - isSearchable: boolean; + isSearchable?: boolean; /** Indicates if the search box should have autoFocus set to true */ autoFocusSearchBox?: boolean; @@ -203,7 +203,7 @@ export type CheckboxTreeProps = { showSearchBox?: boolean; /** PlaceHolder text; shown in grey if searchTerm is empty */ - searchBoxPlaceholder: string; + searchBoxPlaceholder?: string; /** Name of icon to show in search box */ searchIconName?: 'search' | 'filter'; @@ -215,13 +215,13 @@ export type CheckboxTreeProps = { searchBoxHelp?: string; /** Current search term; if non-empty, expandability is disabled */ - searchTerm: string; + searchTerm?: string; /** Takes single arg: the new search text. Called when user types into the search box */ - onSearchTermChange: (term: string) => void; + onSearchTermChange?: (term: string) => void; /** Takes (node, searchTerms) and returns boolean. searchTerms is a list of query terms, parsed from the original input string. This function returns a boolean indicating if a node matches search criteria and should be shown */ - searchPredicate: (node: T, terms: string[]) => boolean; + searchPredicate?: (node: T, terms: string[]) => boolean; renderNoResults?: (searchTerm: string, tree: T) => React.ReactNode; @@ -247,6 +247,29 @@ export type CheckboxTreeProps = { customTreeNodeCssSelectors?: object; }; +// Default values. Used across multiple functions in this file. +const defaultCheckboxTreeProps = { + showRoot: false, + expandedList: null, + isSelectable: false, + selectedList: [], + customCheckboxes: {}, + isMultiPick: true, + onSelectionChange: () => { + /* */ + }, + isSearchable: false, + showSearchBox: true, + searchBoxPlaceholder: 'Search...', + searchBoxHelp: '', + searchTerm: '', + onSearchTermChange: () => { + /* */ + }, + searchPredicate: () => true, + linksPosition: LinksPosition.Both, +}; + type TreeLinkHandler = MouseEventHandler; type TreeLinksProps = { @@ -464,15 +487,12 @@ function applyPropsToStatefulTree( isSearchable: CheckboxTreeProps['isSearchable'], isMultiPick: CheckboxTreeProps['isMultiPick'], searchTerm: CheckboxTreeProps['searchTerm'], - selectedList: CheckboxTreeProps['selectedList'], + selectedList: CheckboxTreeProps['selectedList'] = defaultCheckboxTreeProps.selectedList, propsExpandedList: CheckboxTreeProps['expandedList'], isAdditionalFilterApplied: CheckboxTreeProps['isAdditionalFilterApplied'], isLeafVisible: (id: string) => boolean, stateExpandedList?: string[] ) { - // set default vaule of selectedList to [] - selectedList = selectedList || []; - // if single-pick then trim selected list so at most 1 item present if (!isMultiPick && selectedList.length > 1) { console.warn( @@ -593,8 +613,8 @@ function applyPropsToStatefulTree( */ function isActiveSearch( isAdditionalFilterApplied: CheckboxTreeProps['isAdditionalFilterApplied'], - isSearchable: CheckboxTreeProps['isSearchable'], - searchTerm: CheckboxTreeProps['searchTerm'] + isSearchable: CheckboxTreeProps['isSearchable'] = defaultCheckboxTreeProps.isSearchable, + searchTerm: CheckboxTreeProps['searchTerm'] = defaultCheckboxTreeProps.searchTerm ) { return isSearchable && isFiltered(searchTerm, isAdditionalFilterApplied); } @@ -629,12 +649,12 @@ function isFiltered(searchTerm: string, isAdditionalFilterApplied?: boolean) { */ function createIsLeafVisible( tree: CheckboxTreeProps['tree'], - searchTerm: CheckboxTreeProps['searchTerm'], - searchPredicate: CheckboxTreeProps['searchPredicate'], + searchTerm: CheckboxTreeProps['searchTerm'] = defaultCheckboxTreeProps.searchTerm, + searchPredicate: CheckboxTreeProps['searchPredicate'] = defaultCheckboxTreeProps.searchPredicate, getNodeId: CheckboxTreeProps['getNodeId'], getNodeChildren: CheckboxTreeProps['getNodeChildren'], isAdditionalFilterApplied: CheckboxTreeProps['isAdditionalFilterApplied'], - isSearchable: CheckboxTreeProps['isSearchable'], + isSearchable: CheckboxTreeProps['isSearchable'] = defaultCheckboxTreeProps.isSearchable, filteredList: CheckboxTreeProps['filteredList'] ) { // if not searching, if no additional filters are applied, and if filteredList is undefined, then all nodes are visible From 52768af74e75c09027696e80856b28743b00a793 Mon Sep 17 00:00:00 2001 From: asizemore Date: Fri, 11 Oct 2024 10:50:46 -0400 Subject: [PATCH 05/11] remove defaultProps from ServerSideAttributeFilter --- .../ServerSideAttributeFilter.jsx | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/packages/libs/wdk-client/src/Components/AttributeFilter/ServerSideAttributeFilter.jsx b/packages/libs/wdk-client/src/Components/AttributeFilter/ServerSideAttributeFilter.jsx index 044bf7d451..0259cb4011 100644 --- a/packages/libs/wdk-client/src/Components/AttributeFilter/ServerSideAttributeFilter.jsx +++ b/packages/libs/wdk-client/src/Components/AttributeFilter/ServerSideAttributeFilter.jsx @@ -10,7 +10,16 @@ import FieldFilter from '../../Components/AttributeFilter/FieldFilter'; * Filtering UI for server-side filtering. */ function ServerSideAttributeFilter(props) { - var { displayName, fieldTree, hideFilterPanel, hideFieldPanel } = props; + const { + fieldTree, + displayName = 'Items', + hideFilterPanel = false, + hideFieldPanel = false, + hideGlobalCounts = false, + selectByDefault = false, + histogramScaleYAxisDefault = true, + histogramTruncateYAxisDefault = false, + } = props; if (fieldTree == null) { return

Data is not available for {displayName}.

; @@ -79,16 +88,6 @@ ServerSideAttributeFilter.propTypes = { onRangeScaleChange: PropTypes.func.isRequired, }; -ServerSideAttributeFilter.defaultProps = { - displayName: 'Items', - hideFilterPanel: false, - hideFieldPanel: false, - hideGlobalCounts: false, - selectByDefault: false, - histogramScaleYAxisDefault: true, - histogramTruncateYAxisDefault: false, -}; - export default wrappable(ServerSideAttributeFilter); export function withOptions(options) { From cb4a3e4287549ac2972dbf7e2176ee6820c5c65e Mon Sep 17 00:00:00 2001 From: asizemore Date: Fri, 11 Oct 2024 16:50:40 -0400 Subject: [PATCH 06/11] remove more defaultProps --- .../src/Views/Records/RecordActionLink.jsx | 30 +++++++++---------- .../src/components/records/Sequence.tsx | 4 --- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/packages/libs/wdk-client/src/Views/Records/RecordActionLink.jsx b/packages/libs/wdk-client/src/Views/Records/RecordActionLink.jsx index 5dc5103bee..67ab169dbc 100644 --- a/packages/libs/wdk-client/src/Views/Records/RecordActionLink.jsx +++ b/packages/libs/wdk-client/src/Views/Records/RecordActionLink.jsx @@ -4,17 +4,26 @@ import Link from '../../Components/Link/Link'; import { wrappable } from '../../Utils/ComponentUtils'; let RecordActionLink = (props) => { - let className = 'wdk-RecordActionLink ' + props.className; - let LinkComponent = props.external ? 'a' : Link; + const { + onClick, + href = '#', + external = false, + label = 'Record action', + iconClassName = 'fa fa-bolt', + showLabel = true, + } = props; + + let className = 'wdk-RecordActionLink ' + (props.className || ''); + let LinkComponent = external ? 'a' : Link; let linkProps = { - [props.external ? 'href' : 'to']: props.href, - title: props.label, + [external ? 'href' : 'to']: href, + title: label, className: className, - onClick: props.onClick, + onClick: onClick, }; return ( - {props.showLabel ? props.label : ''} + {showLabel ? label : ''} ); }; @@ -30,13 +39,4 @@ RecordActionLink.propTypes = { showLabel: PropTypes.bool, }; -RecordActionLink.defaultProps = { - href: '#', - external: false, - className: '', - label: 'Record action', - iconClassName: 'fa fa-bolt', - showLabel: true, -}; - export default wrappable(RecordActionLink); diff --git a/packages/libs/web-common/src/components/records/Sequence.tsx b/packages/libs/web-common/src/components/records/Sequence.tsx index 81368ebbfa..1d6f82824c 100644 --- a/packages/libs/web-common/src/components/records/Sequence.tsx +++ b/packages/libs/web-common/src/components/records/Sequence.tsx @@ -139,10 +139,6 @@ Sequence.propTypes = { ), }; -Sequence.defaultProps = { - highlightRegions: [], -}; - function handleCopy(event: React.ClipboardEvent) { const string = window.getSelection()?.toString() ?? ''; const selection = makeSequenceLines(string).join('\n'); From b8bced10e7194f49c62be5c5b573a1fb7ab3a454 Mon Sep 17 00:00:00 2001 From: asizemore Date: Fri, 11 Oct 2024 16:55:32 -0400 Subject: [PATCH 07/11] fix overlooked default in ServerSideAttributeFilter --- .../Components/AttributeFilter/ServerSideAttributeFilter.jsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/libs/wdk-client/src/Components/AttributeFilter/ServerSideAttributeFilter.jsx b/packages/libs/wdk-client/src/Components/AttributeFilter/ServerSideAttributeFilter.jsx index 0259cb4011..df70a6d538 100644 --- a/packages/libs/wdk-client/src/Components/AttributeFilter/ServerSideAttributeFilter.jsx +++ b/packages/libs/wdk-client/src/Components/AttributeFilter/ServerSideAttributeFilter.jsx @@ -27,7 +27,9 @@ function ServerSideAttributeFilter(props) { return (
- {hideFilterPanel || } + {hideFilterPanel || ( + + )} {/* Main selection UI */}
From da1b453736a62d08f8d7b46169831944450ee236 Mon Sep 17 00:00:00 2001 From: asizemore Date: Wed, 4 Dec 2024 08:45:05 -0500 Subject: [PATCH 08/11] cleanup after merge --- .../inputs/SelectTree/SelectTree.tsx | 51 ++----------------- 1 file changed, 5 insertions(+), 46 deletions(-) diff --git a/packages/libs/coreui/src/components/inputs/SelectTree/SelectTree.tsx b/packages/libs/coreui/src/components/inputs/SelectTree/SelectTree.tsx index 6aaf452465..73168dca1e 100644 --- a/packages/libs/coreui/src/components/inputs/SelectTree/SelectTree.tsx +++ b/packages/libs/coreui/src/components/inputs/SelectTree/SelectTree.tsx @@ -21,6 +21,9 @@ function SelectTree(props: SelectTreeProps) { wrapPopover, currentList, selectedList = [], + onSelectionChange, + hasPopoverButton = true, + instantUpdate = true, } = props; const [buttonDisplayContent, setButtonDisplayContent] = useState( @@ -28,14 +31,6 @@ function SelectTree(props: SelectTreeProps) { ? currentList.join(', ') : props.buttonDisplayContent ); - const { - selectedList, - onSelectionChange, - shouldCloseOnSelection, - hasPopoverButton = true, - instantUpdate = true, - wrapPopover, - } = props; // This local state is updated whenever a checkbox is clicked in the species tree. // When `instantUpdate` is false, pass the final value to `onSelectionChange` when the popover closes. @@ -55,7 +50,7 @@ function SelectTree(props: SelectTreeProps) { useEffect(() => { if (!instantUpdate) return; onSelectionChange(localSelectedList); - }, [onSelectionChange, localSelectedList]); + }, [onSelectionChange, localSelectedList, instantUpdate]); function truncatedButtonContent(selectedList: string[]) { return ( @@ -82,47 +77,11 @@ function SelectTree(props: SelectTreeProps) { if (!instantUpdate) onSelectionChange(localSelectedList); }; - // ANN LOOK HERE - // const checkboxTree = ; const checkboxTree = ( ); From b088d05c460de63de1d6f11c6b9081daa1f2d0da Mon Sep 17 00:00:00 2001 From: Ann Sizemore Blevins Date: Wed, 4 Dec 2024 10:27:32 -0500 Subject: [PATCH 09/11] Apply suggestions from code review Co-authored-by: Dave Falke --- .../checkboxes/CheckboxTree/CheckboxTree.tsx | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/packages/libs/coreui/src/components/inputs/checkboxes/CheckboxTree/CheckboxTree.tsx b/packages/libs/coreui/src/components/inputs/checkboxes/CheckboxTree/CheckboxTree.tsx index b641d2b518..e0d86e6012 100644 --- a/packages/libs/coreui/src/components/inputs/checkboxes/CheckboxTree/CheckboxTree.tsx +++ b/packages/libs/coreui/src/components/inputs/checkboxes/CheckboxTree/CheckboxTree.tsx @@ -719,7 +719,7 @@ function CheckboxTree(props: CheckboxTreeProps) { getNodeId, getNodeChildren, searchTerm = '', - selectedList = [], + selectedList = defaultCheckboxTreeProps.selectedList, currentList, defaultList, expandedList = null, @@ -728,9 +728,7 @@ function CheckboxTree(props: CheckboxTreeProps) { name, shouldExpandDescendantsWithOneChild, onExpansionChange, - onSelectionChange = () => { - // - }, + onSelectionChange = defaultCheckboxTreeProps.onSelectionChange, isSelectable = false, isMultiPick = true, showRoot = false, @@ -738,18 +736,16 @@ function CheckboxTree(props: CheckboxTreeProps) { linksPosition = LinksPosition.Both, showSearchBox = true, autoFocusSearchBox, - onSearchTermChange = () => { - // - }, + onSearchTermChange = defaultCheckboxTreeProps.onSearchTermChange, searchBoxPlaceholder = 'Search...', searchIconName, searchIconPosition, searchBoxHelp = '', - searchPredicate = () => true, + searchPredicate = defaultCheckboxTreeProps.searchPredicate, additionalFilters, wrapTreeSection, shouldExpandOnClick = true, - customCheckboxes = {}, + customCheckboxes = defaultCheckboxTreeProps.customCheckboxes, renderNoResults, styleOverrides = {}, customTreeNodeCssSelectors = {}, From d2932a8a014a107b365b557b86b44fb61c3c5082 Mon Sep 17 00:00:00 2001 From: asizemore Date: Wed, 4 Dec 2024 10:29:15 -0500 Subject: [PATCH 10/11] use more default values in props --- .../checkboxes/CheckboxTree/CheckboxTree.tsx | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/packages/libs/coreui/src/components/inputs/checkboxes/CheckboxTree/CheckboxTree.tsx b/packages/libs/coreui/src/components/inputs/checkboxes/CheckboxTree/CheckboxTree.tsx index e0d86e6012..0f6ebbf09e 100644 --- a/packages/libs/coreui/src/components/inputs/checkboxes/CheckboxTree/CheckboxTree.tsx +++ b/packages/libs/coreui/src/components/inputs/checkboxes/CheckboxTree/CheckboxTree.tsx @@ -247,6 +247,8 @@ export type CheckboxTreeProps = { }; // Default values. Used across multiple functions in this file. +// Define defaultCheckboxTreeProps as a partial of CheckboxTreeProps + const defaultCheckboxTreeProps = { showRoot: false, expandedList: null, @@ -718,30 +720,28 @@ function CheckboxTree(props: CheckboxTreeProps) { tree, getNodeId, getNodeChildren, - searchTerm = '', + searchTerm = defaultCheckboxTreeProps.searchTerm, selectedList = defaultCheckboxTreeProps.selectedList, currentList, defaultList, - expandedList = null, - isSearchable = false, + isSearchable = defaultCheckboxTreeProps.isSearchable, isAdditionalFilterApplied, name, shouldExpandDescendantsWithOneChild, onExpansionChange, onSelectionChange = defaultCheckboxTreeProps.onSelectionChange, - isSelectable = false, - isMultiPick = true, - showRoot = false, + isSelectable = defaultCheckboxTreeProps.isSelectable, + isMultiPick = defaultCheckboxTreeProps.isMultiPick, + showRoot = defaultCheckboxTreeProps.showRoot, additionalActions, - linksPosition = LinksPosition.Both, - showSearchBox = true, + linksPosition = defaultCheckboxTreeProps.linksPosition, + showSearchBox = defaultCheckboxTreeProps.showSearchBox, autoFocusSearchBox, onSearchTermChange = defaultCheckboxTreeProps.onSearchTermChange, - searchBoxPlaceholder = 'Search...', + searchBoxPlaceholder = defaultCheckboxTreeProps.searchBoxPlaceholder, searchIconName, searchIconPosition, - searchBoxHelp = '', - searchPredicate = defaultCheckboxTreeProps.searchPredicate, + searchBoxHelp = defaultCheckboxTreeProps.searchBoxHelp, additionalFilters, wrapTreeSection, shouldExpandOnClick = true, From 721751b70743102d41b8066fd51da35582001bd5 Mon Sep 17 00:00:00 2001 From: asizemore Date: Thu, 5 Dec 2024 10:07:50 -0500 Subject: [PATCH 11/11] fix undefined error --- .../coreui/src/components/inputs/SelectTree/SelectTree.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/libs/coreui/src/components/inputs/SelectTree/SelectTree.tsx b/packages/libs/coreui/src/components/inputs/SelectTree/SelectTree.tsx index 73168dca1e..c39476a488 100644 --- a/packages/libs/coreui/src/components/inputs/SelectTree/SelectTree.tsx +++ b/packages/libs/coreui/src/components/inputs/SelectTree/SelectTree.tsx @@ -49,6 +49,7 @@ function SelectTree(props: SelectTreeProps) { // live updates to caller when needed useEffect(() => { if (!instantUpdate) return; + if (!onSelectionChange) return; onSelectionChange(localSelectedList); }, [onSelectionChange, localSelectedList, instantUpdate]); @@ -74,7 +75,8 @@ function SelectTree(props: SelectTreeProps) { ? truncatedButtonContent(localSelectedList) : props.buttonDisplayContent ); - if (!instantUpdate) onSelectionChange(localSelectedList); + if (!instantUpdate && onSelectionChange) + onSelectionChange(localSelectedList); }; const checkboxTree = (