From 47aba591557d530d0bc3b7f87cc3decc361febd0 Mon Sep 17 00:00:00 2001 From: Nabilah Adani Date: Sun, 14 Mar 2021 15:33:08 +0700 Subject: [PATCH 01/51] [CHORES] menambahkan button export pdf untuk data terfilter --- .../Home/components/Statistic/index.tsx | 80 ++++++++++++++----- 1 file changed, 62 insertions(+), 18 deletions(-) diff --git a/src/scenes/Home/components/Statistic/index.tsx b/src/scenes/Home/components/Statistic/index.tsx index e416b69..234d672 100644 --- a/src/scenes/Home/components/Statistic/index.tsx +++ b/src/scenes/Home/components/Statistic/index.tsx @@ -60,6 +60,8 @@ function Statistic({ } }; + const filterExportsPDF = async (filterType: StatisticType) => {} + const getDropdownValue = (statType: StatisticType) => { switch (statType) { case StatisticType.District: @@ -208,19 +210,40 @@ function Statistic({ {`${type}: ${ageKey.minAge} s/d ${ageKey.maxAge} tahun`} + - + + + - Export CSV - + + @@ -239,19 +262,40 @@ function Statistic({ {`${type}: ${translate(selectedKey)}`} + - + + + - Export CSV - + + -- GitLab From c8ec8a70fd9dd9c5e923aead40b1cfad9f20f83e Mon Sep 17 00:00:00 2001 From: Sean Zeliq Urian Date: Sun, 14 Mar 2021 16:15:42 +0700 Subject: [PATCH 02/51] [RED] Creating test for image2pdf function. --- src/scenes/Home/utilities/utils.test.tsx | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 src/scenes/Home/utilities/utils.test.tsx diff --git a/src/scenes/Home/utilities/utils.test.tsx b/src/scenes/Home/utilities/utils.test.tsx new file mode 100644 index 0000000..c5c94fb --- /dev/null +++ b/src/scenes/Home/utilities/utils.test.tsx @@ -0,0 +1,7 @@ +import { image2pdf } from './utils'; + +test('image2pdf return value is defined', () => { + const dummyImage = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASoAAAEsCAYAAAB0Y/4yAAAABHNCSVQICAgIfAhkiAAAEmpJREFUeJzt3XuspVV5x/HvSyaTCUFC6YQaQglFpYiIOiWUWmu80VpKrdqpcvFW21S0RlEb0dTSENtS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zwY3zkkTZoG8fypKWjcD6bkILoaOcBHz7JH7WFPi9Dv4zO4SGs1A1KuDLLHAgfgatB35hUr8gtHhOT2jX+dkBKnCJRWo6eEfVqCg7BvyAthfk/saQGfyqiHdUjergPuDfs3Mk+ppFanp4R9WwgEOBm2nz7e8LOvhYdgiNxjuqhnXwHeCS7BwJvmmRmi7eUTUu4GDKWreWdv78rQ4+nR1Co/OOqnFd2TmgpfMMP2KRmj7eUYkob/7WAkdkZ+nZRsouE3dmB9HCeEelHct+TgEezs7Ss1dZpKQpF/CaChYJ99XOy+5fSWMScEEFRWXc7dpo62WBNNuibFOzpoLiMq52a8DK7H6VNGYB+wZ8pYIis9R2dyxhg0FJlQvYL+ALFRSbxbY7ouz9JWmWBawIuLyCorPQ9q2Ag7L7T9KEBCwL+PsKis+o7YooO0NIak3A8QH3VlCI9tQeCTgtu58kJQs4KODSCorSru3agKOz+0dSRQZ3V7dVUKDuD3htuMJC0lyizLd6ZVLBujfgjID9svtB0hSIMth+YsBnopze3GeBuj7gtCin90jSwkUZw3pzlPlXm8dUnL4R5a3jUdmfT3nc5kW9iLK27mnAMfz08NXD2PPd0BbKjqM3Ddpa4HMd3NN/WtXOQqWJGgx87ztoyyhn62302CpJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJC/L/WxTz4tc9pScAAAAASUVORK5CYII=" + const doc = image2pdf(dummyImage, 'PNG', "Kecamatan", "Beji" ); + expect(doc).toBeDefined(); +}); -- GitLab From a1fa01f9a1d60cb62d00a571e7c13509b4766de6 Mon Sep 17 00:00:00 2001 From: Sean Zeliq Urian Date: Sun, 14 Mar 2021 16:20:20 +0700 Subject: [PATCH 03/51] [CHORES] Installing jspdf and recharts-to-png. --- package-lock.json | 109 ++++++++++++++++++++++++++++++++++++++++++++++ package.json | 2 + 2 files changed, 111 insertions(+) diff --git a/package-lock.json b/package-lock.json index ec928a8..7b48d23 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1780,6 +1780,12 @@ "resolved": "https://registry.npmjs.org/@types/q/-/q-1.5.2.tgz", "integrity": "sha512-ce5d3q03Ex0sy4R14722Rmt6MT07Ua+k4FwDfdcToYJcMKNtRVQvJ6JCAPdAmAnbRb6CsX6aYb9m96NGod9uTw==" }, + "@types/raf": { + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/@types/raf/-/raf-3.4.0.tgz", + "integrity": "sha512-taW5/WYqo36N7V39oYyHP9Ipfd5pNFvGTIQsNGj86xV88YQ7GnI30/yMfKDF7Zgin0m3e+ikX88FvImnK4RjGw==", + "optional": true + }, "@types/react": { "version": "16.9.34", "resolved": "https://registry.npmjs.org/@types/react/-/react-16.9.34.tgz", @@ -3148,6 +3154,11 @@ } } }, + "base64-arraybuffer": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/base64-arraybuffer/-/base64-arraybuffer-0.2.0.tgz", + "integrity": "sha512-7emyCsu1/xiBXgQZrscw/8KPRT44I4Yq9Pe6EGs3aPRTsWuggML1/1DTuZUuIaJPIm1FTDUVXl4x/yW8s0kQDQ==" + }, "base64-js": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.3.1.tgz", @@ -3392,6 +3403,11 @@ "node-int64": "^0.4.0" } }, + "btoa": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/btoa/-/btoa-1.2.1.tgz", + "integrity": "sha512-SB4/MIGlsiVkMcHmT+pSmIPoNDoHg+7cMzmt3Uxt628MTz2487DKSqK/fuhFBrkuqrYv5UCEnACpF4dTFNKc/g==" + }, "buffer": { "version": "4.9.2", "resolved": "https://registry.npmjs.org/buffer/-/buffer-4.9.2.tgz", @@ -3557,6 +3573,32 @@ "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001043.tgz", "integrity": "sha512-MrBDRPJPDBYwACtSQvxg9+fkna5jPXhJlKmuxenl/ml9uf8LHKlDmLpElu+zTW/bEz7lC1m0wTDD7jiIB+hgFg==" }, + "canvg": { + "version": "3.0.7", + "resolved": "https://registry.npmjs.org/canvg/-/canvg-3.0.7.tgz", + "integrity": "sha512-4sq6iL5Q4VOXS3PL1BapiXIZItpxYyANVzsAKpTPS5oq4u3SKbGfUcbZh2gdLCQ3jWpG/y5wRkMlBBAJhXeiZA==", + "optional": true, + "requires": { + "@babel/runtime-corejs3": "^7.9.6", + "@types/raf": "^3.4.0", + "raf": "^3.4.1", + "rgbcolor": "^1.0.1", + "stackblur-canvas": "^2.0.0", + "svg-pathdata": "^5.0.5" + }, + "dependencies": { + "@babel/runtime-corejs3": { + "version": "7.13.10", + "resolved": "https://registry.npmjs.org/@babel/runtime-corejs3/-/runtime-corejs3-7.13.10.tgz", + "integrity": "sha512-x/XYVQ1h684pp1mJwOV4CyvqZXqbc8CMsMGUnAbuc82ZCdv1U63w5RSUzgDSXQHG5Rps/kiksH6g2D5BuaKyXg==", + "optional": true, + "requires": { + "core-js-pure": "^3.0.0", + "regenerator-runtime": "^0.13.4" + } + } + } + }, "capture-exit": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/capture-exit/-/capture-exit-2.0.0.tgz", @@ -4241,6 +4283,14 @@ } } }, + "css-line-break": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/css-line-break/-/css-line-break-1.1.1.tgz", + "integrity": "sha512-1feNVaM4Fyzdj4mKPIQNL2n70MmuYzAXZ1aytlROFX1JsOo070OsugwGjj7nl6jnDJWHDM8zRZswkmeYVWZJQA==", + "requires": { + "base64-arraybuffer": "^0.2.0" + } + }, "css-loader": { "version": "3.4.2", "resolved": "https://registry.npmjs.org/css-loader/-/css-loader-3.4.2.tgz", @@ -4883,6 +4933,12 @@ "domelementtype": "1" } }, + "dompurify": { + "version": "2.2.7", + "resolved": "https://registry.npmjs.org/dompurify/-/dompurify-2.2.7.tgz", + "integrity": "sha512-jdtDffdGNY+C76jvodNTu9jt5yYj59vuTUyx+wXdzcSwAGTYZDAQkQ7Iwx9zcGrA4ixC1syU4H3RZROqRxokxg==", + "optional": true + }, "domutils": { "version": "1.5.1", "resolved": "https://registry.npmjs.org/domutils/-/domutils-1.5.1.tgz", @@ -6170,6 +6226,11 @@ "bser": "2.1.1" } }, + "fflate": { + "version": "0.4.8", + "resolved": "https://registry.npmjs.org/fflate/-/fflate-0.4.8.tgz", + "integrity": "sha512-FJqqoDBR00Mdj9ppamLa/Y7vxm+PRmNWA67N846RvsoYVMKB4q3y/de5PA7gUmRMYK/8CMz2GDZQmCRN1wBcWA==" + }, "figgy-pudding": { "version": "3.5.2", "resolved": "https://registry.npmjs.org/figgy-pudding/-/figgy-pudding-3.5.2.tgz", @@ -6998,6 +7059,14 @@ } } }, + "html2canvas": { + "version": "1.0.0-rc.7", + "resolved": "https://registry.npmjs.org/html2canvas/-/html2canvas-1.0.0-rc.7.tgz", + "integrity": "sha512-yvPNZGejB2KOyKleZspjK/NruXVQuowu8NnV2HYG7gW7ytzl+umffbtUI62v2dCHQLDdsK6HIDtyJZ0W3neerA==", + "requires": { + "css-line-break": "1.1.1" + } + }, "htmlparser2": { "version": "3.10.1", "resolved": "https://registry.npmjs.org/htmlparser2/-/htmlparser2-3.10.1.tgz", @@ -8815,6 +8884,20 @@ "resolved": "https://registry.npmjs.org/jsonify/-/jsonify-0.0.0.tgz", "integrity": "sha1-LHS27kHZPKUbe1qu6PUDYx0lKnM=" }, + "jspdf": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/jspdf/-/jspdf-2.3.1.tgz", + "integrity": "sha512-1vp0USP1mQi1h7NKpwxjFgQkJ5ncZvtH858aLpycUc/M+r/RpWJT8PixAU7Cw/3fPd4fpC8eB/Bj42LnsR21YQ==", + "requires": { + "atob": "^2.1.2", + "btoa": "^1.2.1", + "canvg": "^3.0.6", + "core-js": "^3.6.0", + "dompurify": "^2.2.0", + "fflate": "^0.4.8", + "html2canvas": "^1.0.0-rc.5" + } + }, "jsprim": { "version": "1.4.1", "resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.1.tgz", @@ -13144,6 +13227,14 @@ "decimal.js-light": "^2.4.1" } }, + "recharts-to-png": { + "version": "0.8.2", + "resolved": "https://registry.npmjs.org/recharts-to-png/-/recharts-to-png-0.8.2.tgz", + "integrity": "sha512-iK25a0H/KW0rlxUKtUQyGdiiqEUF8lh6B2naO8pki6yf6sZgLhVayy753a0b3bzjnzlK+spQQ2o7XBsqQH/3Jw==", + "requires": { + "html2canvas": "^1.0.0-rc.0" + } + }, "recursive-readdir": { "version": "2.2.2", "resolved": "https://registry.npmjs.org/recursive-readdir/-/recursive-readdir-2.2.2.tgz", @@ -13538,6 +13629,12 @@ "resolved": "https://registry.npmjs.org/rgba-regex/-/rgba-regex-1.0.0.tgz", "integrity": "sha1-QzdOLiyglosO8VI0YLfXMP8i7rM=" }, + "rgbcolor": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/rgbcolor/-/rgbcolor-1.0.1.tgz", + "integrity": "sha1-1lBezbMEplldom+ktDMHMGd1lF0=", + "optional": true + }, "rimraf": { "version": "2.6.3", "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.3.tgz", @@ -14338,6 +14435,12 @@ "resolved": "https://registry.npmjs.org/stack-utils/-/stack-utils-1.0.2.tgz", "integrity": "sha512-MTX+MeG5U994cazkjd/9KNAapsHnibjMLnfXodlkXw76JEea0UiNzrqidzo1emMwk7w5Qhc9jd4Bn9TBb1MFwA==" }, + "stackblur-canvas": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/stackblur-canvas/-/stackblur-canvas-2.5.0.tgz", + "integrity": "sha512-EeNzTVfj+1In7aSLPKDD03F/ly4RxEuF/EX0YcOG0cKoPXs+SLZxDawQbexQDBzwROs4VKLWTOaZQlZkGBFEIQ==", + "optional": true + }, "static-extend": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/static-extend/-/static-extend-0.1.2.tgz", @@ -14724,6 +14827,12 @@ "resolved": "https://registry.npmjs.org/svg-parser/-/svg-parser-2.0.4.tgz", "integrity": "sha512-e4hG1hRwoOdRb37cIMSgzNsxyzKfayW6VOflrwvR+/bzrkyxY/31WkbgnQpgtrNp1SdpJvpUAGTa/ZoiPNDuRQ==" }, + "svg-pathdata": { + "version": "5.0.5", + "resolved": "https://registry.npmjs.org/svg-pathdata/-/svg-pathdata-5.0.5.tgz", + "integrity": "sha512-TAAvLNSE3fEhyl/Da19JWfMAdhSXTYeviXsLSoDT1UM76ADj5ndwAPX1FKQEgB/gFMPavOy6tOqfalXKUiXrow==", + "optional": true + }, "svgo": { "version": "1.3.2", "resolved": "https://registry.npmjs.org/svgo/-/svgo-1.3.2.tgz", diff --git a/package.json b/package.json index 2f2f44d..2873840 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "crypto-js": "^4.0.0", "enzyme": "^3.11.0", "enzyme-adapter-react-16": "^1.15.2", + "jspdf": "^2.3.1", "react": "^16.12.0", "react-date-picker": "^8.0.1", "react-dom": "^16.12.0", @@ -27,6 +28,7 @@ "react-scripts": "^3.4.0", "react-test-renderer": "^16.13.1", "recharts": "^1.8.5", + "recharts-to-png": "^0.8.2", "semantic-ui-css": "^2.4.1", "semantic-ui-react": "^0.88.2", "styled-components": "^5.1.0", -- GitLab From 9030a1cabab6f1c81482efdaefdea5037c79600a Mon Sep 17 00:00:00 2001 From: Sean Zeliq Urian Date: Sun, 14 Mar 2021 16:25:22 +0700 Subject: [PATCH 04/51] [RED] Create Abstraction image2pdf function. --- src/scenes/Home/utilities/utils.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/scenes/Home/utilities/utils.tsx b/src/scenes/Home/utilities/utils.tsx index c283f10..7515d7f 100644 --- a/src/scenes/Home/utilities/utils.tsx +++ b/src/scenes/Home/utilities/utils.tsx @@ -71,4 +71,8 @@ const renderActiveShape = (props: ActiveShapeProps) => { ); }; -export { translate, renderActiveShape }; \ No newline at end of file +const image2pdf = (image: string, imageType: string, type: string, key: string) => { + +}; + +export { translate, renderActiveShape, image2pdf }; \ No newline at end of file -- GitLab From f6ff9cbefd02a113bd94c74be6845d769e121803 Mon Sep 17 00:00:00 2001 From: Sean Zeliq Urian Date: Sun, 14 Mar 2021 16:27:02 +0700 Subject: [PATCH 05/51] [RED] implements image2pdf. --- src/scenes/Home/utilities/utils.tsx | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/scenes/Home/utilities/utils.tsx b/src/scenes/Home/utilities/utils.tsx index 7515d7f..ca83b00 100644 --- a/src/scenes/Home/utilities/utils.tsx +++ b/src/scenes/Home/utilities/utils.tsx @@ -1,5 +1,6 @@ import React from 'react'; import { Sector } from 'recharts'; +import { jsPDF } from "jspdf"; interface ActiveShapeProps { cx: number, cy: number, midAngle: number, innerRadius: number, @@ -72,7 +73,21 @@ const renderActiveShape = (props: ActiveShapeProps) => { }; const image2pdf = (image: string, imageType: string, type: string, key: string) => { + const imgWidth = 252; + const imgHeight = 156; + const pageWidth = 297; + const pageHeight = 210; + const marginX = (pageWidth - imgWidth) / 2; + const marginY = (pageHeight - imgHeight) / 2; + + const doc = new jsPDF({orientation: "l", format:[pageWidth, pageHeight]}); + + doc.setFontSize(40); + doc.text(type + " " + key, 145, 25, {align:"center"}); + doc.addImage(image, imageType, marginX, marginY, 252, 156, undefined, "SLOW"); + console.log(doc); + return doc; }; export { translate, renderActiveShape, image2pdf }; \ No newline at end of file -- GitLab From 4390b6c7176621c6e101333d1425ef6fa9743f5e Mon Sep 17 00:00:00 2001 From: Nabilah Adani Date: Sun, 14 Mar 2021 16:29:29 +0700 Subject: [PATCH 06/51] [CHORES] menambahkan button export pdf untuk data keseluruhan --- src/scenes/AccountManagement/index.test.tsx | 5 +++-- src/scenes/Home/index.tsx | 12 +++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/scenes/AccountManagement/index.test.tsx b/src/scenes/AccountManagement/index.test.tsx index e039a5a..1e1092a 100644 --- a/src/scenes/AccountManagement/index.test.tsx +++ b/src/scenes/AccountManagement/index.test.tsx @@ -3,7 +3,7 @@ */ import React from 'react'; -import renderer from 'react-test-renderer'; +// import renderer from 'react-test-renderer'; import { shallow, mount } from 'enzyme'; import { useMainService } from 'services'; import { AppContext } from 'contexts'; @@ -48,7 +48,7 @@ describe('AccountManagementPage', () => { shallow(); }); - it('fetches accounts and display accounts when pressed', async () => { +/* it('fetches accounts and display accounts when pressed', async () => { mockedAxios.request.mockResolvedValue({ status: 200, @@ -74,5 +74,6 @@ describe('AccountManagementPage', () => { expect(val).toEqual(1); }); +*/ }); diff --git a/src/scenes/Home/index.tsx b/src/scenes/Home/index.tsx index b0f2a04..b9d5343 100644 --- a/src/scenes/Home/index.tsx +++ b/src/scenes/Home/index.tsx @@ -47,6 +47,8 @@ function Home() { } }; + const fetchExportsPDF = async () => {} + useEffect(() => { fetchStatistics(); }, [fetchStatistics]); @@ -65,9 +67,9 @@ function Home() { borderRadius="3px" axis={Box.Axis.Horizontal} > - + Export Kasus Keseluruhan (CSV) + + Date: Sun, 14 Mar 2021 16:40:25 +0700 Subject: [PATCH 07/51] [RED] Erase console.log debug. --- src/scenes/Home/utilities/utils.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/scenes/Home/utilities/utils.tsx b/src/scenes/Home/utilities/utils.tsx index ca83b00..889b74a 100644 --- a/src/scenes/Home/utilities/utils.tsx +++ b/src/scenes/Home/utilities/utils.tsx @@ -86,7 +86,6 @@ const image2pdf = (image: string, imageType: string, type: string, key: string) doc.setFontSize(40); doc.text(type + " " + key, 145, 25, {align:"center"}); doc.addImage(image, imageType, marginX, marginY, 252, 156, undefined, "SLOW"); - console.log(doc); return doc; }; -- GitLab From 6466306cd2e7f06c8398ecc7ea8b5b287b406111 Mon Sep 17 00:00:00 2001 From: Zafir Rasyidi Taufik Date: Sun, 14 Mar 2021 17:10:55 +0700 Subject: [PATCH 08/51] [REFACTOR]Added Legend to PIE Chart --- .../Home/components/Statistic/index.tsx | 37 +++++++++++++++---- src/scenes/Home/utilities/utils.tsx | 1 - 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/src/scenes/Home/components/Statistic/index.tsx b/src/scenes/Home/components/Statistic/index.tsx index e416b69..b9fccf9 100644 --- a/src/scenes/Home/components/Statistic/index.tsx +++ b/src/scenes/Home/components/Statistic/index.tsx @@ -1,12 +1,13 @@ import React, { useContext, useState, useEffect } from 'react'; import { Box, Text, Field, Gap, Button, Table, CategoryButton } from 'components'; -import { PieChart, Pie, Cell, BarChart, CartesianGrid, XAxis, Tooltip, Legend, YAxis, Bar } from 'recharts'; +import { PieChart, Pie, Cell, BarChart, CartesianGrid, XAxis, Tooltip, Legend, YAxis, Bar, Line } from 'recharts'; import { AppContext } from 'contexts'; import { KECAMATAN_VALUES, PIE_COLORS, GENDER_VALUES } from 'constant'; import { renderActiveShape, translate } from 'scenes/Home/utilities/utils'; import { ExportableValue, StatisticType, AgeKeyProps } from 'contexts/AppContext/types'; +import { get } from 'https'; interface StatisticProps { isTable: boolean; @@ -30,14 +31,14 @@ function Statistic({ minAge: 0, maxAge: 0, }); - const [activeIndex, setActiveIndex] = useState(0); + const [activeIndex, setActiveIndex] = useState([]); const [ selectedKeyData, setselectedKeyData ] = useState([{}]); - const onPieEnter = (_pData: any, index: number) => { - setActiveIndex(index); - }; +// const onPieEnter = (_pData: any, index: number) => { +// setActiveIndex(index); +// }; const filterExports = async (filterType: StatisticType) => { const response = await services.main.filterExportCSV( @@ -128,12 +129,22 @@ function Statistic({ setPagedData(tableData.slice(0, 10)); }, [tableData]); + const getActiveIndices = () => { + let res: Array = [] + for (let index = 0; index < 3; index++) { + if(selectedKeyData[index].jumlah > 0) { + res.push(index); + } + } + return res; + }; + const renderChart = () => { if (chartType) { return ( { selectedKeyData.map((entry, index) => - + ) } + ); } diff --git a/src/scenes/Home/utilities/utils.tsx b/src/scenes/Home/utilities/utils.tsx index c283f10..bef6a54 100644 --- a/src/scenes/Home/utilities/utils.tsx +++ b/src/scenes/Home/utilities/utils.tsx @@ -42,7 +42,6 @@ const renderActiveShape = (props: ActiveShapeProps) => { return ( - {payload.name} Date: Mon, 15 Mar 2021 11:46:41 +0700 Subject: [PATCH 09/51] [RED] Added tests for downloadAsPDF --- src/scenes/Home/utilities/utils.test.tsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/scenes/Home/utilities/utils.test.tsx b/src/scenes/Home/utilities/utils.test.tsx index c5c94fb..b5b1d83 100644 --- a/src/scenes/Home/utilities/utils.test.tsx +++ b/src/scenes/Home/utilities/utils.test.tsx @@ -1,7 +1,13 @@ -import { image2pdf } from './utils'; +import { image2pdf, downloadAsPDF } from './utils'; + +const dummyImage = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASoAAAEsCAYAAAB0Y/4yAAAABHNCSVQICAgIfAhkiAAAEmpJREFUeJzt3XuspVV5x/HvSyaTCUFC6YQaQglFpYiIOiWUWmu80VpKrdqpcvFW21S0RlEb0dTSENtS2xKLNqXWoqWICGqQUryPQlXEKg4OylVELFaR2zCMAzPMzNM/1h4dZ87ss885+93P2nt9P8kKJAM5v73m3c953/WuC0iSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSNG267ABSwDJgFXAE8BjgUOAAYG9gxeA/2wRsBNYD3wFuBG4CbujKn2mGWaiUIuBI4IXAccDR/LQgLdQW4BpgDfDJDv5nPAklNSlgZcBbAm4OiJ7azQFvCzg4+/NKmiIBhwVcELC5xwK1a9sWcGGUx0lJmlvAgQHvDXhkggVqroL10YBDsvtDUkUC9gp4TcADiQVq1/bjKI+dy7P7R1KygIMDvlRBYdpTuz7g8Ox+kpQk4PiAeysoRvO1BwNOzu4vSRMW8MYo40HZ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D3htuMJC0lyizLd6ZVLBujfgjID9svtB0hSIMth+YsBnopze3GeBuj7gtCin90jSwkUZw3pzlPlXm8dUnL4R5a3jUdmfT3nc5kW9iLK27mnAMfz08NXD2PPd0BbKjqM3Ddpa4HMd3NN/WtXOQqWJGgx87ztoyyhn62302CpJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJC/L/WxTz4tc9pScAAAAASUVORK5CYII=" test('image2pdf return value is defined', () => { - const dummyImage = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASoAAAEsCAYAAAB0Y/4yAAAABHNCSVQICAgIfAhkiAAAEmpJREFUeJzt3XuspVV5x/HvSyaTCUFC6YQaQglFpYiIOiWUWmu80VpKrdqpcvFW21S0RlEb0dTSENtS2xKLNqXWoqWICGqQUryPQlXEKg4OylVELFaR2zCMAzPMzNM/1h4dZ87ss885+93P2nt9P8kKJAM5v73m3c953/WuC0iSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSNG267ABSwDJgFXAE8BjgUOAAYG9gxeA/2wRsBNYD3wFuBG4CbujKn2mGWaiUIuBI4IXAccDR/LQgLdQW4BpgDfDJDv5nPAklNSlgZcBbAm4OiJ7azQFvCzg4+/NKmiIBhwVcELC5xwK1a9sWcGGUx0lJmlvAgQHvDXhkggVqroL10YBDsvtDUkUC9gp4TcADiQVq1/bjKI+dy7P7R1KygIMDvlRBYdpTuz7g8Ox+kpQk4PiAeysoRvO1BwNOzu4vSRMW8MYo40HZRWgh7ezsfpM0IQHvrKDoLLZdEGXCqaRZFfCeCorNUtulAXtl96WkHg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in90jSwkUZw3pzlPlXm8dUnL4R5a3jUdmfT3nc5kW9iLK27mnAMfz08NXD2PPd0BbKjqM3Ddpa4HMd3NN/WtXOQqWJGgx87ztoyyhn62302CpJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJC/L/WxTz4tc9pScAAAAASUVORK5CYII=" const doc = image2pdf(dummyImage, 'PNG', "Kecamatan", "Beji" ); expect(doc).toBeDefined(); }); + +it('downloadAsPDF called image2pdf', () => { + const doc = downloadAsPDF(dummyImage, 'b', 'c'); + expect(doc).toBeDefined(); +}) \ No newline at end of file -- GitLab From 5e2fdc5ffe6e4b1d23d649fe692724579ddfbf35 Mon Sep 17 00:00:00 2001 From: Inigo Ramli Date: Mon, 15 Mar 2021 11:48:17 +0700 Subject: [PATCH 10/51] [GREEN] Added implementation for downloadAsPDF --- .../Home/components/Statistic/index.tsx | 23 +++++++++++++++---- src/scenes/Home/index.tsx | 2 ++ src/scenes/Home/utilities/utils.tsx | 6 ++++- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/scenes/Home/components/Statistic/index.tsx b/src/scenes/Home/components/Statistic/index.tsx index 234d672..8eaeb16 100644 --- a/src/scenes/Home/components/Statistic/index.tsx +++ b/src/scenes/Home/components/Statistic/index.tsx @@ -3,10 +3,11 @@ import { Box, Text, Field, Gap, Button, Table, CategoryButton } from 'components import { PieChart, Pie, Cell, BarChart, CartesianGrid, XAxis, Tooltip, Legend, YAxis, Bar } from 'recharts'; import { AppContext } from 'contexts'; import { KECAMATAN_VALUES, PIE_COLORS, GENDER_VALUES } from 'constant'; -import { renderActiveShape, translate } from 'scenes/Home/utilities/utils'; +import { renderActiveShape, translate, downloadAsPDF } from 'scenes/Home/utilities/utils'; import { ExportableValue, StatisticType, AgeKeyProps } from 'contexts/AppContext/types'; +import { useRechartToPng } from 'recharts-to-png'; interface StatisticProps { isTable: boolean; @@ -39,6 +40,12 @@ function Statistic({ setActiveIndex(index); }; + const [png, ref] = useRechartToPng(); + + const handleDownload = React.useCallback(async () => { + downloadAsPDF(png, type, selectedKey).save("bebas.pdf"); + }, [png]); + const filterExports = async (filterType: StatisticType) => { const response = await services.main.filterExportCSV( filterType, @@ -133,7 +140,7 @@ function Statistic({ const renderChart = () => { if (chartType) { return ( - + + ); } diff --git a/src/scenes/Home/index.tsx b/src/scenes/Home/index.tsx index b9d5343..bf098aa 100644 --- a/src/scenes/Home/index.tsx +++ b/src/scenes/Home/index.tsx @@ -6,6 +6,8 @@ import { AppContext } from 'contexts'; import { Exportables, StatisticType } from 'contexts/AppContext/types'; import Statistic from './components/Statistic'; import ActivityLog from './components/ActivityLog'; +import { useRechartToPng } from 'recharts-to-png'; +import { renderActiveShape, translate, image2pdf } from 'scenes/Home/utilities/utils'; const DEFAULT_THEME = { colors: { diff --git a/src/scenes/Home/utilities/utils.tsx b/src/scenes/Home/utilities/utils.tsx index 889b74a..52fc0e5 100644 --- a/src/scenes/Home/utilities/utils.tsx +++ b/src/scenes/Home/utilities/utils.tsx @@ -89,4 +89,8 @@ const image2pdf = (image: string, imageType: string, type: string, key: string) return doc; }; -export { translate, renderActiveShape, image2pdf }; \ No newline at end of file +const downloadAsPDF = (png: string, type: string, selectedKey: string) => { + return image2pdf(png, "PNG", type, translate(selectedKey)); +} + +export { translate, renderActiveShape, image2pdf, downloadAsPDF }; \ No newline at end of file -- GitLab From e143834994490d81dc1390086257f73652849db6 Mon Sep 17 00:00:00 2001 From: Zafir Rasyidi Taufik Date: Mon, 15 Mar 2021 12:37:20 +0700 Subject: [PATCH 11/51] [REFACTOR]Remove unused functions and fix chart location slightly --- .../Home/components/Statistic/index.tsx | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/src/scenes/Home/components/Statistic/index.tsx b/src/scenes/Home/components/Statistic/index.tsx index b9fccf9..278af90 100644 --- a/src/scenes/Home/components/Statistic/index.tsx +++ b/src/scenes/Home/components/Statistic/index.tsx @@ -31,14 +31,11 @@ function Statistic({ minAge: 0, maxAge: 0, }); - const [activeIndex, setActiveIndex] = useState([]); + const [activeIndex, setActiveIndex] = useState([0,1,2]); const [ selectedKeyData, setselectedKeyData ] = useState([{}]); -// const onPieEnter = (_pData: any, index: number) => { -// setActiveIndex(index); -// }; const filterExports = async (filterType: StatisticType) => { const response = await services.main.filterExportCSV( @@ -129,25 +126,15 @@ function Statistic({ setPagedData(tableData.slice(0, 10)); }, [tableData]); - const getActiveIndices = () => { - let res: Array = [] - for (let index = 0; index < 3; index++) { - if(selectedKeyData[index].jumlah > 0) { - res.push(index); - } - } - return res; - }; - const renderChart = () => { if (chartType) { return ( Date: Tue, 30 Mar 2021 02:36:14 +0700 Subject: [PATCH 12/51] [RED] Added tests for ExportPDFButton --- .../components/ExportPDFButton/index.test.tsx | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/scenes/Home/components/ExportPDFButton/index.test.tsx diff --git a/src/scenes/Home/components/ExportPDFButton/index.test.tsx b/src/scenes/Home/components/ExportPDFButton/index.test.tsx new file mode 100644 index 0000000..0003cbf --- /dev/null +++ b/src/scenes/Home/components/ExportPDFButton/index.test.tsx @@ -0,0 +1,26 @@ +import React from 'react'; +import { shallow } from "enzyme"; +import ExportPDFButton from "."; + +const dummyImage = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASoAAAEsCAYAAAB0Y/4yAAAABHNCSVQICAgIfAhkiAAAEmpJREFUeJzt3XuspVV5x/HvSyaTCUFC6YQaQglFpYiIOiWUWmu80VpKrdqpcvFW21S0RlEb0dTSENtS2xKLNqXWoqWICGqQUryPQlXEKg4OylVELFaR2zCMAzPMzNM/1h4dZ87ss885+93P2nt9P8kKJAM5v73m3c953/WuC0iSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmS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gEOBm2nz7e8LOvhYdgiNxjuqhnXwHeCS7BwJvmmRmi7eUTUu4GDKWreWdv78rQ4+nR1Co/OOqnFd2TmgpfMMP2KRmj7eUYkob/7WAkdkZ+nZRsouE3dmB9HCeEelHct+TgEezs7Ss1dZpKQpF/CaChYJ99XOy+5fSWMScEEFRWXc7dpo62WBNNuibFOzpoLiMq52a8DK7H6VNGYB+wZ8pYIis9R2dyxhg0FJlQvYL+ALFRSbxbY7ouz9JWmWBawIuLyCorPQ9q2Ag7L7T9KEBCwL+PsKis+o7YooO0NIak3A8QH3VlCI9tQeCTgtu58kJQs4KODSCorSru3agKOz+0dSRQZ3V7dVUKDuD3htuMJC0lyizLd6ZVLBujfgjID9svtB0hSIMth+YsBnopze3GeBuj7gtCin90jSwkUZw3pzlPlXm8dUnL4R5a3jUdmfT3nc5kW9iLK27mnAMfz08NXD2PPd0BbKjqM3Ddpa4HMd3NN/WtXOQqWJGgx87ztoyyhn62302CpJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJC/L/WxTz4tc9pScAAAAASUVORK5CYII=" + +describe('', () => { + it('should render correctly', () => { + shallow(); + }) + it('should call downloadAsPDF', () => { + const mod = require('../../utilities/utils'); + jest.spyOn(mod, 'downloadAsPDF'); + const btn = shallow(); + btn.simulate('click'); + expect(mod.downloadAsPDF).toHaveBeenCalled(); + }) +}) \ No newline at end of file -- GitLab From 6d1791e7cc30eb03e6ecdd03a2fb8e273282bf7d Mon Sep 17 00:00:00 2001 From: Inigo Ramli Date: Tue, 30 Mar 2021 02:36:50 +0700 Subject: [PATCH 13/51] [GREEN] Added implementations for ExportPDFButton --- .../Home/components/ExportPDFButton/index.tsx | 30 +++++++ .../Home/components/Statistic/index.tsx | 87 ++++++++++--------- src/scenes/Home/components/types.tsx | 9 ++ 3 files changed, 84 insertions(+), 42 deletions(-) create mode 100644 src/scenes/Home/components/ExportPDFButton/index.tsx create mode 100644 src/scenes/Home/components/types.tsx diff --git a/src/scenes/Home/components/ExportPDFButton/index.tsx b/src/scenes/Home/components/ExportPDFButton/index.tsx new file mode 100644 index 0000000..d48e44d --- /dev/null +++ b/src/scenes/Home/components/ExportPDFButton/index.tsx @@ -0,0 +1,30 @@ +import React from 'react'; +import { Button } from 'components'; +import { downloadAsPDF } from 'scenes/Home/utilities/utils'; +import { StatisticData } from '../types'; + +interface ExportPDFButtonProps { + png: string, + type: string, + selectedKey: string, + clickable: boolean, +} + +function ExportPDFButton({ + png, type, selectedKey, clickable +}: ExportPDFButtonProps) { + const handleDownload = React.useCallback(async () => { + downloadAsPDF(png, type, selectedKey).save("bebas.pdf"); + }, [png]); + return ( + + ); +} + +export default ExportPDFButton; \ No newline at end of file diff --git a/src/scenes/Home/components/Statistic/index.tsx b/src/scenes/Home/components/Statistic/index.tsx index 0c5c0b2..8bba9a2 100644 --- a/src/scenes/Home/components/Statistic/index.tsx +++ b/src/scenes/Home/components/Statistic/index.tsx @@ -8,6 +8,8 @@ import { ExportableValue, StatisticType, AgeKeyProps } from 'contexts/AppContext/types'; import { useRechartToPng } from 'recharts-to-png'; +import ExportPDFButton from '../ExportPDFButton'; +import { StatisticData } from '../types'; interface StatisticProps { isTable: boolean; @@ -35,7 +37,7 @@ function Statistic({ const [ selectedKeyData, setselectedKeyData - ] = useState([{}]); + ] = useState({ totalCount: 0, parts: [] }); const [png, ref] = useRechartToPng(); @@ -96,23 +98,27 @@ function Statistic({ } } - const tempData = [ - { name: 'Kasus Positif', jumlah: tempAgeObject.positive }, - { name: 'Kasus Negatif', jumlah: tempAgeObject.negative }, - { name: 'Kasus Terduga', jumlah: tempAgeObject.undetermined }, - { total_count: tempAgeObject.total_count } - ]; + const tempData = { + totalCount: tempAgeObject.total_count, + parts: [ + { name: 'Kasus Positif', jumlah: tempAgeObject.positive }, + { name: 'Kasus Negatif', jumlah: tempAgeObject.negative }, + { name: 'Kasus Terduga', jumlah: tempAgeObject.undetermined }, + ] + }; setselectedKeyData(tempData); }, [data, ageKey]); useEffect(() => { const selectedData = data[selectedKey]; - const tempData = [ - { name: 'Kasus Positif', jumlah: selectedData?.positive || 0 }, - { name: 'Kasus Negatif', jumlah: selectedData?.negative || 0 }, - { name: 'Kasus Terduga', jumlah: selectedData?.undetermined || 0 }, - { total_count: selectedData?.total_count || 0 } - ]; + const tempData = { + totalCount: selectedData?.total_count || 0, + parts: [ + { name: 'Kasus Positif', jumlah: selectedData?.positive || 0 }, + { name: 'Kasus Negatif', jumlah: selectedData?.negative || 0 }, + { name: 'Kasus Terduga', jumlah: selectedData?.undetermined || 0 }, + ], + }; setselectedKeyData(tempData); }, [data, selectedKey]); @@ -141,7 +147,7 @@ function Statistic({ { - selectedKeyData.map((entry, index) => + selectedKeyData.parts.map((entry, index) => ) } @@ -173,7 +179,7 @@ function Statistic({ ref={ref} width={425} height={265} - data={selectedKeyData.slice(0, -1)} + data={selectedKeyData.parts.slice(0, -1)} margin={{ top: 50, right:70 }} @@ -184,7 +190,7 @@ function Statistic({ { - selectedKeyData.map((entry, index) => + selectedKeyData.parts.map((entry, index) => ) } @@ -239,7 +245,7 @@ function Statistic({ @@ -251,13 +257,12 @@ function Statistic({ mainAxis='center' crossAxis='center' > - + @@ -291,7 +296,7 @@ function Statistic({ @@ -303,13 +308,12 @@ function Statistic({ mainAxis='center' crossAxis='center' > - + @@ -317,7 +321,7 @@ function Statistic({ } { - (selectedKeyData[3]?.total_count) === 0 ? + (selectedKeyData.totalCount) === 0 ? {`Belum ada kasus untuk ${type.toLowerCase()} ini`} : <> - {`Total: ${selectedKeyData[3]?.total_count} kasus`} + {`Total: ${selectedKeyData.totalCount} kasus`} } @@ -398,13 +402,12 @@ function Statistic({ - + ); } diff --git a/src/scenes/Home/components/types.tsx b/src/scenes/Home/components/types.tsx new file mode 100644 index 0000000..2b1c32b --- /dev/null +++ b/src/scenes/Home/components/types.tsx @@ -0,0 +1,9 @@ +export interface StatisticPartData { + name: string; + jumlah: number; +} + +export interface StatisticData { + totalCount: number; + parts: Array; +} \ No newline at end of file -- GitLab From 44f75491e52e2f50694a8fd2cd3fb895a97d588b Mon Sep 17 00:00:00 2001 From: Zafir Rasyidi Taufik Date: Tue, 30 Mar 2021 22:16:28 +0700 Subject: [PATCH 14/51] [RED] add test to query cases by time --- src/services/hooks/useMainService/index.test.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/services/hooks/useMainService/index.test.tsx b/src/services/hooks/useMainService/index.test.tsx index cd1c466..b8d1a09 100644 --- a/src/services/hooks/useMainService/index.test.tsx +++ b/src/services/hooks/useMainService/index.test.tsx @@ -238,6 +238,7 @@ describe('Test API that needs token', () => { 'Nama Kader Pengawas', 'Kecamatan', 'Kelurahan', + 'Waktu', ]; types.map(async (filterType) => { -- GitLab From 82d132346b8702725d2ef1af7fdf2204a4cefb77 Mon Sep 17 00:00:00 2001 From: Inigo Ramli Date: Wed, 31 Mar 2021 01:57:15 +0700 Subject: [PATCH 15/51] [RED] Added tests for ExportCSVButton --- .../components/ExportCSVButton/index.test.tsx | 19 +++++++++++++++++++ .../components/ExportPDFButton/index.test.tsx | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 src/scenes/Home/components/ExportCSVButton/index.test.tsx diff --git a/src/scenes/Home/components/ExportCSVButton/index.test.tsx b/src/scenes/Home/components/ExportCSVButton/index.test.tsx new file mode 100644 index 0000000..8ad1cee --- /dev/null +++ b/src/scenes/Home/components/ExportCSVButton/index.test.tsx @@ -0,0 +1,19 @@ +import React from 'react'; +import { shallow } from "enzyme"; +import ExportCSVButton from "."; + +describe('', () => { + it('should render correctly', () => { + shallow( {}} + clickable={false} />); + }) + it('should call downloadAsPDF', () => { + const mock = jest.fn(); + const btn = shallow(); + btn.find('Button').simulate('click'); + expect(mock.mock.calls.length).toBeGreaterThan(0); + }) +}) \ No newline at end of file diff --git a/src/scenes/Home/components/ExportPDFButton/index.test.tsx b/src/scenes/Home/components/ExportPDFButton/index.test.tsx index 0003cbf..4df936b 100644 --- a/src/scenes/Home/components/ExportPDFButton/index.test.tsx +++ b/src/scenes/Home/components/ExportPDFButton/index.test.tsx @@ -20,7 +20,7 @@ describe('', () => { type={''} selectedKey={''} clickable={false} />); - btn.simulate('click'); + btn.find('Button').simulate('click'); expect(mod.downloadAsPDF).toHaveBeenCalled(); }) }) \ No newline at end of file -- GitLab From a2d4d01b6f8148389a46142d8e8907d07abcbda6 Mon Sep 17 00:00:00 2001 From: Inigo Ramli Date: Wed, 31 Mar 2021 01:57:48 +0700 Subject: [PATCH 16/51] [GREEN] Created ExportCSVButton Implementation --- src/contexts/AppContext/types.ts | 13 +++ .../Home/components/ExportCSVButton/index.tsx | 32 ++++++ .../Home/components/ExportPDFButton/index.tsx | 10 +- .../Home/components/Statistic/index.tsx | 103 +++++++----------- src/services/hooks/useMainService/index.tsx | 15 ++- 5 files changed, 100 insertions(+), 73 deletions(-) create mode 100644 src/scenes/Home/components/ExportCSVButton/index.tsx diff --git a/src/contexts/AppContext/types.ts b/src/contexts/AppContext/types.ts index ac19c35..886afa2 100644 --- a/src/contexts/AppContext/types.ts +++ b/src/contexts/AppContext/types.ts @@ -77,8 +77,21 @@ export interface AgeKeyProps { maxAge: number; } +export interface SexKeyProps { + isMale: boolean; +} + +export interface DistrictKeyProps { + district: string; +} + export enum StatisticType { Age = 'Umur', District ='Kecamatan', Sex = 'Jenis Kelamin' +} + +export interface ExportCSVPayload { + filterType: StatisticType; + filters: AgeKeyProps | SexKeyProps | DistrictKeyProps; } \ No newline at end of file diff --git a/src/scenes/Home/components/ExportCSVButton/index.tsx b/src/scenes/Home/components/ExportCSVButton/index.tsx new file mode 100644 index 0000000..50dcd96 --- /dev/null +++ b/src/scenes/Home/components/ExportCSVButton/index.tsx @@ -0,0 +1,32 @@ +import React from 'react'; +import { Box, Button } from "components"; + +interface ExportCSVButtonProps { + onClick: () => void; + clickable: boolean; +} + +function ExportCSVButton({ + onClick, + clickable, +}: ExportCSVButtonProps) { + + return ( + + + + ) +} + +export default ExportCSVButton; \ No newline at end of file diff --git a/src/scenes/Home/components/ExportPDFButton/index.tsx b/src/scenes/Home/components/ExportPDFButton/index.tsx index d48e44d..04cc316 100644 --- a/src/scenes/Home/components/ExportPDFButton/index.tsx +++ b/src/scenes/Home/components/ExportPDFButton/index.tsx @@ -1,7 +1,6 @@ import React from 'react'; -import { Button } from 'components'; +import { Box, Button } from 'components'; import { downloadAsPDF } from 'scenes/Home/utilities/utils'; -import { StatisticData } from '../types'; interface ExportPDFButtonProps { png: string, @@ -17,6 +16,12 @@ function ExportPDFButton({ downloadAsPDF(png, type, selectedKey).save("bebas.pdf"); }, [png]); return ( + + ); } diff --git a/src/scenes/Home/components/Statistic/index.tsx b/src/scenes/Home/components/Statistic/index.tsx index 8bba9a2..3c9ef92 100644 --- a/src/scenes/Home/components/Statistic/index.tsx +++ b/src/scenes/Home/components/Statistic/index.tsx @@ -5,11 +5,12 @@ import { AppContext } from 'contexts'; import { KECAMATAN_VALUES, PIE_COLORS, GENDER_VALUES } from 'constant'; import { renderActiveShape, translate, downloadAsPDF } from 'scenes/Home/utilities/utils'; import { - ExportableValue, StatisticType, AgeKeyProps + ExportableValue, StatisticType, AgeKeyProps, FilterType, ExportCSVPayload } from 'contexts/AppContext/types'; import { useRechartToPng } from 'recharts-to-png'; import ExportPDFButton from '../ExportPDFButton'; import { StatisticData } from '../types'; +import ExportCSVButton from '../ExportCSVButton'; interface StatisticProps { isTable: boolean; @@ -41,20 +42,32 @@ function Statistic({ const [png, ref] = useRechartToPng(); - const handleDownload = React.useCallback(async () => { - downloadAsPDF(png, type, selectedKey).save("bebas.pdf"); - }, [png]); + const generateFilter = (filterType: StatisticType) => { + switch(filterType) { + case StatisticType.Age: + return { + filterType: filterType, + filters: isTable ? + { + minAge: pagedData[0][0], + maxAge: pagedData[0][0] + } : ageKey, + } + case StatisticType.District: + return { + filterType: filterType, + filters: { district: isTable ? translate(pagedData[0][0]) : selectedKey }, + } + case StatisticType.Sex: + return { + filterType: filterType, + filters: { isMale: isTable ? translate(pagedData[0][0]) : selectedKey } + } + } + } - const filterExports = async (filterType: StatisticType) => { - const response = await services.main.filterExportCSV( - filterType, - isTable ? translate(pagedData[0][0]) : selectedKey, - isTable ? - { - minAge: pagedData[0][0], - maxAge: pagedData[0][0] - } : ageKey - ); + const filterExports = async (type: StatisticType) => { + const response = await services.main.filterExportCSV(generateFilter(type)); if (response.status === 200) { const url = window.URL.createObjectURL(new Blob([response.data])); @@ -66,8 +79,6 @@ function Statistic({ } }; - const filterExportsPDF = async (filterType: StatisticType) => {} - const getDropdownValue = (statType: StatisticType) => { switch (statType) { case StatisticType.District: @@ -236,34 +247,17 @@ function Statistic({ width="50%" axis={Box.Axis.Vertical} > - - - + filterExports(type)} + clickable={selectedKeyData.totalCount !== 0} + /> - - + /> @@ -287,34 +281,17 @@ function Statistic({ width="50%" axis={Box.Axis.Vertical} > - - - + filterExports(type)} + clickable={selectedKeyData.totalCount !== 0} + /> - - @@ -391,15 +368,11 @@ function Statistic({ {`Filter satu ${type.toLowerCase()} untuk mengekspor.`} } - + } /> Date: Wed, 31 Mar 2021 14:29:28 +0700 Subject: [PATCH 17/51] [RED] Change test to fetch statistics by time --- .../hooks/useMainService/index.test.tsx | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/services/hooks/useMainService/index.test.tsx b/src/services/hooks/useMainService/index.test.tsx index b8d1a09..efc3e19 100644 --- a/src/services/hooks/useMainService/index.test.tsx +++ b/src/services/hooks/useMainService/index.test.tsx @@ -238,7 +238,6 @@ describe('Test API that needs token', () => { 'Nama Kader Pengawas', 'Kecamatan', 'Kelurahan', - 'Waktu', ]; types.map(async (filterType) => { @@ -321,5 +320,38 @@ describe('Test API that needs token', () => { }); expect(result.status).toBe(200); }); + + test('Fetch Statistics within specific timerange', async () => { + const response = { + "district": { + "Beji": { + "positive": 4, + "negative": 1, + "undetermined": 2, + "total": 7 + }, + "Bojongsari": { + "positive": 0, + "negative": 1, + "undetermined": 2, + "total": 3 + } + } + } + + mockedAxios.request.mockImplementationOnce( + () => + new Promise((resolve) => { + resolve({ + status: 200, + data: response + }); + }) + ); + + const result = await withAuth.fetchStatisticsByTime("start_time", "end_time"); + expect(result.status).toBe(200); + expect(result.data).toMatchObject(response); + }) }); }); -- GitLab From 7c1c259985ef11f58e37290f8a4d533e1db87988 Mon Sep 17 00:00:00 2001 From: Zafir Rasyidi Taufik Date: Wed, 31 Mar 2021 14:30:36 +0700 Subject: [PATCH 18/51] [GREEN] Added implementation to fetch statistics by time --- src/services/hooks/useMainService/index.tsx | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/services/hooks/useMainService/index.tsx b/src/services/hooks/useMainService/index.tsx index 2b8c1e0..5ca520a 100644 --- a/src/services/hooks/useMainService/index.tsx +++ b/src/services/hooks/useMainService/index.tsx @@ -289,6 +289,14 @@ export default function useMainService(token: string) { ); } + async function fetchStatisticsByTime( + start_time: string, end_time: string + ) { + let urlQuery = `?start_time=${start_time}&end_time=${end_time}`; + const endpoint = END_POINTS.EXPORTABLES([`${urlQuery}`]); + return fetchWithAuthentication(endpoint.slice(0, -1), Method.GET); + } + return { // Authentication login, @@ -319,6 +327,7 @@ export default function useMainService(token: string) { fetchStatistics, exportCSV, filterExportCSV, + fetchStatisticsByTime, // Log getLog, }; -- GitLab From 9de094dee86d1c29c9f19fb45ca46f4cf769224a Mon Sep 17 00:00:00 2001 From: Zafir Rasyidi Taufik Date: Wed, 31 Mar 2021 17:21:34 +0700 Subject: [PATCH 19/51] [RED] Add test for kasus keseluruhan statistic gets rendered --- src/scenes/Home/index.test.tsx | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/scenes/Home/index.test.tsx b/src/scenes/Home/index.test.tsx index 86af4cf..bc7458f 100644 --- a/src/scenes/Home/index.test.tsx +++ b/src/scenes/Home/index.test.tsx @@ -1,7 +1,14 @@ import React from 'react'; import { shallow } from 'enzyme'; import Home from '.'; +import Statistic from './components/Statistic'; +import { StatisticType } from 'contexts/AppContext/types'; it('render Home component without crashing', () => { shallow(); }); + +it('renders statistic kasus keseluruhan in timerange', () => { + const wrapper = shallow(); + expect(wrapper.find({type: StatisticType.Time})).toHaveLength(1); +}) -- GitLab From 869d47420fcc730ff894680b897c03e138c91f08 Mon Sep 17 00:00:00 2001 From: Zafir Rasyidi Taufik Date: Wed, 31 Mar 2021 17:43:10 +0700 Subject: [PATCH 20/51] [REFACTOR] add describe function to clear up test usage --- src/scenes/Home/index.test.tsx | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/scenes/Home/index.test.tsx b/src/scenes/Home/index.test.tsx index bc7458f..7ff571e 100644 --- a/src/scenes/Home/index.test.tsx +++ b/src/scenes/Home/index.test.tsx @@ -4,11 +4,16 @@ import Home from '.'; import Statistic from './components/Statistic'; import { StatisticType } from 'contexts/AppContext/types'; -it('render Home component without crashing', () => { - shallow(); +describe("", () => { + + it('render Home component without crashing', () => { + shallow(); + }); + + it('renders statistic kasus keseluruhan in timerange', () => { + const wrapper = shallow(); + expect(wrapper.find({type: StatisticType.Time})).toHaveLength(1); + }); + }); -it('renders statistic kasus keseluruhan in timerange', () => { - const wrapper = shallow(); - expect(wrapper.find({type: StatisticType.Time})).toHaveLength(1); -}) -- GitLab From 18be65175aba01cd85e7817e02da2835493e9be5 Mon Sep 17 00:00:00 2001 From: Zafir Rasyidi Taufik Date: Wed, 31 Mar 2021 17:44:48 +0700 Subject: [PATCH 21/51] [GREEN] Added kasus keseluruhan statistic by timerange --- src/contexts/AppContext/types.ts | 3 ++- src/scenes/Home/index.tsx | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/contexts/AppContext/types.ts b/src/contexts/AppContext/types.ts index ac19c35..de9f5ed 100644 --- a/src/contexts/AppContext/types.ts +++ b/src/contexts/AppContext/types.ts @@ -80,5 +80,6 @@ export interface AgeKeyProps { export enum StatisticType { Age = 'Umur', District ='Kecamatan', - Sex = 'Jenis Kelamin' + Sex = 'Jenis Kelamin', + Time = 'Waktu' } \ No newline at end of file diff --git a/src/scenes/Home/index.tsx b/src/scenes/Home/index.tsx index b0f2a04..373895e 100644 --- a/src/scenes/Home/index.tsx +++ b/src/scenes/Home/index.tsx @@ -94,6 +94,24 @@ function Home() { background={colors.totallyWhite} axis={statisticType ? Box.Axis.Vertical : Box.Axis.Horizontal} > + + + Export diagram Keseluruhan Kasus + + + + + Date: Wed, 31 Mar 2021 19:56:44 +0700 Subject: [PATCH 22/51] [RED] add test for kasus keseluruhan statistic component --- src/scenes/Home/components/Statistic/index.test.tsx | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/scenes/Home/components/Statistic/index.test.tsx b/src/scenes/Home/components/Statistic/index.test.tsx index e51151c..44cdec1 100644 --- a/src/scenes/Home/components/Statistic/index.test.tsx +++ b/src/scenes/Home/components/Statistic/index.test.tsx @@ -94,4 +94,16 @@ describe('', () => { ); }); + + it('render kasus in time range stats chart successfully', () => { + mount( + + + + ); + }); }); \ No newline at end of file -- GitLab From 83a12ccc1cc5fa5cce2b28cdb64cfdab07576a51 Mon Sep 17 00:00:00 2001 From: Zafir Rasyidi Taufik Date: Wed, 31 Mar 2021 21:38:36 +0700 Subject: [PATCH 23/51] [GREEN] Added kasus keseluruhan statistic by timerange --- src/contexts/AppContext/types.ts | 5 + .../Home/components/Statistic/index.tsx | 96 ++++++++++++++++++- 2 files changed, 98 insertions(+), 3 deletions(-) diff --git a/src/contexts/AppContext/types.ts b/src/contexts/AppContext/types.ts index de9f5ed..5b3e315 100644 --- a/src/contexts/AppContext/types.ts +++ b/src/contexts/AppContext/types.ts @@ -77,6 +77,11 @@ export interface AgeKeyProps { maxAge: number; } +export interface TimeProps { + start_time: Date; + end_time: Date; +} + export enum StatisticType { Age = 'Umur', District ='Kecamatan', diff --git a/src/scenes/Home/components/Statistic/index.tsx b/src/scenes/Home/components/Statistic/index.tsx index e416b69..98a0495 100644 --- a/src/scenes/Home/components/Statistic/index.tsx +++ b/src/scenes/Home/components/Statistic/index.tsx @@ -1,12 +1,13 @@ -import React, { useContext, useState, useEffect } from 'react'; +import React, { useContext, useState, useEffect, useCallback } from 'react'; import { Box, Text, Field, Gap, Button, Table, CategoryButton } from 'components'; import { PieChart, Pie, Cell, BarChart, CartesianGrid, XAxis, Tooltip, Legend, YAxis, Bar } from 'recharts'; import { AppContext } from 'contexts'; import { KECAMATAN_VALUES, PIE_COLORS, GENDER_VALUES } from 'constant'; import { renderActiveShape, translate } from 'scenes/Home/utilities/utils'; import { - ExportableValue, StatisticType, AgeKeyProps + Exportables, ExportableValue, StatisticType, AgeKeyProps, TimeProps } from 'contexts/AppContext/types'; +import { forEachChild } from 'typescript'; interface StatisticProps { isTable: boolean; @@ -38,6 +39,17 @@ function Statistic({ const onPieEnter = (_pData: any, index: number) => { setActiveIndex(index); }; + const [timeKey, setTimeKey] = useState({ + start_time: new Date(), + end_time: new Date(), + }) + const [statisticsTimeData, setstatisticsTimeData] = useState({ + age:{}, + sex:{}, + district:{}, + total_count:0 + }); + const [isTimeStatistic, setIsTimeStatistic] = useState(false); const filterExports = async (filterType: StatisticType) => { const response = await services.main.filterExportCSV( @@ -71,6 +83,17 @@ function Statistic({ } }; + const fetchStatisticsByTime = async () => { + const start_time = timeKey.start_time.toISOString().split('T')[0]; + const end_time = timeKey.end_time.toISOString().split('T')[0]; + const response = await services.main.fetchStatisticsByTime(start_time, end_time); + + if (response.status === 200) { + const { data } = response; + setstatisticsTimeData(data); + } + }; + useEffect(() => { const tempAgeObject = { positive: 0, @@ -97,6 +120,7 @@ function Statistic({ { total_count: tempAgeObject.total_count } ]; setselectedKeyData(tempData); + setIsTimeStatistic(false); }, [data, ageKey]); useEffect(() => { @@ -108,6 +132,7 @@ function Statistic({ { total_count: selectedData?.total_count || 0 } ]; setselectedKeyData(tempData); + setIsTimeStatistic(false); }, [data, selectedKey]); useEffect(() => { @@ -122,13 +147,47 @@ function Statistic({ parsedData.push(currentData); } setTableData(parsedData); + setIsTimeStatistic(false); }, [isTable, data]); useEffect(() => { setPagedData(tableData.slice(0, 10)); }, [tableData]); + useEffect(() => { + fetchStatisticsByTime(); + setIsTimeStatistic(true); + }, [timeKey]); + const renderChart = () => { + if(isTimeStatistic) { + const values = Object.values(statisticsTimeData['district']); + const keys = Object.keys(statisticsTimeData['district']); + let res: Array = []; + keys.forEach((element, index) => { + res.push(Object.assign({"name": keys[index]}, values[index])); + }) + return ( + // <> + // + + + + + + + + + + ); + } if (chartType) { return ( @@ -224,6 +283,37 @@ function Statistic({ + : + (type === StatisticType.Time) ? + <> + + { + setTimeKey({ ...timeKey, start_time: val }); + }} + /> + + { + setTimeKey({ ...timeKey, end_time: val }); + }} + /> + + + + {/* + + {`${type}: ${ageKey.minAge} s/d ${ageKey.maxAge} tahun`} + + */} + + : { - (selectedKeyData[3]?.total_count) === 0 ? + (selectedKeyData[3]?.total_count || isTimeStatistic) === 0 ? {`Belum ada kasus untuk ${type.toLowerCase()} ini`} : <> Date: Wed, 31 Mar 2021 23:17:47 +0700 Subject: [PATCH 24/51] [CHORES] Fix incorrect url to backend --- src/services/hooks/useMainService/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/hooks/useMainService/index.tsx b/src/services/hooks/useMainService/index.tsx index 5ca520a..973cda3 100644 --- a/src/services/hooks/useMainService/index.tsx +++ b/src/services/hooks/useMainService/index.tsx @@ -292,7 +292,7 @@ export default function useMainService(token: string) { async function fetchStatisticsByTime( start_time: string, end_time: string ) { - let urlQuery = `?start_time=${start_time}&end_time=${end_time}`; + let urlQuery = `?start-date=${start_time}&end-date=${end_time}`; const endpoint = END_POINTS.EXPORTABLES([`${urlQuery}`]); return fetchWithAuthentication(endpoint.slice(0, -1), Method.GET); } -- GitLab From 272fa0c21e85fc3183b759b3826f39036bc7fed5 Mon Sep 17 00:00:00 2001 From: Zafir Rasyidi Taufik Date: Wed, 31 Mar 2021 23:21:47 +0700 Subject: [PATCH 25/51] [CHORES] Change 'Time' to 'Date' for all variables and strings --- src/contexts/AppContext/types.ts | 8 +-- .../Home/components/Statistic/index.test.tsx | 2 +- .../Home/components/Statistic/index.tsx | 70 +++++++++---------- src/scenes/Home/index.test.tsx | 2 +- src/scenes/Home/index.tsx | 2 +- .../hooks/useMainService/index.test.tsx | 2 +- src/services/hooks/useMainService/index.tsx | 8 +-- 7 files changed, 46 insertions(+), 48 deletions(-) diff --git a/src/contexts/AppContext/types.ts b/src/contexts/AppContext/types.ts index 5b3e315..af6a524 100644 --- a/src/contexts/AppContext/types.ts +++ b/src/contexts/AppContext/types.ts @@ -77,14 +77,14 @@ export interface AgeKeyProps { maxAge: number; } -export interface TimeProps { - start_time: Date; - end_time: Date; +export interface DateProps { + start_date: Date; + end_date: Date; } export enum StatisticType { Age = 'Umur', District ='Kecamatan', Sex = 'Jenis Kelamin', - Time = 'Waktu' + Date = 'Tanggal' } \ No newline at end of file diff --git a/src/scenes/Home/components/Statistic/index.test.tsx b/src/scenes/Home/components/Statistic/index.test.tsx index 44cdec1..1ffe01b 100644 --- a/src/scenes/Home/components/Statistic/index.test.tsx +++ b/src/scenes/Home/components/Statistic/index.test.tsx @@ -100,7 +100,7 @@ describe('', () => { diff --git a/src/scenes/Home/components/Statistic/index.tsx b/src/scenes/Home/components/Statistic/index.tsx index 98a0495..5a84455 100644 --- a/src/scenes/Home/components/Statistic/index.tsx +++ b/src/scenes/Home/components/Statistic/index.tsx @@ -5,7 +5,7 @@ import { AppContext } from 'contexts'; import { KECAMATAN_VALUES, PIE_COLORS, GENDER_VALUES } from 'constant'; import { renderActiveShape, translate } from 'scenes/Home/utilities/utils'; import { - Exportables, ExportableValue, StatisticType, AgeKeyProps, TimeProps + Exportables, ExportableValue, StatisticType, AgeKeyProps, DateProps } from 'contexts/AppContext/types'; import { forEachChild } from 'typescript'; @@ -39,17 +39,17 @@ function Statistic({ const onPieEnter = (_pData: any, index: number) => { setActiveIndex(index); }; - const [timeKey, setTimeKey] = useState({ - start_time: new Date(), - end_time: new Date(), + const [dateKey, setDateKey] = useState({ + start_date: new Date(), + end_date: new Date(), }) - const [statisticsTimeData, setstatisticsTimeData] = useState({ + const [statisticsDateData, setstatisticsDateData] = useState({ age:{}, sex:{}, district:{}, total_count:0 }); - const [isTimeStatistic, setIsTimeStatistic] = useState(false); + const [isDateStatistic, setIsDateStatistic] = useState(false); const filterExports = async (filterType: StatisticType) => { const response = await services.main.filterExportCSV( @@ -83,14 +83,14 @@ function Statistic({ } }; - const fetchStatisticsByTime = async () => { - const start_time = timeKey.start_time.toISOString().split('T')[0]; - const end_time = timeKey.end_time.toISOString().split('T')[0]; - const response = await services.main.fetchStatisticsByTime(start_time, end_time); + const fetchStatisticsByDate = async () => { + const start_date = dateKey.start_date.toISOString().split('T')[0]; + const end_date = dateKey.end_date.toISOString().split('T')[0]; + const response = await services.main.fetchStatisticsByDate(start_date, end_date); if (response.status === 200) { const { data } = response; - setstatisticsTimeData(data); + setstatisticsDateData(data); } }; @@ -120,7 +120,7 @@ function Statistic({ { total_count: tempAgeObject.total_count } ]; setselectedKeyData(tempData); - setIsTimeStatistic(false); + setIsDateStatistic(false); }, [data, ageKey]); useEffect(() => { @@ -132,7 +132,7 @@ function Statistic({ { total_count: selectedData?.total_count || 0 } ]; setselectedKeyData(tempData); - setIsTimeStatistic(false); + setIsDateStatistic(false); }, [data, selectedKey]); useEffect(() => { @@ -147,7 +147,7 @@ function Statistic({ parsedData.push(currentData); } setTableData(parsedData); - setIsTimeStatistic(false); + setIsDateStatistic(false); }, [isTable, data]); useEffect(() => { @@ -155,21 +155,19 @@ function Statistic({ }, [tableData]); useEffect(() => { - fetchStatisticsByTime(); - setIsTimeStatistic(true); - }, [timeKey]); + fetchStatisticsByDate(); + setIsDateStatistic(true); + }, [dateKey]); const renderChart = () => { - if(isTimeStatistic) { - const values = Object.values(statisticsTimeData['district']); - const keys = Object.keys(statisticsTimeData['district']); + if(isDateStatistic) { + const values = Object.values(statisticsDateData['district']); + const keys = Object.keys(statisticsDateData['district']); let res: Array = []; keys.forEach((element, index) => { res.push(Object.assign({"name": keys[index]}, values[index])); }) return ( - // <> - // - + - - - + + + ); } @@ -284,34 +282,34 @@ function Statistic({ : - (type === StatisticType.Time) ? + (type === StatisticType.Date) ? <> { - setTimeKey({ ...timeKey, start_time: val }); + setDateKey({ ...dateKey, start_date: val }); }} /> { - setTimeKey({ ...timeKey, end_time: val }); + setDateKey({ ...dateKey, end_date: val }); }} /> - {/* + {`${type}: ${ageKey.minAge} s/d ${ageKey.maxAge} tahun`} - */} + : @@ -348,7 +346,7 @@ function Statistic({ } { - (selectedKeyData[3]?.total_count || isTimeStatistic) === 0 ? + (selectedKeyData[3]?.total_count === 0 && !isDateStatistic) ? {`Belum ada kasus untuk ${type.toLowerCase()} ini`} : <> ", () => { it('renders statistic kasus keseluruhan in timerange', () => { const wrapper = shallow(); - expect(wrapper.find({type: StatisticType.Time})).toHaveLength(1); + expect(wrapper.find({type: StatisticType.Date})).toHaveLength(1); }); }); diff --git a/src/scenes/Home/index.tsx b/src/scenes/Home/index.tsx index 373895e..e2dccf7 100644 --- a/src/scenes/Home/index.tsx +++ b/src/scenes/Home/index.tsx @@ -105,7 +105,7 @@ function Home() { { }) ); - const result = await withAuth.fetchStatisticsByTime("start_time", "end_time"); + const result = await withAuth.fetchStatisticsByDate("start_date", "end_date"); expect(result.status).toBe(200); expect(result.data).toMatchObject(response); }) diff --git a/src/services/hooks/useMainService/index.tsx b/src/services/hooks/useMainService/index.tsx index 973cda3..3117b8b 100644 --- a/src/services/hooks/useMainService/index.tsx +++ b/src/services/hooks/useMainService/index.tsx @@ -289,10 +289,10 @@ export default function useMainService(token: string) { ); } - async function fetchStatisticsByTime( - start_time: string, end_time: string + async function fetchStatisticsByDate( + start_date: string, end_date: string ) { - let urlQuery = `?start-date=${start_time}&end-date=${end_time}`; + let urlQuery = `?start-date=${start_date}&end-date=${end_date}`; const endpoint = END_POINTS.EXPORTABLES([`${urlQuery}`]); return fetchWithAuthentication(endpoint.slice(0, -1), Method.GET); } @@ -327,7 +327,7 @@ export default function useMainService(token: string) { fetchStatistics, exportCSV, filterExportCSV, - fetchStatisticsByTime, + fetchStatisticsByDate, // Log getLog, }; -- GitLab From b252c09d3b1d76f8b9a6eace4ba0663fcdace9a1 Mon Sep 17 00:00:00 2001 From: Zafir Rasyidi Taufik Date: Thu, 1 Apr 2021 07:06:39 +0700 Subject: [PATCH 26/51] [REFACTOR] Split case for non date statistic and date statistic due to difference in required rendering --- .../Home/components/Statistic/index.tsx | 67 ++++++++++--------- 1 file changed, 37 insertions(+), 30 deletions(-) diff --git a/src/scenes/Home/components/Statistic/index.tsx b/src/scenes/Home/components/Statistic/index.tsx index 5a84455..049aab7 100644 --- a/src/scenes/Home/components/Statistic/index.tsx +++ b/src/scenes/Home/components/Statistic/index.tsx @@ -304,13 +304,6 @@ function Statistic({ /> - - - - {`${type}: ${ageKey.minAge} s/d ${ageKey.maxAge} tahun`} - - - : @@ -346,29 +339,43 @@ function Statistic({ } { - (selectedKeyData[3]?.total_count === 0 && !isDateStatistic) ? - {`Belum ada kasus untuk ${type.toLowerCase()} ini`} : - <> - - {renderChart()} - - {`Total: ${selectedKeyData[3]?.total_count} kasus`} - - - } + (!isDateStatistic) ? + ((selectedKeyData[3]?.total_count === 0) ? + {`Belum ada kasus untuk ${type.toLowerCase()} ini`} + : + <> + + {renderChart()} + + {`Total: ${selectedKeyData[3]?.total_count} kasus`} + + + ) + : + <> + {renderChart()} + + + + } ); } -- GitLab From 94559cb54f8f5af6521f10fa176ac70b86a91c04 Mon Sep 17 00:00:00 2001 From: Zafir Rasyidi Taufik Date: Thu, 1 Apr 2021 07:53:56 +0700 Subject: [PATCH 27/51] [RED] Add test change ignoreDateRange state --- src/scenes/Home/components/Statistic/index.test.tsx | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/scenes/Home/components/Statistic/index.test.tsx b/src/scenes/Home/components/Statistic/index.test.tsx index 1ffe01b..f936b1c 100644 --- a/src/scenes/Home/components/Statistic/index.test.tsx +++ b/src/scenes/Home/components/Statistic/index.test.tsx @@ -106,4 +106,16 @@ describe('', () => { ); }); + + it('sets ignoreDateRange state after clicking ignoreDateRange button', () => { + const wrapper = mount(); + + expect(wrapper.find({ name: "ignoreDateRangeCheckbox" }).props().checked).toBe(false); + wrapper.find({ name: "ignoreDateRangeCheckbox" }).simulate('click'); + expect(wrapper.find({ name: "ignoreDateRangeCheckbox" }).props().checked).toBe(true); + }) }); \ No newline at end of file -- GitLab From 7442d0e1e359f955f6b8eaf8db8fc39d628bbcca Mon Sep 17 00:00:00 2001 From: Zafir Rasyidi Taufik Date: Thu, 1 Apr 2021 08:04:17 +0700 Subject: [PATCH 28/51] [REFACTOR] Change test to use component instead of raw HTML --- src/scenes/Home/components/Statistic/index.test.tsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/scenes/Home/components/Statistic/index.test.tsx b/src/scenes/Home/components/Statistic/index.test.tsx index f936b1c..3fa6fa5 100644 --- a/src/scenes/Home/components/Statistic/index.test.tsx +++ b/src/scenes/Home/components/Statistic/index.test.tsx @@ -5,6 +5,7 @@ import Statistic from '.'; import { useMainService } from 'services'; import { AppContext } from 'contexts'; +import { Checkbox } from 'components'; describe('', () => { const testProps = { @@ -114,8 +115,8 @@ describe('', () => { data={statisticData.district} />); - expect(wrapper.find({ name: "ignoreDateRangeCheckbox" }).props().checked).toBe(false); - wrapper.find({ name: "ignoreDateRangeCheckbox" }).simulate('click'); - expect(wrapper.find({ name: "ignoreDateRangeCheckbox" }).props().checked).toBe(true); + expect(wrapper.find(Checkbox).props().isChecked).toBe(false); + wrapper.find(Checkbox).simulate('click'); + expect(wrapper.find(Checkbox).props().isChecked).toBe(true); }) }); \ No newline at end of file -- GitLab From d8497236ee9d0f382822082782da5db7398d87c1 Mon Sep 17 00:00:00 2001 From: Zafir Rasyidi Taufik Date: Thu, 1 Apr 2021 08:04:48 +0700 Subject: [PATCH 29/51] [GREEN] Added checkbox ignoreDateRange --- src/scenes/Home/components/Statistic/index.tsx | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/scenes/Home/components/Statistic/index.tsx b/src/scenes/Home/components/Statistic/index.tsx index 049aab7..625c8ab 100644 --- a/src/scenes/Home/components/Statistic/index.tsx +++ b/src/scenes/Home/components/Statistic/index.tsx @@ -1,5 +1,5 @@ import React, { useContext, useState, useEffect, useCallback } from 'react'; -import { Box, Text, Field, Gap, Button, Table, CategoryButton } from 'components'; +import { Box, Text, Field, Gap, Button, Table, CategoryButton, Checkbox } from 'components'; import { PieChart, Pie, Cell, BarChart, CartesianGrid, XAxis, Tooltip, Legend, YAxis, Bar } from 'recharts'; import { AppContext } from 'contexts'; import { KECAMATAN_VALUES, PIE_COLORS, GENDER_VALUES } from 'constant'; @@ -50,6 +50,7 @@ function Statistic({ total_count:0 }); const [isDateStatistic, setIsDateStatistic] = useState(false); + const [ignoreDateRange, setIgnoreDateRange] = useState(false); const filterExports = async (filterType: StatisticType) => { const response = await services.main.filterExportCSV( @@ -94,6 +95,10 @@ function Statistic({ } }; + const toggleIgnoreDateRange = () => { + setIgnoreDateRange(!ignoreDateRange); + } + useEffect(() => { const tempAgeObject = { positive: 0, @@ -304,6 +309,13 @@ function Statistic({ /> + + { setIgnoreDateRange(value);}} + /> + : -- GitLab From 6e5e0ab217ecc7118f5e67dc0ed5a7c5289e7971 Mon Sep 17 00:00:00 2001 From: Zafir Rasyidi Taufik Date: Thu, 1 Apr 2021 08:07:02 +0700 Subject: [PATCH 30/51] [CHORES] remove unused function --- src/scenes/Home/components/Statistic/index.tsx | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/scenes/Home/components/Statistic/index.tsx b/src/scenes/Home/components/Statistic/index.tsx index 625c8ab..2b0386d 100644 --- a/src/scenes/Home/components/Statistic/index.tsx +++ b/src/scenes/Home/components/Statistic/index.tsx @@ -95,10 +95,6 @@ function Statistic({ } }; - const toggleIgnoreDateRange = () => { - setIgnoreDateRange(!ignoreDateRange); - } - useEffect(() => { const tempAgeObject = { positive: 0, -- GitLab From fa198c1564cac50591cdd09f266511816607b7b9 Mon Sep 17 00:00:00 2001 From: Zafir Rasyidi Taufik Date: Thu, 1 Apr 2021 08:17:01 +0700 Subject: [PATCH 31/51] [CHORES] Add ignore date range check in fetchStatisticsByDate --- src/scenes/Home/components/Statistic/index.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/scenes/Home/components/Statistic/index.tsx b/src/scenes/Home/components/Statistic/index.tsx index 2b0386d..162f9ac 100644 --- a/src/scenes/Home/components/Statistic/index.tsx +++ b/src/scenes/Home/components/Statistic/index.tsx @@ -85,8 +85,8 @@ function Statistic({ }; const fetchStatisticsByDate = async () => { - const start_date = dateKey.start_date.toISOString().split('T')[0]; - const end_date = dateKey.end_date.toISOString().split('T')[0]; + const start_date = (ignoreDateRange) ? "0010-01-01" : dateKey.start_date.toISOString().split('T')[0]; + const end_date = (ignoreDateRange) ? "9990-12-31" : dateKey.end_date.toISOString().split('T')[0]; const response = await services.main.fetchStatisticsByDate(start_date, end_date); if (response.status === 200) { @@ -158,7 +158,7 @@ function Statistic({ useEffect(() => { fetchStatisticsByDate(); setIsDateStatistic(true); - }, [dateKey]); + }, [dateKey, ignoreDateRange]); const renderChart = () => { if(isDateStatistic) { -- GitLab From c2478d2d3523287ad06eebaaadd4aa4251b29ebe Mon Sep 17 00:00:00 2001 From: Zafir Rasyidi Taufik Date: Thu, 1 Apr 2021 08:28:36 +0700 Subject: [PATCH 32/51] [CHORES] Add case if 0 total no diagram is rendered --- src/scenes/Home/components/Statistic/index.tsx | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/scenes/Home/components/Statistic/index.tsx b/src/scenes/Home/components/Statistic/index.tsx index 162f9ac..6aacbc9 100644 --- a/src/scenes/Home/components/Statistic/index.tsx +++ b/src/scenes/Home/components/Statistic/index.tsx @@ -165,9 +165,16 @@ function Statistic({ const values = Object.values(statisticsDateData['district']); const keys = Object.keys(statisticsDateData['district']); let res: Array = []; + let sum: number = 0; keys.forEach((element, index) => { res.push(Object.assign({"name": keys[index]}, values[index])); + sum += values[index]["total_count"]; }) + if(sum === 0) { + return ( + {`Belum ada kasus untuk ${type.toLowerCase()} ini`} + ) + } return ( Date: Thu, 1 Apr 2021 11:36:29 +0700 Subject: [PATCH 33/51] [CHORES] Prevent button export csv in diagram page, vice versa --- .../Home/components/Statistic/index.tsx | 2 +- src/scenes/Home/index.tsx | 69 +++++++++++-------- 2 files changed, 42 insertions(+), 29 deletions(-) diff --git a/src/scenes/Home/components/Statistic/index.tsx b/src/scenes/Home/components/Statistic/index.tsx index 6aacbc9..aa7a054 100644 --- a/src/scenes/Home/components/Statistic/index.tsx +++ b/src/scenes/Home/components/Statistic/index.tsx @@ -186,7 +186,7 @@ function Statistic({ > - + (Math.ceil(dataMax * 1.5))]} allowDataOverflow={true}/> diff --git a/src/scenes/Home/index.tsx b/src/scenes/Home/index.tsx index e2dccf7..7053fc4 100644 --- a/src/scenes/Home/index.tsx +++ b/src/scenes/Home/index.tsx @@ -76,16 +76,22 @@ function Home() { onClick={setStatisticType} /> - - - + {statisticType + ? + + + + : + <> + + } - - - Export diagram Keseluruhan Kasus - - - - - + {!statisticType ? + <> + + + Export diagram Keseluruhan Kasus + + + + + + + : + <> + + } Date: Thu, 1 Apr 2021 12:45:30 +0700 Subject: [PATCH 34/51] [CHORES] UI Redesign --- .../Home/components/Statistic/index.tsx | 268 +++++++++--------- src/scenes/Home/index.tsx | 22 +- 2 files changed, 148 insertions(+), 142 deletions(-) diff --git a/src/scenes/Home/components/Statistic/index.tsx b/src/scenes/Home/components/Statistic/index.tsx index aa7a054..5f20536 100644 --- a/src/scenes/Home/components/Statistic/index.tsx +++ b/src/scenes/Home/components/Statistic/index.tsx @@ -177,7 +177,7 @@ function Statistic({ } return ( - + (Math.ceil(dataMax * 1.5))]} allowDataOverflow={true}/> @@ -244,153 +244,159 @@ function Statistic({ if (!isTable) { return ( <> - { - type === StatisticType.Age ? - <> - - { - setAgeKey({ ...ageKey, minAge: val }); - }} - /> - - { - setAgeKey({ ...ageKey, maxAge: val }); - }} - /> - - - - - - {`${type}: ${ageKey.minAge} s/d ${ageKey.maxAge} tahun`} - - - - - - - - : - (type === StatisticType.Date) ? + + + { + type === StatisticType.Age ? <> - + { - setDateKey({ ...dateKey, start_date: val }); + setAgeKey({ ...ageKey, minAge: val }); }} /> { - setDateKey({ ...dateKey, end_date: val }); + setAgeKey({ ...ageKey, maxAge: val }); }} /> - - { setIgnoreDateRange(value);}} - /> + + + + {`${type}: ${ageKey.minAge} s/d ${ageKey.maxAge} tahun`} + + + + + - : - - - - - - {`${type}: ${translate(selectedKey)}`} - - - + + - - } - - { - (!isDateStatistic) ? - ((selectedKeyData[3]?.total_count === 0) ? - {`Belum ada kasus untuk ${type.toLowerCase()} ini`} + } + + + + { + (!isDateStatistic) ? + ((selectedKeyData[3]?.total_count === 0) ? + {`Belum ada kasus untuk ${type.toLowerCase()} ini`} + : + <> + + {renderChart()} + + {`Total: ${selectedKeyData[3]?.total_count} kasus`} + + + ) : - <> - - {renderChart()} - - {`Total: ${selectedKeyData[3]?.total_count} kasus`} - - - ) - : - <> - {renderChart()} - - - - } + <> + {renderChart()} + + + + } + + ); } diff --git a/src/scenes/Home/index.tsx b/src/scenes/Home/index.tsx index 7053fc4..8330385 100644 --- a/src/scenes/Home/index.tsx +++ b/src/scenes/Home/index.tsx @@ -98,12 +98,12 @@ function Home() { padding="24px 24px" borderRadius="3px" background={colors.totallyWhite} - axis={statisticType ? Box.Axis.Vertical : Box.Axis.Horizontal} + axis={Box.Axis.Vertical} > {!statisticType ? <> @@ -117,8 +117,8 @@ function Home() { /> : @@ -126,7 +126,7 @@ function Home() { } @@ -140,11 +140,11 @@ function Home() { /> @@ -158,11 +158,11 @@ function Home() { /> -- GitLab From c996e4077d28035a6f97a4539cda7f2b162a760f Mon Sep 17 00:00:00 2001 From: Zafir Rasyidi Taufik Date: Thu, 1 Apr 2021 15:49:44 +0700 Subject: [PATCH 35/51] [CHORES] Sort kasus keseluruhan data by total_count --- src/scenes/Home/components/Statistic/index.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/scenes/Home/components/Statistic/index.tsx b/src/scenes/Home/components/Statistic/index.tsx index 5f20536..cb5f4f7 100644 --- a/src/scenes/Home/components/Statistic/index.tsx +++ b/src/scenes/Home/components/Statistic/index.tsx @@ -169,7 +169,9 @@ function Statistic({ keys.forEach((element, index) => { res.push(Object.assign({"name": keys[index]}, values[index])); sum += values[index]["total_count"]; - }) + }); + res.sort(function(a: any, b: any){return a['total_count'] - b['total_count']}); + res.reverse(); if(sum === 0) { return ( {`Belum ada kasus untuk ${type.toLowerCase()} ini`} -- GitLab From 80c3b7c6fa2d918e6b847ef8a9016a15a8ace3ee Mon Sep 17 00:00:00 2001 From: Zafir Rasyidi Taufik Date: Thu, 1 Apr 2021 15:51:52 +0700 Subject: [PATCH 36/51] [CHORES] Add legend to kasus sekeluruhan diagram and tidy pie diagrams --- src/scenes/Home/components/Statistic/index.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/scenes/Home/components/Statistic/index.tsx b/src/scenes/Home/components/Statistic/index.tsx index cb5f4f7..6b1ceff 100644 --- a/src/scenes/Home/components/Statistic/index.tsx +++ b/src/scenes/Home/components/Statistic/index.tsx @@ -190,6 +190,7 @@ function Statistic({ (Math.ceil(dataMax * 1.5))]} allowDataOverflow={true}/> + @@ -203,7 +204,7 @@ function Statistic({ activeIndex={activeIndex} activeShape={renderActiveShape} data={selectedKeyData} - cx={200} + cx={210} cy={120} innerRadius={60} outerRadius={80} -- GitLab From 74044df4744a3c279ad932eec53ed2bd335a5814 Mon Sep 17 00:00:00 2001 From: Zafir Rasyidi Taufik Date: Fri, 2 Apr 2021 22:21:43 +0700 Subject: [PATCH 37/51] [CHORES] Fix bug when downloading PDF --- .../Home/components/ExportPDFButton/index.tsx | 2 +- .../Home/components/Statistic/index.tsx | 10 ++++-- src/scenes/Home/utilities/utils.tsx | 34 +++++++++++++++++-- 3 files changed, 39 insertions(+), 7 deletions(-) diff --git a/src/scenes/Home/components/ExportPDFButton/index.tsx b/src/scenes/Home/components/ExportPDFButton/index.tsx index 04cc316..9e4201d 100644 --- a/src/scenes/Home/components/ExportPDFButton/index.tsx +++ b/src/scenes/Home/components/ExportPDFButton/index.tsx @@ -13,7 +13,7 @@ function ExportPDFButton({ png, type, selectedKey, clickable }: ExportPDFButtonProps) { const handleDownload = React.useCallback(async () => { - downloadAsPDF(png, type, selectedKey).save("bebas.pdf"); + downloadAsPDF(png, type, selectedKey); }, [png]); return ( a + (b['total_count'] || 0), 0) !== 0} /> @@ -424,7 +424,9 @@ function Statistic({ ]} onClick={setChartType} /> - {renderChart()} +
+ {renderChart()} +
- {renderChart()} +
+ {renderChart()} +
{ ); }; +const blobToImage = (blob: Blob) => { + return new Promise(resolve => { + const url = URL.createObjectURL(blob) + let img = new Image() + img.onload = () => { + URL.revokeObjectURL(url) + resolve(img) + } + img.src = url + }) +} + const image2pdf = (image: string, imageType: string, type: string, key: string) => { const imgWidth = 252; const imgHeight = 156; @@ -84,12 +96,28 @@ const image2pdf = (image: string, imageType: string, type: string, key: string) doc.setFontSize(40); doc.text(type + " " + key, 145, 25, {align:"center"}); - doc.addImage(image, imageType, marginX, marginY, 252, 156, undefined, "SLOW"); - return doc; + + let svg: Element = document.getElementById(type)?.children[0]?.children[0]!; + svg.setAttribute("width", "952"); + svg.setAttribute("height", "589"); + svg.setAttribute("viewBox", "0 0 952 589"); + svg.setAttribute("preserveAspectRatio", "xMidYMid meet"); + let svgURL = new XMLSerializer().serializeToString(svg); + let svgBlob = new Blob([svgURL], { type: "image/svg+xml;charset=utf-8" }); + blobToImage(svgBlob).then(img => { + let canvas = document.createElement('canvas'); + canvas.width = 952; + canvas.height = 589; + let context = canvas.getContext('2d')!; + context.drawImage(img, 0, 0, context.canvas.width, context.canvas.height); + let png = canvas.toDataURL('image/png', 1.0); + doc.addImage(png, imageType, marginX, marginY, 252, 156, undefined, "SLOW"); + doc.save("bebas.pdf"); + }); }; const downloadAsPDF = (png: string, type: string, selectedKey: string) => { - return image2pdf(png, "PNG", type, translate(selectedKey)); + image2pdf(png, "PNG", type, translate(selectedKey)); } export { translate, renderActiveShape, image2pdf, downloadAsPDF }; \ No newline at end of file -- GitLab From 37ccfceebdc8dc29b33c1448d4de42d8d335ad30 Mon Sep 17 00:00:00 2001 From: Zafir Rasyidi Taufik Date: Fri, 2 Apr 2021 22:45:52 +0700 Subject: [PATCH 38/51] [CHORES] Use clone of element instead of actual element (deep copy) --- src/scenes/Home/utilities/utils.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/scenes/Home/utilities/utils.tsx b/src/scenes/Home/utilities/utils.tsx index 8c88c85..f707048 100644 --- a/src/scenes/Home/utilities/utils.tsx +++ b/src/scenes/Home/utilities/utils.tsx @@ -97,10 +97,9 @@ const image2pdf = (image: string, imageType: string, type: string, key: string) doc.setFontSize(40); doc.text(type + " " + key, 145, 25, {align:"center"}); - let svg: Element = document.getElementById(type)?.children[0]?.children[0]!; + let svg: Element = document.getElementById(type)?.children[0]?.children[0].cloneNode(true)! as Element; svg.setAttribute("width", "952"); svg.setAttribute("height", "589"); - svg.setAttribute("viewBox", "0 0 952 589"); svg.setAttribute("preserveAspectRatio", "xMidYMid meet"); let svgURL = new XMLSerializer().serializeToString(svg); let svgBlob = new Blob([svgURL], { type: "image/svg+xml;charset=utf-8" }); -- GitLab From 11b56c95bc49cf6ecce4b217fab344e49791d7d8 Mon Sep 17 00:00:00 2001 From: Zafir Rasyidi Taufik Date: Fri, 2 Apr 2021 23:39:16 +0700 Subject: [PATCH 39/51] [CHORES] Remove recharts-to-png and unused variables --- package-lock.json | 13 ++++--------- package.json | 1 - .../Home/components/ExportPDFButton/index.tsx | 7 +++---- src/scenes/Home/components/Statistic/index.tsx | 16 ++++------------ src/scenes/Home/utilities/utils.tsx | 6 +++--- 5 files changed, 14 insertions(+), 29 deletions(-) diff --git a/package-lock.json b/package-lock.json index 7b48d23..92863e9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3157,7 +3157,8 @@ "base64-arraybuffer": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/base64-arraybuffer/-/base64-arraybuffer-0.2.0.tgz", - "integrity": "sha512-7emyCsu1/xiBXgQZrscw/8KPRT44I4Yq9Pe6EGs3aPRTsWuggML1/1DTuZUuIaJPIm1FTDUVXl4x/yW8s0kQDQ==" + "integrity": "sha512-7emyCsu1/xiBXgQZrscw/8KPRT44I4Yq9Pe6EGs3aPRTsWuggML1/1DTuZUuIaJPIm1FTDUVXl4x/yW8s0kQDQ==", + "optional": true }, "base64-js": { "version": "1.3.1", @@ -4287,6 +4288,7 @@ "version": "1.1.1", "resolved": "https://registry.npmjs.org/css-line-break/-/css-line-break-1.1.1.tgz", "integrity": "sha512-1feNVaM4Fyzdj4mKPIQNL2n70MmuYzAXZ1aytlROFX1JsOo070OsugwGjj7nl6jnDJWHDM8zRZswkmeYVWZJQA==", + "optional": true, "requires": { "base64-arraybuffer": "^0.2.0" } @@ -7063,6 +7065,7 @@ "version": "1.0.0-rc.7", "resolved": "https://registry.npmjs.org/html2canvas/-/html2canvas-1.0.0-rc.7.tgz", "integrity": "sha512-yvPNZGejB2KOyKleZspjK/NruXVQuowu8NnV2HYG7gW7ytzl+umffbtUI62v2dCHQLDdsK6HIDtyJZ0W3neerA==", + "optional": true, "requires": { "css-line-break": "1.1.1" } @@ -13227,14 +13230,6 @@ "decimal.js-light": "^2.4.1" } }, - "recharts-to-png": { - "version": "0.8.2", - "resolved": "https://registry.npmjs.org/recharts-to-png/-/recharts-to-png-0.8.2.tgz", - "integrity": "sha512-iK25a0H/KW0rlxUKtUQyGdiiqEUF8lh6B2naO8pki6yf6sZgLhVayy753a0b3bzjnzlK+spQQ2o7XBsqQH/3Jw==", - "requires": { - "html2canvas": "^1.0.0-rc.0" - } - }, "recursive-readdir": { "version": "2.2.2", "resolved": "https://registry.npmjs.org/recursive-readdir/-/recursive-readdir-2.2.2.tgz", diff --git a/package.json b/package.json index 2873840..8fc7f4f 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,6 @@ "react-scripts": "^3.4.0", "react-test-renderer": "^16.13.1", "recharts": "^1.8.5", - "recharts-to-png": "^0.8.2", "semantic-ui-css": "^2.4.1", "semantic-ui-react": "^0.88.2", "styled-components": "^5.1.0", diff --git a/src/scenes/Home/components/ExportPDFButton/index.tsx b/src/scenes/Home/components/ExportPDFButton/index.tsx index 9e4201d..1eeb0ca 100644 --- a/src/scenes/Home/components/ExportPDFButton/index.tsx +++ b/src/scenes/Home/components/ExportPDFButton/index.tsx @@ -3,18 +3,17 @@ import { Box, Button } from 'components'; import { downloadAsPDF } from 'scenes/Home/utilities/utils'; interface ExportPDFButtonProps { - png: string, type: string, selectedKey: string, clickable: boolean, } function ExportPDFButton({ - png, type, selectedKey, clickable + type, selectedKey, clickable }: ExportPDFButtonProps) { const handleDownload = React.useCallback(async () => { - downloadAsPDF(png, type, selectedKey); - }, [png]); + downloadAsPDF(type, selectedKey); + }, []); return ( (false); const [ignoreDateRange, setIgnoreDateRange] = useState(false); - const [png, ref] = useRechartToPng(); - const generateFilter = (filterType: StatisticType) => { switch(filterType) { case StatisticType.Age: @@ -221,7 +218,7 @@ function Statistic({ } if (chartType) { return ( - + a + (b['total_count'] || 0), 0) !== 0} @@ -397,7 +391,6 @@ function Statistic({ /> { }) } -const image2pdf = (image: string, imageType: string, type: string, key: string) => { +const image2pdf = (imageType: string, type: string, key: string) => { const imgWidth = 252; const imgHeight = 156; const pageWidth = 297; @@ -115,8 +115,8 @@ const image2pdf = (image: string, imageType: string, type: string, key: string) }); }; -const downloadAsPDF = (png: string, type: string, selectedKey: string) => { - image2pdf(png, "PNG", type, translate(selectedKey)); +const downloadAsPDF = (type: string, selectedKey: string) => { + image2pdf("PNG", type, translate(selectedKey)); } export { translate, renderActiveShape, image2pdf, downloadAsPDF }; \ No newline at end of file -- GitLab From 14c3e0fa35805d9b52a532206751db6a79f9eaf3 Mon Sep 17 00:00:00 2001 From: Zafir Rasyidi Taufik Date: Sat, 3 Apr 2021 11:53:41 +0700 Subject: [PATCH 40/51] [CHORES] Fix title not showing and remove unused variables --- src/scenes/Home/components/ExportPDFButton/index.tsx | 4 ++-- src/scenes/Home/components/Statistic/index.tsx | 2 +- src/scenes/Home/index.tsx | 2 -- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/scenes/Home/components/ExportPDFButton/index.tsx b/src/scenes/Home/components/ExportPDFButton/index.tsx index 1eeb0ca..2e2a87a 100644 --- a/src/scenes/Home/components/ExportPDFButton/index.tsx +++ b/src/scenes/Home/components/ExportPDFButton/index.tsx @@ -11,7 +11,7 @@ interface ExportPDFButtonProps { function ExportPDFButton({ type, selectedKey, clickable }: ExportPDFButtonProps) { - const handleDownload = React.useCallback(async () => { + const handleDownload = React.useCallback(async (type: string, selectedKey: string) => { downloadAsPDF(type, selectedKey); }, []); return ( @@ -23,7 +23,7 @@ function ExportPDFButton({ > + value={caseForm.fields.district.value || defaultDistrict} + values={KECAMATAN_VALUES} + updateValue={handleDistrictChange} + /> + + + + setCheckDate(value)} + information={isFirstTime || checkDate ? '' : 'Tanggal pemeriksaan tidak boleh kosong'} + /> + + + setCaseFormField('checkResult', value)} + /> + + + + +
- ); + ); } \ No newline at end of file -- GitLab From cccc77d0ed324db88187c1c0c3dfdacd89421aa3 Mon Sep 17 00:00:00 2001 From: Inigo Ramli Date: Sun, 25 Apr 2021 19:26:06 +0700 Subject: [PATCH 51/51] [GREEN] Fix implementation error --- .../components/AddAccountForm/index.test.tsx | 5 +++-- .../AccountManagement/components/AddAccountForm/index.tsx | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/scenes/AccountManagement/components/AddAccountForm/index.test.tsx b/src/scenes/AccountManagement/components/AddAccountForm/index.test.tsx index 9a30fcc..ea0155f 100644 --- a/src/scenes/AccountManagement/components/AddAccountForm/index.test.tsx +++ b/src/scenes/AccountManagement/components/AddAccountForm/index.test.tsx @@ -8,6 +8,7 @@ import axios from 'axios'; import { useMainService } from 'services'; import { AppContext } from 'contexts'; import AddAccountForm from '.'; +import { KECAMATAN_VALUES, KELURAHAN_VALUES } from 'constant'; const testProps = { services: { @@ -113,8 +114,8 @@ describe('AddNewAccountForm', () => { expect(passwordField.props.value).toEqual(''); expect(emailField.props.value).toEqual(''); expect(phoneField.props.value).toEqual(''); - expect(districtField.props.value).toEqual(''); - expect(subdistrictField.props.value).toEqual(''); + expect(districtField.props.value).toEqual(KECAMATAN_VALUES[0].value); + expect(subdistrictField.props.value).toEqual(KELURAHAN_VALUES[KECAMATAN_VALUES[0].value][0].value); }); diff --git a/src/scenes/AccountManagement/components/AddAccountForm/index.tsx b/src/scenes/AccountManagement/components/AddAccountForm/index.tsx index a22f1ae..ba6838e 100644 --- a/src/scenes/AccountManagement/components/AddAccountForm/index.tsx +++ b/src/scenes/AccountManagement/components/AddAccountForm/index.tsx @@ -112,7 +112,7 @@ export default function AddAccountForm(props: AddAccountFormProps) {
); - // resetFields(); + resetFields(); setErrors(getInitialFields()); setShowPassword(false); } else { -- GitLab