From a31eb552dfb32ddcda19b7aa918bd88faa6819f4 Mon Sep 17 00:00:00 2001 From: Dinuka De Silva Date: Fri, 17 Jul 2020 18:18:29 +0530 Subject: [PATCH 1/2] gh-664: Fixed the pagination environment variables --- results-tabulation-ui/.env | 5 ++++ results-tabulation-ui/src/config.js | 42 +++++++++++++++++++++++++---- 2 files changed, 42 insertions(+), 5 deletions(-) create mode 100644 results-tabulation-ui/.env diff --git a/results-tabulation-ui/.env b/results-tabulation-ui/.env new file mode 100644 index 00000000..77aac1c8 --- /dev/null +++ b/results-tabulation-ui/.env @@ -0,0 +1,5 @@ +REACT_APP_AUTH_APP_URL='http://localhost:3001' +REACT_APP_TABULATION_API_URL='http://localhost:5000' +REACT_APP_DEBUG=false +REACT_APP_TABULATION_API_PAGINATION_LIMIT=3 +REACT_APP_USE_PDF_SERVICE=false diff --git a/results-tabulation-ui/src/config.js b/results-tabulation-ui/src/config.js index ed0476a3..36adf44a 100644 --- a/results-tabulation-ui/src/config.js +++ b/results-tabulation-ui/src/config.js @@ -13,13 +13,45 @@ if (process.env.REACT_APP_TABULATION_API_URL) { } if (process.env.REACT_APP_DEBUG) { - DEBUG = process.env.REACT_APP_DEBUG; + DEBUG = getBooleanEnvVar(process.env.REACT_APP_DEBUG, DEBUG); } -if (process.env.TABULATION_API_PAGINATION_LIMIT) { - TABULATION_API_PAGINATION_LIMIT = process.env.TABULATION_API_PAGINATION_LIMIT; +if (process.env.REACT_APP_TABULATION_API_PAGINATION_LIMIT) { + TABULATION_API_PAGINATION_LIMIT = getIntEnvVar(process.env.REACT_APP_TABULATION_API_PAGINATION_LIMIT, TABULATION_API_PAGINATION_LIMIT); } -if (process.env.USE_PDF_SERVICE) { - USE_PDF_SERVICE = process.env.USE_PDF_SERVICE; +if (process.env.REACT_APP_USE_PDF_SERVICE) { + USE_PDF_SERVICE = getBooleanEnvVar(process.env.REACT_APP_USE_PDF_SERVICE, USE_PDF_SERVICE); +} + +function getBooleanEnvVar(envVar, defaultValue) { + if (envVar) { + envVar = envVar.toLowerCase(); + if (envVar === "true") { + envVar = true; + } else if (envVar === "false") { + envVar = false; + } else { + envVar = defaultValue; + } + } else { + envVar = defaultValue; + } + + return envVar; +} + + +function getIntEnvVar(envVar, defaultValue) { + if (envVar) { + try { + envVar = parseInt(envVar); + } catch (e) { + envVar = defaultValue; + } + } else { + envVar = defaultValue; + } + + return envVar; } From 967a01afeb2ba967064798c5e5ee67e47c956e35 Mon Sep 17 00:00:00 2001 From: Dinuka De Silva Date: Fri, 17 Jul 2020 18:19:53 +0530 Subject: [PATCH 2/2] gh-664: Update the docker files with the environment variables --- results-tabulation-ui/Dockerfile | 3 ++- results-tabulation-ui/Stage.Dockerfile | 4 +++- results-tabulation-ui/Staging.Dockerfile | 4 +++- results-tabulation-ui/prod.Dockerfile | 4 +++- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/results-tabulation-ui/Dockerfile b/results-tabulation-ui/Dockerfile index 7732aa30..d5ddbe80 100644 --- a/results-tabulation-ui/Dockerfile +++ b/results-tabulation-ui/Dockerfile @@ -9,7 +9,8 @@ RUN npm install ENV REACT_APP_AUTH_APP_URL="https://tabulations.ecdev.opensource.lk" ENV REACT_APP_TABULATION_API_URL="https://apim-gateway.ecdev.opensource.lk/tabulation/0.1.0" ENV REACT_APP_DEBUG=true -ENV TABULATION_API_PAGINATION_LIMIT=250 +ENV REACT_APP_TABULATION_API_PAGINATION_LIMIT=250 +ENV REACT_APP_USE_PDF_SERVICE=true RUN npm run build diff --git a/results-tabulation-ui/Stage.Dockerfile b/results-tabulation-ui/Stage.Dockerfile index 0b18868d..833d891b 100644 --- a/results-tabulation-ui/Stage.Dockerfile +++ b/results-tabulation-ui/Stage.Dockerfile @@ -8,7 +8,9 @@ RUN npm install ENV REACT_APP_AUTH_APP_URL="https://tabulations.ecstage.opensource.lk" ENV REACT_APP_TABULATION_API_URL="https://apim-gw.ecstage.opensource.lk/tabulation/0.1.0" -ENV TABULATION_API_PAGINATION_LIMIT=250 +ENV REACT_APP_DEBUG=false +ENV REACT_APP_TABULATION_API_PAGINATION_LIMIT=250 +ENV REACT_APP_USE_PDF_SERVICE=true RUN npm run build diff --git a/results-tabulation-ui/Staging.Dockerfile b/results-tabulation-ui/Staging.Dockerfile index 74316812..ac890db6 100644 --- a/results-tabulation-ui/Staging.Dockerfile +++ b/results-tabulation-ui/Staging.Dockerfile @@ -8,7 +8,9 @@ RUN npm install ENV REACT_APP_AUTH_APP_URL="https://tabulations.ecstag.opensource.lk" ENV REACT_APP_TABULATION_API_URL="https://apim-gw.ecstag.opensource.lk/tabulation/0.1.0" -ENV TABULATION_API_PAGINATION_LIMIT=250 +ENV REACT_APP_DEBUG=false +ENV REACT_APP_TABULATION_API_PAGINATION_LIMIT=250 +ENV REACT_APP_USE_PDF_SERVICE=true RUN npm run build diff --git a/results-tabulation-ui/prod.Dockerfile b/results-tabulation-ui/prod.Dockerfile index 4374b465..6d514c05 100644 --- a/results-tabulation-ui/prod.Dockerfile +++ b/results-tabulation-ui/prod.Dockerfile @@ -8,7 +8,9 @@ RUN npm install ENV REACT_APP_AUTH_APP_URL="https://tabulations-lgc.elections.gov.lk" ENV REACT_APP_TABULATION_API_URL="https://apim-gw-lgc.elections.gov.lk/tabulation/0.1.0" -ENV TABULATION_API_PAGINATION_LIMIT=250 +ENV REACT_APP_DEBUG=false +ENV REACT_APP_TABULATION_API_PAGINATION_LIMIT=250 +ENV REACT_APP_USE_PDF_SERVICE=true RUN npm run build