@agilant/toga-blox 1.0.62 → 1.0.63

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -52,17 +52,21 @@ const Template = (args) => {
52
52
  const [selectedDate, setSelectedDate] = useState(args.selectedDate);
53
53
  const [selectedStartDate, setSelectedStartDate] = useState(args.selectedStartDate);
54
54
  const [selectedEndDate, setSelectedEndDate] = useState(args.selectedEndDate);
55
- // NEW: State for searchCriteria and editingHeader
55
+ // NEW: State for searchCriteria and editingHeader.
56
+ // Set editingHeader to 0 so that the search input renders.
56
57
  const [searchCriteria, setSearchCriteria] = useState([]);
57
- const [editingHeader, setEditingHeader] = useState(null);
58
- // Handle onChange from the multi-select
58
+ const [editingHeader, setEditingHeader] = useState(0);
59
+ // Log current state to verify updates.
60
+ console.log("Template render: editingHeader =", editingHeader);
61
+ console.log("Template render: searchCriteria =", searchCriteria);
62
+ // Handle onChange from the multi-select.
59
63
  const handleOnChange = (newSelected) => {
60
64
  setSelectedValue(newSelected);
61
65
  args.onChange?.(newSelected);
62
66
  console.log("Selected items:", newSelected);
63
67
  };
64
68
  return (_jsx(SearchInput, { ...args, column: mockColumn, selectedDropdownOption: selectedOption, onDropdownOptionSelect: (option) => setSelectedOption(option), searchItems: searchItems, setSearchItems: setSearchItems, toggleStatus: toggleStatus, setToggleStatus: setToggleStatus, minValue: minValue, maxValue: maxValue, setMinValue: setMinValue, setMaxValue: setMaxValue, onChange: handleOnChange, selectedValue: selectedValue, selectedDate: selectedDate, onDateSelect: setSelectedDate, selectedStartDate: selectedStartDate, onStartDateSelect: setSelectedStartDate, selectedEndDate: selectedEndDate, onEndDateSelect: setSelectedEndDate, setSearchCriteria: setSearchCriteria, setEditingHeader: setEditingHeader,
65
- // Optionally pass in handleFilter, or use the default from args
69
+ // Optionally pass in handleFilter, or use the default from args.
66
70
  handleFilter: args.handleFilter }));
67
71
  };
68
72
  export const Default = Template.bind({});
@@ -38,8 +38,15 @@ const SearchTextInput = ({ pillColor = "bg-sky-500", textHighlight = "text-sky-5
38
38
  setLocalSearchText(event.target.value);
39
39
  };
40
40
  const handleSearchBadgeClick = (item) => {
41
- const filteredItems = searchItems.filter((ele) => ele !== item);
42
- setSearchItems && setSearchItems(filteredItems);
41
+ // Remove from searchItems.
42
+ const newSearchItems = searchItems.filter((ele) => ele !== item);
43
+ setSearchItems && setSearchItems(newSearchItems);
44
+ // Remove from searchCriteria based on the submittedSearchText.
45
+ setSearchCriteria((prev) => {
46
+ const newCriteria = prev.filter((crit) => crit.submittedSearchText !== item);
47
+ updateLocalStorage(newCriteria);
48
+ return newCriteria;
49
+ });
43
50
  };
44
51
  const handleKeyDown = (e) => {
45
52
  if (e.key === "Enter" && localSearchText.length > 0) {
@@ -52,39 +59,26 @@ const SearchTextInput = ({ pillColor = "bg-sky-500", textHighlight = "text-sky-5
52
59
  const handleSubmit = () => {
53
60
  const trimmed = localSearchText.trim();
54
61
  if (!trimmed) {
62
+ // If input is empty, remove all criteria for this column.
55
63
  setSearchCriteria((prev) => {
56
- const updated = prev.filter((c) => c.searchColumn.id !== column.id);
57
- updateLocalStorage(updated);
58
- return updated;
64
+ const newCriteria = prev.filter((c) => c.searchColumn.id !== column.id);
65
+ updateLocalStorage(newCriteria);
66
+ return newCriteria;
59
67
  });
60
68
  }
61
69
  else {
70
+ // Always append a new criterion, even if one already exists.
62
71
  setSearchCriteria((prev) => {
63
- const existingIndex = prev.findIndex((c) => c.searchColumn.id === column.id);
64
- let updated;
65
- if (existingIndex >= 0) {
66
- updated = [...prev];
67
- updated[existingIndex] = {
68
- searchColumn: column,
69
- submittedSearchText: trimmed,
70
- };
71
- }
72
- else {
73
- updated = [
74
- ...prev,
75
- { searchColumn: column, submittedSearchText: trimmed },
76
- ];
77
- }
78
- updateLocalStorage(updated);
79
- return updated;
72
+ const newCriteria = [
73
+ ...prev,
74
+ { searchColumn: column, submittedSearchText: trimmed },
75
+ ];
76
+ updateLocalStorage(newCriteria);
77
+ return newCriteria;
80
78
  });
81
79
  }
82
80
  setEditingHeader(null);
83
81
  };
84
- return (_jsx("div", { ref: containerRef, className: "w-[425px]", children: _jsxs("div", { className: "flex flex-col border-2 border-navy-200 rounded-md", children: [_jsxs("div", { className: `flex ${searchItems.length ? "border-b-2" : ""} h-full`, children: [_jsx(Dropdown, { options: dropdownOptions, selectedOption: selectedDropdownOption, onOptionSelect: onDropdownOptionSelect, optionClasses: "px-4 py-1 h-full flex items-center", menuClasses: "bg-white min-w-32", icon: dropdownIconProp, dropdownClasses: "border-0 border-r-2 w-auto" }), _jsx(Input, { focusRingColor: "focus:ring-transparent", hasAutoFocus: true, value: localSearchText, iconColor: "text-navy-400", onKeyDown: handleKeyDown, required: false, id: "", name: "", type: "text", onChange: handleInputChange, additionalClasses: "min-w-[250px] min-h-full text-gray flex", placeholder: "Search", hasIcons: true, firstIcon: localSearchText === "" ? (_jsx(AnimatePresence, { children: _jsx(motion.div, { initial: "initial", animate: "animate", exit: "exit", className: "text-navy-400", children: getFontAwesomeIcon("search", "regular") }) })) : undefined, iconPosition: "both", secondIcon: _jsx("div", { className: "border-transparent text-white min-w-9", children: _jsx(AnimatePresence, { children: localSearchText !== "" && (_jsxs(motion.div, { className: "flex justify-between items-center min-w-4 text-navy-400 hover:cursor-pointer hover:text-primary", initial: "initial", animate: "animate", exit: "exit", children: [_jsx("div", { className: "bg-navy-50 pr-2 pl-1 text-gray-500", onClick: () => {
85
- setLocalSearchText("");
86
- }, "data-testid": "clear-icon", children: getFontAwesomeIcon("xmark", "regular") }), _jsx("div", { className: `${textHighlight} text-sm hover:text-primary`, children: getFontAwesomeIcon("search", "solid") })] })) }) }), onIconClick: () => {
87
- setLocalSearchText("");
88
- } })] }), searchItems?.length ? (_jsx("div", { className: "flex flex-wrap bg-white py-2 px-2 rounded-md", children: searchItems.map((item, index) => (_jsx(Badge, { backgroundColor: pillColor, borderRadius: "rounded-full", hasRightIcon: true, icon: _jsx("div", { className: "text-white text-xxs", "data-testid": "item-clear-icon", children: getFontAwesomeIcon("xmark", "solid") }), iconSize: "text-sm", mobileIconLabel: item, onClick: () => handleSearchBadgeClick(item), text: _jsx(Text, { color: "text-white", fontFamily: "font-serif", size: "text-sm", tag: "span", text: item }), badgeContainerClasses: `${pillColor} p-1 max-w-fit min-w-20 rounded-full flex justify-between items-center text-white text-xs px-4 border-none mr-4 mb-1`, type: "span" }, index))) })) : null] }) }));
82
+ return (_jsx("div", { ref: containerRef, className: "w-[425px]", children: _jsxs("div", { className: "flex flex-col border-2 border-navy-200 rounded-md", children: [_jsxs("div", { className: `flex ${searchItems.length ? "border-b-2" : ""} h-full`, children: [_jsx(Dropdown, { options: dropdownOptions, selectedOption: selectedDropdownOption, onOptionSelect: onDropdownOptionSelect, optionClasses: "px-4 py-1 h-full flex items-center", menuClasses: "bg-white min-w-32", icon: dropdownIconProp, dropdownClasses: "border-0 border-r-2 w-auto" }), _jsx(Input, { focusRingColor: "focus:ring-transparent", hasAutoFocus: true, value: localSearchText, iconColor: "text-navy-400", onKeyDown: handleKeyDown, required: false, id: "", name: "", type: "text", onChange: handleInputChange, additionalClasses: "min-w-[250px] min-h-full text-gray flex", placeholder: "Search", hasIcons: true, firstIcon: localSearchText === "" ? (_jsx(AnimatePresence, { children: _jsx(motion.div, { initial: "initial", animate: "animate", exit: "exit", className: "text-navy-400", children: getFontAwesomeIcon("search", "regular") }) })) : undefined, iconPosition: "both", secondIcon: _jsx("div", { className: "border-transparent text-white min-w-9", children: _jsx(AnimatePresence, { children: localSearchText !== "" && (_jsxs(motion.div, { className: "flex justify-between items-center min-w-4 text-navy-400 hover:cursor-pointer hover:text-primary", initial: "initial", animate: "animate", exit: "exit", children: [_jsx("div", { className: "bg-navy-50 pr-2 pl-1 text-gray-500", onClick: () => setLocalSearchText(""), "data-testid": "clear-icon", children: getFontAwesomeIcon("xmark", "regular") }), _jsx("div", { className: `${textHighlight} text-sm hover:text-primary`, children: getFontAwesomeIcon("search", "solid") })] })) }) }), onIconClick: () => setLocalSearchText("") })] }), searchItems?.length ? (_jsx("div", { className: "flex flex-wrap bg-white py-2 px-2 rounded-md", children: searchItems.map((item, index) => (_jsx(Badge, { backgroundColor: pillColor, borderRadius: "rounded-full", hasRightIcon: true, icon: _jsx("div", { className: "text-white text-xxs", "data-testid": "item-clear-icon", children: getFontAwesomeIcon("xmark", "solid") }), iconSize: "text-sm", mobileIconLabel: item, onClick: () => handleSearchBadgeClick(item), text: _jsx(Text, { color: "text-white", fontFamily: "font-serif", size: "text-sm", tag: "span", text: item }), badgeContainerClasses: `${pillColor} p-1 max-w-fit min-w-20 rounded-full flex justify-between items-center text-white text-xs px-4 border-none mr-4 mb-1`, type: "span" }, index))) })) : null] }) }));
89
83
  };
90
84
  export default SearchTextInput;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@agilant/toga-blox",
3
3
  "private": false,
4
- "version": "1.0.62",
4
+ "version": "1.0.63",
5
5
  "description": "",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",