refactor(migration): simplify CSV service data structures

Remove labels from service structs and move them to the component.
The service now exports simple arrays of values, while the component
handles translation through mapping functions.
This commit is contained in:
Claude
2025-12-07 22:15:40 +00:00
parent 274cce7cd1
commit 316d2645d1
3 changed files with 64 additions and 38 deletions

View File

@@ -582,7 +582,13 @@
"import": "Import Tasks",
"untitled": "Untitled Task",
"completed": "Completed",
"ignore": "Ignore"
"ignore": "Ignore",
"delimiters": {
"comma": "Comma (,)",
"semicolon": "Semicolon (;)",
"tab": "Tab",
"pipe": "Pipe (|)"
}
}
},
"label": {

View File

@@ -19,18 +19,18 @@ export type TaskAttribute =
| 'reminder'
| 'ignore'
export const TASK_ATTRIBUTES: { value: TaskAttribute; label: string }[] = [
{ value: 'title', label: 'Title' },
{ value: 'description', label: 'Description' },
{ value: 'due_date', label: 'Due Date' },
{ value: 'start_date', label: 'Start Date' },
{ value: 'end_date', label: 'End Date' },
{ value: 'done', label: 'Done/Completed' },
{ value: 'priority', label: 'Priority' },
{ value: 'labels', label: 'Labels/Tags' },
{ value: 'project', label: 'Project' },
{ value: 'reminder', label: 'Reminder' },
{ value: 'ignore', label: 'Ignore' },
export const TASK_ATTRIBUTES: TaskAttribute[] = [
'title',
'description',
'due_date',
'start_date',
'end_date',
'done',
'priority',
'labels',
'project',
'reminder',
'ignore',
]
export interface DetectionResult {
@@ -73,24 +73,19 @@ export interface MigrationStatus {
finished_at: string | null
}
export const SUPPORTED_DELIMITERS = [
{ value: ',', label: 'Comma (,)' },
{ value: ';', label: 'Semicolon (;)' },
{ value: '\t', label: 'Tab' },
{ value: '|', label: 'Pipe (|)' },
]
export const SUPPORTED_DELIMITERS = [',', ';', '\t', '|'] as const
export const SUPPORTED_DATE_FORMATS = [
{ value: '2006-01-02', label: 'YYYY-MM-DD (2024-01-15)' },
{ value: '2006-01-02T15:04:05', label: 'ISO DateTime (2024-01-15T10:30:00)' },
{ value: '02/01/2006', label: 'DD/MM/YYYY (15/01/2024)' },
{ value: '01/02/2006', label: 'MM/DD/YYYY (01/15/2024)' },
{ value: '02-01-2006', label: 'DD-MM-YYYY (15-01-2024)' },
{ value: '01-02-2006', label: 'MM-DD-YYYY (01-15-2024)' },
{ value: '02.01.2006', label: 'DD.MM.YYYY (15.01.2024)' },
{ value: '2006/01/02', label: 'YYYY/MM/DD (2024/01/15)' },
{ value: '2006-01-02 15:04:05', label: 'DateTime (2024-01-15 10:30:00)' },
]
'2006-01-02',
'2006-01-02T15:04:05',
'02/01/2006',
'01/02/2006',
'02-01-2006',
'01-02-2006',
'02.01.2006',
'2006/01/02',
'2006-01-02 15:04:05',
] as const
export default class CSVMigrationService extends AbstractService {
constructor() {

View File

@@ -55,10 +55,10 @@
>
<option
v-for="delim in SUPPORTED_DELIMITERS"
:key="delim.value"
:value="delim.value"
:key="delim"
:value="delim"
>
{{ delim.label }}
{{ getDelimiterLabel(delim) }}
</option>
</select>
</div>
@@ -71,10 +71,10 @@
>
<option
v-for="format in SUPPORTED_DATE_FORMATS"
:key="format.value"
:value="format.value"
:key="format"
:value="format"
>
{{ format.label }}
{{ getDateFormatLabel(format) }}
</option>
</select>
</div>
@@ -105,10 +105,10 @@
>
<option
v-for="attr in TASK_ATTRIBUTES"
:key="attr.value"
:value="attr.value"
:key="attr"
:value="attr"
>
{{ getAttributeLabel(attr.value) }}
{{ getAttributeLabel(attr) }}
</option>
</select>
</div>
@@ -269,6 +269,31 @@ function getAttributeLabel(attribute: string): string {
return t(attributeMap[attribute] || attribute)
}
function getDelimiterLabel(delimiter: string): string {
const labels: Record<string, string> = {
',': t('migrate.csv.delimiters.comma'),
';': t('migrate.csv.delimiters.semicolon'),
'\t': t('migrate.csv.delimiters.tab'),
'|': t('migrate.csv.delimiters.pipe'),
}
return labels[delimiter] || delimiter
}
function getDateFormatLabel(format: string): string {
const labels: Record<string, string> = {
'2006-01-02': 'YYYY-MM-DD (2024-01-15)',
'2006-01-02T15:04:05': 'ISO DateTime (2024-01-15T10:30:00)',
'02/01/2006': 'DD/MM/YYYY (15/01/2024)',
'01/02/2006': 'MM/DD/YYYY (01/15/2024)',
'02-01-2006': 'DD-MM-YYYY (15-01-2024)',
'01-02-2006': 'MM-DD-YYYY (01-15-2024)',
'02.01.2006': 'DD.MM.YYYY (15.01.2024)',
'2006/01/02': 'YYYY/MM/DD (2024/01/15)',
'2006-01-02 15:04:05': 'DateTime (2024-01-15 10:30:00)',
}
return labels[format] || format
}
function truncate(text: string, length: number): string {
if (text.length <= length) return text
return text.substring(0, length) + '...'