Skip to content

Commit

Permalink
Merge pull request #707 from dinukadesilva/gh-664-fix-pagination-env
Browse files Browse the repository at this point in the history
gh-664: fix pagination env
  • Loading branch information
dinukadesilva authored Jul 17, 2020
2 parents ce80df3 + 967a01a commit 88c301e
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 9 deletions.
5 changes: 5 additions & 0 deletions results-tabulation-ui/.env
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion results-tabulation-ui/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion results-tabulation-ui/Stage.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion results-tabulation-ui/Staging.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion results-tabulation-ui/prod.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
42 changes: 37 additions & 5 deletions results-tabulation-ui/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 88c301e

Please sign in to comment.