Skip to content

Commit

Permalink
#282 Update config
Browse files Browse the repository at this point in the history
  • Loading branch information
nhumblot committed Sep 3, 2022
1 parent cae868c commit a76215c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/state/State.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export namespace SearchRequest {
}

export type CodeTriCentre = 'date' | 'distance';
export type DoseType = 'covid';
export type DoseType = 'covid' | 'monkeypox';

export type TypePlateforme = "Doctolib"|"Maiia"|"Ordoclic"|"Keldoc"|"Pandalab"|"Mapharma"|"AvecMonDoc"|"Clikodoc"|"mesoigner"|"Bimedoc"|"Valwin";
export type Plateforme = {
Expand Down Expand Up @@ -457,7 +457,7 @@ export class State {
const urlGenerator = await RemoteConfig.INSTANCE.urlGenerator();
const [principalLieuxDepartement, ...lieuxDepartementsAditionnels] = await Promise.all(
codesDepartements.map(codeDept => Promise.all([
fetch(urlGenerator.infosDepartement(codeDept), { cache: 'no-cache' })
fetch(urlGenerator.infosDepartement(codeDept, doseType), { cache: 'no-cache' })
.then(resp => resp.json())
.then((statsDept: LieuxParDepartement_JSON) => ({...statsDept, codeDepartement: codeDept} as LieuxParDepartement_JSON & {codeDepartement: string})),
fetch(urlGenerator.creneauxQuotidiensDepartement(codeDept, doseType), { cache: 'no-cache' })
Expand Down
18 changes: 15 additions & 3 deletions src/utils/LocalConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export type DataUrlGenerator = {
listDepartements: () => string,
statsByDate: () => string,
stats: () => string,
infosDepartement: (codeDepartement: string) => string,
infosDepartement: (codeDepartement: string, doseType: DoseType) => string,
creneauxQuotidiensDepartement: (codeDepartement: string, doseType: DoseType) => string,
};

Expand All @@ -13,13 +13,25 @@ export const GITLAB_DATA_URLS: DataUrlGenerator = {
statsByDate: () => `https://vitemadose.gitlab.io/vitemadose/stats_by_date.json`,
stats: () => `https://vitemadose.gitlab.io/vitemadose/stats.json`,
infosDepartement: (codeDepartement) => `https://vitemadose.gitlab.io/vitemadose/${codeDepartement}.json`,
creneauxQuotidiensDepartement: (codeDepartement) => `https://vitemadose.gitlab.io/vitemadose/${codeDepartement}/creneaux-quotidiens.json`
creneauxQuotidiensDepartement: (codeDepartement, doseType) => {
if (doseType == 'covid') {
return `https://vitemadose.gitlab.io/vitemadose/${codeDepartement}/creneaux-quotidiens.json`;
}

return `https://vitemadose.gitlab.io/vitemadose/monkeypox/${codeDepartement}/creneaux-quotidiens.json`;
}
}

export const GITHUB_DATA_URLS: DataUrlGenerator = {
listDepartements: () => `https://raw.githubusercontent.com/CovidTrackerFr/vitemadose/data-auto/data/output/departements.json`,
statsByDate: () => `https://raw.githubusercontent.com/CovidTrackerFr/vitemadose/data-auto/data/output/stats_by_date.json`,
stats: () => `https://raw.githubusercontent.com/CovidTrackerFr/vitemadose/data-auto/data/output/stats.json`,
infosDepartement: (codeDepartement) => `https://raw.githubusercontent.com/CovidTrackerFr/vitemadose/data-auto/data/output/${codeDepartement}.json`,
creneauxQuotidiensDepartement: (codeDepartement) => `https://raw.githubusercontent.com/CovidTrackerFr/vitemadose/data-auto/data/output/${codeDepartement}/creneaux-quotidiens.json`
creneauxQuotidiensDepartement: (codeDepartement,doseType) => {
if (doseType == 'covid') {
return `https://raw.githubusercontent.com/CovidTrackerFr/vitemadose/data-auto/data/output/${codeDepartement}/creneaux-quotidiens.json`
}

return `https://raw.githubusercontent.com/CovidTrackerFr/vitemadose/data-auto/data/output/monkeypox/${codeDepartement}/creneaux-quotidiens.json`
}
}
21 changes: 18 additions & 3 deletions src/utils/RemoteConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type RemoteConfigEntries = {
"data_disclaimer_severity": string,
"path_contributors": string,
"path_data_department": string,
"path_monkeypox_data_department": string,
"path_list_departments": string,
"path_stats": string,
"url_base": string,
Expand All @@ -22,6 +23,7 @@ const REMOTE_CONFIG_ENTRIES_FALLBACK: RemoteConfigEntries = {
"data_disclaimer_severity": "warning",
"path_contributors": "/vitemadose/contributors_all.json",
"path_data_department": "/vitemadose/{code}.json",
"path_monkeypox_data_department": "/vitemadose/monkeypox/{code}.json",
"path_list_departments": "/vitemadose/departements.json",
"path_stats": "/vitemadose/stats.json",
"url_base": "https://vitemadose.gitlab.io",
Expand Down Expand Up @@ -68,7 +70,13 @@ export class RemoteConfig {
statsByDate: () => `/offline/stats_by_date.json`,
stats: () => `/offline/stats.json`,
infosDepartement: (codeDepartement) => `/offline/${codeDepartement}.json`,
creneauxQuotidiensDepartement: (codeDepartement) => `/offline/${codeDepartement}/creneaux-quotidiens.json`
creneauxQuotidiensDepartement: (codeDepartement, doseType) => {
if (doseType == 'covid') {
return `/offline/${codeDepartement}/creneaux-quotidiens.json`;
}

return `/offline/monkeypox/${codeDepartement}/creneaux-quotidiens.json`
}
};
this.configurationSyncedPromise = Promise.resolve();

Expand Down Expand Up @@ -105,12 +113,19 @@ export class RemoteConfig {
const statsByDatePath = `/vitemadose/stats_by_date.json`;
const departementsListPath = this.configuration.path_list_departments || `/vitemadose/departements.json`;
const infosDepartementPath = this.configuration.path_data_department || `/vitemadose/{code}.json`;
const monkeypoxDepartmentDataPath = this.configuration.path_monkeypox_data_department || REMOTE_CONFIG_ENTRIES_FALLBACK.path_monkeypox_data_department;
this._urlGenerator = {
listDepartements: () => `${urlBase}${departementsListPath}`,
statsByDate: () => `${urlBase}${statsByDatePath}`,
stats: () => `${urlBase}${statsPath}`,
infosDepartement: (codeDepartement) => `${urlBase}${infosDepartementPath.replace('{code}', codeDepartement)}`,
creneauxQuotidiensDepartement: (codeDepartement) => `${urlBase}/vitemadose/${codeDepartement}/creneaux-quotidiens.json`
infosDepartement: (codeDepartement, doseType) => doseType === 'monkeypox' ? `${urlBase}${monkeypoxDepartmentDataPath.replace('{code}', codeDepartement)}` : `${urlBase}${infosDepartementPath.replace('{code}', codeDepartement)}`,
creneauxQuotidiensDepartement: (codeDepartement, doseType) => {
if (doseType == 'covid') {
return `${urlBase}/vitemadose/${codeDepartement}/creneaux-quotidiens.json`;
}

return `${urlBase}/vitemadose/monkeypox/${codeDepartement}/creneaux-quotidiens.json`;
}
};
} else if(USE_GITLAB_AS_FALLBACK) {
this._urlGenerator = GITLAB_DATA_URLS;
Expand Down

0 comments on commit a76215c

Please sign in to comment.