Skip to content

Commit

Permalink
chore(web): add dataSource, layerSidePanel component in beta (#633)
Browse files Browse the repository at this point in the history
  • Loading branch information
pyshx authored Sep 6, 2023
1 parent f015000 commit 9972e66
Show file tree
Hide file tree
Showing 33 changed files with 1,277 additions and 62 deletions.
1 change: 1 addition & 0 deletions web/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const config: CodegenConfig = {
URL: "string",
Lang: "string",
TranslatedString: "{ [lang in string]?: string } | null",
JSON: "any",
},
},
},
Expand Down
12 changes: 12 additions & 0 deletions web/src/beta/components/Icon/Icons/addLayer.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions web/src/beta/components/Icon/icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import Bin from "./Icons/bin.svg";
import Install from "./Icons/install.svg";
import UploadSimple from "./Icons/uploadSimple.svg";
import Search from "./Icons/search.svg";
import AddLayerIcon from "./Icons/addLayer.svg";

// MSIC
import CheckCircle from "./Icons/checkCircle.svg";
Expand Down Expand Up @@ -107,6 +108,7 @@ import PublicGitHubRepo from "./Icons/publicGitHubRepo.svg";
import Marketplace from "./Icons/marketplace.svg";

export default {
addLayer: AddLayerIcon,
file: File,
dl: InfoTable,
infobox: Infobox,
Expand Down
21 changes: 14 additions & 7 deletions web/src/beta/components/Modal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type Props = {
children?: ReactNode;
isVisible?: boolean;
onClose?: () => void;
onTabChange?: (tabId: string) => void;
sidebarTabs?: SidebarTab[];
};

Expand All @@ -35,6 +36,7 @@ const Modal: React.FC<Props> = ({
children,
isVisible,
onClose,
onTabChange,
sidebarTabs,
}) => {
const [TabsFields, setTabsFields] = useState<SwitchField<SidebarTab>[]>([]);
Expand All @@ -56,8 +58,9 @@ const Modal: React.FC<Props> = ({
const handleTabChange = useCallback(
(tabId: string) => {
handleActivate(tabId);
onTabChange?.(tabId);
},
[handleActivate],
[handleActivate, onTabChange],
);

return (
Expand All @@ -79,11 +82,13 @@ const Modal: React.FC<Props> = ({
)}
<ContentWrapper>
{tabs.length > 0 && <Content>{tabs.find(tab => tab.active === true)?.content}</Content>}
<Content> {children}</Content>
<ButtonWrapper>
{tabs.find(tab => tab.active === true)?.tabButton1 ?? button1}
{tabs.find(tab => tab.active === true)?.tabButton2 ?? button2}
</ButtonWrapper>
{children && <Content> {children}</Content>}
{button1 || button2 ? (
<ButtonWrapper>
{tabs.find(tab => tab.active === true)?.tabButton1 ?? button1}
{tabs.find(tab => tab.active === true)?.tabButton2 ?? button2}
</ButtonWrapper>
) : null}
</ContentWrapper>
</InnerWrapper>
</Wrapper>
Expand All @@ -99,6 +104,7 @@ const NavBarWrapper = styled.div`
flex-direction: column;
padding: 16px;
gap: 10px;
background: ${({ theme }) => theme.bg[0]};
border-right: 1px solid ${({ theme }) => theme.bg[3]};
`;

Expand All @@ -107,13 +113,14 @@ const Tab = styled.button<{ isSelected?: boolean }>`
padding: 4px 8px;
border-radius: 4px;
background: ${({ isSelected, theme }) => (isSelected ? theme.bg[2] : "transparent")};
color: ${({ isSelected, theme }) => (isSelected ? theme.content.main : theme.bg[2])};
color: ${({ isSelected, theme }) => (isSelected ? theme.content.main : theme.content.weak)};
`;

const ContentWrapper = styled.div`
display: flex;
flex-direction: column;
flex: 1;
background: ${({ theme }) => theme.bg[0]};
`;

const Content = styled.div`
Expand Down
153 changes: 153 additions & 0 deletions web/src/beta/features/Editor/DataSourceManager/Asset/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
import React from "react";

import Button from "@reearth/beta/components/Button";
import Toggle from "@reearth/beta/components/Toggle";
import generateRandomString from "@reearth/beta/utils/generate-random-string";
import RadioButton from "@reearth/classic/components/atoms/RadioButton";
import Select from "@reearth/classic/components/atoms/Select";
import { Option } from "@reearth/classic/components/atoms/SelectOption";

import { DataProps } from "..";
import {
ColJustiftBetween,
AssetWrapper,
InputGroup,
Input,
SourceTypeWrapper,
RadioButtonLabel,
SubmitWrapper,
TextArea,
} from "../utils";

const Asset: React.FC<DataProps> = ({ sceneId, onSubmit, onClose }) => {
const [sourceType, setSourceType] = React.useState("url"); // ["url", "local", "value"]
const [fileFormat, setFileFormat] = React.useState("GeoJSON");
const [value, setValue] = React.useState("");
const [prioritizePerformance, setPrioritizePerformance] = React.useState(false);

const handleSubmit = () => {
onSubmit({
layerType: "simple",
sceneId,
title: generateRandomString(5),
visible: true,
config: {
data: {
url: sourceType === "url" && value !== "" ? value : null,
type: fileFormat.toLowerCase(),
value: sourceType === "value" && value !== "" ? value : null,
},
resource: {
clampToGround: true,
},
marker: {
heightReference: "clamp",
},
polygon: {
heightReference: "clamp",
},
polyline: {
clampToGround: true,
},
},
});
onClose();
};

return (
<ColJustiftBetween>
<AssetWrapper>
<InputGroup
label="Source Type"
description="Select the type of data source you want to add.">
<SourceTypeWrapper>
<RadioButtonLabel>
<RadioButton
value="url"
checked={sourceType == "url"}
handleChange={c => c && setSourceType("url")}
/>
From URL
</RadioButtonLabel>
<RadioButtonLabel>
<RadioButton
value="value"
checked={sourceType == "value"}
handleChange={c => c && setSourceType("value")}
/>
From Value
</RadioButtonLabel>
</SourceTypeWrapper>
</InputGroup>
{sourceType == "url" && (
<>
<InputGroup
label="File Format"
description="File format of the data source you want to add.">
<Select value={fileFormat} onChange={setFileFormat}>
{["GeoJSON", "KML", "CZML"].map(op => (
<Option key={op} value={op} label={op}>
{op}
</Option>
))}
</Select>
</InputGroup>
<InputGroup label="Resource URL" description="URL of the data source you want to add.">
<Input
type="text"
placeholder="Input Text"
value={value}
onChange={e => setValue(e.target.value)}
/>
</InputGroup>
{fileFormat === "GeoJSON" && (
<InputGroup
label="Prioritize Performance"
description="URL of the data source you want to add.">
<Toggle
checked={prioritizePerformance}
disabled={true}
onChange={v => setPrioritizePerformance(v)}
/>
</InputGroup>
)}
</>
)}
{sourceType == "value" && (
<>
<InputGroup
label="File Format"
description="File format of the data source you want to add.">
<Select value={fileFormat} onChange={setFileFormat}>
{["GeoJSON", "KML", "CZML"].map(op => (
<Option key={op} value={op} label={op}>
{op}
</Option>
))}
</Select>
</InputGroup>
<InputGroup label="Value" description="Description around.">
<TextArea
placeholder="Write down your text"
rows={8}
value={value}
onChange={e => setValue(e.target.value)}
/>
</InputGroup>
</>
)}
</AssetWrapper>
<SubmitWrapper>
<Button
text="Add to Layer"
buttonType="primary"
size="medium"
onClick={handleSubmit}
disabled={(sourceType === "url" || sourceType === "value") && !value}
/>
</SubmitWrapper>
</ColJustiftBetween>
);
};

export default Asset;
113 changes: 113 additions & 0 deletions web/src/beta/features/Editor/DataSourceManager/DelimitedText/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import React from "react";

import Button from "@reearth/beta/components/Button";
import Text from "@reearth/beta/components/Text";
import generateRandomString from "@reearth/beta/utils/generate-random-string";
import RadioButton from "@reearth/classic/components/atoms/RadioButton";

import { DataProps } from "..";
import {
ColJustiftBetween,
AssetWrapper,
InputGroup,
Input,
SourceTypeWrapper,
SubmitWrapper,
RadioButtonLabel,
} from "../utils";

const DelimitedText: React.FC<DataProps> = ({ sceneId, onSubmit, onClose }) => {
const [sourceType, setSourceType] = React.useState("url"); // ["url", "local", "value"]
const [value, setValue] = React.useState("");
const [lat, setLat] = React.useState("");
const [long, setLong] = React.useState("");

const handleSubmit = () => {
onSubmit({
layerType: "simple",
sceneId,
title: generateRandomString(5),
visible: true,
config: {
data: {
url: sourceType === "url" && value !== "" ? value : null,
type: "csv",
csv: {
latColumn: lat,
lngColumn: long,
},
},
resource: {
clampToGround: true,
},
marker: {
heightReference: "clamp",
},
polygon: {
heightReference: "clamp",
},
polyline: {
clampToGround: true,
},
},
});
onClose();
};

return (
<ColJustiftBetween>
<AssetWrapper>
<InputGroup
label="Source Type"
description="Select the type of data source you want to add.">
<SourceTypeWrapper>
<RadioButtonLabel>
<RadioButton
value="url"
checked={sourceType == "url"}
handleChange={c => c && setSourceType("url")}
/>
From URL
</RadioButtonLabel>
</SourceTypeWrapper>
</InputGroup>
<InputGroup label="Resource URL" description="URL of the data source you want to add.">
<Input
type="text"
placeholder="Input Text"
value={value}
onChange={e => setValue(e.target.value)}
/>
</InputGroup>
<Text size="body">Point coordinates</Text>
<InputGroup label="Latitude Field" description="Description around">
<Input
type="number"
placeholder="Input Text"
value={lat}
onChange={e => setLat(e.target.value)}
/>
</InputGroup>
<InputGroup label="Longitude Field" description="Description around">
<Input
type="number"
placeholder="Input Text"
value={long}
onChange={e => setLong(e.target.value)}
/>
</InputGroup>
</AssetWrapper>
<SubmitWrapper>
<Button
text="Add to Layer"
buttonType="primary"
size="medium"
onClick={handleSubmit}
disabled={(sourceType === "url" || sourceType === "value") && !value}
/>
</SubmitWrapper>
</ColJustiftBetween>
);
};

export default DelimitedText;
Loading

0 comments on commit 9972e66

Please sign in to comment.