Skip to content

Commit 27fa5fa

Browse files
author
Jin Igarashi
authored
fix: handle layer name correctly if it contains dot (.) in title (#4927)
* fix: show accordion and floating panel titile correctly if title contains dot (.) * fix: fixed /datasets/{id}/table endpoint to handle layer name correctly if layer name contains dot (.)
1 parent fa70b52 commit 27fa5fa

8 files changed

Lines changed: 40 additions & 12 deletions

File tree

.changeset/great-pumas-attack.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@undp-data/svelte-maplibre-storymap": patch
3+
"@undp-data/svelte-undp-components": patch
4+
"geohub": patch
5+
---
6+
7+
fix: show accordion and floating panel titile correctly if title contains dot (.)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"geohub": patch
3+
---
4+
5+
fix: fixed /datasets/{id}/table endpoint to handle layer name correctly if layer name contains dot (.)

packages/svelte-maplibre-storymap/src/lib/MaplibreLegendControl.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@
337337
{#if showInvisibleLayers || (!showInvisibleLayers && getLayerOpacity(l.id) > 0 && !isRemoteLegend)}
338338
{#if showInteractive}
339339
<Accordion
340-
title={clean(l.name)}
340+
title={l.name}
341341
bind:isExpanded={expanded[l.id]}
342342
isSelected={false}
343343
showHoveredColor={true}

packages/svelte-undp-components/src/lib/components/ui/Accordion.svelte

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
isSelected?: boolean;
1010
showHoveredColor?: boolean;
1111
isUppercase?: boolean;
12+
removeExtension?: boolean;
1213
padding?: string;
1314
buttons?: import('svelte').Snippet;
1415
content?: import('svelte').Snippet;
@@ -21,6 +22,7 @@
2122
isSelected = false,
2223
showHoveredColor = false,
2324
isUppercase = true,
25+
removeExtension = false,
2426
padding = 'px-4',
2527
buttons,
2628
content,
@@ -72,7 +74,7 @@
7274
class="fa-solid fa-chevron-down toggle-icon {isExpanded ? 'active' : ''} has-text-primary"
7375
></i>
7476
</span>
75-
<span class="has-text-grey-dark">{clean(title, isUppercase)}</span>
77+
<span class="has-text-grey-dark">{clean(title, isUppercase, removeExtension)}</span>
7678
</span>
7779

7880
{@render buttons?.()}

packages/svelte-undp-components/src/lib/components/ui/FloatingPanel.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
}}
5555
onkeydown={handleEnterKey}
5656
>
57-
{clean(title)}
57+
{clean(title, true, false)}
5858
</div>
5959
{#if showExpand || showClose}
6060
<div class="header-buttons is-flex is-align-items-center ml-auto">

packages/svelte-undp-components/src/lib/util/clean.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@
22
* Remove underscore and extension and apply start/title case to a string
33
* @param val String to clean
44
*/
5-
export const clean = (val: string, isUppercase = true) => {
5+
export const clean = (val: string, isUppercase = true, removeExtension = true) => {
66
if (!val) return '';
77
// apply start/title case
8-
return val
9-
.replace(/[_-]/g, ' ') // remove underscore and hyphen
10-
.replace(/\.[^/.]+$/, '') // remove extension
11-
.replace(/\b\w/g, (str) => (isUppercase ? str.toUpperCase() : str));
8+
let result = val.replace(/[_-]/g, ' '); // remove underscore and hyphen
9+
10+
if (removeExtension) {
11+
result = result.replace(/\.[^/.]+$/, '');
12+
}
13+
14+
result = result.replace(/\b\w/g, (str) => (isUppercase ? str.toUpperCase() : str));
15+
16+
return result;
1217
};

sites/geohub/src/components/pages/map/layers/LayerTemplate.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@
452452
</script>
453453

454454
<Accordion
455-
title={clean(layer.name)}
455+
title={clean(layer.name, true, false)}
456456
bind:isExpanded
457457
isSelected={$editingLayerStore?.id === layer.id}
458458
showHoveredColor={true}

sites/geohub/src/lib/server/api/datasets/[id]/table/layers/[layer].[format]/GET.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export const Param = z.object({
3333
.describe(`a layer ID. This should be equivalent to maplibre's source layer ID.`)
3434
.openapi({ example: 'zanzibar_tourism_attractions' }),
3535
format: z
36-
.enum([...SupportedTableFormats] as [string, ...string[]])
36+
.string()
3737
.describe(`Table format either json or csv or geojson or xlsx. default is json.`)
3838
});
3939

@@ -162,8 +162,17 @@ export default new Endpoint({ Param, Query, Output, Modifier }).handle(
162162
}
163163

164164
const id: string = param.id;
165-
const layer: string = param.layer.toLowerCase();
166-
const format: string = param.format.toLowerCase();
165+
let layer: string = param.layer.toLowerCase();
166+
let format: string = param.format.toLowerCase();
167+
168+
// if layer name consists of dot, sveltekit will split layer name and format weirdly.
169+
// this code will fix layer name and format name correctly.
170+
const formatParts = format.split('.');
171+
if (formatParts.length > 1) {
172+
format = formatParts[formatParts.length - 1];
173+
layer = [layer, ...formatParts.slice(0, formatParts.length - 1)].join('.');
174+
}
175+
167176
if (!SupportedTableFormats.includes(format)) {
168177
error(400, {
169178
message: `${format} is not supported. Please select it from ${SupportedTableFormats.join(', ')}`

0 commit comments

Comments
 (0)