Skip to content

Commit

Permalink
added transformation interface and removed redundant classes in trans…
Browse files Browse the repository at this point in the history
…formation store
  • Loading branch information
punith300i committed Oct 28, 2023
1 parent ef5a72c commit f847567
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 34 deletions.
8 changes: 2 additions & 6 deletions www/src/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ import { Entity, EntityStore } from "./entity";
import { ClassStore } from "./ontology/ClassStore";
import { PropertyStore } from "./ontology/PropertyStore";
import { Project, ProjectStore } from "./project";
import {
TransformationStore,
TestTransformationRequest,
} from "./transformation";
import { TransformationStore } from "./transformation";

import {
DraftSemanticModel,
Expand Down Expand Up @@ -71,7 +68,7 @@ export function useStores(): IStore {
export type { Property, DataType } from "./ontology/Property";
export type { SMEdge, SMNode } from "./sm/SMGraph";
export type { Table, TableRow } from "./table";
export type { TransformationResult } from "./transformation";
export type { TransformationResult, Transformation } from "./transformation";
export {
ProjectStore,
TableStore,
Expand All @@ -83,7 +80,6 @@ export {
ClassStore,
EntityStore,
TransformationStore,
TestTransformationRequest,
SemanticModel,
SMGraph,
URICount,
Expand Down
31 changes: 15 additions & 16 deletions www/src/models/transformation/TransformationStore.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import { SimpleCRUDStore } from "gena-app";
import { SimpleCRUDStore, CRUDStore, Record } from "gena-app";
import { SERVER } from "../../env";
import { TransformationResult } from "./TransformationResult";
import axios from "axios";

export interface Transformation {
id: number;
export interface Transformation extends Record<number> {
type: string;
mode: string;
tableId: number;
datapath: string[];
code: string | undefined;
outputpath: string[] | undefined;
tolerance: number;
rows: number;
}

export class TransformationStore extends SimpleCRUDStore<
Expand All @@ -16,23 +23,15 @@ export class TransformationStore extends SimpleCRUDStore<
}

async testTransformation(
id: number,
payload: TestTransformationRequest
payload: Transformation
): Promise<TransformationResult[] | undefined> {
let resp: any = await axios
.post(`${SERVER}/api/transform/${id}/transformations`, payload)
.post(
`${SERVER}/api/transform/${payload.tableId}/transformations`,
payload
)
.then((res) => res.data)
.catch((error) => error.response.data.message);
return resp;
}
}

export class TestTransformationRequest {
public type?: string;
public mode?: string;
public datapath?: string[];
public code?: string | undefined;
public outputpath?: string[] | undefined;
public tolerance?: number;
public rows?: number;
}
29 changes: 17 additions & 12 deletions www/src/pages/table/forms/TransformationForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ import { observer } from "mobx-react";
import { ActionType } from "@ant-design/pro-table";
import { useRef, useState } from "react";
import Editor from "@monaco-editor/react";
import { TransformationResult, useStores } from "../../../models";
import { TestTransformationRequest } from "../../../models";
import {
TransformationResult,
useStores,
Transformation,
} from "../../../models";

const styles = {};

Expand Down Expand Up @@ -69,18 +72,20 @@ export const TransformationForm = withStyles(styles)(
];

const onExecute = async () => {
const transformPayload = new TestTransformationRequest();
transformPayload.type = form.getFieldValue("type");
transformPayload.code = form.getFieldValue("code");
transformPayload.mode = "restrictedpython";
transformPayload.datapath = form.getFieldValue("datapath");
transformPayload.outputpath = form.getFieldValue("outputpath");
transformPayload.tolerance = form.getFieldValue("tolerance");
transformPayload.rows = form.getFieldValue("rows");
const transformationPayload: Transformation = {
id: -1,
tableId: tableId,
type: form.getFieldValue("type"),
code: form.getFieldValue("code"),
mode: "restrictedpython",
datapath: form.getFieldValue("datapath"),
outputpath: form.getFieldValue("outputpath"),
tolerance: form.getFieldValue("tolerance"),
rows: form.getFieldValue("rows"),
};

let response = await transformationStore.testTransformation(
tableId,
transformPayload
transformationPayload
);
setResult(response);
};
Expand Down

0 comments on commit f847567

Please sign in to comment.