@teselagen/ui 0.3.65 → 0.3.67
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.cjs.js +173 -175
- package/index.es.js +173 -175
- package/package.json +1 -1
- package/src/FormComponents/tryToMatchSchemas.js +20 -3
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { forEach, isArray, map, snakeCase } from "lodash";
|
|
1
|
+
import { forEach, isArray, isPlainObject, map, snakeCase } from "lodash";
|
|
2
2
|
import { nanoid } from "nanoid";
|
|
3
3
|
import Fuse from "fuse.js";
|
|
4
4
|
import { editCellHelper } from "../DataTable/editCellHelper";
|
|
@@ -82,25 +82,42 @@ async function matchSchemas({ userSchema, officialSchema }) {
|
|
|
82
82
|
let csvValidationIssue = false;
|
|
83
83
|
const fuse = new Fuse(userSchema.fields, options);
|
|
84
84
|
|
|
85
|
+
const matchedAltPaths = [];
|
|
85
86
|
officialSchema.fields.forEach(h => {
|
|
86
87
|
let hasMatch = false;
|
|
87
88
|
//run fuse search for results
|
|
88
89
|
let result = fuse.search(h.path) || [];
|
|
89
90
|
|
|
91
|
+
const hadNormalPathMatch = userSchema.fields.some(
|
|
92
|
+
uh => norm(uh.path) === norm(h.path)
|
|
93
|
+
);
|
|
90
94
|
//if there are any exact matches, push them onto the results array
|
|
91
95
|
userSchema.fields.forEach((uh, i) => {
|
|
92
96
|
const pathMatch = norm(uh.path) === norm(h.path);
|
|
93
97
|
const displayNameMatch =
|
|
94
98
|
h.displayName && norm(uh.path) === norm(getTextFromEl(h.displayName));
|
|
95
99
|
const hasAlternatePathMatch =
|
|
100
|
+
!hadNormalPathMatch &&
|
|
96
101
|
h.alternatePathMatch &&
|
|
97
102
|
(isArray(h.alternatePathMatch)
|
|
98
103
|
? h.alternatePathMatch
|
|
99
104
|
: [h.alternatePathMatch]
|
|
100
|
-
).
|
|
101
|
-
|
|
105
|
+
).find(alternatePathMatch => {
|
|
106
|
+
let altPath = alternatePathMatch;
|
|
107
|
+
if (isPlainObject(alternatePathMatch)) {
|
|
108
|
+
altPath = alternatePathMatch.path;
|
|
109
|
+
}
|
|
110
|
+
return norm(uh.path) === norm(altPath);
|
|
102
111
|
});
|
|
103
112
|
|
|
113
|
+
if (hasAlternatePathMatch) {
|
|
114
|
+
matchedAltPaths.push(
|
|
115
|
+
hasAlternatePathMatch.path || hasAlternatePathMatch
|
|
116
|
+
);
|
|
117
|
+
if (hasAlternatePathMatch.format) {
|
|
118
|
+
h.format = hasAlternatePathMatch.format;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
104
121
|
if (pathMatch || displayNameMatch || hasAlternatePathMatch) {
|
|
105
122
|
result = result.filter(({ path }) => path === uh.path);
|
|
106
123
|
//add a fake perfect match result to make sure we get the match
|