Skip to content
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

feat(web): Generic List - UX improvements #15983

Merged
merged 2 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions apps/web/components/GenericList/GenericList.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@ import { style } from '@vanilla-extract/css'
export const clickableItemTopRowContainer = style({
minHeight: '30px',
})

export const filterTagsContainer = style({
minHeight: '32px',
})
83 changes: 44 additions & 39 deletions apps/web/components/GenericList/GenericList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ export const GenericList = ({
variant={isMobile ? 'dialog' : 'popover'}
onFilterClear={() => {
setParameters(null)
setPage(null)
}}
filterInput={filterInputComponent}
>
Expand All @@ -342,6 +343,7 @@ export const GenericList = ({
: 'Clear selection'
}
onChange={({ categoryId, selected }) => {
setPage(null)
setParameters((prevParameters) => {
// Make sure we clear out the query params from the url when there is nothing selected
if (
Expand All @@ -361,6 +363,7 @@ export const GenericList = ({
})
}}
onClear={(categoryId) => {
setPage(null)
setParameters((prevParameters) => {
const updatedParameters = {
...prevParameters,
Expand All @@ -384,43 +387,45 @@ export const GenericList = ({
</Filter>
</Stack>

<Inline space={1} alignY="top">
{selectedFilters.length > 0 && (
<Text>
{activeLocale === 'is' ? 'Síað eftir:' : 'Filtered by:'}
</Text>
)}
<Inline space={1}>
{selectedFilters.map(({ value, label, category }) => (
<FilterTag
key={value}
onClick={() => {
setParameters((prevParameters) => {
const updatedParameters = {
...prevParameters,
[category]: (
prevParameters?.[category] ?? []
).filter((prevValue) => prevValue !== value),
}

// Make sure we clear out the query params from the url when there is nothing selected
if (
Object.values(updatedParameters).every(
(s) => !s || s.length === 0,
)
) {
return null
}

return updatedParameters
})
}}
>
{label}
</FilterTag>
))}
<Box className={styles.filterTagsContainer}>
<Inline space={1} alignY="top">
{selectedFilters.length > 0 && (
<Text>
{activeLocale === 'is' ? 'Síað eftir:' : 'Filtered by:'}
</Text>
)}
<Inline space={1}>
{selectedFilters.map(({ value, label, category }) => (
<FilterTag
key={value}
onClick={() => {
setParameters((prevParameters) => {
const updatedParameters = {
...prevParameters,
[category]: (
prevParameters?.[category] ?? []
).filter((prevValue) => prevValue !== value),
}

// Make sure we clear out the query params from the url when there is nothing selected
if (
Object.values(updatedParameters).every(
(s) => !s || s.length === 0,
)
) {
return null
}

return updatedParameters
})
}}
>
{label}
</FilterTag>
))}
</Inline>
</Inline>
</Inline>
</Box>
</Stack>
)}
{filterCategories.length === 0 && filterInputComponent}
Expand All @@ -436,7 +441,7 @@ export const GenericList = ({
}
/>
)}
{totalItems === 0 && !displayError && (
{totalItems === 0 && !displayError && !loading && (
<Text>{noResultsFoundText}</Text>
)}
{totalItems > 0 && (
Expand Down Expand Up @@ -511,7 +516,7 @@ export const GenericListWrapper = ({
useState<GenericListItemResponse | null>(null)
const [errorOccurred, setErrorOccurred] = useState(false)

const [fetchListItems, { loading }] = useLazyQuery<
const [fetchListItems, { loading, called }] = useLazyQuery<
Query,
GetGenericListItemsQueryVariables
>(GET_GENERIC_LIST_ITEMS_QUERY, {
Expand Down Expand Up @@ -567,7 +572,7 @@ export const GenericListWrapper = ({
})
}}
totalItems={totalItems}
loading={loading}
loading={loading || !called}
pageQueryId={pageQueryId}
searchQueryId={searchQueryId}
tagQueryId={tagQueryId}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const TeamMemberListWrapper = ({
)
const [errorOccurred, setErrorOccurred] = useState(false)

const [fetchListItems, { loading }] = useLazyQuery<Query>(
const [fetchListItems, { loading, called }] = useLazyQuery<Query>(
GET_TEAM_MEMBERS_QUERY,
{
onCompleted(data) {
Expand Down Expand Up @@ -89,7 +89,7 @@ export const TeamMemberListWrapper = ({
})
}}
totalItems={totalItems}
loading={loading}
loading={loading || !called}
pageQueryId={pageQueryId}
searchQueryId={searchQueryId}
tagQueryId={tagQueryId}
Expand Down