mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-30 00:20:07 +00:00
fix(ci): the file import's words resolve through t, the unused key count drops
The KML skip reasons and the file errors were looked up from plain maps, which lint:i18n-keys cannot follow, so the new map keys counted as unused. Both are switches over t() now; the older file error keys are reached as well, so collection.ts holds 29 unused keys instead of 35.
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
"budget.ts": 35,
|
||||
"categories.ts": 1,
|
||||
"collab.ts": 9,
|
||||
"collection.ts": 35,
|
||||
"collection.ts": 29,
|
||||
"common.ts": 7,
|
||||
"dashboard.ts": 64,
|
||||
"dawarich.ts": 15,
|
||||
|
||||
@@ -35,14 +35,22 @@ interface ImportCollectionModalProps {
|
||||
t: TranslationFn
|
||||
}
|
||||
|
||||
/** Keyed by the error type, so a new way for a file to fail does not build without its words. */
|
||||
const ERROR_KEYS: Record<CollectionFileError, string> = {
|
||||
'too-large': 'collections.file.errorTooLarge',
|
||||
unreadable: 'collections.file.errorUnreadable',
|
||||
'not-a-collection': 'collections.file.errorNotACollection',
|
||||
'not-gpx': 'collections.file.errorNotGpx',
|
||||
'not-map': 'collections.file.errorNotMap',
|
||||
'too-many-places': 'collections.file.errorTooManyPlaces',
|
||||
/** The words for each way a file can fail; a switch, so a new way does not build without its words. */
|
||||
function errorText(error: CollectionFileError, t: TranslationFn, count: number): string {
|
||||
switch (error) {
|
||||
case 'too-large':
|
||||
return t('collections.file.errorTooLarge')
|
||||
case 'unreadable':
|
||||
return t('collections.file.errorUnreadable')
|
||||
case 'not-a-collection':
|
||||
return t('collections.file.errorNotACollection')
|
||||
case 'not-gpx':
|
||||
return t('collections.file.errorNotGpx')
|
||||
case 'not-map':
|
||||
return t('collections.file.errorNotMap')
|
||||
case 'too-many-places':
|
||||
return t('collections.file.errorTooManyPlaces', { count })
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -270,7 +278,7 @@ export default function ImportCollectionModal({
|
||||
|
||||
const errorText = error === 'failed'
|
||||
? (failedMessage ?? t('common.error'))
|
||||
: error ? t(ERROR_KEYS[error], { count: MAX_COLLECTION_FILE_PLACES }) : null
|
||||
: error ? errorText(error, t, MAX_COLLECTION_FILE_PLACES) : null
|
||||
|
||||
// A GPX of nothing but a track would make an empty list, which is never what was meant.
|
||||
const nothingToImport = (!!leftovers || !!map) && !!file && (map ? picked.size === 0 : file.places.length === 0)
|
||||
|
||||
@@ -4,11 +4,17 @@ import React, { useState } from 'react';
|
||||
import type { TranslationFn } from '../../types';
|
||||
import { fs } from '../shared/DialogShell';
|
||||
|
||||
const SKIP_KEYS: Record<CollectionMapSkipReason, string> = {
|
||||
line: 'collections.file.mapSkipLine',
|
||||
no_point: 'collections.file.mapSkipNoPoint',
|
||||
invalid: 'collections.file.mapSkipInvalid',
|
||||
};
|
||||
/** Why a placemark was left out, in words; a switch, so a new reason does not build without them. */
|
||||
function skipText(reason: CollectionMapSkipReason, t: TranslationFn): string {
|
||||
switch (reason) {
|
||||
case 'line':
|
||||
return t('collections.file.mapSkipLine');
|
||||
case 'no_point':
|
||||
return t('collections.file.mapSkipNoPoint');
|
||||
case 'invalid':
|
||||
return t('collections.file.mapSkipInvalid');
|
||||
}
|
||||
}
|
||||
|
||||
/** What a list file holds for a place; the file schema leaves its places to the server to check. */
|
||||
type MapPlace = { name?: string; address?: string | null };
|
||||
@@ -112,7 +118,7 @@ export default function MapImportPreview({
|
||||
<ul className="m-0 flex list-none flex-col gap-0.5 ps-5">
|
||||
{map.skipped.map((entry, i) => (
|
||||
<li key={i} className="text-content-faint" style={fs(11.5)}>
|
||||
{entry.name || t('collections.file.mapUnnamed')}: {t(SKIP_KEYS[entry.reason])}
|
||||
{entry.name || t('collections.file.mapUnnamed')}: {skipText(entry.reason, t)}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
|
||||
Reference in New Issue
Block a user