Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add multiple source fields #223

Merged
merged 4 commits into from
Sep 8, 2024

Conversation

pedromml
Copy link

This PR implements multiple source fields.
To use them, a user first has to write something in any of the inputs in the first "Source" field, then go to Add field -> Source 2. If something is written in any "Source 2" input, the user will be able to add "Source 3", and so on up to "Source 4".
The first source field will still be mapped to source=* / source:name=* , while the next source fields will be mapped to source:2=* / source:2:name=*
image
image

@pedromml pedromml linked an issue Aug 22, 2024 that may be closed by this pull request
modules/presets/index.js Outdated Show resolved Hide resolved
modules/presets/index.js Outdated Show resolved Hide resolved
modules/ui/field.js Outdated Show resolved Hide resolved
data/core.yaml Outdated Show resolved Hide resolved
modules/presets/index.js Outdated Show resolved Hide resolved
modules/ui/sections/preset_fields.js Outdated Show resolved Hide resolved
Copy link
Member

@1ec5 1ec5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good to go as soon as the localization issues are resolved. Thanks!

keys: ['source' + id, 'source' + id + ':url', 'source' + id + ':name', 'source' + id + ':date'],
key: id,
keys: [id, id + ':url', id + ':name', id + ':date'],
overrideLabel: 'Source ' + i,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still needs to be localized. You can define a format string in the localization and pass in the number as a parameter to replace the token in the format string:

iD/data/core.yaml

Lines 766 to 767 in cb779ea

# format for the label of a feature that has a name and date range
dated: "{name} [{dateRange}]"
import { t, localizer } from '../core/localizer';
return dateRange ? t('inspector.display_name.dated', {dateRange: dateRange, name: name}) : name;

/ref #224

Comment on lines 65 to 66
let id = 'source' + (i > 0 ? ':' + i.toString() : '');
let previousId = 'source' + ((i-1) > 0 ? ':' + (i-1).toString() : '');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: String.prototype.toString() is suitable for Western languages, but not for some other languages we support, like Persian. Number.prototype.toLocaleString automatically adapts the number to the given writing system. Fortunately, you can just pass a number into the t function and it’ll do the right thing.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This String.prototype.toString() is being used to define the source:2 key. If the "2" is localized, couldn't that cause problems? With the key ending up like source:٢

Copy link
Member

@1ec5 1ec5 Aug 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, you’re right, you’re only appending i to “Source” below. So as long as you pass i into the t() call for that field name, it should work fine.

modules/presets/field.js Outdated Show resolved Hide resolved
modules/presets/field.js Outdated Show resolved Hide resolved
modules/presets/field.js Outdated Show resolved Hide resolved
Copy link
Member

@1ec5 1ec5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks good!

@1ec5 1ec5 merged commit b101364 into OpenHistoricalMap:staging Sep 8, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add UI to edit multiple unrelated sources
2 participants