@@ -22,6 +22,14 @@ import { navigateToEntry } from '../routing/history';
2222import { getProcessSegment } from '../lib/formatters' ;
2323import { hasI18n , duplicateDefaultI18nFields , serializeI18n , I18N , I18N_FIELD } from '../lib/i18n' ;
2424import { isPaginationEnabled } from '../lib/pagination' ;
25+ import {
26+ hasActiveFilters ,
27+ hasActiveGroups ,
28+ hasActiveSorts ,
29+ extractActiveFilters ,
30+ matchesFilters ,
31+ getFieldValue ,
32+ } from '../lib/entryHelpers' ;
2533import { addNotification } from './notifications' ;
2634
2735import type { ImplementationMediaFile } from 'decap-cms-lib-util' ;
@@ -240,38 +248,9 @@ export function sortByField(
240248
241249 // Check if filtering is active - if so, apply filters first
242250 const activeFilters = state . entries . getIn ( [ 'filter' , collectionName ] ) ;
243- // eslint-disable-next-line @typescript-eslint/no-explicit-any
244- const hasActiveFilters =
245- activeFilters &&
246- typeof ( activeFilters as any ) . some === 'function' &&
247- // eslint-disable-next-line @typescript-eslint/no-explicit-any
248- ( activeFilters as any ) . some ( ( f : any ) => f . get ( 'active' ) === true ) ;
249-
250- if ( hasActiveFilters ) {
251- entries = entries . filter ( entry => {
252- // eslint-disable-next-line @typescript-eslint/no-explicit-any
253- const filters : any [ ] = [ ] ;
254- // eslint-disable-next-line @typescript-eslint/no-explicit-any
255- ( activeFilters as any ) . forEach ( ( f : any ) => {
256- if ( f . get ( 'active' ) === true ) {
257- filters . push ( {
258- pattern : f . get ( 'pattern' ) ,
259- field : f . get ( 'field' ) ,
260- } ) ;
261- }
262- } ) ;
263-
264- return filters . every ( ( { pattern, field } ) => {
265- const data = entry . data || { } ;
266- const fieldParts = field . split ( '.' ) ;
267- // eslint-disable-next-line @typescript-eslint/no-explicit-any
268- let value : any = data ;
269- for ( const part of fieldParts ) {
270- value = value ?. [ part ] ;
271- }
272- return value !== undefined && new RegExp ( String ( pattern ) ) . test ( String ( value ) ) ;
273- } ) ;
274- } ) ;
251+ if ( hasActiveFilters ( activeFilters ) ) {
252+ const filters = extractActiveFilters ( activeFilters ) ;
253+ entries = entries . filter ( entry => matchesFilters ( entry , filters ) ) ;
275254 }
276255
277256 // Sort entries by the specified field
@@ -282,13 +261,7 @@ export function sortByField(
282261 entries ,
283262 [
284263 entry => {
285- // dataPath is a string like "data.title" or "updatedOn"
286- const pathParts = dataPath . split ( '.' ) ;
287- // eslint-disable-next-line @typescript-eslint/no-explicit-any
288- let value : any = entry ;
289- for ( const part of pathParts ) {
290- value = value ?. [ part ] ;
291- }
264+ const value = getFieldValue ( entry , dataPath ) ;
292265 // Handle case-insensitive string sorting
293266 return typeof value === 'string' ? value . toLowerCase ( ) : value ;
294267 } ,
@@ -298,14 +271,8 @@ export function sortByField(
298271
299272 // Check if grouping is active - if so, use GROUP_ENTRIES_SUCCESS to avoid pagination
300273 const activeGroups = state . entries . getIn ( [ 'group' , collectionName ] ) ;
301- // eslint-disable-next-line @typescript-eslint/no-explicit-any
302- const hasActiveGroups =
303- activeGroups &&
304- typeof ( activeGroups as any ) . some === 'function' &&
305- // eslint-disable-next-line @typescript-eslint/no-explicit-any
306- ( activeGroups as any ) . some ( ( g : any ) => g . get ( 'active' ) === true ) ;
307274
308- if ( hasActiveGroups ) {
275+ if ( hasActiveGroups ( activeGroups ) ) {
309276 dispatch ( {
310277 type : GROUP_ENTRIES_SUCCESS ,
311278 payload : {
@@ -421,14 +388,9 @@ export function filterByField(collection: Collection, filter: ViewFilter) {
421388
422389 // Check if sorting is active - if so, apply sort after filtering
423390 const activeSorts = updatedState . entries . getIn ( [ 'sort' , collection . get ( 'name' ) ] ) ;
424- // eslint-disable-next-line @typescript-eslint/no-explicit-any
425- const hasActiveSort =
426- activeSorts &&
427- typeof ( activeSorts as any ) . size === 'number' &&
428- ( activeSorts as any ) . size > 0 ;
429391
430392 let finalEntries = filteredEntries ;
431- if ( hasActiveSort ) {
393+ if ( hasActiveSorts ( activeSorts ) ) {
432394 // eslint-disable-next-line @typescript-eslint/no-explicit-any
433395 const sortField = ( activeSorts as any ) . valueSeq ( ) . first ( ) ;
434396 const sortKey = sortField . get ( 'key' ) ;
@@ -440,12 +402,7 @@ export function filterByField(collection: Collection, filter: ViewFilter) {
440402 filteredEntries ,
441403 [
442404 entry => {
443- const pathParts = dataPath . split ( '.' ) ;
444- // eslint-disable-next-line @typescript-eslint/no-explicit-any
445- let value : any = entry ;
446- for ( const part of pathParts ) {
447- value = value ?. [ part ] ;
448- }
405+ const value = getFieldValue ( entry , dataPath ) ;
449406 return typeof value === 'string' ? value . toLowerCase ( ) : value ;
450407 } ,
451408 ] ,
@@ -455,14 +412,8 @@ export function filterByField(collection: Collection, filter: ViewFilter) {
455412
456413 // Check if grouping is active - if so, use GROUP_ENTRIES_SUCCESS to avoid pagination
457414 const activeGroups = updatedState . entries . getIn ( [ 'group' , collection . get ( 'name' ) ] ) ;
458- // eslint-disable-next-line @typescript-eslint/no-explicit-any
459- const hasActiveGroups =
460- activeGroups &&
461- typeof ( activeGroups as any ) . some === 'function' &&
462- // eslint-disable-next-line @typescript-eslint/no-explicit-any
463- ( activeGroups as any ) . some ( ( g : any ) => g . get ( 'active' ) === true ) ;
464415
465- if ( hasActiveGroups ) {
416+ if ( hasActiveGroups ( activeGroups ) ) {
466417 dispatch ( {
467418 type : GROUP_ENTRIES_SUCCESS ,
468419 payload : {
@@ -543,49 +494,16 @@ export function groupByField(collection: Collection, group: ViewGroup) {
543494
544495 // Check if filtering is active - if so, apply filters
545496 const activeFilters = updatedState . entries . getIn ( [ 'filter' , collection . get ( 'name' ) ] ) ;
546- // eslint-disable-next-line @typescript-eslint/no-explicit-any
547- const hasActiveFilters =
548- activeFilters &&
549- typeof ( activeFilters as any ) . some === 'function' &&
550- // eslint-disable-next-line @typescript-eslint/no-explicit-any
551- ( activeFilters as any ) . some ( ( f : any ) => f . get ( 'active' ) === true ) ;
552-
553- if ( hasActiveFilters ) {
554- entries = entries . filter ( entry => {
555- // eslint-disable-next-line @typescript-eslint/no-explicit-any
556- const filters : any [ ] = [ ] ;
557- // eslint-disable-next-line @typescript-eslint/no-explicit-any
558- ( activeFilters as any ) . forEach ( ( f : any ) => {
559- if ( f . get ( 'active' ) === true ) {
560- filters . push ( {
561- pattern : f . get ( 'pattern' ) ,
562- field : f . get ( 'field' ) ,
563- } ) ;
564- }
565- } ) ;
566497
567- return filters . every ( ( { pattern, field } ) => {
568- const data = entry . data || { } ;
569- const fieldParts = field . split ( '.' ) ;
570- // eslint-disable-next-line @typescript-eslint/no-explicit-any
571- let value : any = data ;
572- for ( const part of fieldParts ) {
573- value = value ?. [ part ] ;
574- }
575- return value !== undefined && new RegExp ( String ( pattern ) ) . test ( String ( value ) ) ;
576- } ) ;
577- } ) ;
498+ if ( hasActiveFilters ( activeFilters ) ) {
499+ const filters = extractActiveFilters ( activeFilters ) ;
500+ entries = entries . filter ( entry => matchesFilters ( entry , filters ) ) ;
578501 }
579502
580503 // Check if sorting is active - if so, apply sort
581504 const activeSorts = updatedState . entries . getIn ( [ 'sort' , collection . get ( 'name' ) ] ) ;
582- // eslint-disable-next-line @typescript-eslint/no-explicit-any
583- const hasActiveSort =
584- activeSorts &&
585- typeof ( activeSorts as any ) . size === 'number' &&
586- ( activeSorts as any ) . size > 0 ;
587505
588- if ( hasActiveSort ) {
506+ if ( hasActiveSorts ( activeSorts ) ) {
589507 // eslint-disable-next-line @typescript-eslint/no-explicit-any
590508 const sortField = ( activeSorts as any ) . valueSeq ( ) . first ( ) ;
591509 const sortKey = sortField . get ( 'key' ) ;
@@ -597,12 +515,7 @@ export function groupByField(collection: Collection, group: ViewGroup) {
597515 entries ,
598516 [
599517 entry => {
600- const pathParts = dataPath . split ( '.' ) ;
601- // eslint-disable-next-line @typescript-eslint/no-explicit-any
602- let value : any = entry ;
603- for ( const part of pathParts ) {
604- value = value ?. [ part ] ;
605- }
518+ const value = getFieldValue ( entry , dataPath ) ;
606519 return typeof value === 'string' ? value . toLowerCase ( ) : value ;
607520 } ,
608521 ] ,
0 commit comments