-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lf 4083 add search to animal list #3152
Changes from 21 commits
dcd2a5c
d228053
99e8508
aeca840
bb11c74
ab76695
311b2a3
3be636f
f0b16ca
1fbe4a6
68564b7
dd75c2a
af075d7
10ac382
f783e27
4a79dbf
24af1bd
403bfdc
4891cd4
4273ef4
3d399ca
8c781fb
62bb1a7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,44 +14,95 @@ | |
*/ | ||
import Table from '../../../components/Table'; | ||
import Layout from '../../../components/Layout'; | ||
import PureSearchBarWithBackdrop from '../../PopupFilter/PureSearchWithBackdrop'; | ||
import NoSearchResults from '../../../components/Card/NoSearchResults'; | ||
import type { AnimalInventory } from '../../../containers/Animals/Inventory/useAnimalInventory'; | ||
import { TableV2Column, TableKind } from '../../Table/types'; | ||
import type { DefaultTheme } from '@mui/styles'; | ||
import type { Dispatch, SetStateAction } from 'react'; | ||
import styles from './styles.module.scss'; | ||
import clsx from 'clsx'; | ||
|
||
export type SearchProps = { | ||
searchString: string | null | undefined; | ||
setSearchString: Dispatch<SetStateAction<string[]>>; | ||
placeHolderText: string; | ||
searchResultsText: string; | ||
}; | ||
|
||
const PureAnimalInventory = ({ | ||
tableData, | ||
filteredInventory, | ||
animalsColumns, | ||
theme, | ||
isMobile, | ||
zIndexBase, | ||
backgroundColor, | ||
isDesktop, | ||
searchProps, | ||
}: { | ||
tableData: AnimalInventory[]; | ||
filteredInventory: AnimalInventory[]; | ||
animalsColumns: TableV2Column[]; | ||
theme: DefaultTheme; | ||
isMobile: boolean; | ||
zIndexBase: number; | ||
backgroundColor: string; | ||
isDesktop: boolean; | ||
searchProps: SearchProps; | ||
}) => { | ||
const { searchString, setSearchString, placeHolderText, searchResultsText } = searchProps; | ||
const hasSearchResults = filteredInventory.length !== 0; | ||
|
||
return ( | ||
<Layout | ||
classes={{ | ||
container: { | ||
backgroundColor: theme.palette.background.paper, | ||
borderRadius: '8px', | ||
border: '1px solid var(--Colors-Primary-Primary-teal-50)', | ||
marginTop: '16px', | ||
backgroundColor: backgroundColor, | ||
borderRadius: isDesktop && '8px', | ||
border: isDesktop && '1px solid var(--Colors-Primary-Primary-teal-50)', | ||
marginTop: isDesktop && '16px', | ||
padding: !isDesktop ? '0px' : '16px', | ||
}, | ||
}} | ||
hasWhiteBackground | ||
footer={false} | ||
> | ||
<Table | ||
kind={TableKind.V2} | ||
alternatingRowColor={true} | ||
columns={animalsColumns} | ||
data={tableData} | ||
shouldFixTableLayout={!isMobile} | ||
minRows={tableData.length} | ||
dense={false} | ||
showHeader={!isMobile} | ||
/> | ||
<div | ||
className={clsx( | ||
isDesktop ? styles.SearchAndFilter_container___desktop : styles.SearchAndFilter_container, | ||
)} | ||
> | ||
<PureSearchBarWithBackdrop | ||
value={searchString} | ||
onChange={(e: any) => setSearchString(e.target.value)} | ||
isSearchActive={!!searchString} | ||
placeholderText={placeHolderText} | ||
zIndexBase={zIndexBase} | ||
isDesktop={isDesktop} | ||
className={clsx(isDesktop ? styles.SearchBar___widthFixed : styles.SearchBar___widthFull)} | ||
/> | ||
<div | ||
className={clsx( | ||
isDesktop ? styles.SearchResults___marginLeft8 : styles.SearchResults___textAlignCenter, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd try to give these classes more generic names rather than names that specifically point out the styling applied. The reason for that is, it leaves little flexibility to update the styling and reuse that selector without having to change the name of the class. Even if we went for BEM, the "modifiers" used are usually things like "compact", "disabled", "active", "big" rather than calling out specific styles There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah. I would only call out specific styles if it is the only style on the property. I don't see value in making the modifier less readable (in JS) when there is just one style. But yeah anyone wanting to add another style would probably rename it to be more generic. Most just showcasing the inline breakpoints readability -- I haven't mastered BEM by any means ahha so what your seeing is my interpretation .. but BEM is nice overall |
||
)} | ||
> | ||
{searchResultsText} | ||
</div> | ||
</div> | ||
{hasSearchResults ? ( | ||
<Table | ||
kind={TableKind.V2} | ||
alternatingRowColor={true} | ||
columns={animalsColumns} | ||
data={filteredInventory} | ||
shouldFixTableLayout={isDesktop} | ||
minRows={filteredInventory.length} | ||
dense={false} | ||
showHeader={isDesktop} | ||
/> | ||
) : ( | ||
<NoSearchResults | ||
className={clsx( | ||
isDesktop ? styles.NoSearchResults___marginTop40 : styles.NoSearchResults__marginTop24, | ||
)} | ||
searchTerm={searchString} | ||
includeFiltersInClearSuggestion | ||
/> | ||
)} | ||
</Layout> | ||
); | ||
}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright 2024 LiteFarm.org | ||
* This file is part of LiteFarm. | ||
* | ||
* LiteFarm is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* LiteFarm is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
.NoSearchResults___marginTop24 { | ||
margin-top: 24px; | ||
} | ||
|
||
.NoSearchResults___marginTop40 { | ||
margin-top: 40px; | ||
} | ||
|
||
.SearchBar___widthFixed { | ||
width: 240px; | ||
} | ||
|
||
.SearchBar___widthFull { | ||
width: 100%; | ||
} | ||
|
||
.SearchAndFilter_container___desktop { | ||
display: inline-flex; | ||
align-items: center; | ||
gap: 8px; | ||
margin-bottom: 16px; | ||
} | ||
|
||
.SearchAndFilter_container { | ||
display: inline-grid; | ||
gap: 4px; | ||
padding: 8px 16px 8px 16px; | ||
background-color: var(--Colors-Primary-Primary-teal-50); | ||
} | ||
|
||
.SearchResults___marginLeft8 { | ||
margin-left: 8px; | ||
} | ||
|
||
.SearchResults___textAlignCenter { | ||
text-align: center; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright 2023 LiteFarm.org | ||
* Copyright 2023-2024 LiteFarm.org | ||
* This file is part of LiteFarm. | ||
* | ||
* LiteFarm is free software: you can redistribute it and/or modify | ||
|
@@ -22,13 +22,14 @@ import Input from '../../Form/Input'; | |
import TextButton from '../../Form/Button/TextButton'; | ||
import { Modal } from '../../Modals'; | ||
|
||
export default function PureCollapsibleSearch({ | ||
export default function PureCollapsingSearch({ | ||
value, | ||
isSearchActive, | ||
onChange, | ||
placeholderText, | ||
className, | ||
containerRef, | ||
isDesktop, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We shouldn't use the breakpoint? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was a media query -- no we should not use media query I don't think.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I really like having the breakpoints being controlled by JS/TS and no longer the mixins... those multiple methods and sources of truth (when finances was created we weren't yet unified around the MUI breakpoints) made it really hard to reason about e.g. the CollapsibleSearch. But GOSH I hate those BEM underscores... do we have to?? 🤣 Edit: and more in the spirit of logic and not just knee-jerk underscore dislike, I don't think we want to adopt a new CSS naming convention like this without discussion + deciding if it's something we'll use moving forward; a mix of naming conventions is pretty confusing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lol no not necessary -- but its a good architecture vs "willy nilly" haha There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, I was in favour of using CSS. I don't think we have discussed which strategy to stick with? I added to the tech daily agenda! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @SayakaOno sounds awesome! I don't have a strong opinion between mixins and inline breakpoints just no more media queries haha There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we made a decision today. @SayakaOno can I make a tech debt ticket to choose ? That way search bar can go through. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought we wouldn't need any further discussion 😅 It's up to you! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be nice to choose a direction haha: https://lite-farm.atlassian.net/browse/LF-4143 |
||
}) { | ||
const searchRef = useRef(null); | ||
const [modalStyle, setModalStyle] = useState({}); | ||
|
@@ -82,7 +83,10 @@ export default function PureCollapsibleSearch({ | |
}, [searchOverlayOpen]); | ||
|
||
return ( | ||
<div className={clsx(styles.container, className)} ref={searchRef}> | ||
<div | ||
className={clsx(styles.container, className, isDesktop && styles.desktopContainer)} | ||
ref={searchRef} | ||
> | ||
<Input | ||
className={styles.searchBar} | ||
isSearchBar | ||
|
@@ -95,7 +99,7 @@ export default function PureCollapsibleSearch({ | |
<Modal dismissModal={onSearchClose} style={modalStyle}> | ||
<form // allows closing modal with enter key (= submit) | ||
onSubmit={handleSubmit} | ||
className={styles.modalContent} | ||
className={clsx(styles.modalContent, isDesktop && styles.displayNone)} | ||
> | ||
<Input | ||
className={styles.modalSearchbar} | ||
|
@@ -109,32 +113,37 @@ export default function PureCollapsibleSearch({ | |
)} | ||
|
||
<TextButton | ||
className={clsx(styles.searchButton, isSearchActive && styles.active)} | ||
className={clsx( | ||
styles.searchButton, | ||
isSearchActive && styles.active, | ||
isDesktop && styles.displayNone, | ||
)} | ||
onClick={onSearchOpen} | ||
> | ||
<SearchIcon className={styles.searchIcon} /> | ||
</TextButton> | ||
|
||
{isSearchActive && ( | ||
<div className={styles.circleContainer}> | ||
<div className={styles.circle} /> | ||
<div className={clsx(styles.circleContainer, isDesktop && styles.displayNone)}> | ||
<div className={clsx(styles.circle, isDesktop && styles.displayNone)} /> | ||
</div> | ||
)} | ||
</div> | ||
); | ||
} | ||
|
||
PureCollapsibleSearch.propTypes = { | ||
PureCollapsingSearch.propTypes = { | ||
value: PropTypes.string, | ||
isSearchActive: PropTypes.bool, | ||
onChange: PropTypes.func, | ||
placeholderText: PropTypes.string, | ||
className: PropTypes.string, | ||
overlayModalOnButton: PropTypes.bool, | ||
containerRef: PropTypes.shape({ current: PropTypes.instanceOf(Element) }), | ||
isDesktop: PropTypes.bool, | ||
}; | ||
|
||
PureCollapsibleSearch.defaultProps = { | ||
PureCollapsingSearch.defaultProps = { | ||
placeholderText: '', | ||
isSearchActive: false, | ||
className: '', | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like BEM overall, but since we haven't made a decision to go for that throughout the app, I'd advocate for consistency here and naming the styles more similarly to how classes are currently named in other files. In general I'm all for BEM but I think these will be out of place unless there's overall consensus to go with BEM from now on. If we do make a decision to go with BEM from now on, I think the convention would actually be something like
search-and-filter__container--desktop
. Unless this is a different one and not BEM?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there are some react problems with the - or something. I linked the article I used to try to apply it but it may be out of date.
I just added it to discuss the isDesktop inline breakpoints readability.