-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #989 from Deltares/981-location-tooltips
Add location information
- Loading branch information
Showing
10 changed files
with
180 additions
and
20 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<template> | ||
<v-chip label class="tooltip-chip"> | ||
<v-icon>mdi-information</v-icon> | ||
<v-menu | ||
v-model="opened" | ||
transition="slide-y-transition" | ||
:close-on-content-click="false" | ||
activator="parent" | ||
persistent | ||
no-click-animation | ||
> | ||
<div class="tooltip-chip px-3 py-2 my-2 elevation-1"> | ||
<div v-html="content" /> | ||
</div> | ||
</v-menu> | ||
</v-chip> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { ref } from 'vue' | ||
interface Props { | ||
content: string | ||
} | ||
defineProps<Props>() | ||
const opened = ref(true) | ||
</script> | ||
|
||
<style scoped> | ||
.tooltip-chip { | ||
font-size: 0.825em; | ||
z-index: 1000; | ||
border-radius: 5px; | ||
backdrop-filter: blur(5px); | ||
background-color: rgba(var(--v-theme-surface), 0.8); | ||
box-shadow: 0 0 5px rgba(0, 0, 0, 0.5); | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { | ||
type filterActionsFilter, | ||
type timeSeriesGridActionsFilter, | ||
} from '@deltares/fews-pi-requests' | ||
|
||
export type Filter = timeSeriesGridActionsFilter | filterActionsFilter | ||
|
||
export function isFilterActionsFilter( | ||
filter: Filter, | ||
): filter is filterActionsFilter { | ||
return (filter as filterActionsFilter).filterId !== undefined | ||
} | ||
|
||
export function isTimeSeriesGridActionsFilter( | ||
filter: Filter, | ||
): filter is timeSeriesGridActionsFilter { | ||
return (filter as timeSeriesGridActionsFilter).x !== undefined | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { createTransformRequestFn } from '@/lib/requests/transformRequest' | ||
import { | ||
LocationsTooltipFilter, | ||
PiWebserviceProvider, | ||
} from '@deltares/fews-pi-requests' | ||
import type { MaybeRefOrGetter, Ref, ShallowRef } from 'vue' | ||
import { ref, shallowRef, toValue, watchEffect } from 'vue' | ||
|
||
export interface UseLocationTooltipReturn { | ||
error: Ref<string | undefined> | ||
tooltip: ShallowRef<string | undefined> | ||
isReady: Ref<boolean> | ||
isLoading: Ref<boolean> | ||
} | ||
|
||
export function useLocationTooltip( | ||
baseUrl: string, | ||
filter: MaybeRefOrGetter<LocationsTooltipFilter | undefined>, | ||
): UseLocationTooltipReturn { | ||
const tooltip = shallowRef<string>() | ||
const isReady = ref(false) | ||
const isLoading = ref(false) | ||
const error = shallowRef<string>() | ||
|
||
async function loadLocationTooltip() { | ||
isLoading.value = true | ||
isReady.value = false | ||
|
||
try { | ||
const _filter = toValue(filter) | ||
if (!_filter) throw new Error('Tooltip filter is undefined') | ||
|
||
const provider = new PiWebserviceProvider(baseUrl, { | ||
transformRequestFn: createTransformRequestFn(), | ||
}) | ||
const response = await provider.getLocationsTooltip(_filter) | ||
if (!response) throw new Error('Tooltip response is undefined') | ||
|
||
tooltip.value = isHTML(response) ? response : formatAsHTML(response) | ||
} catch { | ||
error.value = 'Error loading location tooltip' | ||
tooltip.value = undefined | ||
} finally { | ||
isLoading.value = false | ||
isReady.value = true | ||
} | ||
} | ||
|
||
watchEffect(loadLocationTooltip) | ||
|
||
return { | ||
tooltip, | ||
isReady, | ||
isLoading, | ||
error, | ||
} | ||
} | ||
|
||
function isHTML(str: string) { | ||
const parser = new DOMParser() | ||
const doc = parser.parseFromString(str, 'text/html') | ||
return Array.from(doc.body.childNodes).some((node) => node.nodeType === 1) | ||
} | ||
|
||
function formatAsHTML(str: string) { | ||
return `<pre>${str}</pre>` | ||
} |