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

chore(web): fix local name is random when added through asset #779

Merged
merged 2 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
6 changes: 3 additions & 3 deletions web/src/beta/components/fields/URLField/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export type Props = {
fileType?: "asset" | "URL" | "layerStyle";
entityType?: "image" | "file" | "layerStyle";
sceneId?: string;
onChange?: (value: string | undefined) => void;
onChange?: (value: string | undefined, name: string | undefined) => void;
};

const URLField: React.FC<Props> = ({
Expand All @@ -38,7 +38,7 @@ const URLField: React.FC<Props> = ({
const [currentValue, setCurrentValue] = useState(value);

const handleChange = useCallback(
(inputValue?: string) => {
(inputValue?: string, name?: string) => {
if (!inputValue) return;

if (
Expand All @@ -54,7 +54,7 @@ const URLField: React.FC<Props> = ({
}

setCurrentValue(inputValue);
onChange?.(inputValue);
onChange?.(inputValue, name);
},
[fileType, onChange, setNotification, t],
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const Asset: React.FC<DataProps> = ({ sceneId, onSubmit, onClose }) => {
const [sourceType, setSourceType] = React.useState<SourceType>("local");
const [fileFormat, setFileFormat] = React.useState<FileFormatType>("GeoJSON");
const [value, setValue] = React.useState("");
const [layerName, setLayerName] = React.useState("");
const [prioritizePerformance, setPrioritizePerformance] = React.useState(false);
const DataSourceOptions: DataSourceOptType = useMemo(
() => [
Expand All @@ -66,7 +67,7 @@ const Asset: React.FC<DataProps> = ({ sceneId, onSubmit, onClose }) => {
onSubmit({
layerType: "simple",
sceneId,
title: generateTitle(value),
title: generateTitle(value, layerName),
visible: true,
config: {
data: {
Expand All @@ -79,7 +80,10 @@ const Asset: React.FC<DataProps> = ({ sceneId, onSubmit, onClose }) => {
onClose();
};

const handleOnChange = useCallback((value?: string) => setValue(value || ""), []);
const handleOnChange = useCallback((value?: string, name?: string) => {
setValue(value || "");
setLayerName(name || "");
}, []);

return (
<ColJustifyBetween>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const DelimitedText: React.FC<DataProps> = ({ sceneId, onSubmit, onClose }) => {

const [sourceType, setSourceType] = React.useState<SourceType>("local");
const [value, setValue] = React.useState("");
const [layerName, setLayerName] = React.useState("");
const [lat, setLat] = React.useState("");
const [long, setLong] = React.useState("");

Expand All @@ -37,7 +38,7 @@ const DelimitedText: React.FC<DataProps> = ({ sceneId, onSubmit, onClose }) => {
onSubmit({
layerType: "simple",
sceneId,
title: generateTitle(value),
title: generateTitle(value, layerName),
visible: true,
config: {
data: {
Expand All @@ -53,7 +54,10 @@ const DelimitedText: React.FC<DataProps> = ({ sceneId, onSubmit, onClose }) => {
onClose();
};

const handleOnChange = useCallback((value?: string) => setValue(value || ""), []);
const handleOnChange = useCallback((value?: string, name?: string) => {
setValue(value || "");
setLayerName(name || "");
}, []);

return (
<ColJustifyBetween>
Expand Down
5 changes: 3 additions & 2 deletions web/src/beta/features/Editor/DataSourceManager/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,9 @@ export const AddLayerWrapper = styled.div`
justify-content: flex-start;
`;

export const generateTitle = (url?: string): string => {
if (url && url.trim() !== "") {
export const generateTitle = (url: string, layerName?: string): string => {
if (layerName && layerName.trim() !== "") return layerName;
if (url.trim() !== "") {
try {
const urlObject = new URL(url);
const pathParts = urlObject.pathname.split("/");
Expand Down
4 changes: 2 additions & 2 deletions web/src/beta/features/Modals/AssetModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export type Props = {
className?: string;
assetType?: "file" | "image";
open?: boolean;
onSelect?: (value: string) => void;
onSelect?: (value: string, name: string) => void;
currentWorkspace?: Workspace;
currentValue?: string;
onModalClose: () => void;
Expand Down Expand Up @@ -89,7 +89,7 @@ const ChooseAssetModal: React.FC<Props> = ({

const handleSelectButtonClick = useCallback(() => {
if (selectedAssets && selectedAssets.length > 0) {
onSelect?.(selectedAssets[0].url);
onSelect?.(selectedAssets[0].url, selectedAssets[0].name);
onClose?.();
} else {
setNotification({
Expand Down
Loading