Skip to content

Commit

Permalink
Merge pull request #3 from Vizzuality/feature/legend
Browse files Browse the repository at this point in the history
Legend and layer settings sync
  • Loading branch information
mbarrenechea authored Nov 2, 2023
2 parents e3bab1c + 836bd67 commit 2489ad5
Show file tree
Hide file tree
Showing 14 changed files with 312 additions and 285 deletions.
4 changes: 2 additions & 2 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"@radix-ui/react-switch": "^1.0.3",
"@radix-ui/react-tooltip": "1.0.7",
"@t3-oss/env-nextjs": "0.6.1",
"@tailwindcss/typography": "^0.5.10",
"@tanstack/react-query": "4.35.3",
"@typescript-eslint/eslint-plugin": "6.7.3",
"@typescript-eslint/parser": "6.7.3",
Expand All @@ -46,7 +47,7 @@
"lodash-es": "^4.17.21",
"mapbox-gl": "2.15.0",
"next": "13.5.3",
"next-usequerystate": "^1.8.4",
"next-usequerystate": "^1.9.1",
"pino": "8.15.1",
"pino-http": "8.5.0",
"pino-pretty": "10.2.0",
Expand All @@ -60,7 +61,6 @@
"tailwind-merge": "1.14.0",
"tailwindcss": "3.3.3",
"tailwindcss-animate": "1.0.7",
"@tailwindcss/typography": "^0.5.10",
"typescript": "5.2.2",
"zod": "3.22.2"
},
Expand Down
219 changes: 0 additions & 219 deletions client/public/presentation.js

This file was deleted.

7 changes: 2 additions & 5 deletions client/src/app/url-query-params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@ export const useSyncLayersSettings = () => {
return useQueryState(
"layers-settings",
parseAsJson<{
[key: string]: {
opacity: number;
visibility: boolean;
};
}>().withDefault({}),
[key: string]: Record<string, unknown>;
}>(),
);
};

Expand Down
8 changes: 1 addition & 7 deletions client/src/components/map/legend/item/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,16 @@ export const LegendItem: React.FC<PropsWithChildren & LegendItemProps> = ({
// events
onChangeOpacity,
onChangeVisibility,
onChangeExpand,
}) => {
const { expand } = settings || {};

const validChildren = useMemo(() => {
const chldn = Children.map(children, (Child) => {
return isValidElement(Child);
});
return chldn && chldn.some((c) => !!c);
}, [children]);

const acordionState = expand ? `${id}` : undefined;

return (
<Accordion type="single" value={acordionState} asChild>
<Accordion type="single" defaultValue={`${id}`} asChild>
<AccordionItem value={`${id}`} asChild>
<div
className={cn({
Expand Down Expand Up @@ -83,7 +78,6 @@ export const LegendItem: React.FC<PropsWithChildren & LegendItemProps> = ({
settingsManager={settingsManager}
onChangeOpacity={onChangeOpacity}
onChangeVisibility={onChangeVisibility}
onChangeExpand={onChangeExpand}
InfoContent={InfoContent}
/>
</header>
Expand Down
40 changes: 2 additions & 38 deletions client/src/components/map/legend/item/toolbar/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useState } from "react";

import { PopoverArrow } from "@radix-ui/react-popover";
import { LuEye, LuEyeOff, LuDroplet, LuChevronDown, LuInfo } from "react-icons/lu";
import { LuEye, LuEyeOff, LuDroplet, LuInfo } from "react-icons/lu";

import { cn } from "@/lib/classnames";

Expand All @@ -19,10 +19,9 @@ export const LegendItemToolbar: React.FC<LegendItemToolbarProps> = ({
settingsManager,
onChangeOpacity,
onChangeVisibility,
onChangeExpand,
}: LegendItemToolbarProps) => {
const [popoverOpen, setPopoverOpen] = useState(false);
const { opacity = 1, visibility = true, expand = true } = settings || {};
const { opacity = 1, visibility = true } = settings || {};

return (
<div id="legend-toolbar" className="mt-0.5 flex divide-x">
Expand Down Expand Up @@ -136,41 +135,6 @@ export const LegendItemToolbar: React.FC<LegendItemToolbarProps> = ({
</div>
)}
</div>

{settingsManager?.expand && (
<div className="pl-2">
<div className="flex items-start">
<Tooltip delayDuration={500}>
{/* <AccordionTrigger> */}
<TooltipTrigger
type="button"
aria-label={expand ? "Collapse layer" : "Expand layer"}
className={cn({
"pointer-events-none": popoverOpen,
})}
onClick={() => {
if (onChangeExpand) onChangeExpand(!expand);
}}
>
<LegendItemButton
Icon={LuChevronDown}
className={cn({
"rotate-180": !expand,
"rotate-0 transform transition-transform": expand,
})}
/>
</TooltipTrigger>
{/* </AccordionTrigger> */}

<TooltipContent side="top" align="end" alignOffset={-10}>
<div className="text-xxs">{expand ? "Collapse layer" : "Expand layer"}</div>

<TooltipArrow className="fill-white" width={10} height={5} />
</TooltipContent>
</Tooltip>
</div>
</div>
)}
</div>
);
};
Expand Down
4 changes: 0 additions & 4 deletions client/src/components/map/legend/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,22 @@ type Sortable = {
type OnChangeOrder = (id: string[]) => void;
type OnChangeOpacity = (opacity: number) => void;
type OnChangeVisibility = (visibility: boolean) => void;
type OnChangeExpand = (expand: boolean) => void;
type OnChangeColumn = (column: string) => void;

export type Settings = Record<string, unknown> & {
opacity?: number;
visibility?: boolean;
expand?: boolean;
};

export type SettingsManager = {
opacity?: boolean;
visibility?: boolean;
expand?: boolean;
info?: boolean;
};

export type LegendItemEvents = {
onChangeOpacity?: OnChangeOpacity;
onChangeVisibility?: OnChangeVisibility;
onChangeExpand?: OnChangeExpand;
onChangeColumn?: OnChangeColumn;
};
/*
Expand Down
Loading

0 comments on commit 2489ad5

Please sign in to comment.