@@ -414,7 +414,7 @@ class P extends React.Component {
414
414
415
415
const get_lexgraph_marker = lexentry_id_source => {
416
416
const lexgraph_entity = get_lexgraph_entity ( lexentry_id_source ) ;
417
- return lexgraph_entity ? lexgraph_entity . content : '' ;
417
+ return lexgraph_entity ? lexgraph_entity . content || '' : '' ;
418
418
} ;
419
419
420
420
const setSort = ( field , order ) => {
@@ -431,47 +431,22 @@ class P extends React.Component {
431
431
( ) => console . log ( "dnd_enabled: " , this . state . dnd_enabled ) ) ;
432
432
} ;
433
433
434
- const dragAndDropEntries = ( lexentry_id_source , lexentry_id_before , lexentry_id_after ) => {
435
-
436
- if ( lexentry_id_source && ( lexentry_id_before || lexentry_id_after ) ) {
437
- const entity_id_change = get_lexgraph_entity ( lexentry_id_source ) . id ;
434
+ const addEntry = ( lexgraph_min ) => {
438
435
439
- const lexgraph_before = get_lexgraph_marker ( lexentry_id_before ) ;
440
- const lexgraph_after = get_lexgraph_marker ( lexentry_id_after ) ;
436
+ /* Will need a valid ordering field and a valid minimal ordering marker. */
441
437
442
- updateLexgraph ( {
443
- variables : {
444
- id : entity_id_change ,
445
- lexgraph_before,
446
- lexgraph_after
447
- } ,
448
- refetchQueries : [
449
- {
450
- query : queryLexicalEntries ,
451
- variables : {
452
- id,
453
- entitiesMode
454
- }
455
- }
456
- ] ,
457
- awaitRefetchQueries : true
458
- } ) . then ( ( { data : mutation } ) => {
438
+ if ( ! lexgraph_field_id )
439
+ {
440
+ window . logger . err ( `Invalid ordering field id ${ lexgraph_field_id } .` ) ;
441
+ return ;
442
+ }
459
443
460
- this . setState ( {
461
- cards : [ ]
462
- } ) ;
463
- /*this.setState({mutation});*/
464
- } ,
465
- ( error ) => {
466
- //window.logger.err(`GraphQL error: ${this.context(error.message)}`);
467
- this . setState ( {
468
- cards : [ ]
469
- } ) ;
470
- } ) ;
444
+ if ( ! lexgraph_min && lexgraph_min !== "" )
445
+ {
446
+ window . logger . err ( `Invalid minimal ordering marker ${ lexgraph_min } .` ) ;
447
+ return ;
471
448
}
472
- } ;
473
449
474
- const addEntry = ( lexgraph_min ) => {
475
450
createLexicalEntry ( {
476
451
variables : {
477
452
id,
@@ -497,34 +472,30 @@ class P extends React.Component {
497
472
} = d ;
498
473
addCreatedEntry ( lexicalentry ) ;
499
474
500
-
501
- if ( lexgraph_field_id && lexgraph_min ) {
502
- createEntity ( {
503
- variables : {
504
- parent_id : lexicalentry . id ,
505
- field_id : lexgraph_field_id ,
506
- lexgraph_after : lexgraph_min
507
- } ,
508
- update : ( cache , { data : { create_entity : { entity } } } ) => {
509
- cache . updateQuery ( {
510
- query : queryLexicalEntries ,
511
- variables : { id, entitiesMode}
512
- } ,
513
- ( data ) => {
514
- const lexical_entries = data . perspective . lexical_entries . filter ( le => ! isEqual ( le . id , lexicalentry . id ) ) ;
515
- const lexicalentry_updated = { ...lexicalentry , entities : [ ...lexicalentry . entities , entity ] } ;
516
- return {
517
- perspective : {
518
- ...data . perspective ,
519
- lexical_entries : [ ...lexical_entries , lexicalentry_updated ]
520
- }
521
- } ;
522
- }
523
- ) ;
524
- } ,
525
- } ) ;
526
- }
527
-
475
+ createEntity ( {
476
+ variables : {
477
+ parent_id : lexicalentry . id ,
478
+ field_id : lexgraph_field_id ,
479
+ lexgraph_after : lexgraph_min
480
+ } ,
481
+ update : ( cache , { data : { create_entity : { entity } } } ) => {
482
+ cache . updateQuery ( {
483
+ query : queryLexicalEntries ,
484
+ variables : { id, entitiesMode}
485
+ } ,
486
+ ( data ) => {
487
+ const lexical_entries = data . perspective . lexical_entries . filter ( le => ! isEqual ( le . id , lexicalentry . id ) ) ;
488
+ const lexicalentry_updated = { ...lexicalentry , entities : [ ...lexicalentry . entities , entity ] } ;
489
+ return {
490
+ perspective : {
491
+ ...data . perspective ,
492
+ lexical_entries : [ ...lexical_entries , lexicalentry_updated ]
493
+ }
494
+ } ;
495
+ }
496
+ ) ;
497
+ } ,
498
+ } ) ;
528
499
}
529
500
} ) ;
530
501
} ;
@@ -592,7 +563,7 @@ class P extends React.Component {
592
563
const sortedEntries = sortBy ( es , e => {
593
564
const entities = e . entities . filter ( entity => isEqual ( entity . field_id , lexgraph_field_id ) ) ;
594
565
if ( entities . length > 0 ) {
595
- return entities [ 0 ] . content ;
566
+ return entities [ 0 ] . content || "" ;
596
567
}
597
568
return "" ;
598
569
} ) ;
@@ -677,16 +648,133 @@ class P extends React.Component {
677
648
if ( ! lexgraph_field_id )
678
649
{ return null ; }
679
650
680
- let min_res = '1 ' ;
651
+ let min_res = '' ;
681
652
for ( let i = 0 ; i < entries . length ; i ++ ) {
682
653
const result = get_lexgraph_marker ( entries [ i ] . id ) ;
683
- if ( result && result < min_res )
654
+ if ( result && ( ! min_res || result < min_res ) )
684
655
{ min_res = result ; }
685
656
}
686
657
687
658
return min_res ;
688
659
} ;
689
660
661
+ const dragAndDropEntries = ( lexentry_id_source , lexentry_id_before , lexentry_id_after ) => {
662
+
663
+ /* Need a valid source lexical entry and at least one of preceeding/succeeding entries. */
664
+
665
+ if ( ! lexentry_id_source || ( ! lexentry_id_before && ! lexentry_id_after ) )
666
+ {
667
+ this . setState ( {
668
+ cards : [ ]
669
+ } ) ;
670
+
671
+ return ;
672
+ }
673
+
674
+ /* Will need a valid ordering field. */
675
+
676
+ if ( ! lexgraph_field_id )
677
+ {
678
+ window . logger . err ( `Invalid ordering field id ${ lexgraph_field_id } .` ) ;
679
+
680
+ this . setState ( {
681
+ cards : [ ]
682
+ } ) ;
683
+
684
+ return ;
685
+ }
686
+
687
+ const entity = get_lexgraph_entity ( lexentry_id_source ) ;
688
+
689
+ let lexgraph_before = get_lexgraph_marker ( lexentry_id_before ) ;
690
+ let lexgraph_after = get_lexgraph_marker ( lexentry_id_after ) ;
691
+
692
+ /* In case we somehow are drag-and-dropping between two entries without ordering markers. */
693
+
694
+ const current_lexgraph_min = lexgraph_min ( ) ;
695
+
696
+ if ( ! current_lexgraph_min && current_lexgraph_min !== '' )
697
+ {
698
+ window . logger . err ( `Invalid minimal ordering marker "${ current_lexgraph_min } ".` ) ;
699
+
700
+ this . setState ( {
701
+ cards : [ ]
702
+ } ) ;
703
+
704
+ return ;
705
+ }
706
+
707
+ if ( lexgraph_after < current_lexgraph_min )
708
+ lexgraph_after = current_lexgraph_min ;
709
+
710
+ /* If for some reason the entry being moved does not have an ordering marker, we create one. */
711
+
712
+ if ( ! entity )
713
+ {
714
+ createEntity ( {
715
+ variables : {
716
+ parent_id : lexentry_id_source ,
717
+ field_id : lexgraph_field_id ,
718
+ lexgraph_after
719
+ } ,
720
+ update : ( cache , { data : { create_entity : { entity } } } ) => {
721
+ cache . updateQuery ( {
722
+ query : queryLexicalEntries ,
723
+ variables : { id, entitiesMode}
724
+ } ,
725
+ ( data ) => {
726
+ const lexical_entries = data . perspective . lexical_entries . filter ( le => ! isEqual ( le . id , lexicalentry . id ) ) ;
727
+ const lexicalentry_updated = { ...lexicalentry , entities : [ ...lexicalentry . entities , entity ] } ;
728
+ return {
729
+ perspective : {
730
+ ...data . perspective ,
731
+ lexical_entries : [ ...lexical_entries , lexicalentry_updated ]
732
+ }
733
+ } ;
734
+ }
735
+ ) ;
736
+ } ,
737
+ } ) ;
738
+
739
+ this . setState ( {
740
+ cards : [ ]
741
+ } ) ;
742
+
743
+ return ;
744
+ }
745
+
746
+ /* Standard lexical entry ordering move. */
747
+
748
+ updateLexgraph ( {
749
+ variables : {
750
+ id : entity . id ,
751
+ lexgraph_before,
752
+ lexgraph_after
753
+ } ,
754
+ refetchQueries : [
755
+ {
756
+ query : queryLexicalEntries ,
757
+ variables : {
758
+ id,
759
+ entitiesMode
760
+ }
761
+ }
762
+ ] ,
763
+ awaitRefetchQueries : true
764
+ } ) . then (
765
+ ( data ) => {
766
+ this . setState ( {
767
+ cards : [ ]
768
+ } ) ;
769
+ } ,
770
+ ( error ) => {
771
+ this . setState ( {
772
+ cards : [ ]
773
+ } ) ;
774
+ }
775
+ ) ;
776
+ } ;
777
+
690
778
const _ROWS_PER_PAGE = lexgraph_field_id ? entries . length : ROWS_PER_PAGE ;
691
779
692
780
const pageEntries =
0 commit comments