Fakultas Ilmu Komputer UI

Commit 14cd1273 authored by Sean Zeliq Urian's avatar Sean Zeliq Urian
Browse files

Merge branch 'sean/tampilan-tabel-statistik-kasus' into 'pbi-10-tabel-statistik-kasus'

Filter by date for excel and csv for table data

See merge request !31
parents 50edcfc1 ff933ba4
Pipeline #76959 passed with stages
in 9 minutes and 19 seconds
......@@ -107,4 +107,6 @@ export enum StatisticType {
export interface ExportPayload {
filterType: StatisticType;
filters: AgeKeyProps | SexKeyProps | DistrictKeyProps | SubDistrictKeyProps;
start_date: string;
end_date: string;
}
\ No newline at end of file
......@@ -5,7 +5,7 @@ import { AppContext } from 'contexts';
import { KECAMATAN_VALUES, KELURAHAN_VALUES, PIE_COLORS, GENDER_VALUES } from 'constant';
import { renderActiveShape, translate, translateTypetoKey } from 'scenes/Home/utilities/utils';
import {
Exportables, ExportableValue, StatisticType, AgeKeyProps, DateProps
Exportables, ExportableValue, StatisticType, AgeKeyProps, DateProps, ExportPayload
} from 'contexts/AppContext/types';
import ExportPDFButton from '../ExportPDFButton';
import { StatisticData } from '../types';
......@@ -63,33 +63,49 @@ function Statistic({
const [ignoreDateRangeTable, setIgnoreDateRangeTable] = useState<boolean>(true);
const generateFilter = (filterType: StatisticType) => {
var data = {} as ExportPayload;
var start_date_Table = (ignoreDateRangeTable) ? "0010-01-01" : (new Date(dateKeyTable.start_date.valueOf() + 1000 * 3600 * 24)).toISOString().split('T')[0];
var end_date_Table = (ignoreDateRangeTable) ? "9990-12-31" : (new Date(dateKeyTable.end_date.valueOf() + 1000 * 3600 * 24)).toISOString().split('T')[0];
switch (filterType) {
case StatisticType.Age:
return {
data = {
filterType: filterType,
filters: isTable ?
{
minAge: pagedData[0][0],
maxAge: pagedData[0][0]
maxAge: pagedData[pagedData.length-1][0]
} : ageKey,
start_date: isTable ? start_date_Table : "",
end_date: isTable ? end_date_Table : ""
}
break;
case StatisticType.District:
return {
data = {
filterType: filterType,
filters: { district: isTable ? translate(pagedData[0][0]) : selectedKey },
filters: { district: (isTable ? translate(pagedData[0][0]) : selectedKey) },
start_date: isTable ? start_date_Table : "",
end_date: isTable ? end_date_Table : ""
}
break;
case StatisticType.SubDistrict:
console.log(pagedData[0][0])
return {
data = {
filterType: filterType,
filters: { subdistrict: isTable ? translate(pagedData[0][0]) : selectedKey },
start_date: isTable ? start_date_Table : "",
end_date: isTable ? end_date_Table : ""
}
break;
case StatisticType.Sex:
return {
data = {
filterType: filterType,
filters: { isMale: isTable ? translate(pagedData[0][0]) === "male" : selectedKey }
filters: { isMale: (isTable ? (translate(pagedData[0][0]) === "male") : selectedKey === "male") },
start_date: isTable ? start_date_Table : "",
end_date: isTable ? end_date_Table : ""
}
break;
}
return data;
}
const filterExportsCSV = async (type: StatisticType) => {
......@@ -557,9 +573,17 @@ function Statistic({
onChange={async (searchVal: string, page: number) => {
let tempData = [];
if (searchVal) {
tempData = tableData.filter(
(val) => val[0].toLowerCase() === searchVal.toLowerCase()
);
if(type === StatisticType.Age && searchVal.toLowerCase().split("&", 2).length > 1) {
tempData = tableData.filter(
(val) => parseInt(searchVal.toLowerCase().split("&", 2)[0]) <= parseInt(val[0].toLowerCase())
&& parseInt(val[0].toLowerCase()) <= parseInt(searchVal.toLowerCase().split("&", 2)[1])
);
}
else {
tempData = tableData.filter(
(val) => val[0].toLowerCase() === searchVal.toLowerCase()
);
}
} else {
const index = (page - 1) * 10;
tempData = tableData.slice(index, index + 10);
......@@ -620,13 +644,17 @@ function Statistic({
<ExportCSVButton
onClick={() => filterExportsCSV(type)}
clickable={
pagedData.length === 1 && parseInt(pagedData[0][4], 10) !== 0
(type === StatisticType.Age ?
(pagedData.length >= 1 && parseInt(pagedData[0][4], 10) !== 0) :
(pagedData.length === 1 && parseInt(pagedData[0][4], 10) !== 0))
} />
<Gap axis={Gap.Axis.Vertical} gap={5} />
<ExportXLSButton
onClick={() => filterExportsXLS(type)}
clickable={
pagedData.length === 1 && parseInt(pagedData[0][4], 10) !== 0
(type === StatisticType.Age ?
(pagedData.length >= 1 && parseInt(pagedData[0][4], 10) !== 0) :
(pagedData.length === 1 && parseInt(pagedData[0][4], 10) !== 0))
}
/>
</Box>
......
......@@ -55,7 +55,7 @@ function Home() {
const url = window.URL.createObjectURL(new Blob([response.data]));
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', 'Data Kasus Keseluruhan.xls');
link.setAttribute('download', 'Data Kasus Keseluruhan.xlsx');
document.body.appendChild(link);
link.click();
}
......
......@@ -280,6 +280,11 @@ export default function useMainService(token: string) {
const ageKey = filter.filters as AgeKeyProps;
urlQuery= `?min_age=${ageKey.minAge}&max_age=${ageKey.maxAge}`;
}
if (filter.start_date !== "" && filter.end_date !== "") {
urlQuery+= `&start_date=${filter.start_date}&end_date=${filter.end_date}`
}
const endpoint = END_POINTS.EXPORTABLES([`investigation-cases-csv${urlQuery}`]);
return downloadWithAuthentication(endpoint.slice(0, -1), Method.GET);
}
......@@ -305,6 +310,11 @@ export default function useMainService(token: string) {
const ageKey = filter.filters as AgeKeyProps;
urlQuery= `?min_age=${ageKey.minAge}&max_age=${ageKey.maxAge}`;
}
if (filter.start_date !== "" && filter.end_date !== "") {
urlQuery+= `&start_date=${filter.start_date}&end_date=${filter.end_date}`
}
const endpoint = END_POINTS.EXPORTABLES([`investigation-cases-csv${urlQuery}&download_as_xls=1`]);
return downloadWithAuthentication(endpoint.slice(0, -1), Method.GET);
}
......@@ -328,7 +338,7 @@ export default function useMainService(token: string) {
async function fetchStatisticsByDate(
start_date: string, end_date: string
) {
let urlQuery = `?start-date=${start_date}&end-date=${end_date}`;
let urlQuery = `?start_date=${start_date}&end_date=${end_date}`;
const endpoint = END_POINTS.EXPORTABLES([`${urlQuery}`]);
return fetchWithAuthentication(endpoint.slice(0, -1), Method.GET);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment