Skip to content

Commit

Permalink
Embed inside feature info
Browse files Browse the repository at this point in the history
  • Loading branch information
tephenavies committed Sep 9, 2024
1 parent 3db8ae2 commit 7707354
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
37 changes: 24 additions & 13 deletions lib/ReactViews/Custom/EmbedWebProcessingServiceHtml.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { ReactElement, useState } from "react";
import styled from "styled-components";
import Button from "../../Styled/Button";
import Text from "../../Styled/Text";
import xml2json from "../../ThirdParty/xml2json";
import CustomComponent, {
DomElement,
ProcessNodeContext
} from "./CustomComponent";
import Button from "../../Styled/Button";
import Text from "../../Styled/Text";
import xml2json from "../../ThirdParty/xml2json";
import { useViewState } from "../Context";
import { action, runInAction } from "mobx";

enum EmbedWpsHtmlState {
Default,
Expand All @@ -16,10 +15,18 @@ enum EmbedWpsHtmlState {
ResponseOk
}

const ContentIframe = styled.iframe`
width: 350px;
height: 300px;
margin: 3px;
border: none;
`;

function EmbedWpsHtml({ url }: { url: string }) {
const viewState = useViewState();
// const viewState = useViewState();
// Doesn't support changing url
const [state, setState] = useState(EmbedWpsHtmlState.Default);
const [replacedHtml, setReplacedHtml] = useState("");

async function sendWpsRequest() {
try {
Expand All @@ -36,10 +43,11 @@ function EmbedWpsHtml({ url }: { url: string }) {
throw new Error("Data error: xml not in expected format");
}
setState(EmbedWpsHtmlState.ResponseOk);
runInAction(() => {
viewState.contentPopoutHtml = String(html);
viewState.contentPopoutOpen = true;
});
// runInAction(() => {
// viewState.contentPopoutHtml = String(html);
// viewState.contentPopoutOpen = true;
// });
setReplacedHtml(html.replace("&", "&"));
} catch (e: any) {
console.error(`Error requesting WPS data: ${(e ?? "").toString()}`);
setState(EmbedWpsHtmlState.ResponseError);
Expand All @@ -56,12 +64,15 @@ function EmbedWpsHtml({ url }: { url: string }) {
} else if (state === EmbedWpsHtmlState.ResponseError) {
text = "Data fetching failed";
} else if (state === EmbedWpsHtmlState.ResponseOk) {
onClick = action(() => {
viewState.contentPopoutOpen = true;
});
// onClick = action(() => {
// viewState.contentPopoutOpen = true;
// });
text = "Open additional data";
}

if (state === EmbedWpsHtmlState.ResponseOk) {
return <ContentIframe srcDoc={replacedHtml} />;
}
return (
<Button enabled={!!onClick} onClick={onClick}>
<Text bold>{text}</Text>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "terriajs",
"version": "8.7.6-time-period.1",
"version": "8.7.6-time-period.2",
"description": "Geospatial data visualization platform.",
"license": "Apache-2.0",
"engines": {
Expand Down

0 comments on commit 7707354

Please sign in to comment.