- 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 React, {useEffect, useState} from "react";
|
||||||
import {fetchFilterData} from "../../utils/RenderTemplate";
|
import {fetchFilterData} from "../../utils/RenderTemplate";
|
||||||
import {DeleteFilled} from "@ant-design/icons";
|
import {DeleteFilled} from "@ant-design/icons";
|
||||||
import {useTranslation} from "react-i18next";
|
import {useTranslation} from "react-i18next";
|
||||||
import {getOperatorsByType} from "../../utils/graphQLmodifier";
|
import {getOperatorsByType} from "../../utils/graphQLmodifier";
|
||||||
|
import LoadingSkeleton from "../loading-skeleton/loading-skeleton.component";
|
||||||
|
|
||||||
export default function ReportCenterModalFiltersSortersComponent({form}) {
|
export default function ReportCenterModalFiltersSortersComponent({form}) {
|
||||||
return (
|
return (
|
||||||
@@ -19,16 +20,19 @@ export default function ReportCenterModalFiltersSortersComponent({form}) {
|
|||||||
function RenderFilters({templateId, form}) {
|
function RenderFilters({templateId, form}) {
|
||||||
const [state, setState] = useState(null);
|
const [state, setState] = useState(null);
|
||||||
const [visible, setVisible] = useState(false);
|
const [visible, setVisible] = useState(false);
|
||||||
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
const {t} = useTranslation();
|
const {t} = useTranslation();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetch = async () => {
|
const fetch = async () => {
|
||||||
|
setIsLoading(true);
|
||||||
const data = await fetchFilterData({name: templateId});
|
const data = await fetchFilterData({name: templateId});
|
||||||
if (data?.success) {
|
if (data?.success) {
|
||||||
setState(data.data);
|
setState(data.data);
|
||||||
} else {
|
} else {
|
||||||
setState(null);
|
setState(null);
|
||||||
}
|
}
|
||||||
|
setIsLoading(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
if (templateId) {
|
if (templateId) {
|
||||||
@@ -37,11 +41,20 @@ function RenderFilters({templateId, form}) {
|
|||||||
}, [templateId]);
|
}, [templateId]);
|
||||||
|
|
||||||
|
|
||||||
if (!templateId || !state) return null;
|
// Conditional display of filters and sorters
|
||||||
return (
|
if (!templateId) return null;
|
||||||
<Card title={t('reportcenter.labels.advanced_filters')} style={{marginTop: '10px'}}>
|
if (isLoading) return <LoadingSkeleton/>;
|
||||||
<Button type='primary' style={{width: '100%'}} onClick={() => setVisible(!visible)}>{visible ? t('reportcenter.labels.advanced_filters_hide') : t('reportcenter.labels.advanced_filters_show')}</Button>
|
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 && (
|
{visible && (
|
||||||
<div>
|
<div>
|
||||||
{state.filters && state.filters.length > 0 && (
|
{state.filters && state.filters.length > 0 && (
|
||||||
@@ -256,6 +269,6 @@ function RenderFilters({templateId, form}) {
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</Card>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user