Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
processed feedback
Browse files Browse the repository at this point in the history
svandenhoek committed Nov 26, 2024
1 parent d2e2d76 commit ff6cdbf
Showing 3 changed files with 23 additions and 2 deletions.
3 changes: 2 additions & 1 deletion apps/metadata-utils/src/fieldHelpers.ts
Original file line number Diff line number Diff line change
@@ -57,7 +57,8 @@ export const isValueType = (column: IColumn) => {
column.columnType === "DATETIME" ||
column.columnType === "INT" ||
column.columnType === "LONG" ||
column.columnType === "DECIMAL"
column.columnType === "DECIMAL" ||
column.columnType === "JSON"
);
};

8 changes: 7 additions & 1 deletion apps/molgenis-components/src/components/forms/InputJson.vue
Original file line number Diff line number Diff line change
@@ -30,12 +30,18 @@
import FormGroup from "./FormGroup.vue";
import InputGroup from "./InputGroup.vue";
import BaseInput from "./baseInputs/BaseInput.vue";
import { parseJson, isJsonObjectOrArray } from "./formUtils/formUtils";
import { isJsonObjectOrArray } from "./formUtils/formUtils";
export default {
name: "InputJson",
components: { FormGroup, InputGroup },
extends: BaseInput,
props: {
modelValue: {
type: [String, null],
default: null,
},
},
computed: {
stringError() {
if (typeof this.modelValue === "string") {
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@ import {
splitColumnIdsByHeadings,
isMissingValue,
isRequired,
isJsonObjectOrArray,
} from "./formUtils";
import type { ITableMetaData, IColumn } from "metadata-utils";
const { AUTO_ID, HEADING } = constants;
@@ -375,4 +376,17 @@ describe("isValidHyperLink", () => {
constants.HYPERLINK_REGEX.test("https://example.com/(test)".toLowerCase())
).toBe(true);
});

describe("isJsonObjectOrArray", () => {
test("only JSON object/array should return true (after parsing from JSON string)", () => {
expect(isJsonObjectOrArray(JSON.parse('{"key":"value"}'))).toBe(true);
expect(isJsonObjectOrArray(JSON.parse('["string1", "string2"]'))).toBe(true);
expect(isJsonObjectOrArray(JSON.parse('{"key1":{"key2":["value1", "value2"]}}'))).toBe(true);
expect(isJsonObjectOrArray(JSON.parse('"string"'))).toBe(false);
expect(isJsonObjectOrArray(JSON.parse('1'))).toBe(false);
expect(isJsonObjectOrArray(JSON.parse('true'))).toBe(false);
expect(isJsonObjectOrArray(JSON.parse('false'))).toBe(false);
expect(isJsonObjectOrArray(JSON.parse('null'))).toBe(false);
});
});
});

0 comments on commit ff6cdbf

Please sign in to comment.