Skip to content

Commit ab3cdad

Browse files
committed
Ignore blank fields even in cautious auto merging
1 parent 7d694cb commit ab3cdad

File tree

1 file changed

+11
-8
lines changed
  • specifyweb/frontend/js_src/lib/components/Merging

1 file changed

+11
-8
lines changed

specifyweb/frontend/js_src/lib/components/Merging/autoMerge.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,11 @@ function mergeField(
6161
cautious: boolean
6262
) {
6363
const values = resources.map((resource) => resource[field.name]);
64-
const nonNullValues = values.filter(
65-
(value) =>
66-
value !== undefined && value !== null && value !== false && value !== ''
64+
const nonNullValues = f.unique(
65+
values.filter(
66+
(value) =>
67+
value !== undefined && value !== null && value !== false && value !== ''
68+
)
6769
);
6870
const firstValue = nonNullValues[0] ?? values[0];
6971
if (field.isRelationship)
@@ -88,17 +90,18 @@ function mergeField(
8890
cautious
8991
);
9092
else return firstValue;
91-
else if (nonNullValues.length > 0) {
92-
const uniqueValues = f.unique(values);
93-
if (uniqueValues.length > 1 && cautious) return null;
93+
// Don't try to merge conflicts
94+
else if (nonNullValues.length > 1 && cautious) return null;
95+
else if (nonNullValues.length > 0)
96+
// Pick the longest value
9497
return (
95-
nonNullValues.sort(
98+
Array.from(nonNullValues).sort(
9699
sortFunction((string) =>
97100
typeof string === 'string' ? string.length : 0
98101
)
99102
)[0] ?? firstValue
100103
);
101-
} else return firstValue;
104+
else return firstValue;
102105
}
103106

104107
/**

0 commit comments

Comments
 (0)