-
-
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.
Merge pull request #78 from solaoi/feature_api-component-handles-path…
…-param Feature api component handles path param
- Loading branch information
Showing
15 changed files
with
345 additions
and
36 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
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
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
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
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
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
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
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
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,23 @@ | ||
import Rete from "rete"; | ||
import { UrlControl } from "../../controls/UrlControl"; | ||
|
||
export class UrlComponent extends Rete.Component { | ||
path = ["New"]; | ||
|
||
constructor(socket) { | ||
super("URL"); | ||
this.socket = socket; | ||
} | ||
|
||
builder(node) { | ||
const out = new Rete.Output("url", "URL", this.socket); | ||
|
||
return node | ||
.addControl(new UrlControl(this.editor, "url", node)) | ||
.addOutput(out); | ||
} | ||
|
||
worker(node, _, outputs) { | ||
outputs.url = node.data.url; | ||
} | ||
} |
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,60 @@ | ||
import Rete from "rete"; | ||
import { UrlWithPathParamControl } from "../../controls/UrlWithPathParamControl"; | ||
|
||
export class UrlWithPathParamComponent extends Rete.Component { | ||
path = ["New"]; | ||
|
||
constructor(socket, jsonSocket) { | ||
super("URLWithPathParam"); | ||
this.socket = socket; | ||
this.jsonSocket = jsonSocket; | ||
} | ||
|
||
builder(node) { | ||
const input = new Rete.Input( | ||
"pathParams", | ||
"PathParams (JSON)", | ||
this.jsonSocket | ||
); | ||
const out = new Rete.Output("url", "URL", this.socket); | ||
|
||
return node | ||
.addInput(input) | ||
.addControl( | ||
new UrlWithPathParamControl(this.editor, "unFormattedUrl", node) | ||
) | ||
.addOutput(out); | ||
} | ||
|
||
worker(node, inputs) { | ||
const pathParams = inputs.pathParams.length | ||
? inputs.pathParams[0] | ||
: node.data.pathParams; | ||
const { unFormattedUrl } = node.data; | ||
|
||
if ( | ||
pathParams && | ||
(unFormattedUrl.startsWith("https://") || | ||
unFormattedUrl.startsWith("http://")) | ||
) { | ||
const urlElements = unFormattedUrl.split("/"); | ||
if (urlElements.length > 3) { | ||
const formatterUrl = `${urlElements[0]}//${urlElements[2]}/${urlElements | ||
.filter((_, i) => i > 2) | ||
.map((v) => { | ||
if (v.startsWith(":")) { | ||
const key = v.slice(1); | ||
return JSON.parse(pathParams)[key] || v; | ||
} | ||
return v; | ||
}) | ||
.join("/")}`; | ||
|
||
this.editor.nodes | ||
.find((n) => n.id === node.id) | ||
.controls.get("unFormattedUrl") | ||
.setValue(unFormattedUrl, formatterUrl); | ||
} | ||
} | ||
} | ||
} |
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 @@ | ||
import React, { useState } from "react"; | ||
import Editor from "react-simple-code-editor"; | ||
import { highlight, languages } from "prismjs/components/prism-core"; | ||
import "prismjs/components/prism-uri"; | ||
import "prismjs/themes/prism.css"; | ||
import useInterval from "use-interval"; | ||
|
||
export const EditableUrlComponent = ({ value, onChange }) => { | ||
const [code, setCode] = useState(value); | ||
const [warn, setWarn] = useState(false); | ||
const [stack, setStack] = useState(null); | ||
useInterval(() => { | ||
if (stack !== null) { | ||
import("react-toastify").then(({ toast }) => toast.error(stack)); | ||
setStack(null); | ||
} | ||
}, 10000); | ||
|
||
return ( | ||
<Editor | ||
value={code} | ||
onValueChange={(c) => { | ||
if (c.startsWith("https://") || c.startsWith("http://")) { | ||
setWarn(false); | ||
setStack(null); | ||
} else { | ||
setStack("URL doesn't start with https:// or http://"); | ||
setWarn(true); | ||
} | ||
setCode(c); | ||
onChange(c); | ||
}} | ||
highlight={(c) => highlight(c, languages.uri)} | ||
padding={10} | ||
style={{ | ||
fontFamily: '"Fira code", "Fira Mono", monospace', | ||
fontSize: 12, | ||
background: warn ? "rgba(255, 0, 80, 0.7)" : "#FFF", | ||
maxWidth: "450px", | ||
}} | ||
/> | ||
); | ||
}; |
Oops, something went wrong.