Skip to content

Commit

Permalink
Merge branch 'main' into storage-dashboard-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
HarishGangula authored Nov 13, 2024
2 parents 5c76847 + fb65393 commit 2c4e2a5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
11 changes: 1 addition & 10 deletions web-console-v2/src/pages/StepsPages/Ingestion/Ingestion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import UploadFiles from 'pages/Dataset/wizard/UploadFiles';
import React, { useEffect, useMemo, useRef, useState } from 'react';
import { useLocation, useNavigate, useParams } from 'react-router-dom';
import {
isJsonSchema,
useCreateDataset,
useFetchDatasetExists,
useFetchDatasetsById,
Expand All @@ -28,7 +29,6 @@ import {
} from 'services/dataset';
import { readJsonFileContents } from 'services/utils';
import { theme } from 'theme';
import Ajv from "ajv";
import { default as ingestionStyle, default as localStyles } from './Ingestion.module.css';

interface FormData {
Expand All @@ -46,15 +46,6 @@ const GenericCard = styled(Card)(({ theme }) => ({
boxShadow: 'none',
margin: theme.spacing(0, 6, 2, 2)
}));
const ajv = new Ajv({strict: false});
const isJsonSchema = (jsonObject: any) => {
try {
ajv.compile(jsonObject);
return true; // If no errors, it's a valid JSON Schema
} catch (err) {
return false; // Not a valid JSON Schema
}
}

const MAX_FILES = 10;

Expand Down
32 changes: 30 additions & 2 deletions web-console-v2/src/services/dataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import _ from 'lodash';
import { fetchSessionStorageItem, storeSessionStorageItem } from 'utils/sessionStorage';
import { generateRequestBody, setDatasetId, setVersionKey, transformResponse } from './utils';
import { queryClient } from 'queryClient';
import apiEndpoints from 'data/apiEndpoints';

// const ENDPOINTS = {
// DATASETS_READ: '/console/config/v2/datasets/read',
Expand Down Expand Up @@ -256,4 +255,33 @@ const omitSuggestions = (schema: any): any => {
export const getConfigValue = (variable: string) => {
const config: string | any = sessionStorage.getItem('systemSettings');
return _.get(JSON.parse(config), variable);
};
};

export const isJsonSchema = (jsonObject: any) => {
if (typeof jsonObject !== "object" || jsonObject === null) {
return false;
}
const schemaKeywords = [
"$schema",
"type",
"properties",
"required",
"additionalProperties",
"definitions",
"items",
"allOf",
"oneOf",
"anyOf",
"not",
];

const hasSchemaKeyword = schemaKeywords.some((keyword) =>
Object.prototype.hasOwnProperty.call(jsonObject, keyword)
);

if (!hasSchemaKeyword) {
return false;
} else {
return true;
}
}

0 comments on commit 2c4e2a5

Please sign in to comment.