@@ -18,6 +18,7 @@ import {
1818} from 'react-querybuilder' ;
1919import { IntlShape } from 'react-intl' ;
2020import { validate as uuidValidate } from 'uuid' ;
21+ import { UUID } from 'crypto' ;
2122import {
2223 CombinatorType ,
2324 CompositeField ,
@@ -251,6 +252,7 @@ export function exportExpertRules(query: RuleGroupType): RuleGroupTypeExport {
251252
252253 // a single rule
253254 return {
255+ id : rule . id as UUID ,
254256 field : rule . field as FieldType ,
255257 operator :
256258 dataType !== DataType . PROPERTY
@@ -296,6 +298,7 @@ export function exportExpertRules(query: RuleGroupType): RuleGroupTypeExport {
296298 ) ;
297299
298300 return {
301+ id : compositeGroup . id as UUID ,
299302 combinator : compositeGroup . combinator as CombinatorType ,
300303 dataType : DataType . COMBINATOR ,
301304 rules : transformedRules ,
@@ -317,6 +320,7 @@ export function exportExpertRules(query: RuleGroupType): RuleGroupTypeExport {
317320 } ) ;
318321
319322 return {
323+ id : group . id as UUID ,
320324 combinator : group . combinator as CombinatorType ,
321325 dataType : DataType . COMBINATOR ,
322326 rules : transformedRules ,
@@ -356,6 +360,7 @@ export function importExpertRules(query: RuleGroupTypeExport): RuleGroupType {
356360
357361 function transformRule ( rule : RuleTypeExport ) : RuleType {
358362 return {
363+ id : rule . id ,
359364 field : rule . field ,
360365 operator :
361366 rule . dataType !== DataType . PROPERTY
@@ -382,6 +387,7 @@ export function importExpertRules(query: RuleGroupTypeExport): RuleGroupType {
382387 ) ;
383388
384389 return {
390+ id : group . id ,
385391 field : group . field as FieldType ,
386392 operator : Object . values ( OPERATOR_OPTIONS ) . find (
387393 ( operator ) => operator . customName === group . operator
@@ -408,6 +414,7 @@ export function importExpertRules(query: RuleGroupTypeExport): RuleGroupType {
408414 } ) ;
409415
410416 return {
417+ id : group . id ,
411418 combinator : group . combinator ,
412419 rules : transformedRules ,
413420 } ;
@@ -417,6 +424,10 @@ export function importExpertRules(query: RuleGroupTypeExport): RuleGroupType {
417424}
418425
419426export function countRules ( query : RuleGroupTypeAny ) : number {
427+ if ( ! query ) {
428+ return 0 ;
429+ }
430+
420431 if ( 'rules' in query ) {
421432 const group = query as RuleGroupType ;
422433 return group . rules . reduce (
@@ -432,6 +443,10 @@ export function countRules(query: RuleGroupTypeAny): number {
432443export const queryValidator : QueryValidator = ( query ) => {
433444 const result : ValidationMap = { } ;
434445
446+ if ( ! query ) {
447+ return result ;
448+ }
449+
435450 const validateRule = ( rule : RuleType ) => {
436451 const isValueAnArray = Array . isArray ( rule . value ) ;
437452 const dataType = getDataType ( rule . field , rule . operator ) ;
@@ -579,7 +594,7 @@ export function getNumberOfSiblings(path: number[], query: RuleGroupTypeAny) {
579594 // Find the parent group object in the query
580595 const parentGroup = findPath ( parentPath , query ) as RuleGroupType ;
581596 // Return the number of siblings
582- return parentGroup . rules . length ;
597+ return parentGroup ? .rules ? .length ;
583598}
584599
585600// Remove a rule or group and its parents if they become empty
0 commit comments