Skip to content

Commit

Permalink
feat: toggle features from map toolbar
Browse files Browse the repository at this point in the history
  • Loading branch information
katharinawuensche committed Nov 26, 2024
1 parent 30fcd40 commit c0ee7a7
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 17 deletions.
60 changes: 60 additions & 0 deletions components/geojson-map-toolbar.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<script lang="ts" setup>
import { ChevronDown } from "lucide-vue-next";
import { useGeojsonStore } from "@/stores/use-geojson-store.ts";
import type { GeojsonMapSchema } from "@/types/global.d";
interface Props {
params: Zod.infer<typeof GeojsonMapSchema>["params"];
}
const props = defineProps<Props>();
const { params } = toRefs(props);
const GeojsonStore = useGeojsonStore();
const { tables } = storeToRefs(GeojsonStore);
const table = computed(() => tables.value.get(params.value.url));
const categories = computed(() => {
return table.value?.getAllColumns().filter((column) => column.getCanHide());
});
function titleCase(s: string) {
return s
.replace(/^[-_]*(.)/, (_, c) => c.toUpperCase()) // Initial char (after -/_)
.replace(/[-_]+(.)/g, (_, c) => " " + c.toUpperCase()); // First char after each -/_
}
const isCollapsibleOpen = ref(categories.value!.map(() => false));
</script>

<template>
<div class="grid items-center border-b border-border bg-surface px-8 py-3 text-on-surface">
<div class="flex flex-wrap items-center gap-x-4 gap-y-1 text-sm font-medium text-on-surface/75">
<div v-for="(group, idx) in categories" :key="group.id">
<DropdownMenu v-slot="{ open }" v-model:open="isCollapsibleOpen[idx]">
<DropdownMenuTrigger class="flex w-full items-center gap-1 p-2 text-sm">
<span>{{ titleCase(group.id) }}</span>
<ChevronDown class="size-4" :class="open ? 'rotate-180' : ''"></ChevronDown>
</DropdownMenuTrigger>

<DropdownMenuContent class="">
<DropdownMenuCheckboxItem
v-for="column in group.columns"
:key="column.id"
:checked="column.getIsVisible()"
@select.prevent
@update:checked="
(value) => {
column.toggleVisibility(!!value);
column.setFilterValue([]);
}
"
>
{{ column.columnDef.header }}
</DropdownMenuCheckboxItem>
</DropdownMenuContent>
</DropdownMenu>
</div>
</div>
</div>
</template>
34 changes: 19 additions & 15 deletions components/geojson-map-window-content.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const props = defineProps<Props>();
const { params } = toRefs(props);
const GeojsonStore = useGeojsonStore();
const { tables } = storeToRefs(GeojsonStore);
const filteredMarkers = computed(() => {
Expand All @@ -26,19 +27,22 @@ const filteredMarkers = computed(() => {
</script>

<template>
<VisualisationContainer
v-slot="{ width, height }"
:class="{ 'opacity-50 grayscale': !filteredMarkers }"
>
<GeoMap
v-if="filteredMarkers"
:height="height"
:marker-type="params.markerType"
:markers="filteredMarkers as Array<Feature<Point, MarkerProperties>>"
:width="width"
/>
<Centered v-if="!filteredMarkers">
<LoadingIndicator />
</Centered>
</VisualisationContainer>
<div class="relative isolate grid size-full grid-rows-[auto_1fr]">
<GeojsonMapToolbar v-if="filteredMarkers" :params="params"></GeojsonMapToolbar>
<VisualisationContainer
v-slot="{ width, height }"
:class="{ 'opacity-50 grayscale': !filteredMarkers }"
>
<GeoMap
v-if="filteredMarkers"
:height="height"
:marker-type="params.markerType"
:markers="filteredMarkers as Array<Feature<Point, MarkerProperties>>"
:width="width"
/>
<Centered v-if="!filteredMarkers">
<LoadingIndicator />
</Centered>
</VisualisationContainer>
</div>
</template>
4 changes: 2 additions & 2 deletions components/ui/dropdown-menu/DropdownMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const forwarded = useForwardPropsEmits(props, emits);
</script>

<template>
<DropdownMenuRoot v-bind="forwarded">
<slot />
<DropdownMenuRoot v-slot="{ open }" v-bind="forwarded">
<slot :open="open" />
</DropdownMenuRoot>
</template>

0 comments on commit c0ee7a7

Please sign in to comment.