|
533 | 533 | }, |
534 | 534 | inheritanceParent() { |
535 | 535 | const firstNode = this.currentInheritingNodes[0]; |
| 536 | +
|
536 | 537 | if (!firstNode) { |
537 | 538 | return; |
538 | 539 | } |
|
726 | 727 | handleDragDrop(drop) { |
727 | 728 | const { data } = drop; |
728 | 729 | const { identity, section, relative } = data.target; |
| 730 | + const targetMetadata = identity.metadata || {}; |
729 | 731 | const isTargetTree = |
730 | 732 | drop.target && drop.target.region && drop.target.region.id === DraggableRegions.TREE; |
731 | 733 |
|
|
742 | 744 | position = this.relativePosition(relative > DraggableFlags.NONE ? relative : section); |
743 | 745 | } else { |
744 | 746 | // Safety check |
745 | | - const { kind } = identity.metadata || {}; |
| 747 | + const { kind } = targetMetadata; |
746 | 748 | if (kind && kind !== ContentKindsNames.TOPIC) { |
747 | 749 | return Promise.reject('Cannot set child of non-topic'); |
748 | 750 | } |
|
756 | 758 | const sources = drop.sources || []; |
757 | 759 | const sourceRegion = sources.length > 0 ? sources[0].region : null; |
758 | 760 | const payload = { |
759 | | - target: identity.metadata.id, |
| 761 | + target: targetMetadata.id, |
760 | 762 | position, |
761 | 763 | }; |
762 | 764 |
|
|
765 | 767 | // `excluded_descendants` by accessing the copy trees through the clipboard node ID |
766 | 768 | if (sourceRegion && sourceRegion.id === DraggableRegions.CLIPBOARD) { |
767 | 769 | return Promise.all( |
768 | | - data.sources.map(source => { |
| 770 | + sources.map(source => { |
769 | 771 | // Using `getCopyTrees` we can access the `excluded_descendants` for the node, such |
770 | 772 | // that we make sure to skip copying nodes that aren't intended to be copied |
771 | 773 | const trees = this.getCopyTrees(source.metadata.clipboardNodeId, true); |
|
789 | 791 | ); |
790 | 792 | } |
791 | 793 |
|
| 794 | + // We want to avoid launching the inherit modal when the move operation is a prepend or |
| 795 | + // append move, and target is the current parent. When the move operation is relative to |
| 796 | + // the target, that is left or right, we want only launch the modal if the parent is |
| 797 | + // changing |
| 798 | + let inherit = false; |
| 799 | + if ( |
| 800 | + position === RELATIVE_TREE_POSITIONS.FIRST_CHILD || |
| 801 | + position === RELATIVE_TREE_POSITIONS.LAST_CHILD |
| 802 | + ) { |
| 803 | + inherit = !sources.some(s => s.metadata.parent === targetMetadata.id); |
| 804 | + } else if ( |
| 805 | + position === RELATIVE_TREE_POSITIONS.LEFT || |
| 806 | + position === RELATIVE_TREE_POSITIONS.RIGHT |
| 807 | + ) { |
| 808 | + inherit = !sources.some(s => s.metadata.parent === targetMetadata.parent); |
| 809 | + } |
| 810 | +
|
792 | 811 | return this.moveContentNodes({ |
793 | 812 | ...payload, |
794 | | - id__in: data.sources.map(s => s.metadata.id), |
795 | | - inherit: !data.sources.some(s => s.metadata.parent === payload.target), |
| 813 | + id__in: sources.map(s => s.metadata.id), |
| 814 | + inherit, |
796 | 815 | }); |
797 | 816 | } |
798 | 817 | }, |
|
0 commit comments