- Update GUI and provide loading state
Signed-off-by: Dave Richer <dave@imexsystems.ca>
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
import {Button, Card, Col, Form, Input, InputNumber, Row, Select} from "antd";
|
||||
import {Button, Card, Checkbox, Col, Form, Input, InputNumber, Row, Select} from "antd";
|
||||
import React, {useEffect, useState} from "react";
|
||||
import {fetchFilterData} from "../../utils/RenderTemplate";
|
||||
import {DeleteFilled} from "@ant-design/icons";
|
||||
import {useTranslation} from "react-i18next";
|
||||
import {getOperatorsByType} from "../../utils/graphQLmodifier";
|
||||
import LoadingSkeleton from "../loading-skeleton/loading-skeleton.component";
|
||||
|
||||
export default function ReportCenterModalFiltersSortersComponent({form}) {
|
||||
return (
|
||||
@@ -19,16 +20,19 @@ export default function ReportCenterModalFiltersSortersComponent({form}) {
|
||||
function RenderFilters({templateId, form}) {
|
||||
const [state, setState] = useState(null);
|
||||
const [visible, setVisible] = useState(false);
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const {t} = useTranslation();
|
||||
|
||||
useEffect(() => {
|
||||
const fetch = async () => {
|
||||
setIsLoading(true);
|
||||
const data = await fetchFilterData({name: templateId});
|
||||
if (data?.success) {
|
||||
setState(data.data);
|
||||
} else {
|
||||
setState(null);
|
||||
}
|
||||
setIsLoading(false);
|
||||
};
|
||||
|
||||
if (templateId) {
|
||||
@@ -37,11 +41,20 @@ function RenderFilters({templateId, form}) {
|
||||
}, [templateId]);
|
||||
|
||||
|
||||
if (!templateId || !state) return null;
|
||||
return (
|
||||
<Card title={t('reportcenter.labels.advanced_filters')} style={{marginTop: '10px'}}>
|
||||
<Button type='primary' style={{width: '100%'}} onClick={() => setVisible(!visible)}>{visible ? t('reportcenter.labels.advanced_filters_hide') : t('reportcenter.labels.advanced_filters_show')}</Button>
|
||||
// Conditional display of filters and sorters
|
||||
if (!templateId) return null;
|
||||
if (isLoading) return <LoadingSkeleton/>;
|
||||
if (!state) return null;
|
||||
|
||||
// Filters and Sorters data available
|
||||
return (
|
||||
<div style={{marginTop: '10px'}}>
|
||||
<Checkbox
|
||||
style={{width: '100%'}}
|
||||
checked={visible}
|
||||
onChange={(e) => setVisible(e.target.checked)}
|
||||
children={t('reportcenter.labels.advanced_filters')}
|
||||
/>
|
||||
{visible && (
|
||||
<div>
|
||||
{state.filters && state.filters.length > 0 && (
|
||||
@@ -256,6 +269,6 @@ function RenderFilters({templateId, form}) {
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user