Skip to content

Commit

Permalink
feat(web): Generic List - UX improvements (#15983)
Browse files Browse the repository at this point in the history
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
RunarVestmann and kodiakhq[bot] authored Sep 13, 2024
1 parent f9c2668 commit 5543763
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 41 deletions.
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

0 comments on commit 5543763

Please sign in to comment.