|
1 | 1 | 'use client'
|
2 |
| -import type { ClientCollectionConfig, FieldAffectingData, Where } from 'payload/types' |
| 2 | +import type { ClientCollectionConfig, Where } from 'payload/types' |
3 | 3 |
|
4 | 4 | import * as facelessUIImport from '@faceless-ui/window-info'
|
5 | 5 | import { getTranslation } from '@payloadcms/translations'
|
6 |
| -import React, { useState } from 'react' |
| 6 | +import React, { useEffect, useRef, useState } from 'react' |
7 | 7 | import AnimateHeightImport from 'react-animate-height'
|
8 | 8 |
|
9 | 9 | const AnimateHeight = (AnimateHeightImport.default ||
|
@@ -59,11 +59,22 @@ export const ListControls: React.FC<ListControlsProps> = (props) => {
|
59 | 59 | breakpoints: { s: smallBreak },
|
60 | 60 | } = useWindowInfo()
|
61 | 61 |
|
| 62 | + const hasWhereParam = useRef(Boolean(searchParams?.where)) |
| 63 | + |
62 | 64 | const shouldInitializeWhereOpened = validateWhereQuery(searchParams?.where)
|
63 | 65 | const [visibleDrawer, setVisibleDrawer] = useState<'columns' | 'sort' | 'where'>(
|
64 | 66 | shouldInitializeWhereOpened ? 'where' : undefined,
|
65 | 67 | )
|
66 | 68 |
|
| 69 | + useEffect(() => { |
| 70 | + if (hasWhereParam.current && !searchParams?.where) { |
| 71 | + setVisibleDrawer(undefined) |
| 72 | + hasWhereParam.current = false |
| 73 | + } else if (searchParams?.where) { |
| 74 | + hasWhereParam.current = true |
| 75 | + } |
| 76 | + }, [setVisibleDrawer, searchParams?.where]) |
| 77 | + |
67 | 78 | return (
|
68 | 79 | <div className={baseClass}>
|
69 | 80 | <div className={`${baseClass}__wrap`}>
|
@@ -156,6 +167,7 @@ export const ListControls: React.FC<ListControlsProps> = (props) => {
|
156 | 167 | <WhereBuilder
|
157 | 168 | collectionPluralLabel={collectionConfig?.labels?.plural}
|
158 | 169 | collectionSlug={collectionConfig.slug}
|
| 170 | + key={String(hasWhereParam.current && !searchParams?.where)} |
159 | 171 | />
|
160 | 172 | </AnimateHeight>
|
161 | 173 | {enableSort && (
|
|
0 commit comments