Skip to content

Commit eb1c20b

Browse files
authored
Merge pull request #603 from Ajay-aot/bugfix/FWF-4675-search-in-dropdown
Feature/FWF-4675-search implemented in buttonDropdown
2 parents f27345d + 0a1426f commit eb1c20b

File tree

4 files changed

+56
-11
lines changed

4 files changed

+56
-11
lines changed

forms-flow-components/src/components/CustomComponents/ButtonDropdown.tsx

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import Dropdown from "react-bootstrap/Dropdown";
55
import { ChevronIcon } from "../SvgIcons/index";
66
import { useTranslation } from "react-i18next";
77
import { StyleServices } from "@formsflow/service";
8+
import { CustomSearch } from "./Search";
89

910
interface DropdownItem {
1011
content?: React.ReactNode;
@@ -24,11 +25,12 @@ interface ButtonDropdownProps {
2425
className?: string;
2526
dropdownType: "DROPDOWN_ONLY" | "DROPDOWN_WITH_EXTRA_ACTION";
2627
dropdownItems?: DropdownItem[];
28+
onSearch?: (searchTerm: string) => void;
2729
extraActionIcon?: React.ReactNode;
2830
extraActionOnClick?:() => void;
2931
dataTestId?: string;
3032
ariaLabel?: string;
31-
}
33+
}
3234

3335
export const ButtonDropdown: React.FC<ButtonDropdownProps> = ({
3436
dropdownType,
@@ -37,6 +39,7 @@ export const ButtonDropdown: React.FC<ButtonDropdownProps> = ({
3739
defaultLabel,
3840
label,
3941
dropdownItems = [],
42+
onSearch,
4043
extraActionIcon = false,
4144
extraActionOnClick,
4245
className = "",
@@ -51,8 +54,24 @@ export const ButtonDropdown: React.FC<ButtonDropdownProps> = ({
5154
const [dropdownOpen, setDropdownOpen] = useState<boolean>(false);
5255
const { t } = useTranslation();
5356
const primaryBtnBgColor = StyleServices.getCSSVariable('--primary-btn-bg-color');
54-
const secondaryBtnBgColor = StyleServices.getCSSVariable('--secondary-btn-bg-color');
55-
// Check if we should use the default label
57+
const secondaryBtnBgColor = StyleServices.getCSSVariable('--secondary-btn-bg-color');
58+
const [search, setSearch] = useState("");
59+
60+
const handleClearSearch = () => {
61+
setSearch("");
62+
onSearch?.("");
63+
}
64+
65+
const handleSearch = () => {
66+
onSearch?.(search);
67+
};
68+
69+
useEffect(()=>{
70+
if (onSearch) {
71+
onSearch(search);
72+
}
73+
},[search]);
74+
// Check if we should use the default label
5675
const isUsingDefaultLabel = !label || label === "";
5776
// Display label if provided, otherwise use defaultLabel
5877
const displayLabel = isUsingDefaultLabel ? defaultLabel : label;
@@ -142,6 +161,15 @@ const { extraActionClass, backgroundColor } = getExtraActionStyles(variant);
142161
</Dropdown.Toggle>
143162

144163
<Dropdown.Menu style={menuStyle}>
164+
{onSearch && (<CustomSearch
165+
handleClearSearch={handleClearSearch}
166+
search={search}
167+
setSearch={setSearch}
168+
handleSearch={handleSearch}
169+
placeholder={t("Search")}
170+
title={t("Search")}
171+
dataTestId="search-filter"
172+
/>)}
145173
{dropdownItems.map((item) => (
146174
<Dropdown.Item
147175
key={item.type}

forms-flow-nav/src/sidenav/MenuComponent.jsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import Accordion from "react-bootstrap/Accordion";
33
import "./Sidebar.scss";
44
import { Link, useLocation, useHistory } from "react-router-dom";
55
import { ChevronIcon ,ShowPremiumIcons } from "@formsflow/components";
6-
import { MULTITENANCY_ENABLED} from "../constants/constants";
76
import { useTranslation } from "react-i18next";
87
import { StorageService } from "@formsflow/service";
98
import PropTypes from "prop-types";
@@ -73,6 +72,12 @@ const MenuComponent = ({
7372
: getComputedStyle(document.documentElement).getPropertyValue("--ff-primary");
7473
};
7574

75+
const chevronColor =
76+
getComputedStyle(document.documentElement).getPropertyValue(
77+
"--navbar-main-menu-active-font-color"
78+
)?.trim() || getComputedStyle(document.documentElement).getPropertyValue(
79+
"--ff-gray-800"
80+
).trim();
7681

7782
return (
7883
<Accordion.Item eventKey={eventKey}>
@@ -89,9 +94,7 @@ const MenuComponent = ({
8994
width="10"
9095
height="5"
9196
className="custom-chevron"
92-
color={getComputedStyle(document.documentElement).getPropertyValue(
93-
"--ff-gray-800"
94-
)}
97+
color={chevronColor}
9598
/>
9699
)}
97100
<span>{t(mainMenu)}</span>

forms-flow-review/src/components/TaskList/TaskFilterDropdown.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { updateDefaultFilter } from "../../api/services/filterServices";
1111
import TaskFilterModal from "../TaskFilterModal/TaskFilterModal";
1212
import { ReorderTaskFilterModal } from "../ReorderTaskFilterModal";
1313
import { UserDetail } from "../../types/taskFilter";
14-
import { StorageService } from "@formsflow/service";
1514

1615
const TaskListDropdownItems = memo(() => {
1716
const { t } = useTranslation();
@@ -34,6 +33,7 @@ const TaskListDropdownItems = memo(() => {
3433

3534
const [showTaskFilterModal, setShowTaskFilterModal] = useState(false);
3635
const [showReorderFilterModal,setShowReorderFilterModal] = useState(false);
36+
const [filterSearchTerm, setFilterSearchTerm] = useState("");
3737

3838
const handleEditTaskFilter = () => {
3939
// Prevent editing if the active filter is the initial "All Tasks".
@@ -64,7 +64,9 @@ const changeFilterSelection = (filter) => {
6464
dispatch(setSelectedFilter(upcomingFilter));
6565
};
6666

67-
67+
const onSearch = (searchTerm: string) => {
68+
setFilterSearchTerm(searchTerm);
69+
};
6870

6971
const filterDropdownItems = useMemo(() => {
7072
const filterDropdownItemsArray = [];
@@ -104,6 +106,15 @@ const changeFilterSelection = (filter) => {
104106
ariaLabel: t("Re-order And Hide Filters"),
105107
};
106108
const mappedItems = filtersAndCount
109+
.filter((filter) => {
110+
const details = filterList.find((item) => item.id === filter.id);
111+
const filterName = t(filter.name).toLowerCase();
112+
return (
113+
details &&
114+
!details.hide &&
115+
filterName.includes(filterSearchTerm.toLowerCase())
116+
); // only include visible filters
117+
})
107118
.map((filter) => {
108119
const filterDetails = filterList.find((item) => item.id === filter.id);
109120
let icon = null;
@@ -150,7 +161,7 @@ const changeFilterSelection = (filter) => {
150161
}
151162

152163
return filterDropdownItemsArray;
153-
}, [filtersAndCount, defaultFilter,filterList,userDetails ]);
164+
}, [filtersAndCount, defaultFilter,filterList,userDetails, filterSearchTerm ]);
154165

155166
// filter title based on unsaved filter, empty list or selected filter
156167
let title;
@@ -178,6 +189,7 @@ const changeFilterSelection = (filter) => {
178189
variant="primary"
179190
size="md"
180191
dropdownType="DROPDOWN_WITH_EXTRA_ACTION"
192+
onSearch={onSearch}
181193
dropdownItems={filterDropdownItems}
182194
extraActionIcon={<PencilIcon color="white" />}
183195
extraActionOnClick={handleEditTaskFilter}

forms-flow-theme/scss/_forms.scss

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,9 @@ select option:hover {
132132
padding: var(--spacer-075) var(--spacer-100) !important;
133133
height: 2.063rem;
134134

135-
135+
&:hover{
136+
background-color: $primary-light !important;
137+
}
136138

137139
&.has-value {
138140
border: 2px solid $primary;

0 commit comments

Comments
 (0)