-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Introduce the hash URL param presetUrlOverwrite
#9475
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,5 +1,6 @@ | ||||||||||||||||||||||||||
import parseVersion from 'vparse'; | ||||||||||||||||||||||||||
import { presetsCdnUrl, ociCdnUrl, wmfSitematrixCdnUrl } from '../../config/id.js'; | ||||||||||||||||||||||||||
import { presetsCdnUrlTemplate, ociCdnUrlTemplate, wmfSitematrixCdnUrlTemplate } from '../../config/id.js'; | ||||||||||||||||||||||||||
import { utilStringQs } from '../util'; | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
import packageJSON from '../../package.json'; | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
|
@@ -11,10 +12,21 @@ export { _mainFileFetcher as fileFetcher }; | |||||||||||||||||||||||||
// coreFileFetcher asynchronously fetches data from JSON files | ||||||||||||||||||||||||||
// | ||||||||||||||||||||||||||
export function coreFileFetcher() { | ||||||||||||||||||||||||||
const presetsVersion = packageJSON.devDependencies['@openstreetmap/id-tagging-schema']; | ||||||||||||||||||||||||||
let presetsCdnUrl = presetsCdnUrlTemplate.replace('{presets_version}', presetsVersion); | ||||||||||||||||||||||||||
// Allow to overwrite the preset source to enable testing PRs for the id-editor-presets repo. | ||||||||||||||||||||||||||
const presetUrlOverwrite = utilStringQs(window.location.hash)?.presetUrlOverwrote; | ||||||||||||||||||||||||||
if (presetUrlOverwrite) { | ||||||||||||||||||||||||||
presetsCdnUrl = presetUrlOverwrite; | ||||||||||||||||||||||||||
console.info('`presetUrlOverwrite` applied. Presets are fetched from', presetsCdnUrl); | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
Comment on lines
+16
to
+22
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
const ociVersion = packageJSON.dependencies['osm-community-index'] || packageJSON.devDependencies['osm-community-index']; | ||||||||||||||||||||||||||
const v = parseVersion(ociVersion); | ||||||||||||||||||||||||||
const ociVersionMinor = `${v.major}.${v.minor}`; | ||||||||||||||||||||||||||
const presetsVersion = packageJSON.devDependencies['@openstreetmap/id-tagging-schema']; | ||||||||||||||||||||||||||
const ociCdnUrl = ociCdnUrlTemplate.replace('{version}', ociVersionMinor); | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
const wmfSitematrixCdnUrl = wmfSitematrixCdnUrlTemplate.replace('{version}', '0.1'); | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
let _this = {}; | ||||||||||||||||||||||||||
let _inflight = {}; | ||||||||||||||||||||||||||
|
@@ -29,24 +41,23 @@ export function coreFileFetcher() { | |||||||||||||||||||||||||
'qa_data': 'data/qa_data.min.json', | ||||||||||||||||||||||||||
'shortcuts': 'data/shortcuts.min.json', | ||||||||||||||||||||||||||
'territory_languages': 'data/territory_languages.min.json', | ||||||||||||||||||||||||||
'oci_defaults': ociCdnUrl.replace('{version}', ociVersionMinor) + 'dist/defaults.min.json', | ||||||||||||||||||||||||||
'oci_features': ociCdnUrl.replace('{version}', ociVersionMinor) + 'dist/featureCollection.min.json', | ||||||||||||||||||||||||||
'oci_resources': ociCdnUrl.replace('{version}', ociVersionMinor) + 'dist/resources.min.json', | ||||||||||||||||||||||||||
'presets_package': presetsCdnUrl.replace('{presets_version}', presetsVersion) + 'package.json', | ||||||||||||||||||||||||||
'oci_defaults': ociCdnUrl + 'dist/defaults.min.json', | ||||||||||||||||||||||||||
'oci_features': ociCdnUrl + 'dist/featureCollection.min.json', | ||||||||||||||||||||||||||
'oci_resources': ociCdnUrl + 'dist/resources.min.json', | ||||||||||||||||||||||||||
'presets_package': presetsCdnUrl + 'package.json', | ||||||||||||||||||||||||||
'deprecated': presetsCdnUrl + 'dist/deprecated.min.json', | ||||||||||||||||||||||||||
'discarded': presetsCdnUrl + 'dist/discarded.min.json', | ||||||||||||||||||||||||||
'preset_categories': presetsCdnUrl + 'dist/preset_categories.min.json', | ||||||||||||||||||||||||||
'preset_defaults': presetsCdnUrl + 'dist/preset_defaults.min.json', | ||||||||||||||||||||||||||
'preset_fields': presetsCdnUrl + 'dist/fields.min.json', | ||||||||||||||||||||||||||
'preset_presets': presetsCdnUrl + 'dist/presets.min.json', | ||||||||||||||||||||||||||
Comment on lines
48
to
53
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These files (except There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For example:
Suggested change
|
||||||||||||||||||||||||||
'wmf_sitematrix': wmfSitematrixCdnUrl.replace('{version}', '0.1') + 'wikipedia.min.json' | ||||||||||||||||||||||||||
'wmf_sitematrix': wmfSitematrixCdnUrl + 'wikipedia.min.json' | ||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
let _cachedData = {}; | ||||||||||||||||||||||||||
// expose the cache; useful for tests | ||||||||||||||||||||||||||
_this.cache = () => _cachedData; | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
// Returns a Promise to fetch data | ||||||||||||||||||||||||||
// (resolved with the data if we have it already) | ||||||||||||||||||||||||||
_this.get = (which) => { | ||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,8 @@ import { fileFetcher } from './file_fetcher'; | |
import { utilDetect } from '../util/detect'; | ||
import { utilStringQs } from '../util'; | ||
import { utilArrayUniq } from '../util/array'; | ||
import { presetsCdnUrl } from '../../config/id.js'; | ||
import { presetsCdnUrlTemplate } from '../../config/id.js'; | ||
import packageJSON from '../../package.json'; | ||
|
||
let _mainLocalizer = coreLocalizer(); // singleton | ||
let _t = _mainLocalizer.t; | ||
|
@@ -88,6 +89,8 @@ export function coreLocalizer() { | |
'locales' // load the list of supported locales | ||
]; | ||
|
||
const presetsVersion = packageJSON.devDependencies['@openstreetmap/id-tagging-schema']; | ||
const presetsCdnUrl = presetsCdnUrlTemplate.replace('{presets_version}', presetsVersion); | ||
Comment on lines
+92
to
+93
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. actually… this was working as intended:
To avoid this, the fileFetcher does first load the preset's -- The url template can be passed to the fileFetcher: const localeDirs = {
general: 'locales',
tagging: presetsCdnUrlTemplate + 'dist/translations'
}; There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tyrasd even thought this PR is closed, I think your feedback and the fact that I was not able to read those details from the variable names hints that the variable names could be improved. The name itself you communicate if its a "template" – as in, something of the string will need to be replaced in order to work – or a URL that will be used as is. This might be something to refactor at some point… |
||
const localeDirs = { | ||
general: 'locales', | ||
tagging: presetsCdnUrl + 'dist/translations' | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.