From 583cb7771cdefe38a4c75ac9a29d5bce5b1a7424 Mon Sep 17 00:00:00 2001 From: juhanikat Date: Fri, 20 Nov 2026 11:34:50 +0200 Subject: [PATCH 1/4] fix occurrence svg map not showing markers properly, and remove svg export option from localities --- .../CrossSearch/CrossSearchTable.tsx | 29 ++++++++++--------- .../Locality/Tabs/OccurrencesTab.tsx | 6 ---- frontend/src/components/Map/generateSvg.ts | 10 +++---- .../Species/Tabs/LocalitySpeciesTab.tsx | 22 ++++++++------ .../Species/localitySpeciesMapExport.ts | 19 +++++++----- frontend/src/shared/types/data.ts | 5 ++++ 6 files changed, 50 insertions(+), 41 deletions(-) diff --git a/frontend/src/components/CrossSearch/CrossSearchTable.tsx b/frontend/src/components/CrossSearch/CrossSearchTable.tsx index b28644ef5..b53e92233 100755 --- a/frontend/src/components/CrossSearch/CrossSearchTable.tsx +++ b/frontend/src/components/CrossSearch/CrossSearchTable.tsx @@ -1,21 +1,22 @@ -import { lazy, Suspense, useMemo } from 'react' -import { type MRT_ColumnDef, type MRT_RowData, type MRT_TableInstance } from 'material-react-table' -import { CrossSearch, formatDevelopmentalCrownType } from '@/shared/types' -import { TableView } from '../TableView/TableView' -import type { ColumnVisibilityGroup } from '../TableView/TableToolBar' -import { useGetAllCrossSearchQuery, useGetAllCrossSearchLocalitiesQuery } from '@/redux/crossSearchReducer' -import { usePageContext } from '../Page' -import { formatWithMaxThreeDecimals } from '@/util/numberFormatting' -import { occurrenceLabels } from '@/constants/occurrenceLabels' -import { OccurrenceDwcExportMenuItem } from '@/components/Occurrence/OccurrenceDwcExportMenuItem' import { OccurrenceDwcDpExportMenuItem } from '@/components/Occurrence/OccurrenceDwcDpExportMenuItem' +import { OccurrenceDwcExportMenuItem } from '@/components/Occurrence/OccurrenceDwcExportMenuItem' import { OccurrenceFullDarwinCoreExportMenuItem } from '@/components/Occurrence/OccurrenceFullDarwinCoreExportMenuItem' -import { matchesCountryOrContinent } from '@/shared/validators/countryContinents' import { exportOccurrenceMapKml, exportOccurrenceMapSvg, getUniqueCrossSearchMapExportLocalities, } from '@/components/Species/localitySpeciesMapExport' +import { occurrenceLabels } from '@/constants/occurrenceLabels' +import { useGetAllCrossSearchLocalitiesQuery, useGetAllCrossSearchQuery } from '@/redux/crossSearchReducer' +import { CrossSearch, formatDevelopmentalCrownType } from '@/shared/types' +import { matchesCountryOrContinent } from '@/shared/validators/countryContinents' +import { formatWithMaxThreeDecimals } from '@/util/numberFormatting' +import { CircularProgress } from '@mui/material' +import { type MRT_ColumnDef, type MRT_RowData, type MRT_TableInstance } from 'material-react-table' +import { lazy, Suspense, useMemo } from 'react' +import { usePageContext } from '../Page' +import type { ColumnVisibilityGroup } from '../TableView/TableToolBar' +import { TableView } from '../TableView/TableView' const LocalitiesMap = lazy(async () => { const module = await import('../Map/LocalitiesMap') @@ -1078,6 +1079,8 @@ export const CrossSearchTable = ({ selectorFn }: { selectorFn?: (newObject: Cros [] ) + if (!localitiesData) return + const checkRowRestriction = (row: CrossSearch) => { return !!row.loc_status } @@ -1091,8 +1094,8 @@ export const CrossSearchTable = ({ selectorFn }: { selectorFn?: (newObject: Cros exportOccurrenceMapKml(table, 'occurrences', getExportLocalities) } - const svgExport = async (table: MRT_TableInstance) => { - await exportOccurrenceMapSvg(table, 'occurrences-map', getExportLocalities) + const svgExport = async () => { + await exportOccurrenceMapSvg('occurrences-map', localitiesData) } return ( diff --git a/frontend/src/components/Locality/Tabs/OccurrencesTab.tsx b/frontend/src/components/Locality/Tabs/OccurrencesTab.tsx index 47457da16..2eee203f6 100644 --- a/frontend/src/components/Locality/Tabs/OccurrencesTab.tsx +++ b/frontend/src/components/Locality/Tabs/OccurrencesTab.tsx @@ -23,7 +23,6 @@ import { OccurrenceIsotopeTab } from '@/components/Occurrence/Tabs/OccurrenceIso import { OccurrenceWearTab } from '@/components/Occurrence/Tabs/OccurrenceWearTab' import { exportOccurrenceMapKml, - exportOccurrenceMapSvg, getUniqueLocalityOccurrenceMapExportLocalities, } from '@/components/Species/localitySpeciesMapExport' import { occurrenceLabels } from '@/constants/occurrenceLabels' @@ -378,10 +377,6 @@ export const OccurrencesTab = () => { exportOccurrenceMapKml(table, 'locality-occurrences', getExportLocalities) } - const svgExport = async (table: MRT_TableInstance) => { - await exportOccurrenceMapSvg(table, 'locality-occurrences-map', getExportLocalities) - } - const textField = (field: keyof EditDataType, options?: TextFieldOptions) => ( field={field} {...options} /> ) @@ -497,7 +492,6 @@ export const OccurrencesTab = () => { url="occurrence" getDetailPath={row => `/occurrence/${row.lid}/${row.species_id}`} kmlExport={kmlExport} - svgExport={svgExport} renderReadRowActions={({ row }) => ( <> diff --git a/frontend/src/components/Map/generateSvg.ts b/frontend/src/components/Map/generateSvg.ts index 14847f64a..d716fc8c9 100644 --- a/frontend/src/components/Map/generateSvg.ts +++ b/frontend/src/components/Map/generateSvg.ts @@ -1,6 +1,6 @@ +import { LocalityCoord } from '@/shared/types' import { SVG } from '@svgdotjs/svg.js' import { countryPolygons } from '../../country_data/countryPolygons.ts' -import { Locality } from '@/shared/types' interface PixelCoordinates { x: number @@ -22,7 +22,7 @@ const webMercatorConvert = (lat: number, long: number, width: number): PixelCoor // Generates and returns an SVG image of localities on a map. export const generateSvg = ( - localities: Locality[], + localityCoords: LocalityCoord[], mapBorderColor = '#000000', mapFillColor = '#ffffff', markerBorderColor = '#ff0000', @@ -48,9 +48,9 @@ export const generateSvg = ( draw.polygon(polygon).stroke({ width: 1, color: mapBorderColor }).fill(mapFillColor) }) - localities.forEach(locality => { - const pixelCoords = webMercatorConvert(locality.dec_lat, locality.dec_long, width) - const radius = 3 + localityCoords.forEach(coord => { + const pixelCoords = webMercatorConvert(coord.dec_lat, coord.dec_long, width) + const radius = 10 const topLeftX = pixelCoords.x - radius const topLeftY = pixelCoords.y - radius draw.circle(radius).move(topLeftX, topLeftY).stroke({ width: 1, color: markerBorderColor }).fill(markerFillColor) diff --git a/frontend/src/components/Species/Tabs/LocalitySpeciesTab.tsx b/frontend/src/components/Species/Tabs/LocalitySpeciesTab.tsx index 37cc03908..ed2f93407 100755 --- a/frontend/src/components/Species/Tabs/LocalitySpeciesTab.tsx +++ b/frontend/src/components/Species/Tabs/LocalitySpeciesTab.tsx @@ -1,23 +1,23 @@ -import { Editable, SpeciesDetailsType, SpeciesLocality } from '@/shared/types' +import { applyDefaultSpeciesOrdering, hasActiveSortingInSearch } from '@/components/DetailView/common/DetailTabTable' import { EditableTable } from '@/components/DetailView/common/EditableTable' import { EditingModal } from '@/components/DetailView/common/EditingModal' +import { EntryUpdateHistory } from '@/components/DetailView/common/FieldUpdateHistory' import { Grouped } from '@/components/DetailView/common/tabLayoutHelpers' import { useDetailContext } from '@/components/DetailView/Context/DetailContext' +import { occurrenceLabels } from '@/constants/occurrenceLabels' +import { Editable, SpeciesDetailsType, SpeciesLocality } from '@/shared/types' +import { calculateNormalizedMesowearScore } from '@/shared/utils/mesowear' +import { matchesCountryOrContinent } from '@/shared/validators/countryContinents' import { Box, TextField } from '@mui/material' import { MRT_ColumnDef, MRT_Row, MRT_RowData, MRT_TableInstance } from 'material-react-table' -import { matchesCountryOrContinent } from '@/shared/validators/countryContinents' +import { useMemo } from 'react' import { useForm } from 'react-hook-form' -import { calculateNormalizedMesowearScore } from '@/shared/utils/mesowear' -import { applyDefaultSpeciesOrdering, hasActiveSortingInSearch } from '@/components/DetailView/common/DetailTabTable' import { useLocation } from 'react-router-dom' -import { useMemo } from 'react' -import { occurrenceLabels } from '@/constants/occurrenceLabels' import { exportOccurrenceMapKml, exportOccurrenceMapSvg, getUniqueSpeciesLocalityMapExportLocalities, } from '../localitySpeciesMapExport' -import { EntryUpdateHistory } from '@/components/DetailView/common/FieldUpdateHistory' const hasMesowearScoreInputs = (row: SpeciesLocality) => { return ( @@ -212,8 +212,12 @@ export const LocalitySpeciesTab = () => { exportOccurrenceMapKml(table, 'locality-species', getExportLocalities) } - const svgExport = async (table: MRT_TableInstance) => { - await exportOccurrenceMapSvg(table, 'locality-species-map', getExportLocalities) + const svgExport = async () => { + const locsWithCoordinates = data.now_ls + .filter(ls => ls.now_loc !== undefined && ls.now_loc.dec_lat && ls.now_loc.dec_long) + .map(ls => ls.now_loc) + + await exportOccurrenceMapSvg('locality-species-map', locsWithCoordinates) } const editingModal = ( diff --git a/frontend/src/components/Species/localitySpeciesMapExport.ts b/frontend/src/components/Species/localitySpeciesMapExport.ts index 46c865a1c..1f1d34672 100644 --- a/frontend/src/components/Species/localitySpeciesMapExport.ts +++ b/frontend/src/components/Species/localitySpeciesMapExport.ts @@ -1,6 +1,13 @@ -import type { CrossSearch, Locality, LocalityDetailsType, LocalitySpecies, SpeciesLocality } from '@/shared/types' -import { generateKml } from '@/util/kml' import { currentDateAsString } from '@/shared/currentDateAsString' +import type { + CrossSearch, + Locality, + LocalityCoord, + LocalityDetailsType, + LocalitySpecies, + SpeciesLocality, +} from '@/shared/types' +import { generateKml } from '@/util/kml' import type { MRT_RowData, MRT_TableInstance } from 'material-react-table' type SpeciesSource = { @@ -177,11 +184,7 @@ export const exportOccurrenceMapKml = ( downloadTextFile(generateKml(getLocalities(table)), 'text/kml', `${filenamePrefix}-${currentDateAsString()}.kml`) } -export const exportOccurrenceMapSvg = async ( - table: MRT_TableInstance, - filenamePrefix: string, - getLocalities: (table: MRT_TableInstance) => MapExportLocality[] -) => { +export const exportOccurrenceMapSvg = async (filenamePrefix: string, localities: LocalityCoord[]) => { const { generateSvg } = await import('@/components/Map/generateSvg') - downloadTextFile(generateSvg(getLocalities(table)), 'image/svg+xml', `${filenamePrefix}-${currentDateAsString()}.svg`) + downloadTextFile(generateSvg(localities), 'image/svg+xml', `${filenamePrefix}-${currentDateAsString()}.svg`) } diff --git a/frontend/src/shared/types/data.ts b/frontend/src/shared/types/data.ts index 18c99373f..775627939 100755 --- a/frontend/src/shared/types/data.ts +++ b/frontend/src/shared/types/data.ts @@ -810,3 +810,8 @@ export type SimplifiedLocality = { dec_long: number loc_name: string } + +export type LocalityCoord = { + dec_lat: number + dec_long: number +} From 49130865ada6dd6314af70dff8be467ca6203c72 Mon Sep 17 00:00:00 2001 From: juhanikat Date: Fri, 20 Nov 2026 13:08:57 +0200 Subject: [PATCH 2/4] update svg/kml exports, and fix kl export opening browser tabs infinitely --- .../CrossSearch/CrossSearchTable.tsx | 28 ++++++++++------ .../Locality/Tabs/OccurrencesTab.tsx | 26 +++++++++++---- frontend/src/components/Map/generateSvg.ts | 8 ++--- .../Species/Tabs/LocalitySpeciesTab.tsx | 32 +++++++++++-------- .../Species/localitySpeciesMapExport.ts | 22 ++++--------- .../src/components/TableView/TableToolBar.tsx | 2 -- frontend/src/shared/types/data.ts | 5 --- frontend/src/util/kml.ts | 3 +- 8 files changed, 67 insertions(+), 59 deletions(-) diff --git a/frontend/src/components/CrossSearch/CrossSearchTable.tsx b/frontend/src/components/CrossSearch/CrossSearchTable.tsx index b53e92233..b98ebf9a3 100755 --- a/frontend/src/components/CrossSearch/CrossSearchTable.tsx +++ b/frontend/src/components/CrossSearch/CrossSearchTable.tsx @@ -4,7 +4,8 @@ import { OccurrenceFullDarwinCoreExportMenuItem } from '@/components/Occurrence/ import { exportOccurrenceMapKml, exportOccurrenceMapSvg, - getUniqueCrossSearchMapExportLocalities, + MapExportLocality, + toMapExportLocality, } from '@/components/Species/localitySpeciesMapExport' import { occurrenceLabels } from '@/constants/occurrenceLabels' import { useGetAllCrossSearchLocalitiesQuery, useGetAllCrossSearchQuery } from '@/redux/crossSearchReducer' @@ -12,11 +13,12 @@ import { CrossSearch, formatDevelopmentalCrownType } from '@/shared/types' import { matchesCountryOrContinent } from '@/shared/validators/countryContinents' import { formatWithMaxThreeDecimals } from '@/util/numberFormatting' import { CircularProgress } from '@mui/material' -import { type MRT_ColumnDef, type MRT_RowData, type MRT_TableInstance } from 'material-react-table' +import { type MRT_ColumnDef } from 'material-react-table' import { lazy, Suspense, useMemo } from 'react' import { usePageContext } from '../Page' import type { ColumnVisibilityGroup } from '../TableView/TableToolBar' import { TableView } from '../TableView/TableView' +import { useNotify } from '@/hooks/notification' const LocalitiesMap = lazy(async () => { const module = await import('../Map/LocalitiesMap') @@ -41,6 +43,7 @@ export const CrossSearchTable = ({ selectorFn }: { selectorFn?: (newObject: Cros columnFilters: sqlColumnFilters, sorting: sqlOrderBy, }) + const { notify } = useNotify() // Show/Hide columns in the following order const columns = useMemo[]>( @@ -1085,17 +1088,22 @@ export const CrossSearchTable = ({ selectorFn }: { selectorFn?: (newObject: Cros return !!row.loc_status } - const getExportLocalities = (table: MRT_TableInstance) => { - const rows = table.getPrePaginationRowModel().rows.map(row => row.original as unknown as CrossSearch) - return getUniqueCrossSearchMapExportLocalities(rows) - } - - const kmlExport = (table: MRT_TableInstance) => { - exportOccurrenceMapKml(table, 'occurrences', getExportLocalities) + const kmlExport = () => { + const exportedLocalities = localitiesData.map(loc => toMapExportLocality(loc)) + if (exportedLocalities.filter(loc => loc === null).length > 0) { + notify('Some localities failed to export, aborting.', 'error', 5) + return + } + exportOccurrenceMapKml('occurrences', exportedLocalities as MapExportLocality[]) } const svgExport = async () => { - await exportOccurrenceMapSvg('occurrences-map', localitiesData) + const exportedLocalities = localitiesData.map(loc => toMapExportLocality(loc)) + if (exportedLocalities.filter(loc => loc === null).length > 0) { + notify('Some localities failed to export, aborting.', 'error', 5) + return + } + await exportOccurrenceMapSvg('occurrences-map', exportedLocalities as MapExportLocality[]) } return ( diff --git a/frontend/src/components/Locality/Tabs/OccurrencesTab.tsx b/frontend/src/components/Locality/Tabs/OccurrencesTab.tsx index 2eee203f6..bda927e22 100644 --- a/frontend/src/components/Locality/Tabs/OccurrencesTab.tsx +++ b/frontend/src/components/Locality/Tabs/OccurrencesTab.tsx @@ -23,7 +23,8 @@ import { OccurrenceIsotopeTab } from '@/components/Occurrence/Tabs/OccurrenceIso import { OccurrenceWearTab } from '@/components/Occurrence/Tabs/OccurrenceWearTab' import { exportOccurrenceMapKml, - getUniqueLocalityOccurrenceMapExportLocalities, + exportOccurrenceMapSvg, + toMapExportLocality, } from '@/components/Species/localitySpeciesMapExport' import { occurrenceLabels } from '@/constants/occurrenceLabels' import { useNotify } from '@/hooks/notification' @@ -43,7 +44,7 @@ import { ValidationObject } from '@/shared/validators/validator' import ManageSearchIcon from '@mui/icons-material/ManageSearch' import SaveIcon from '@mui/icons-material/Save' import { Box, Button, DialogActions, DialogContent, Tooltip } from '@mui/material' -import type { MRT_ColumnDef, MRT_Row, MRT_RowData, MRT_TableInstance } from 'material-react-table' +import type { MRT_ColumnDef, MRT_Row } from 'material-react-table' import { useMemo, useState } from 'react' import { Link, useLocation } from 'react-router-dom' @@ -183,6 +184,7 @@ export const OccurrencesTab = () => { const { mode, data, editData, setEditData } = useDetailContext() const [fieldsWithErrors, setFieldsWithErrors] = useState({}) const location = useLocation() + const { notify } = useNotify() const sortedOccurrenceRows = useMemo(() => { const sourceRows = (mode.read ? data.now_ls : editData.now_ls) as unknown as Editable[] @@ -368,13 +370,22 @@ export const OccurrencesTab = () => { }, ] - const getExportLocalities = (table: MRT_TableInstance) => { - const rows = table.getPrePaginationRowModel().rows.map(row => row.original as unknown as LocalitySpecies) - return getUniqueLocalityOccurrenceMapExportLocalities(data, rows) + const kmlExport = () => { + const exportedLocality = toMapExportLocality(editData) + if (!exportedLocality) { + notify('Failed to export locality.', 'error', 5) + return + } + exportOccurrenceMapKml('locality-species', [exportedLocality]) } - const kmlExport = (table: MRT_TableInstance) => { - exportOccurrenceMapKml(table, 'locality-occurrences', getExportLocalities) + const svgExport = async () => { + const exportedLocality = toMapExportLocality(editData) + if (!exportedLocality) { + notify('Failed to export locality.', 'error', 5) + return + } + await exportOccurrenceMapSvg('locality-species-map', [exportedLocality]) } const textField = (field: keyof EditDataType, options?: TextFieldOptions) => ( @@ -492,6 +503,7 @@ export const OccurrencesTab = () => { url="occurrence" getDetailPath={row => `/occurrence/${row.lid}/${row.species_id}`} kmlExport={kmlExport} + svgExport={svgExport} renderReadRowActions={({ row }) => ( <> diff --git a/frontend/src/components/Map/generateSvg.ts b/frontend/src/components/Map/generateSvg.ts index d716fc8c9..973e4dfb0 100644 --- a/frontend/src/components/Map/generateSvg.ts +++ b/frontend/src/components/Map/generateSvg.ts @@ -1,6 +1,6 @@ -import { LocalityCoord } from '@/shared/types' import { SVG } from '@svgdotjs/svg.js' import { countryPolygons } from '../../country_data/countryPolygons.ts' +import { MapExportLocality } from '../Species/localitySpeciesMapExport.ts' interface PixelCoordinates { x: number @@ -22,7 +22,7 @@ const webMercatorConvert = (lat: number, long: number, width: number): PixelCoor // Generates and returns an SVG image of localities on a map. export const generateSvg = ( - localityCoords: LocalityCoord[], + localities: MapExportLocality[], mapBorderColor = '#000000', mapFillColor = '#ffffff', markerBorderColor = '#ff0000', @@ -48,8 +48,8 @@ export const generateSvg = ( draw.polygon(polygon).stroke({ width: 1, color: mapBorderColor }).fill(mapFillColor) }) - localityCoords.forEach(coord => { - const pixelCoords = webMercatorConvert(coord.dec_lat, coord.dec_long, width) + localities.forEach(loc => { + const pixelCoords = webMercatorConvert(loc.dec_lat, loc.dec_long, width) const radius = 10 const topLeftX = pixelCoords.x - radius const topLeftY = pixelCoords.y - radius diff --git a/frontend/src/components/Species/Tabs/LocalitySpeciesTab.tsx b/frontend/src/components/Species/Tabs/LocalitySpeciesTab.tsx index ed2f93407..4da05a039 100755 --- a/frontend/src/components/Species/Tabs/LocalitySpeciesTab.tsx +++ b/frontend/src/components/Species/Tabs/LocalitySpeciesTab.tsx @@ -9,15 +9,17 @@ import { Editable, SpeciesDetailsType, SpeciesLocality } from '@/shared/types' import { calculateNormalizedMesowearScore } from '@/shared/utils/mesowear' import { matchesCountryOrContinent } from '@/shared/validators/countryContinents' import { Box, TextField } from '@mui/material' -import { MRT_ColumnDef, MRT_Row, MRT_RowData, MRT_TableInstance } from 'material-react-table' +import { MRT_ColumnDef, MRT_Row } from 'material-react-table' import { useMemo } from 'react' import { useForm } from 'react-hook-form' import { useLocation } from 'react-router-dom' import { exportOccurrenceMapKml, exportOccurrenceMapSvg, - getUniqueSpeciesLocalityMapExportLocalities, + MapExportLocality, + toMapExportLocality, } from '../localitySpeciesMapExport' +import { useNotify } from '@/hooks/notification' const hasMesowearScoreInputs = (row: SpeciesLocality) => { return ( @@ -37,6 +39,7 @@ export const LocalitySpeciesTab = () => { register, formState: { errors }, } = useForm() + const { notify } = useNotify() const sortedLocalitySpeciesRows = useMemo(() => { const sourceRows = (mode.read ? data.now_ls : editData.now_ls) as unknown as Editable[] @@ -203,21 +206,22 @@ export const LocalitySpeciesTab = () => { return Object.keys(errors).length === 0 } - const getExportLocalities = (table: MRT_TableInstance) => { - const rows = table.getPrePaginationRowModel().rows.map(row => row.original as unknown as SpeciesLocality) - return getUniqueSpeciesLocalityMapExportLocalities(data, rows) - } - - const kmlExport = (table: MRT_TableInstance) => { - exportOccurrenceMapKml(table, 'locality-species', getExportLocalities) + const kmlExport = () => { + const exportedLocalities = data.now_ls.map(loc => toMapExportLocality(loc)) + if (exportedLocalities.filter(loc => loc === null).length > 0) { + notify('Some localities failed to export, aborting.', 'error', 5) + return + } + exportOccurrenceMapKml('locality-species', exportedLocalities as MapExportLocality[]) } const svgExport = async () => { - const locsWithCoordinates = data.now_ls - .filter(ls => ls.now_loc !== undefined && ls.now_loc.dec_lat && ls.now_loc.dec_long) - .map(ls => ls.now_loc) - - await exportOccurrenceMapSvg('locality-species-map', locsWithCoordinates) + const exportedLocalities = data.now_ls.map(loc => toMapExportLocality(loc)) + if (exportedLocalities.filter(loc => loc === null).length > 0) { + notify('Some localities failed to export, aborting.', 'error', 5) + return + } + await exportOccurrenceMapSvg('locality-species-map', exportedLocalities as MapExportLocality[]) } const editingModal = ( diff --git a/frontend/src/components/Species/localitySpeciesMapExport.ts b/frontend/src/components/Species/localitySpeciesMapExport.ts index 1f1d34672..4c07cea71 100644 --- a/frontend/src/components/Species/localitySpeciesMapExport.ts +++ b/frontend/src/components/Species/localitySpeciesMapExport.ts @@ -1,14 +1,6 @@ import { currentDateAsString } from '@/shared/currentDateAsString' -import type { - CrossSearch, - Locality, - LocalityCoord, - LocalityDetailsType, - LocalitySpecies, - SpeciesLocality, -} from '@/shared/types' +import type { CrossSearch, Locality, LocalityDetailsType, LocalitySpecies, SpeciesLocality } from '@/shared/types' import { generateKml } from '@/util/kml' -import type { MRT_RowData, MRT_TableInstance } from 'material-react-table' type SpeciesSource = { species_id?: number | null @@ -174,17 +166,15 @@ const downloadTextFile = (dataString: string, type: string, filename: string) => a.href = url a.download = filename a.click() + a.remove() + URL.revokeObjectURL(url) } -export const exportOccurrenceMapKml = ( - table: MRT_TableInstance, - filenamePrefix: string, - getLocalities: (table: MRT_TableInstance) => MapExportLocality[] -) => { - downloadTextFile(generateKml(getLocalities(table)), 'text/kml', `${filenamePrefix}-${currentDateAsString()}.kml`) +export const exportOccurrenceMapKml = (filenamePrefix: string, localities: MapExportLocality[]) => { + downloadTextFile(generateKml(localities), 'text/kml', `${filenamePrefix}-${currentDateAsString()}.kml`) } -export const exportOccurrenceMapSvg = async (filenamePrefix: string, localities: LocalityCoord[]) => { +export const exportOccurrenceMapSvg = async (filenamePrefix: string, localities: MapExportLocality[]) => { const { generateSvg } = await import('@/components/Map/generateSvg') downloadTextFile(generateSvg(localities), 'image/svg+xml', `${filenamePrefix}-${currentDateAsString()}.svg`) } diff --git a/frontend/src/components/TableView/TableToolBar.tsx b/frontend/src/components/TableView/TableToolBar.tsx index e7050fd33..962bf3835 100644 --- a/frontend/src/components/TableView/TableToolBar.tsx +++ b/frontend/src/components/TableView/TableToolBar.tsx @@ -192,8 +192,6 @@ export const TableToolBar = ({ const runMapExport = async (label: string, exportFn: (table: MRT_TableInstance) => void | Promise) => { notify(`Preparing ${label} export...`, 'info', null) - const rowCount = table.getPrePaginationRowModel().rows.length - setNotificationMessage(`Generating ${label} export from ${rowCount} rows...`) await exportFn(table) setNotificationMessage(`Saving ${label} export...`) notify('Download finished.') diff --git a/frontend/src/shared/types/data.ts b/frontend/src/shared/types/data.ts index 775627939..18c99373f 100755 --- a/frontend/src/shared/types/data.ts +++ b/frontend/src/shared/types/data.ts @@ -810,8 +810,3 @@ export type SimplifiedLocality = { dec_long: number loc_name: string } - -export type LocalityCoord = { - dec_lat: number - dec_long: number -} diff --git a/frontend/src/util/kml.ts b/frontend/src/util/kml.ts index 32382a2fc..9cb32b0ab 100644 --- a/frontend/src/util/kml.ts +++ b/frontend/src/util/kml.ts @@ -1,3 +1,4 @@ +import { MapExportLocality } from '@/components/Species/localitySpeciesMapExport' import { Locality } from '@/shared/types' type KmlLocality = Locality & { @@ -78,7 +79,7 @@ const generatePlacemarkKml = (locality: KmlLocality) => { } // Returns an XML / KML string containing locality information as map markers, openable in Google Earth for example. -export const generateKml = (localities: KmlLocality[]) => { +export const generateKml = (localities: MapExportLocality[]) => { let kmlString = `\n` kmlString += ` Date: Fri, 20 Nov 2026 13:51:56 +0200 Subject: [PATCH 3/4] fix test --- frontend/src/tests/components/LocalitySpeciesTab.test.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/frontend/src/tests/components/LocalitySpeciesTab.test.tsx b/frontend/src/tests/components/LocalitySpeciesTab.test.tsx index 2f891142a..6155b1223 100644 --- a/frontend/src/tests/components/LocalitySpeciesTab.test.tsx +++ b/frontend/src/tests/components/LocalitySpeciesTab.test.tsx @@ -114,6 +114,7 @@ describe('LocalitySpeciesTab MW score prerequisites', () => { data: { now_ls: [] }, editData: { now_ls: [] }, mode: modeOptionToMode.edit, + notify: () => null, } as never) render() From 0643935690142f040738617e95f5f56edda92b14 Mon Sep 17 00:00:00 2001 From: juhanikat Date: Fri, 20 Nov 2026 14:05:02 +0200 Subject: [PATCH 4/4] fix test again --- .../components/LocalitySpeciesTab.test.tsx | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/frontend/src/tests/components/LocalitySpeciesTab.test.tsx b/frontend/src/tests/components/LocalitySpeciesTab.test.tsx index 6155b1223..6c32b9d5f 100644 --- a/frontend/src/tests/components/LocalitySpeciesTab.test.tsx +++ b/frontend/src/tests/components/LocalitySpeciesTab.test.tsx @@ -1,11 +1,12 @@ -import type { ReactNode } from 'react' -import { beforeEach, describe, expect, it, jest } from '@jest/globals' -import { render } from '@testing-library/react' -import { LocalitySpeciesTab } from '@/components/Species/Tabs/LocalitySpeciesTab' import { modeOptionToMode, useDetailContext } from '@/components/DetailView/Context/DetailContext' +import { NotificationContextProvider } from '@/components/Notification' +import { LocalitySpeciesTab } from '@/components/Species/Tabs/LocalitySpeciesTab' +import { occurrenceLabels } from '@/constants/occurrenceLabels' import type { SpeciesLocality } from '@/shared/types' +import { beforeEach, describe, expect, it, jest } from '@jest/globals' +import { render } from '@testing-library/react' import type { MRT_ColumnDef, MRT_Row } from 'material-react-table' -import { occurrenceLabels } from '@/constants/occurrenceLabels' +import type { ReactNode } from 'react' jest.mock('react-router-dom', () => { const actual = jest.requireActual('react-router-dom') @@ -75,7 +76,11 @@ describe('LocalitySpeciesTab MW score prerequisites', () => { }) it('passes MW scale/value columns and MW Score cell can read values from row data', () => { - render() + render( + + + + ) const firstCall = editableTableMock.mock.calls[0] expect(firstCall).toBeDefined() @@ -114,10 +119,13 @@ describe('LocalitySpeciesTab MW score prerequisites', () => { data: { now_ls: [] }, editData: { now_ls: [] }, mode: modeOptionToMode.edit, - notify: () => null, } as never) - render() + render( + + + + ) const grouped = document.querySelector('[data-testid="grouped"]')