Skip to content

Commit

Permalink
Merge pull request #84 from ulitol97/master
Browse files Browse the repository at this point in the history
Bumped to 0.2.2
  • Loading branch information
ulitol97 authored Mar 3, 2022
2 parents e97f89f + 0298bc7 commit cac3418
Show file tree
Hide file tree
Showing 45 changed files with 1,206 additions and 693 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rdfshape-client",
"version": "0.2.0",
"version": "0.2.2",
"private": true,
"dependencies": {
"axios": "^0.21.4",
Expand Down Expand Up @@ -47,7 +47,7 @@
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"test": "react-scripts test --passWithNoTests",
"eject": "react-scripts eject"
},
"eslintConfig": {
Expand Down
218 changes: 115 additions & 103 deletions src/API.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,113 @@
/** This class contains global definitions */

import React from "react";
import environmentConfiguration from "./EnvironmentConfig";
import { rootApi } from "./utils/networking/axiosConfig";

class API {
// Formats (most formats come from server but we need defaults for data initialization)
static formats = {
turtle: "turtle",
triG: "TriG",
compact: "Compact",
shexc: "ShExC",
shexj: "ShExJ",
sparql: "SPARQL",
xml: "XML",
rdfXml: "RDF/XML",
rdfJson: "RDF/JSON",
svg: "SVG",
png: "PNG",
html: "HTML",
htmlMicrodata: "html-microdata",
htmlRdf: "html-rdfa11",
htmlMixed: "htmlmixed",
json: "JSON",
jsonld: "JSON-LD",
javascript: "javascript",
dot: "DOT",
ps: "PS",
xmi: "XMI",
txt: "txt",
htmlForm: "HTML form",

defaultData: "turtle",
defaultShex: "ShExC",
defaultShacl: "turtle",
defaultShapeMap: "Compact",
defaultQuery: "SPARQL",
defaultGraphical: "SVG",
};

// Mime types
static mimeTypes = {
shex: "text/shex",
svg: "image/svg+xml",
png: "image/png",
};

// Inferences
static inferences = {
default: "None",

none: "None",
};

// Engines
static engines = {
default: "ShEx",
defaultShex: "ShEx",
defaultShacl: "SHACLex",

shex: "ShEx",
shacl: "SHACL", // For general purpose, don't use in API requests
shaclex: "SHACLex",
jenaShacl: "JenaSHACL",
shacl_tq: "SHACL_TQ",

shumlex: "Shumlex",
shapeForms: "ShapeForms",
};

// Trigger modes
static triggerModes = {
default: "ShapeMap",

shapeMap: "ShapeMap",
targetDecls: "TargetDecls",
};
// Routes
static rootApi = environmentConfiguration.apiHost + "/api/";
static routes = {
// Routes in server
server: {
root: this.rootApi,
health: this.rootApi + "health",

dataInfo: this.rootApi + "data/info",
dataConvert: this.rootApi + "data/convert",
dataQuery: this.rootApi + "data/query",
dataExtract: this.rootApi + "data/extract",
dataFormatsInput: this.rootApi + "data/formats/input",
dataFormatsOutput: this.rootApi + "data/formats/output",
dataVisualFormats: this.rootApi + "data/formats/visual",

schemaInfo: this.rootApi + "schema/info",
schemaConvert: this.rootApi + "schema/convert",
schemaValidate: this.rootApi + "schema/validate",
shExFormats: this.rootApi + "schema/formats?schemaEngine=shex",
shaclFormats: this.rootApi + "schema/formats?schemaEngine=shaclex",
schemaShaclEngines: this.rootApi + "schema/engines/shacl",

shapeMapInfo: this.rootApi + "shapemap/info",
shapeMapFormats: this.rootApi + "shapemap/formats",

endpointInfo: this.rootApi + "endpoint/info",
wikibaseQuery: this.rootApi + "wikibase/query",

inferenceEngines: this.rootApi + "data/inferenceEngines",

serverPermalinkEndpoint: this.rootApi + "permalink/generate",
serverOriginalLinkEndpoint: this.rootApi + "permalink/get",
fetchUrl: this.rootApi + "fetch",
root: rootApi,
health: "health",

dataInfo: "data/info",
dataConvert: "data/convert",
dataQuery: "data/query",
dataExtract: "data/extract",
dataFormatsInput: "data/formats/input",
dataFormatsOutput: "data/formats/output",
dataVisualFormats: "data/formats/visual",

schemaInfo: "schema/info",
schemaConvert: "schema/convert",
schemaValidate: "schema/validate",
shExFormats: `schema/formats/${this.engines.shex}`,
shaclFormats: `schema/formats/${this.engines.shaclex}`,
schemaShaclEngines: `schema/engines/${this.engines.shacl}`,

shapeMapInfo: "shapemap/info",
shapeMapFormats: "shapemap/formats",

endpointInfo: "endpoint/info",
wikibaseQuery: "wikibase/query",

inferenceEngines: "data/inferenceEngines",

serverPermalinkEndpoint: "permalink/generate",
serverOriginalLinkEndpoint: "permalink/get",
fetchUrl: "fetch",
},
// Routes in client
client: {
Expand Down Expand Up @@ -157,13 +227,23 @@ class API {
endpoint: "endpoint",
payload: "payload",
},

content: "content",
format: "format",
engine: "engine",
source: "source",
inference: "inference",
targetFormat: "targetFormat",
targetEngine: "targetEngine",
type: "type",
};

// Information sources / tabs
static sources = {
byText: "byText",
byUrl: "byUrl",
byFile: "byFile",
byCompound: "byCompound",
bySchema: "bySchema",

default: "byText",
Expand All @@ -173,6 +253,7 @@ class API {
none: "none",
overview: "overview",
result: "result",
associations: "associations",
xmi: "XMI",
html: "HTML",
uml: "UML",
Expand All @@ -191,78 +272,6 @@ class API {
shaclValidationReportNodes: "shaclReportNodes",
};

// Formats (most formats come from server but we need defaults for data initialization)
static formats = {
turtle: "turtle",
triG: "TriG",
compact: "Compact",
shexc: "ShExC",
shexj: "ShExJ",
sparql: "SPARQL",
xml: "XML",
rdfXml: "RDF/XML",
rdfJson: "RDF/JSON",
svg: "SVG",
png: "PNG",
html: "HTML",
htmlMicrodata: "html-microdata",
htmlRdf: "html-rdfa11",
htmlMixed: "htmlmixed",
json: "JSON",
jsonld: "JSON-LD",
javascript: "javascript",
dot: "DOT",
ps: "PS",
xmi: "UML/XMI",
txt: "txt",
htmlForm: "HTML form",

defaultData: "turtle",
defaultShex: "ShExC",
defaultShacl: "turtle",
defaultShapeMap: "Compact",
defaultQuery: "SPARQL",
defaultGraphical: "SVG",
};

// Mime types
static mimeTypes = {
shex: "text/shex",
svg: "image/svg+xml",
png: "image/png",
};

// Inferences
static inferences = {
default: "None",

none: "None",
};

// Engines
static engines = {
default: "ShEx",
defaultShex: "ShEx",
defaultShacl: "SHACLex",

shex: "ShEx",
shacl: "SHACL", // For general purpose, don't use in API requests
shaclex: "SHACLex",
jenaShacl: "JenaSHACL",
shacl_tq: "SHACL_TQ",

shumlex: "Shumlex",
shapeForms: "ShapeForms",
};

// Trigger modes
static triggerModes = {
default: "ShapeMap",

shapeMap: "ShapeMap",
targetDecls: "TargetDecls",
};

// By text limitations
static limits = {
byTextCharacterLimit: 2200,
Expand Down Expand Up @@ -501,11 +510,13 @@ class API {
visualizations: "Visualizations",
visualizationDot: "DOT",
visualizationCyto: "Cytoscape",
associations: "Associations",
},

endpoints: {
commonEndpoints: "Common endpoints",
online: "Endpoint ONLINE",
offline: "Endpoint OFFLINE",
},

xmi: {
Expand Down Expand Up @@ -585,6 +596,7 @@ class API {
networkError: "Network error",
errorDetails: "Error details",
errorParsingUrl: "Could not parse URL information",
errorFetchingQuery: "Could not fetch the query data",
emptyDataUrl: "No URL data to process",
noProvidedRdf: "No RDF data provided",
noProvidedSchema: "No schema provided",
Expand Down
9 changes: 0 additions & 9 deletions src/App.test.js

This file was deleted.

40 changes: 22 additions & 18 deletions src/Permalink.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import axios from "axios";
import FormData from "form-data";
import PropTypes from "prop-types";
import qs from "query-string";
Expand All @@ -10,6 +9,7 @@ import { toast, ToastContainer } from "react-toastify";
import "react-toastify/dist/ReactToastify.css";
import ReactTooltip from "react-tooltip";
import API from "./API";
import axios from "./utils/networking/axiosConfig";
import { notificationSettings } from "./utils/Utils";

// Returns a promise that will return a shortened permalink generated on the server
Expand Down Expand Up @@ -106,7 +106,7 @@ export function Permalink(props) {
const [loading, setLoading] = useState(false);
const [permalink, setPermalink] = useState();

async function handleClick(e) {
async function requestPermalink(e) {
e.preventDefault();

// If a permalink has been generated already, copy to clipboard and notify
Expand All @@ -116,21 +116,25 @@ export function Permalink(props) {
return;
}

// Set to loading
setLoading(true);

// Generate short URL / return the long link in case of error
const newPermalink = props.shorten
? await mkPermalinkFromUrl(props.url)
: props.url;

// Copy results and update state
navigator.clipboard.writeText(newPermalink);
setPermalink(newPermalink);
setLoading(false);

// Notify
toast.info(notificationSettings.permalinkText);
// Get permalink from server
try {
// Set to loading
setLoading(true);
// Generate short URL / return the long link in case of error
const newPermalink = props.shorten
? await mkPermalinkFromUrl(props.url)
: props.url;

// Copy results and update state
navigator.clipboard.writeText(newPermalink);
setPermalink(newPermalink);
// Notify
toast.info(notificationSettings.permalinkText);
} catch (err) {
console.error(err);
} finally {
setLoading(false);
}
}

if (props.url)
Expand All @@ -143,7 +147,7 @@ export function Permalink(props) {
<Button
disabled={!!props.disabled}
className={"btn-with-icon " + (loading ? "disabled" : "")}
onClick={handleClick}
onClick={requestPermalink}
variant="secondary"
href={permalink || props.url}
>
Expand Down
Loading

0 comments on commit cac3418

Please sign in to comment.