Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(web): plugin playground / display console #1263

Merged
merged 64 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
3c377d0
display plugin list
devshun Oct 22, 2024
362287b
display code input
devshun Oct 23, 2024
642c6c8
feat file upload todo refactor
devshun Oct 25, 2024
bd6cc93
refactor(web): update Code component and FileListItem component
devshun Oct 27, 2024
ae44b45
feat upload file & refrect editor
devshun Oct 31, 2024
93718e9
fix plugin download
devshun Oct 31, 2024
a2d2b01
fixup! fix plugin download
devshun Nov 4, 2024
02ce6eb
Refactor validateFileTitle function in Plugins/utils.ts
devshun Nov 4, 2024
50b7be2
feat reflect viewer
devshun Nov 5, 2024
f62b092
Revert "Refactor validateFileTitle function in Plugins/utils.ts"
devshun Nov 5, 2024
f395ee2
Merge branch 'main' of https://github.com/reearth/reearth-visualizer …
devshun Nov 5, 2024
ac0bab4
fixup! Merge branch 'main' of https://github.com/reearth/reearth-visu…
devshun Nov 5, 2024
00ddfa7
Refactor ALLOWED_FILE_EXTENSIONS in PluginPlayground/Plugins/constant…
devshun Nov 5, 2024
a389041
Refactor PluginListWrapper padding in PluginPlayground/Plugins/index.tsx
devshun Nov 5, 2024
ee060e0
Refactor PluginPlayground/Plugins/hook.ts
devshun Nov 5, 2024
fb316e2
Merge branch 'playground/display-code-editor' of https://github.com/r…
devshun Nov 5, 2024
f29eed2
fix type error
devshun Nov 5, 2024
e97cdb0
use uuid
devshun Nov 7, 2024
ff7229a
initialize selected file when file delete
devshun Nov 7, 2024
e2b6480
add error handling download
devshun Nov 7, 2024
4ceecdd
fix prop name
devshun Nov 7, 2024
6270b1a
add fb for error message
devshun Nov 7, 2024
e7d4c3d
Merge branch 'playground/display-code-editor' of https://github.com/r…
devshun Nov 7, 2024
b6a5505
fixup! Merge branch 'playground/display-code-editor' of https://githu…
devshun Nov 7, 2024
e1f81d5
Merge branch 'main' into playground/display-code-editor
airslice Nov 8, 2024
f7a51f0
add html editor file
devshun Nov 9, 2024
90f337c
refactor(web): streamline error handling in file title validation
devshun Nov 9, 2024
df4ca9d
Merge branch 'main' of https://github.com/reearth/reearth-visualizer …
devshun Nov 9, 2024
1dd6c93
Merge branch 'playground/display-code-editor' of https://github.com/r…
devshun Nov 9, 2024
1bec19e
Provide feedback to the user if fetching the YAML JSON fails.
devshun Nov 9, 2024
9bc0153
fixup! refactor(web): streamline error handling in file title validation
devshun Nov 9, 2024
3f0d214
Merge branch 'playground/display-code-editor' of https://github.com/r…
devshun Nov 9, 2024
031c2ab
update demo widget details in constants and hook
devshun Nov 9, 2024
e15c4d8
refactor: simplify getYmlJson function and improve error handling
devshun Nov 9, 2024
e8c60a1
Merge branch 'playground/reflect-code-to-visual' of https://github.co…
devshun Nov 9, 2024
575fde5
add html editor modal
devshun Nov 9, 2024
92e4b2d
refactor: reorder Props type definition for better readability
devshun Nov 9, 2024
09c8b4e
refactor: extract HTML handling logic into utility functions and upda…
devshun Nov 9, 2024
4b0199e
fix: correct HTML extraction and injection logic in utility functions
devshun Nov 10, 2024
aee7b03
fix: update parameter name in HTML editor submission handler for clarity
devshun Nov 10, 2024
7be8788
rm comment
devshun Nov 10, 2024
15c1a61
tmp file out put
devshun Nov 13, 2024
6e10a0e
fix typo
devshun Nov 13, 2024
cceb0bc
Merge branch 'main' of https://github.com/reearth/reearth-visualizer …
devshun Nov 13, 2024
13a74cc
fixup! fix typo
devshun Nov 13, 2024
2e27ee6
fix typo
devshun Nov 13, 2024
8c39c0d
fix: update button disabled state logic in HTML editor
devshun Nov 13, 2024
039f229
Merge branch 'main' of https://github.com/reearth/reearth-visualizer …
devshun Nov 13, 2024
d3cae87
fix: update regex pattern for HTML injection to correctly capture quotes
devshun Nov 13, 2024
f940da6
Merge branch 'main' of https://github.com/reearth/reearth-visualizer …
devshun Nov 13, 2024
26d5869
Merge branch 'playground/reflect-code-to-visual' of https://github.co…
devshun Nov 13, 2024
7f1db63
add file output state
devshun Nov 16, 2024
8e1ce2a
add console capture
devshun Nov 16, 2024
63a568d
fix style
devshun Nov 20, 2024
a8105ed
add popup and modal show functions to reearth object
devshun Nov 20, 2024
0deeb5a
Merge branch 'main' of https://github.com/reearth/reearth-visualizer …
devshun Nov 20, 2024
df82880
Merge branch 'main' of https://github.com/reearth/reearth-visualizer …
devshun Nov 24, 2024
8829c19
fix(web): add key prop to fileOutputs mapping in Console component
devshun Nov 24, 2024
a374ff0
Merge branch 'main' of https://github.com/reearth/reearth-visualizer …
devshun Nov 27, 2024
c8d3723
add bracket
devshun Nov 28, 2024
c2fa604
wrap try block
devshun Nov 28, 2024
c8a5d07
Merge branch 'main' of https://github.com/reearth/reearth-visualizer …
devshun Nov 28, 2024
48dc58e
Merge branch 'main' into playground/display-console
airslice Nov 28, 2024
7fbc0aa
Merge branch 'main' into playground/display-console
devshun Nov 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 63 additions & 8 deletions web/src/beta/features/PluginPlayground/Code/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,70 @@ const getYmlJson = (file: FileType) => {
export default ({ files }: Props) => {
const [widgets, setWidgets] = useState<Widgets>();
const [, setNotification] = useNotification();
const [fileOutputs, setFileOutputs] = useState<
{
title: string;
output: string;
}[]
>();

const executeCode = useCallback(() => {
const ymlFile = files.find((file) => file.title.endsWith(".yml"));

const jsFiles = files.filter((file) => file.title.endsWith(".js"));

const outputs = jsFiles.map((file) => {
try {
const fn = new Function(
`"use strict";
const reearth = {
ui: {
show: function () {}
},
popup: {
show: function () {}
},
modal: {
show: function () {}
}
};

let capturedConsole = [];

console.log = (message) => {
capturedConsole.push(message);
};

console.error = (message) => {
capturedConsole.push(message);
};

${file.sourceCode};

return capturedConsole.join("\\n");
`
);

return {
title: file.title,
output: fn()
};
} catch (error) {
if (error instanceof Error) {
return {
title: file.title,
output: error.message
};
}
return {
title: file.title,
output: "Failed to execute"
};
}
});

setFileOutputs(outputs);

if (!ymlFile) return;

const getYmlResult = getYmlJson(ymlFile);
Expand All @@ -66,13 +126,7 @@ export default ({ files }: Props) => {

const ymlJson = getYmlResult.data;

if (!Array.isArray(ymlJson.extensions) || ymlJson.extensions.length === 0) {
setNotification({
type: "error",
text: "No extensions found in YAML file."
});
return;
}
if (!ymlJson.extensions) return;

const widgets = ymlJson.extensions.reduce<NonNullable<Widgets>>(
(prv, cur) => {
Expand Down Expand Up @@ -126,6 +180,7 @@ export default ({ files }: Props) => {

return {
executeCode,
widgets
widgets,
fileOutputs
};
};
31 changes: 29 additions & 2 deletions web/src/beta/features/PluginPlayground/Console/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,34 @@
import { styled } from "@reearth/services/theme";
import { FC } from "react";

const Console: FC = () => {
return <div>Console content</div>;
type Props = {
fileOutputs:
| {
title: string;
output: string;
}[]
| undefined;
};

const Console: FC<Props> = ({ fileOutputs }) => {
if (!fileOutputs) return null;
return (
<Wrapper>
{fileOutputs.map(({ title, output }, index) => (
<div key={index}>
{`[${title}]`} {output}
</div>
))}
</Wrapper>
);
};

const Wrapper = styled.div(() => ({
display: "flex",
flexDirection: "column",
maxHeight: "100%",
height: "100%",
overflow: "auto"
}));

export default Console;
6 changes: 3 additions & 3 deletions web/src/beta/features/PluginPlayground/hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default () => {
handlePluginDownload
} = usePlugins();

const { widgets, executeCode } = useCode({
const { widgets, executeCode, fileOutputs } = useCode({
files: selectedPlugin.files
});

Expand All @@ -46,10 +46,10 @@ export default () => {
{
id: "console",
name: "Console",
children: <Console />
children: <Console fileOutputs={fileOutputs} />
}
],
[]
[fileOutputs]
);

const SubRightAreaTabs: TabItem[] = useMemo(
Expand Down
Loading