Skip to content

Commit

Permalink
updating normalization of path matching
Browse files Browse the repository at this point in the history
  • Loading branch information
tnrich committed Jan 10, 2024
1 parent 81fb224 commit 319f3d1
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 20 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
- Export validateSequenceArray [`#2`](https://github.com/TeselaGen/tg-oss/pull/2)
- genbank ss-DNA should not be overwirte to DNA [`#1`](https://github.com/TeselaGen/tg-oss/pull/1)
- closes #35 [`#35`](https://github.com/TeselaGen/tg-oss/issues/35)
- trying out updating auto-changelog to run on publish [`4b8537f`](https://github.com/TeselaGen/tg-oss/commit/4b8537f4d375d2e74edf3dee5e3340c12e6faac5)
- merging in master [`04c5445`](https://github.com/TeselaGen/tg-oss/commit/04c544591eb3f2630408e5bb2756e75d8eaacdd0)
- updating table styling to remove table last row bottom margin, removing unused S3Download, removing axios dep, updating deps [`8a6fb1f`](https://github.com/TeselaGen/tg-oss/commit/8a6fb1f047550f617c3e56b8c3ebf145967076ef)
- updating normalizeCsvHeader so camel case -> snake case is preserved, and allowing TooFewFields as csv parse error [`81fb224`](https://github.com/TeselaGen/tg-oss/commit/81fb22445e42a2786e73ffeae72c3052b82b0710)
- trying out updating auto-changelog to run on publish [`4b8537f`](https://github.com/TeselaGen/tg-oss/commit/4b8537f4d375d2e74edf3dee5e3340c12e6faac5)
2 changes: 1 addition & 1 deletion packages/file-utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@teselagen/file-utils",
"version": "0.3.12",
"version": "0.3.14",
"type": "commonjs",
"dependencies": {
"bluebird": "^3.7.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@teselagen/ui",
"version": "0.3.62",
"version": "0.3.63",
"main": "./src/index.js",
"exports": {
".": {
Expand Down
10 changes: 9 additions & 1 deletion packages/ui/src/FormComponents/Uploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,15 @@ function UploaderInner({
if (isCsvOrExcelFile(file)) {
let parsedF;
try {
parsedF = await parseCsvOrExcelFile(file);
parsedF = await parseCsvOrExcelFile(file, {
csvParserOptions: isFunction(
validateAgainstSchema.csvParserOptions
)
? validateAgainstSchema.csvParserOptions({
validateAgainstSchema
})
: validateAgainstSchema.csvParserOptions
});
} catch (error) {
console.error("error:", error);
window.toastr &&
Expand Down
27 changes: 12 additions & 15 deletions packages/ui/src/FormComponents/tryToMatchSchemas.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { forEach, isArray, map } from "lodash";
import { forEach, isArray, map, snakeCase } from "lodash";
import { nanoid } from "nanoid";
import Fuse from "fuse.js";
import { editCellHelper } from "../DataTable/editCellHelper";
Expand Down Expand Up @@ -89,24 +89,17 @@ async function matchSchemas({ userSchema, officialSchema }) {

//if there are any exact matches, push them onto the results array
userSchema.fields.forEach((uh, i) => {
const pathMatch =
uh.path.toLowerCase().replace(/ /g, "") ===
h.path.toLowerCase().replace(/ /g, "");
const pathMatch = norm(uh.path) === norm(h.path);
const displayNameMatch =
h.displayName &&
uh.path.toLowerCase().replace(/ /g, "") ===
getTextFromEl(h.displayName).toLowerCase().replace(/ /g, "");
h.displayName && norm(uh.path) === norm(getTextFromEl(h.displayName));
const hasAlternatePathMatch =
h.alternatePathMatch &&
(isArray(h.alternatePathMatch)
? h.alternatePathMatch.some(alternatePathMatch => {
return (
uh.path.toLowerCase().replace(/ /g, "") ===
alternatePathMatch.toLowerCase().replace(/ /g, "")
);
})
: uh.path.toLowerCase().replace(/ /g, "") ===
h.alternatePathMatch.toLowerCase().replace(/ /g, ""));
? h.alternatePathMatch
: [h.alternatePathMatch]
).some(alternatePathMatch => {
return norm(uh.path) === norm(alternatePathMatch);
});

if (pathMatch || displayNameMatch || hasAlternatePathMatch) {
result = result.filter(({ path }) => path === uh.path);
Expand Down Expand Up @@ -232,3 +225,7 @@ async function resolveValidateAgainstSchema() {
// }
// })
}

function norm(h) {
return snakeCase(h).toLowerCase().replace(/ /g, "");
}

0 comments on commit 319f3d1

Please sign in to comment.