Skip to content

Commit

Permalink
Surveys list: fixed "only own" filtering (#3552)
Browse files Browse the repository at this point in the history
Co-authored-by: Stefano Ricci <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Sep 2, 2024
1 parent 8240e22 commit a9850e2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 19 deletions.
2 changes: 2 additions & 0 deletions server/modules/survey/repository/surveyRepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ export const fetchUserSurveys = async (
sortBy = Survey.sortableKeys.dateModified,
sortOrder = 'DESC',
includeOwnerEmailAddress = false,
onlyOwn = false,
},
client = db
) => {
Expand All @@ -189,6 +190,7 @@ export const fetchUserSurveys = async (
sortBy,
sortOrder,
includeOwnerEmailAddress,
onlyOwn,
}),
{ userUuid: User.getUuid(user), template, search },
(def) => DB.transformCallback(def, true)
Expand Down
32 changes: 16 additions & 16 deletions webapp/components/survey/Surveys/HeaderLeft/HeaderLeft.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,37 @@ import { ButtonDownload } from '@webapp/components/buttons'
import { useAuthCanExportSurveysList, useUserIsSystemAdmin } from '@webapp/store/user/hooks'

const HeaderLeft = (props) => {
const { handleSearch, onlyOwn = false, search, setOnlyOwn = null, totalCount } = props
const { count, handleSearch, onlyOwn = false, search, setOnlyOwn = null } = props

const isSystemAdmin = useUserIsSystemAdmin()
const canExportSurveys = useAuthCanExportSurveysList()

if (!totalCount) return null

return (
<>
<TextInput
className="surveys__header-left__input-search"
defaultValue={search}
onChange={(val) => {
handleSearch(val)
}}
placeholder="surveysView.filterPlaceholder"
/>
{isSystemAdmin && setOnlyOwn && (
<Checkbox checked={onlyOwn} label="surveysView.onlyOwn" onChange={() => setOnlyOwn(!onlyOwn)} />
)}
{canExportSurveys && <ButtonDownload href="/api/surveys/export" label="common.csvExport" />}
<div className="filter-container">
<TextInput
className="surveys__header-left__input-search"
defaultValue={search}
onChange={(val) => {
handleSearch(val)
}}
placeholder="surveysView.filterPlaceholder"
/>
{isSystemAdmin && setOnlyOwn && (
<Checkbox checked={onlyOwn} label="surveysView.onlyOwn" onChange={() => setOnlyOwn(!onlyOwn)} />
)}
</div>
{canExportSurveys && count > 0 && <ButtonDownload href="/api/surveys/export" label="common.csvExport" />}
</>
)
}

HeaderLeft.propTypes = {
count: PropTypes.number.isRequired,
handleSearch: PropTypes.func.isRequired,
onlyOwn: PropTypes.bool,
search: PropTypes.string.isRequired,
setOnlyOwn: PropTypes.func,
totalCount: PropTypes.number.isRequired,
}

export default HeaderLeft
10 changes: 7 additions & 3 deletions webapp/components/survey/Surveys/Surveys.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@
.table__header {
column-gap: 5rem;

input {
width: 25rem;
padding: 0.5rem;
.filter-container {
display: flex;
gap: 2rem;

.surveys__header-left__input-search {
width: 25rem;
}
}
}

Expand Down

0 comments on commit a9850e2

Please sign in to comment.