diff --git a/src/components/Search/FilterDropdowns/DropdownButton.tsx b/src/components/Search/FilterDropdowns/DropdownButton.tsx index a5c970fea727..6d8cc2a1723c 100644 --- a/src/components/Search/FilterDropdowns/DropdownButton.tsx +++ b/src/components/Search/FilterDropdowns/DropdownButton.tsx @@ -20,6 +20,7 @@ import ONYXKEYS from '@src/ONYXKEYS'; import type WithSentryLabel from '@src/types/utils/SentryLabel'; type PopoverComponentProps = { + isExpanded: boolean; closeOverlay: () => void; }; @@ -122,8 +123,8 @@ function DropdownButton({label, value, viewportOffsetTop, PopoverComponent, medi }, [isSmallScreenWidth, styles]); const popoverContent = useMemo(() => { - return PopoverComponent({closeOverlay: toggleOverlay}); - }, [PopoverComponent, toggleOverlay]); + return PopoverComponent({closeOverlay: toggleOverlay, isExpanded: isOverlayVisible}); + }, [PopoverComponent, toggleOverlay, isOverlayVisible]); return ( = { /** Search input placeholder. Defaults to 'common.search' when not provided. */ searchPlaceholder?: string; + + /** Whether the data for the popover is loading */ + loading?: boolean; }; -function MultiSelectPopup({label, value, items, closeOverlay, onChange, isSearchable, searchPlaceholder}: MultiSelectPopupProps) { +function MultiSelectPopup({label, loading, value, items, closeOverlay, onChange, isSearchable, searchPlaceholder}: MultiSelectPopupProps) { + const theme = useTheme(); const {translate} = useLocalize(); const styles = useThemeStyles(); + // eslint-disable-next-line rulesdir/prefer-shouldUseNarrowLayout-instead-of-isSmallScreenWidth const {isSmallScreenWidth} = useResponsiveLayout(); const {windowHeight} = useWindowDimensions(); @@ -99,18 +107,32 @@ function MultiSelectPopup({label, value, items, closeOverlay, [searchTerm, isSearchable, searchPlaceholder, translate, setSearchTerm, headerMessage], ); + const reasonAttributes: SkeletonSpanReasonAttributes = {context: 'MultiSelectPopupDataLoading'}; + return ( {isSmallScreenWidth && {label}} - + {!!loading && ( + + + + )} + + {!loading && ( + + )} diff --git a/src/components/Search/SearchPageHeader/FeedFilterPopup.tsx b/src/components/Search/SearchPageHeader/FeedFilterPopup.tsx new file mode 100644 index 000000000000..7b9aba95f226 --- /dev/null +++ b/src/components/Search/SearchPageHeader/FeedFilterPopup.tsx @@ -0,0 +1,43 @@ +import React, {useEffect} from 'react'; +import type {MultiSelectItem} from '@components/Search/FilterDropdowns/MultiSelectPopup'; +import useNetwork from '@hooks/useNetwork'; +import useOnyx from '@hooks/useOnyx'; +import {openSearchCardFiltersPage} from '@libs/actions/Search'; +import ONYXKEYS from '@src/ONYXKEYS'; +import MultiSelectFilterPopup from './MultiSelectFilterPopup'; + +type FeedFilterPopupProps = { + isExpanded: boolean; + items: Array>; + value: Array>; + closeOverlay: () => void; + onChangeCallback: (items: Array>) => void; +}; + +function FeedFilterPopup({closeOverlay, items, value, isExpanded, onChangeCallback}: FeedFilterPopupProps) { + const {isOffline} = useNetwork(); + const [areCardsLoaded] = useOnyx(ONYXKEYS.IS_SEARCH_FILTERS_CARD_DATA_LOADED); + + useEffect(() => { + if (isOffline || !isExpanded) { + return; + } + openSearchCardFiltersPage(); + }, [isOffline, isExpanded]); + + const shouldShowLoadingState = !areCardsLoaded && !isOffline; + + return ( + + ); +} + +export default FeedFilterPopup; diff --git a/src/components/Search/SearchPageHeader/MultiSelectFilterPopup.tsx b/src/components/Search/SearchPageHeader/MultiSelectFilterPopup.tsx index 1cf0404cf548..50af2ba45032 100644 --- a/src/components/Search/SearchPageHeader/MultiSelectFilterPopup.tsx +++ b/src/components/Search/SearchPageHeader/MultiSelectFilterPopup.tsx @@ -6,6 +6,7 @@ import useLocalize from '@hooks/useLocalize'; import type {TranslationPaths} from '@src/languages/types'; type MultiSelectFilterPopupProps = PopoverComponentProps & { + loading?: boolean; translationKey: TranslationPaths; items: Array>; value: Array>; @@ -13,13 +14,14 @@ type MultiSelectFilterPopupProps = PopoverComponentProps & { isSearchable?: boolean; }; -function MultiSelectFilterPopup({closeOverlay, translationKey, items, value, onChangeCallback, isSearchable}: MultiSelectFilterPopupProps) { +function MultiSelectFilterPopup({closeOverlay, loading, translationKey, items, value, onChangeCallback, isSearchable}: MultiSelectFilterPopupProps) { const {translate} = useLocalize(); return ( { + if (isOffline || !isExpanded) { + return; + } + openSearchCardFiltersPage(); + }, [isOffline, isExpanded]); const updateFeedFilterForm = (items: Array>) => { updateFilterForm({feed: items.map((item) => item.value)}); }; + const feedOptions = getFeedOptions(allFeeds, personalAndWorkspaceCards, translate, localeCompare, feedKeysWithCards); const feedValue = feed ? feedOptions.filter((option) => feed.includes(option.value)) : []; + const shouldShowLoadingState = !areCardsLoaded && !isOffline; return ( ); @@ -177,6 +192,7 @@ function makeDateFilterItem( return { PopoverComponent: (props) => ( ( + PopoverComponent: ({closeOverlay, isExpanded}) => ( @@ -256,6 +273,7 @@ function useSearchActionsBar(queryJSON: SearchQueryJSON, isMobileSelectionModeEn }; const hasComponent = (props: PopoverComponentProps) => ( ( ( + PopoverComponent: ({closeOverlay, isExpanded}) => ( @@ -343,6 +363,7 @@ function useSearchActionsBar(queryJSON: SearchQueryJSON, isMobileSelectionModeEn }; const statusComponent = (props: PopoverComponentProps) => ( ( + PopoverComponent: ({closeOverlay, isExpanded}) => ( item.value)}); }; const feedComponent = (props: PopoverComponentProps) => ( - ( ( ( ( ( (