Csv import tweaks (#1920)

* Don't use special label for tags column

This was setting the label of whichever column the user chose for tags
to "Tags". Showing field content is more helpful.

* Map tags column automatically like fields
This commit is contained in:
RumovZ 2022-06-22 01:44:12 +02:00 committed by GitHub
parent 3eb8a6ce9d
commit 1b8bab73d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 4 deletions

View File

@ -57,6 +57,7 @@ impl Collection {
maybe_set_fallback_columns(&mut metadata)?;
self.maybe_set_fallback_notetype(&mut metadata, notetype_id)?;
self.maybe_init_notetype_map(&mut metadata)?;
maybe_set_tags_column(&mut metadata);
self.maybe_set_fallback_deck(&mut metadata)?;
Ok(metadata)
@ -377,6 +378,17 @@ fn maybe_set_fallback_delimiter(
Ok(())
}
fn maybe_set_tags_column(metadata: &mut CsvMetadata) {
if metadata.tags_column == 0 {
if let Some(CsvNotetype::GlobalNotetype(ref global)) = metadata.notetype {
let max_field = global.field_columns.iter().max().copied().unwrap_or(0);
if max_field < metadata.column_labels.len() as u32 {
metadata.tags_column = max_field + 1;
}
}
}
}
fn delimiter_from_value(value: &str) -> Option<Delimiter> {
let normed = value.to_ascii_lowercase();
for delimiter in Delimiter::iter() {

View File

@ -56,7 +56,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
preview[0].vals,
notetypeColumn,
deckColumn,
tagsColumn,
guidColumn,
);
$: getCsvMetadata(path, delimiter, undefined, isHtml).then((meta) => {
@ -68,6 +67,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
lastDelimeter = delimiter;
getCsvMetadata(path, delimiter, globalNotetype?.id).then((meta) => {
globalNotetype = meta.globalNotetype ?? null;
tagsColumn = meta.tagsColumn;
});
}

View File

@ -21,7 +21,6 @@ export function getColumnOptions(
firstRow: string[],
notetypeColumn: number | null,
deckColumn: number | null,
tagsColumn: number,
guidColumn: number,
): ColumnOption[] {
return [{ label: tr.changeNotetypeNothing(), value: 0, disabled: false }].concat(
@ -33,8 +32,6 @@ export function getColumnOptions(
return columnOption(tr.decksDeck(), true, index);
} else if (index === guidColumn) {
return columnOption("GUID", true, index);
} else if (index === tagsColumn) {
return columnOption(tr.editingTags(), false, index);
} else if (label === "") {
return columnOption(firstRow[index - 1], false, index, true);
} else {