Skip to content

Commit 44c9d8d

Browse files
committed
changes for mali - data extract
1 parent 288f7c0 commit 44c9d8d

File tree

3 files changed

+55
-17
lines changed

3 files changed

+55
-17
lines changed

src/features/dataExtracts/DataExtract.tsx

+43-15
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,17 @@ import { PageableModel } from '../../api/providers';
66
import { PlanModel } from '../plan/providers/types';
77
import Select from 'react-select';
88
import { Button, Col, Container, Form, FormGroup, Row } from 'react-bootstrap';
9-
import { getDataExtract } from './api';
9+
import { getDataExtract, getQueryLabels } from './api';
10+
11+
import { DataExtractQueryResponse } from './providers/types';
1012

1113
const DataExtract = () => {
1214
const [planList, setPlanList] = useState<PageableModel<PlanModel>>();
1315
const [selectedPlan, setSelectedPlan] = useState<string>();
16+
const [dataExtractLabels, setDataExtractLabels] = useState<DataExtractQueryResponse[]>();
17+
const [selectedDataExtractLabelId, setSelectedDataExtractLabelId] = useState<string>();
1418
let link = useRef<HTMLAnchorElement>(null);
1519

16-
// const paginationHandler = (size: number, page: number) => {
17-
// loadData(size, page);
18-
// };
19-
//
20-
// const sortHandler = (sortValue: string, direction: boolean) => {
21-
// setCurrentSortDirection(direction);
22-
// setCurrentSortField(sortValue);
23-
// };
24-
2520
const loadData = useCallback((size: number, page: number) => {
2621
getPlanList(size, page, true, '', '', false)
2722
.then(res => setPlanList(res))
@@ -34,18 +29,19 @@ const DataExtract = () => {
3429

3530
const getCSV = useCallback(() => {
3631
const planModel = planList?.content.find(plan => plan.identifier === selectedPlan);
37-
if (planModel) {
38-
getDataExtract(planModel.identifier)
32+
if (planModel && selectedDataExtractLabelId) {
33+
getDataExtract(planModel.identifier, selectedDataExtractLabelId)
3934
.then(res => {
4035
if (link && link.current) {
4136
link.current.href = window.URL.createObjectURL(new Blob([res], { type: 'text/csv;charset=utf-8' }));
4237
link.current.download = 'data-extract.csv';
4338
link.current.click();
4439
}
4540
})
41+
4642
.catch(ex => toast.error(ex));
4743
}
48-
}, [selectedPlan, planList]);
44+
}, [selectedPlan, planList, selectedDataExtractLabelId]);
4945

5046
return (
5147
<Container fluid className="text-center my-4">
@@ -54,12 +50,44 @@ const DataExtract = () => {
5450
<FormGroup style={{ display: 'flex', alignItems: 'center' }}>
5551
<Form.Label style={{ marginRight: '10px' }}>Select Plan</Form.Label>
5652
<Select
53+
styles={{
54+
container: provided => ({
55+
...provided,
56+
width: 800 // Control the width here
57+
})
58+
}}
5759
options={planList?.content.map(plan => new Option(plan.name, plan.identifier))}
58-
onChange={e => setSelectedPlan(e?.value)}
60+
onChange={e => {
61+
setSelectedPlan(e?.value);
62+
if (e?.value != null) {
63+
getQueryLabels(e?.value).then(labels => setDataExtractLabels(labels));
64+
}
65+
}}
5966
/>
6067
</FormGroup>
6168
</Col>
62-
<Col md={1}>{selectedPlan ? <Button onClick={() => getCSV()}>Get CSV</Button> : null}</Col>
69+
<Col md={2}>
70+
{selectedPlan ? (
71+
<FormGroup style={{ display: 'flex', alignItems: 'center' }}>
72+
<Form.Label style={{ marginRight: '10px' }}>Select Extract</Form.Label>
73+
<Select
74+
styles={{
75+
container: provided => ({
76+
...provided,
77+
width: 300 // Control the width here
78+
})
79+
}}
80+
options={dataExtractLabels?.map(
81+
dataExtractLabel => new Option(dataExtractLabel.queryLabel, dataExtractLabel.queryLabel)
82+
)}
83+
onChange={e => setSelectedDataExtractLabelId(e?.value)}
84+
/>
85+
</FormGroup>
86+
) : null}
87+
</Col>
88+
<Col md={1}>
89+
{selectedPlan && selectedDataExtractLabelId ? <Button onClick={() => getCSV()}>Get CSV</Button> : null}
90+
</Col>
6391
</Row>
6492
<a
6593
style={{ display: 'none' }}
+7-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import api from '../../../api/axios';
2+
import { DataExtractQueryResponse } from '../providers/types';
23

3-
export const getDataExtract = async (planIdentifier: string): Promise<File> => {
4-
return await api.get<File>('data-extract/' + planIdentifier).then(res => res.data);
4+
export const getDataExtract = async (planIdentifier: string, queryLabel: string): Promise<File> => {
5+
return await api.get<File>('data-extract/extract/' + planIdentifier + '/' + queryLabel).then(res => res.data);
6+
};
7+
8+
export const getQueryLabels = async (planIdentifier: string): Promise<DataExtractQueryResponse[]> => {
9+
return await api.get<DataExtractQueryResponse[]>('data-extract/queryLabels/' + planIdentifier).then(res => res.data);
510
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export interface DataExtractQueryResponse {
2+
id: string;
3+
planIdentifier: string;
4+
queryLabel: string;
5+
}

0 commit comments

Comments
 (0)