Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

serializer: handle marketplace errors #38

Merged
merged 4 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:

strategy:
matrix:
node-version: [18.x]
node-version: [18]

steps:
- name: Checkout
Expand Down
4 changes: 2 additions & 2 deletions docker/builder/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ docker compose -f docker/builder/docker-compose.yml up -d
#

# installing utility tool to auth
npm install -g npm-cli-adduser
npm install -g npm-cli-login

# authenticating
npm-cli-adduser \
npm-cli-login \
-u $VERDACCIO_USERNAME \
-p $VERDACCIO_PASSWORD \
-e $VERDACCIO_EMAIL \
Expand Down
18 changes: 0 additions & 18 deletions src/lib/DepositRecordSerializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,24 +296,6 @@ export class RDMDepositRecordSerializer extends DepositRecordSerializer {
fieldpath: "metadata.marketplace.vendor_contact",
deserializedDefault: "",
}),
pricing: new SchemaField({
fieldpath: "metadata.marketplace.pricing",
schema: {
title: new Field({
fieldpath: "title",
}),
description: new Field({
fieldpath: "description",
}),
url: new Field({
fieldpath: "url",
}),
value: new Field({
fieldpath: "value",
}),
},
deserializedDefault: [],
}),
};
}

Expand Down
2 changes: 0 additions & 2 deletions src/lib/DepositRecordSerializer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ describe("RDMDepositRecordSerializer tests", () => {
marketplace: {
launch_url: "",
vendor_contact: "",
pricing: [],
},
version: "",
geo_work_programme_activity: "",
Expand Down Expand Up @@ -361,7 +360,6 @@ describe("RDMDepositRecordSerializer tests", () => {
marketplace: {
launch_url: "",
vendor_contact: "",
pricing: [],
},
contributors: [
{
Expand Down
9 changes: 5 additions & 4 deletions src/lib/components/FormFeedback.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
FILE_UPLOAD_SAVE_DRAFT_FAILED,
RESERVE_PID_FAILED,
} from "../state/types";
import { leafTraverse } from "../utils";
import { leafTraverse, objectAsList } from "../utils";
import PropTypes from "prop-types";

const defaultLabels = {
Expand All @@ -47,6 +47,9 @@ const defaultLabels = {
"metadata.publisher": i18next.t("Publisher"),
"metadata.related_identifiers": i18next.t("Related works"),
"metadata.identifiers": i18next.t("Alternate identifiers"),
"metadata.marketplace": i18next.t("Launch URL and Vendor Contact"),
"metadata.marketplace_launch_url": i18next.t("Launch URL"),
"metadata.marketplace_vendor_contact": i18next.t("Vendor Contact"),
"access.embargo.until": i18next.t("Embargo until"),
"pids.doi": i18next.t("DOI"),
};
Expand Down Expand Up @@ -193,9 +196,7 @@ class DisconnectedFormFeedback extends Component {
// e.g., {metadata: {creators: ,,,}} => {"metadata.creators": ...}
// For now, only for metadata, files and access.embargo
const metadata = errors.metadata || {};
const step0Metadata = Object.entries(metadata).map(([key, value]) => {
return ["metadata." + key, value];
});
const step0Metadata = objectAsList(metadata, "metadata");
const files = errors.files || {};
const step0Files = Object.entries(files).map(([key, value]) => {
return ["files." + key, value];
Expand Down
46 changes: 46 additions & 0 deletions src/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,52 @@ export function leafTraverse(obj, func = (l) => l) {
}
}

/**
* Transforms an object into an array of key-value pairs with a specified prefix.
* Nested objects are flattened with keys joined by underscores.
* The top-level key is prefixed with a given string.
*
* @param {Object} obj - The object to be transformed.
* @param {string} prefix - The prefix to be added to each key.
* @returns {Array} An array of key-value pairs with transformed keys.
*
* @example
* const inputObj = {
* "title": "Missing data for required field.",
* "marketplace": {
* "launch_url": "Missing data for required field."
* };
* };
*
* const prefix = 'metadata';
* console.log(objectAsList(inputObj, prefix));
* // Output:
* // [
* // ["metadata.title", "Missing data for required field."],
* // ["metadata.marketplace_launch_url", "Missing data for required field."]
* // ]
*/
export function objectAsList(obj, prefix) {
function transform(obj, parentKey = "", result = []) {
for (let key in obj) {
let hasProperty = obj.hasOwnProperty(key); // eslint-disable-line no-prototype-builtins

if (hasProperty) {
const newKey = parentKey ? `${parentKey}_${key}` : key;
if (typeof obj[key] === "object" && obj[key] !== null) {
transform(obj[key], newKey, result);
} else {
result.push([newKey, obj[key]]);
}
}
}
return result;
}

const result = transform(obj);
return result.map(([key, value]) => [`${prefix}.${key}`, value]);
}

/**
* Sort a list of string values (options).
* @param {list} options
Expand Down
Loading