generated from ensaremirerol/nextjs-fastapi-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b36359f
commit 68d0d54
Showing
14 changed files
with
336 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"arrowParens": "avoid", | ||
"bracketSpacing": true, | ||
"htmlWhitespaceSensitivity": "css", | ||
"insertPragma": false, | ||
"jsxBracketSameLine": false, | ||
"jsxSingleQuote": true, | ||
"printWidth": 80, | ||
"proseWrap": "always", | ||
"quoteProps": "as-needed", | ||
"requirePragma": false, | ||
"semi": true, | ||
"singleQuote": true, | ||
"tabWidth": 2, | ||
"trailingComma": "all", | ||
"useTabs": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import encodeFileToBase64 from '../../../utils/base64encoder'; | ||
import ApiService from '../../services/api_service'; | ||
import { MappingGraph } from './types'; | ||
|
||
class MappingService { | ||
private static getApiClient(): ApiService { | ||
return ApiService.getInstance('default'); | ||
} | ||
|
||
public static async getMappingsInWorkspace( | ||
workspaceUuid: string, | ||
): Promise<MappingGraph[]> { | ||
const result = await this.getApiClient().callApi<MappingGraph[]>( | ||
`/workspaces/${workspaceUuid}/mapping`, | ||
{ | ||
method: 'GET', | ||
parser: data => data as MappingGraph[], | ||
}, | ||
); | ||
|
||
if (result.type === 'success') { | ||
return result.data; | ||
} | ||
|
||
throw new Error( | ||
`Failed to get mappings: ${result.message} (status: ${result.status})`, | ||
); | ||
} | ||
|
||
public static async createMappingInWorkspace( | ||
workspaceUuid: string, | ||
name: string, | ||
description: string, | ||
content: File, | ||
sourceType: 'csv' | 'json', | ||
extra: Record<string, unknown>, | ||
): Promise<boolean> { | ||
const base64EncodedFile = await encodeFileToBase64(content); | ||
const data = { | ||
name, | ||
description, | ||
content: base64EncodedFile, | ||
source_type: sourceType, | ||
extra, | ||
}; | ||
|
||
const result = await this.getApiClient().callApi<boolean>( | ||
`/workspaces/${workspaceUuid}/mapping`, | ||
{ | ||
method: 'POST', | ||
body: data, | ||
parser: () => true, | ||
}, | ||
); | ||
|
||
if (result.type === 'success') { | ||
return result.data; | ||
} | ||
|
||
throw new Error( | ||
`Failed to create mapping: ${result.message} (status: ${result.status})`, | ||
); | ||
} | ||
|
||
public static async deleteMappingInWorkspace( | ||
workspaceUuid: string, | ||
mappingUuid: string, | ||
): Promise<boolean> { | ||
const result = await this.getApiClient().callApi<boolean>( | ||
`/workspaces/${workspaceUuid}/mapping/${mappingUuid}`, | ||
{ | ||
method: 'DELETE', | ||
parser: () => true, | ||
}, | ||
); | ||
|
||
if (result.type === 'success') { | ||
return result.data; | ||
} | ||
|
||
throw new Error( | ||
`Failed to delete mapping: ${result.message} (status: ${result.status})`, | ||
); | ||
} | ||
|
||
public static async updateMapping( | ||
workspaceUuid: string, | ||
mappingUuid: string, | ||
data: MappingGraph, | ||
): Promise<boolean> { | ||
const result = await this.getApiClient().callApi<boolean>( | ||
`/workspaces/${workspaceUuid}/mapping/${mappingUuid}`, | ||
{ | ||
method: 'PUT', | ||
body: data, | ||
parser: () => true, | ||
}, | ||
); | ||
|
||
if (result.type === 'success') { | ||
return result.data; | ||
} | ||
|
||
throw new Error( | ||
`Failed to update mapping: ${result.message} (status: ${result.status})`, | ||
); | ||
} | ||
} | ||
|
||
export default MappingService; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
export enum MappingNodeType { | ||
ENTITY = 'entity', | ||
LITERAL = 'literal', | ||
URIRef = 'uri_ref', | ||
} | ||
|
||
export interface MappingNode { | ||
id: string; | ||
type: MappingNodeType.ENTITY; | ||
label: string; | ||
uri_pattern: string; | ||
rdf_type: string[]; | ||
} | ||
|
||
export interface MappingLiteral { | ||
id: string; | ||
type: MappingNodeType.LITERAL; | ||
label: string; | ||
value: string; | ||
literal_type: string; | ||
} | ||
|
||
export interface MappingURIRef { | ||
id: string; | ||
type: MappingNodeType.URIRef; | ||
uri_pattern: string; | ||
} | ||
|
||
export interface MappingEdge { | ||
id: string; | ||
source: string; | ||
target: string; | ||
predicate_uri: string; | ||
} | ||
|
||
export interface MappingGraph { | ||
uuid: string; | ||
name: string; | ||
description: string; | ||
source_id: string; | ||
nodes: (MappingNode | MappingLiteral | MappingURIRef)[]; | ||
edges: MappingEdge[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
app/src/pages/workspace_page/components/MappingCard/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Button } from '@blueprintjs/core'; | ||
import CardItem from '../../../../components/CardItem'; | ||
import { MappingGraph } from '../../../../lib/api/mapping_service/types'; | ||
|
||
interface MappingCardItemProps { | ||
mapping: MappingGraph; | ||
onSelected: (mapping: MappingGraph) => void; | ||
onDelete: (mapping: MappingGraph) => void; | ||
} | ||
|
||
const MappingCardItem = ({ | ||
mapping, | ||
onSelected, | ||
onDelete, | ||
}: MappingCardItemProps) => { | ||
return ( | ||
<CardItem | ||
title={mapping.name} | ||
description={ | ||
<p> | ||
<b>Description:</b> {mapping.description} | ||
</p> | ||
} | ||
actions={ | ||
<> | ||
<Button onClick={() => onSelected(mapping)}>Open</Button> | ||
<Button onClick={() => onDelete(mapping)}>Delete</Button> | ||
</> | ||
} | ||
/> | ||
); | ||
}; | ||
|
||
export default MappingCardItem; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.