@@ -79,6 +79,8 @@ const Page = () => {
7979 const [ currentContentType , setCurrentContentType ] = useState < ContentTypeProps | null > ( null ) ;
8080 const [ searchQuery , setSearchQuery ] = useState < string > ( '' ) ;
8181 const [ initialTotal , setInitialTotal ] = useState ( 0 ) ;
82+ // Used to force a re-render of the table when the selection changes
83+ const [ tableKey , setTableKey ] = useState ( 0 ) ;
8284
8385 const hasActiveFilters = ( ) => {
8486 const hasSearchQuery = searchQuery . trim ( ) !== '' ;
@@ -94,8 +96,12 @@ const Page = () => {
9496 setActivePage ( 0 ) ;
9597 } ;
9698
97- const shouldDisableFilters = ( ) => {
98- return ( entries . length === 0 && initialTotal === 0 ) || ! selectedContentType || entriesLoading ;
99+ const shouldDisableFilters = ( disableIfLoading : boolean = true ) => {
100+ return (
101+ ( entries . length === 0 && initialTotal === 0 ) ||
102+ ! selectedContentType ||
103+ ( disableIfLoading ? entriesLoading : false )
104+ ) ;
99105 } ;
100106
101107 const getAllContentTypes = async ( ) : Promise < ContentTypeProps [ ] > => {
@@ -226,6 +232,13 @@ const Page = () => {
226232 setInitialTotal ( 0 ) ;
227233 } ;
228234
235+ // Used to clear the selection states and force a re-render of the table
236+ const clearSelectionState = ( ) => {
237+ setSelectedField ( null ) ;
238+ setSelectedEntryIds ( [ ] ) ;
239+ setTableKey ( ( tableKey ) => tableKey + 1 ) ;
240+ } ;
241+
229242 // Fetch content type and fields when selectedContentTypeId changes
230243 useEffect ( ( ) => {
231244 const fetchContentTypeAndFields = async ( ) : Promise < void > => {
@@ -521,6 +534,7 @@ const Page = () => {
521534 setActivePage ( 0 ) ;
522535 setSearchQuery ( '' ) ;
523536 setInitialTotal ( 0 ) ;
537+ clearSelectionState ( ) ;
524538 } }
525539 disabled = { entriesLoading }
526540 />
@@ -538,8 +552,9 @@ const Page = () => {
538552 onSearchChange = { ( query ) => {
539553 setSearchQuery ( query ) ;
540554 setActivePage ( 0 ) ;
555+ clearSelectionState ( ) ;
541556 } }
542- isDisabled = { shouldDisableFilters ( ) }
557+ isDisabled = { shouldDisableFilters ( false ) }
543558 debounceDelay = { 300 }
544559 />
545560
@@ -560,6 +575,7 @@ const Page = () => {
560575 setSelectedItems = { ( statuses ) => {
561576 setSelectedStatuses ( statuses ) ;
562577 setActivePage ( 0 ) ;
578+ clearSelectionState ( ) ;
563579 } }
564580 disabled = { shouldDisableFilters ( ) }
565581 placeholderConfig = { {
@@ -579,7 +595,6 @@ const Page = () => {
579595 return aIndex - bIndex ;
580596 } ) ;
581597 setSelectedColumns ( sortedSelectedColumns ) ;
582- setActivePage ( 0 ) ;
583598 } }
584599 disabled = { shouldDisableFilters ( ) }
585600 placeholderConfig = { {
@@ -600,18 +615,26 @@ const Page = () => {
600615 ) }
601616 </ Flex >
602617 { ! entriesLoading && (
603- < Flex alignItems = "center" gap = "spacingS" style = { styles . editButton } >
604- < Button
605- variant = "primary"
606- onClick = { ( ) => setIsModalOpen ( true ) }
607- isDisabled = { ! selectedField || selectedEntryIds . length === 0 } >
608- { selectedEntryIds . length > 1 ? 'Bulk edit' : 'Edit' }
609- </ Button >
618+ < >
619+ < Flex alignItems = "center" gap = "spacingS" style = { styles . editButton } >
620+ < Button
621+ variant = "primary"
622+ onClick = { ( ) => setIsModalOpen ( true ) }
623+ isDisabled = { ! selectedField || selectedEntryIds . length === 0 } >
624+ { selectedEntryIds . length > 1 ? 'Bulk edit' : 'Edit' }
625+ </ Button >
626+ < Button
627+ variant = "secondary"
628+ onClick = { ( ) => clearSelectionState ( ) }
629+ isDisabled = { ! selectedField || selectedEntryIds . length === 0 } >
630+ Clear selection
631+ </ Button >
632+ </ Flex >
610633 < Text fontColor = "gray600" >
611634 { selectedEntryIds . length || 'No' } entry field
612635 { selectedEntryIds . length === 1 ? '' : 's' } selected
613636 </ Text >
614- </ Flex >
637+ </ >
615638 ) }
616639 { entriesLoading ? (
617640 < Table style = { styles . loadingTableBorder } >
@@ -637,6 +660,7 @@ const Page = () => {
637660 />
638661 ) }
639662 < EntryTable
663+ key = { tableKey }
640664 entries = { entries }
641665 fields = { selectedColumns . flatMap (
642666 ( field ) => fields . find ( ( f ) => f . uniqueId === field . value ) || [ ]
0 commit comments