From e58f8cc42a18bf412e8a8bedfdba09dc0e8d0ccc Mon Sep 17 00:00:00 2001 From: lby Date: Mon, 19 Aug 2024 10:52:27 +0800 Subject: [PATCH 01/23] fix(web): disable link when id undefined (#1104) --- web/src/beta/features/Navbar/LeftSection/index.tsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/web/src/beta/features/Navbar/LeftSection/index.tsx b/web/src/beta/features/Navbar/LeftSection/index.tsx index 6da1c4484..de3c27cd3 100644 --- a/web/src/beta/features/Navbar/LeftSection/index.tsx +++ b/web/src/beta/features/Navbar/LeftSection/index.tsx @@ -50,11 +50,11 @@ const LeftSection: React.FC = ({ return ( - + {page !== "editor" && ( - + )} @@ -79,10 +79,11 @@ const Wrapper = styled("div")(({ theme }) => ({ gap: theme.spacing.small, })); -const StyledLink = styled(Link)(({ theme }) => ({ +const StyledLink = styled(Link)<{ disabled?: boolean }>(({ theme, disabled }) => ({ display: "flex", color: theme.content.main, textDecoration: "none", + pointerEvents: disabled ? "none" : "all", "&:hover": { textDecoration: "none", }, From 422db8776f334c141ea7229d8f5a907c1e334d4a Mon Sep 17 00:00:00 2001 From: lby Date: Mon, 19 Aug 2024 16:44:36 +0800 Subject: [PATCH 02/23] feat(web): support delete sketch feature (#1105) --- .../LayerInspector/FeatureInspector/index.tsx | 24 +++++++++++++++++- .../InspectorPanel/LayerInspector/index.tsx | 9 ++++++- .../Editor/Map/InspectorPanel/index.tsx | 2 ++ web/src/beta/features/Editor/Map/context.tsx | 3 ++- web/src/beta/features/Editor/hooks/index.ts | 3 +++ .../beta/features/Editor/hooks/useSketch.ts | 19 +++++++++++++- .../api/featureCollectionApi/index.ts | 25 ++++++++++++++++++- web/src/services/gql/__gen__/gql.ts | 5 ++++ web/src/services/gql/__gen__/graphql.ts | 8 ++++++ .../services/gql/queries/featureCollection.ts | 8 ++++++ web/src/services/i18n/translations/en.yml | 6 +++-- web/src/services/i18n/translations/ja.yml | 6 +++-- 12 files changed, 109 insertions(+), 9 deletions(-) diff --git a/web/src/beta/features/Editor/Map/InspectorPanel/LayerInspector/FeatureInspector/index.tsx b/web/src/beta/features/Editor/Map/InspectorPanel/LayerInspector/FeatureInspector/index.tsx index b52c8e67b..540e89d4e 100644 --- a/web/src/beta/features/Editor/Map/InspectorPanel/LayerInspector/FeatureInspector/index.tsx +++ b/web/src/beta/features/Editor/Map/InspectorPanel/LayerInspector/FeatureInspector/index.tsx @@ -3,7 +3,10 @@ import "react18-json-view/src/style.css"; import "react18-json-view/src/dark.css"; import JsonView from "react18-json-view"; -import { GeoJsonFeatureUpdateProps } from "@reearth/beta/features/Editor/hooks/useSketch"; +import { + GeoJsonFeatureDeleteProps, + GeoJsonFeatureUpdateProps, +} from "@reearth/beta/features/Editor/hooks/useSketch"; import { Button, Collapse, Typography } from "@reearth/beta/lib/reearth-ui"; import { Geometry } from "@reearth/core"; import { NLSLayer, SketchFeature } from "@reearth/services/api/layersApi/utils"; @@ -21,6 +24,7 @@ type Props = { layer?: NLSLayer; sketchFeature?: SketchFeature; onGeoJsonFeatureUpdate?: (inp: GeoJsonFeatureUpdateProps) => void; + onGeoJsonFeatureDelete?: (inp: GeoJsonFeatureDeleteProps) => void; }; export type ValueProp = string | number | boolean | undefined; @@ -36,6 +40,7 @@ const FeatureData: FC = ({ layer, sketchFeature, onGeoJsonFeatureUpdate, + onGeoJsonFeatureDelete, }) => { const t = useT(); const theme = useTheme(); @@ -87,6 +92,14 @@ const FeatureData: FC = ({ [theme.fonts.sizes.body], ); + const handleDeleteSketchFeature = useCallback(() => { + if (!layer?.id || !sketchFeature?.id) return; + onGeoJsonFeatureDelete?.({ + layerId: layer.id, + featureId: sketchFeature.id, + }); + }, [layer?.id, sketchFeature?.id, onGeoJsonFeatureDelete]); + return ( {!!layer?.isSketch && ( @@ -134,6 +147,15 @@ const FeatureData: FC = ({ + {!!layer?.isSketch && sketchFeature?.id && ( + + // `asChild` allows the user to pass any element as the anchor + if (asChild && isValidElement(children)) { + return cloneElement( + children, + context.getReferenceProps({ + ref, + ...props, + ...children.props, + "data-state": context.open ? "open" : "closed", + }), ); - }, -); + } + + return ( + + ); +}); type ContentProps = { className?: string; attachToRoot?: boolean; }; -export const Content = forwardRef & ContentProps>( - function Content({ style, className, attachToRoot = false, ...props }, propRef) { - const { context: floatingContext, ...context } = usePopoverContext(); - const theme = useTheme(); - const ref = useMergeRefs([context.refs.setFloating, propRef]); - const { isMounted, styles: transitionStyles } = useTransitionStyles(floatingContext, { +export const Content = forwardRef< + HTMLDivElement, + HTMLProps & ContentProps +>(function Content( + { style, className, attachToRoot = false, ...props }, + propRef, +) { + const { context: floatingContext, ...context } = usePopoverContext(); + const theme = useTheme(); + const ref = useMergeRefs([context.refs.setFloating, propRef]); + const { isMounted, styles: transitionStyles } = useTransitionStyles( + floatingContext, + { duration: 50, - }); + }, + ); - if (!isMounted) return null; + if (!isMounted) return null; - return ( - ) : null}> - -
- {props.children} -
-
-
- ); - }, -); + return ( + ) + : null + } + > + +
+ {props.children} +
+
+
+ ); +}); -export const Close = forwardRef>( - function PopoverClose(props, ref) { - const { setOpen } = usePopoverContext(); - return ( -