Skip to content

Commit

Permalink
Apply Filter button issue (#1011)
Browse files Browse the repository at this point in the history
Signed-off-by: sudeep <[email protected]>
  • Loading branch information
Sudeep7353 authored Dec 11, 2024
1 parent 012aa72 commit 50b11b9
Show file tree
Hide file tree
Showing 10 changed files with 455 additions and 384 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ function AdminApiKeysList () {
const [totalRecords, setTotalRecords] = useState(0);
const [resetPageNo, setResetPageNo] = useState(false);
const [applyFilter, setApplyFilter] = useState(false);
const [initialRender, setInitialRender] = useState(true);
const [isApplyFilterClicked, setIsApplyFilterClicked] = useState(false);
const [showDeactivatePopup, setShowDeactivatePopup] = useState(false);
const [deactivateRequest, setDeactivateRequest] = useState({});
const [filterAttributes, setFilterAttributes] = useState({
Expand Down Expand Up @@ -70,55 +72,61 @@ function AdminApiKeysList () {
handleMouseClickForDropdown(submenuRef, () => setActionId(-1));
}, [submenuRef]);

useEffect(() => {
const fetch = async () => {
const queryParams = new URLSearchParams();
queryParams.append('sortFieldName', sortFieldName);
queryParams.append('sortType', sortType);
queryParams.append('pageSize', pageSize);
const fetchApiKeysListData = async () => {
const queryParams = new URLSearchParams();
queryParams.append('sortFieldName', sortFieldName);
queryParams.append('sortType', sortType);
queryParams.append('pageSize', pageSize);

//reset page number to 0 if filter applied or page number is out of bounds
const effectivePageNo = resetPageNumber(totalRecords, pageNo, pageSize, resetPageNo);
queryParams.append('pageNo', effectivePageNo);
setResetPageNo(false);
//reset page number to 0 if filter applied or page number is out of bounds
const effectivePageNo = resetPageNumber(totalRecords, pageNo, pageSize, resetPageNo);
queryParams.append('pageNo', effectivePageNo);
setResetPageNo(false);

if (filterAttributes.partnerId) queryParams.append('partnerId', filterAttributes.partnerId);
if (filterAttributes.orgName) queryParams.append('orgName', filterAttributes.orgName);
if (filterAttributes.policyGroupName) queryParams.append('policyGroupName', filterAttributes.policyGroupName);
if (filterAttributes.policyName) queryParams.append('policyName', filterAttributes.policyName);
if (filterAttributes.apiKeyLabel) queryParams.append('apiKeyLabel', filterAttributes.apiKeyLabel);
if (filterAttributes.status) queryParams.append('status', filterAttributes.status);
if (filterAttributes.partnerId) queryParams.append('partnerId', filterAttributes.partnerId);
if (filterAttributes.orgName) queryParams.append('orgName', filterAttributes.orgName);
if (filterAttributes.policyGroupName) queryParams.append('policyGroupName', filterAttributes.policyGroupName);
if (filterAttributes.policyName) queryParams.append('policyName', filterAttributes.policyName);
if (filterAttributes.apiKeyLabel) queryParams.append('apiKeyLabel', filterAttributes.apiKeyLabel);
if (filterAttributes.status) queryParams.append('status', filterAttributes.status);

const url = `${getPartnerManagerUrl('/partners/apikey/search/v2', process.env.NODE_ENV)}?${queryParams.toString()}`;
try {
fetchData ? setTableDataLoaded(false) : setDataLoaded(false);
const response = await HttpService.get(url);
if (response) {
const responseData = response.data;
if (responseData && responseData.response) {
const resData = responseData.response.data;
setTotalRecords(responseData.response.totalResults);
setApiKeysList(resData);
} else {
handleServiceErrors(responseData, setErrorCode, setErrorMsg);
}
const url = `${getPartnerManagerUrl('/partners/apikey/search/v2', process.env.NODE_ENV)}?${queryParams.toString()}`;
try {
fetchData ? setTableDataLoaded(false) : setDataLoaded(false);
const response = await HttpService.get(url);
if (response) {
const responseData = response.data;
if (responseData && responseData.response) {
const resData = responseData.response.data;
setTotalRecords(responseData.response.totalResults);
setApiKeysList(resData);
} else {
setErrorMsg(t('apiKeysList.errorInApiKeysList'));
handleServiceErrors(responseData, setErrorCode, setErrorMsg);
}
fetchData ? setTableDataLoaded(true) : setDataLoaded(true);
setFetchData(false);
} catch (err) {
setFetchData(false);
fetchData ? setTableDataLoaded(true) : setDataLoaded(true);
console.error('Error fetching data:', err);
setErrorMsg(err);
} else {
setErrorMsg(t('apiKeysList.errorInApiKeysList'));
}
fetchData ? setTableDataLoaded(true) : setDataLoaded(true);
setFetchData(false);
} catch (err) {
setFetchData(false);
fetchData ? setTableDataLoaded(true) : setDataLoaded(true);
console.error('Error fetching data:', err);
setErrorMsg(err);
}
}

useEffect(() => {

if (isApplyFilterClicked || initialRender) {
fetchApiKeysListData();
setInitialRender(false);
setIsApplyFilterClicked(false);
}
fetch();
}, [sortFieldName, sortType, pageNo, pageSize, filterAttributes]);
}, [sortFieldName, sortType, pageNo, pageSize, isApplyFilterClicked]);

const onApplyFilter = (updatedfilters) => {
onClickApplyFilter(updatedfilters, setApplyFilter, setResetPageNo, setFetchData, setFilterAttributes);
onClickApplyFilter(updatedfilters, setApplyFilter, setResetPageNo, setFetchData, setFilterAttributes, setIsApplyFilterClicked);
};

const getPaginationValues = (recordsPerPage, pageIndex) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ function AdminOidcClientsList () {
const [totalRecords, setTotalRecords] = useState(0);
const [resetPageNo, setResetPageNo] = useState(false);
const [applyFilter, setApplyFilter] = useState(false);
const [initialRender, setInitialRender] = useState(true);
const [isApplyFilterClicked, setIsApplyFilterClicked] = useState(false);
const [showClientIdPopup, setShowClientIdPopup] = useState(false);
const [currentClient, setCurrentClient] = useState(null);
const [showDeactivatePopup, setShowDeactivatePopup] = useState(false);
Expand Down Expand Up @@ -78,56 +80,62 @@ function AdminOidcClientsList () {
{ id: "action", headerNameKey: 'oidcClientsList.action' }
];

useEffect(() => {
const fetch = async () => {
const queryParams = new URLSearchParams();
queryParams.append('sortFieldName', sortFieldName);
queryParams.append('sortType', sortType);
queryParams.append('pageSize', pageSize);
const fetchOidcClientsListData = async () => {
const queryParams = new URLSearchParams();
queryParams.append('sortFieldName', sortFieldName);
queryParams.append('sortType', sortType);
queryParams.append('pageSize', pageSize);

//reset page number to 0 if filter applied or page number is out of bounds
const effectivePageNo = resetPageNumber(totalRecords, pageNo, pageSize, resetPageNo);
queryParams.append('pageNo', effectivePageNo);
setResetPageNo(false);
//reset page number to 0 if filter applied or page number is out of bounds
const effectivePageNo = resetPageNumber(totalRecords, pageNo, pageSize, resetPageNo);
queryParams.append('pageNo', effectivePageNo);
setResetPageNo(false);

if (filterAttributes.partnerId) queryParams.append('partnerId', filterAttributes.partnerId);
if (filterAttributes.orgName) queryParams.append('orgName', filterAttributes.orgName);
if (filterAttributes.policyGroupName) queryParams.append('policyGroupName', filterAttributes.policyGroupName);
if (filterAttributes.policyName) queryParams.append('policyName', filterAttributes.policyName);
if (filterAttributes.clientNameEng) queryParams.append('clientName', filterAttributes.clientNameEng);
if (filterAttributes.status) queryParams.append('status', filterAttributes.status);
if (filterAttributes.partnerId) queryParams.append('partnerId', filterAttributes.partnerId);
if (filterAttributes.orgName) queryParams.append('orgName', filterAttributes.orgName);
if (filterAttributes.policyGroupName) queryParams.append('policyGroupName', filterAttributes.policyGroupName);
if (filterAttributes.policyName) queryParams.append('policyName', filterAttributes.policyName);
if (filterAttributes.clientNameEng) queryParams.append('clientName', filterAttributes.clientNameEng);
if (filterAttributes.status) queryParams.append('status', filterAttributes.status);

const url = `${getPartnerManagerUrl('/oauth/partners/clients', process.env.NODE_ENV)}?${queryParams.toString()}`;
try {
fetchData ? setTableDataLoaded(false) : setDataLoaded(false);
const response = await HttpService.get(url);
if (response) {
const responseData = response.data;
if (responseData && responseData.response) {
const resData = responseData.response.data;
const populatedData = populateClientNames(resData);
setTotalRecords(responseData.response.totalResults);
setOidcClientsList(populatedData);
} else {
handleServiceErrors(responseData, setErrorCode, setErrorMsg);
}
const url = `${getPartnerManagerUrl('/oauth/partners/clients', process.env.NODE_ENV)}?${queryParams.toString()}`;
try {
fetchData ? setTableDataLoaded(false) : setDataLoaded(false);
const response = await HttpService.get(url);
if (response) {
const responseData = response.data;
if (responseData && responseData.response) {
const resData = responseData.response.data;
const populatedData = populateClientNames(resData);
setTotalRecords(responseData.response.totalResults);
setOidcClientsList(populatedData);
} else {
setErrorMsg(t('oidcClientsList.errorInOidcClientsList'));
handleServiceErrors(responseData, setErrorCode, setErrorMsg);
}
fetchData ? setTableDataLoaded(true) : setDataLoaded(true);
setFetchData(false);
} catch (err) {
setFetchData(false);
fetchData ? setTableDataLoaded(true) : setDataLoaded(true);
console.error('Error fetching data:', err);
setErrorMsg(err);
} else {
setErrorMsg(t('oidcClientsList.errorInOidcClientsList'));
}
fetchData ? setTableDataLoaded(true) : setDataLoaded(true);
setFetchData(false);
} catch (err) {
setFetchData(false);
fetchData ? setTableDataLoaded(true) : setDataLoaded(true);
console.error('Error fetching data:', err);
setErrorMsg(err);
}
}

useEffect(() => {

if (isApplyFilterClicked || initialRender) {
fetchOidcClientsListData();
setInitialRender(false);
setIsApplyFilterClicked(false);
}
fetch();
}, [sortFieldName, sortType, pageNo, pageSize, filterAttributes]);
}, [sortFieldName, sortType, pageNo, pageSize, isApplyFilterClicked]);

const onApplyFilter = (updatedfilters) => {
onClickApplyFilter(updatedfilters, setApplyFilter, setResetPageNo, setFetchData, setFilterAttributes);
onClickApplyFilter(updatedfilters, setApplyFilter, setResetPageNo, setFetchData, setFilterAttributes, setIsApplyFilterClicked);
};

const getPaginationValues = (recordsPerPage, pageIndex) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ function AdminDevicesList() {
const [totalRecords, setTotalRecords] = useState(0);
const [resetPageNo, setResetPageNo] = useState(false);
const [applyFilter, setApplyFilter] = useState(false);
const [initialRender, setInitialRender] = useState(true);
const [isApplyFilterClicked, setIsApplyFilterClicked] = useState(false);
const [showDeviceDetailApproveRejectPopup, setShowDeviceDetailApproveRejectPopup] = useState(false);
const [deactivateRequest, setDeactivateRequest] = useState({});
const [showDeactivatePopup, setShowDeactivatePopup] = useState(false);
Expand Down Expand Up @@ -79,59 +81,65 @@ function AdminDevicesList() {
handleMouseClickForDropdown(submenuRef, () => setActionId(-1));
}, [submenuRef]);

useEffect(() => {
const fetch = async () => {
const queryParams = new URLSearchParams();
queryParams.append('sortFieldName', sortFieldName);
queryParams.append('sortType', sortType);
queryParams.append('pageSize', pageSize);
const fetchDeviceDetails = async () => {
const queryParams = new URLSearchParams();
queryParams.append('sortFieldName', sortFieldName);
queryParams.append('sortType', sortType);
queryParams.append('pageSize', pageSize);

//reset page number to 0 if filter applied or page number is out of bounds
const effectivePageNo = resetPageNumber(totalRecords, pageNo, pageSize, resetPageNo);
queryParams.append('pageNo', effectivePageNo);
setResetPageNo(false);
//reset page number to 0 if filter applied or page number is out of bounds
const effectivePageNo = resetPageNumber(totalRecords, pageNo, pageSize, resetPageNo);
queryParams.append('pageNo', effectivePageNo);
setResetPageNo(false);

if (filterAttributes.partnerId) queryParams.append('partnerId', filterAttributes.partnerId);
if (filterAttributes.orgName) queryParams.append('orgName', filterAttributes.orgName);
if (filterAttributes.make) queryParams.append('make', filterAttributes.make);
if (filterAttributes.model) queryParams.append('model', filterAttributes.model);
if (filterAttributes.status) queryParams.append('status', filterAttributes.status);
if (filterAttributes.deviceType) queryParams.append('deviceType', filterAttributes.deviceType);
if (filterAttributes.deviceSubType) queryParams.append('deviceSubType', filterAttributes.deviceSubType);
if (filterAttributes.deviceId) queryParams.append('deviceId', filterAttributes.deviceId);
if (filterAttributes.sbiId) queryParams.append('sbiId', filterAttributes.sbiId);
if (filterAttributes.sbiVersion) queryParams.append('sbiVersion', filterAttributes.sbiVersion);
if (filterAttributes.partnerId) queryParams.append('partnerId', filterAttributes.partnerId);
if (filterAttributes.orgName) queryParams.append('orgName', filterAttributes.orgName);
if (filterAttributes.make) queryParams.append('make', filterAttributes.make);
if (filterAttributes.model) queryParams.append('model', filterAttributes.model);
if (filterAttributes.status) queryParams.append('status', filterAttributes.status);
if (filterAttributes.deviceType) queryParams.append('deviceType', filterAttributes.deviceType);
if (filterAttributes.deviceSubType) queryParams.append('deviceSubType', filterAttributes.deviceSubType);
if (filterAttributes.deviceId) queryParams.append('deviceId', filterAttributes.deviceId);
if (filterAttributes.sbiId) queryParams.append('sbiId', filterAttributes.sbiId);
if (filterAttributes.sbiVersion) queryParams.append('sbiVersion', filterAttributes.sbiVersion);

const url = `${getPartnerManagerUrl('/devicedetail/search/v2', process.env.NODE_ENV)}?${queryParams.toString()}`;
try {
fetchData ? setTableDataLoaded(false) : setDataLoaded(false);
const response = await HttpService.get(url);
if (response) {
const responseData = response.data;
if (responseData && responseData.response) {
const resData = responseData.response.data;
setTotalRecords(responseData.response.totalResults);
setDevicesList(resData);
} else {
handleServiceErrors(responseData, setErrorCode, setErrorMsg);
}
const url = `${getPartnerManagerUrl('/devicedetail/search/v2', process.env.NODE_ENV)}?${queryParams.toString()}`;
try {
fetchData ? setTableDataLoaded(false) : setDataLoaded(false);
const response = await HttpService.get(url);
if (response) {
const responseData = response.data;
if (responseData && responseData.response) {
const resData = responseData.response.data;
setTotalRecords(responseData.response.totalResults);
setDevicesList(resData);
} else {
setErrorMsg(t('adminDeviceDetailsList.errorInAdminDeviceDetailsList'));
handleServiceErrors(responseData, setErrorCode, setErrorMsg);
}
fetchData ? setTableDataLoaded(true) : setDataLoaded(true);
setFetchData(false);
} catch (err) {
setFetchData(false);
fetchData ? setTableDataLoaded(true) : setDataLoaded(true);
console.error('Error fetching data:', err);
setErrorMsg(err);
} else {
setErrorMsg(t('adminDeviceDetailsList.errorInAdminDeviceDetailsList'));
}
fetchData ? setTableDataLoaded(true) : setDataLoaded(true);
setFetchData(false);
} catch (err) {
setFetchData(false);
fetchData ? setTableDataLoaded(true) : setDataLoaded(true);
console.error('Error fetching data:', err);
setErrorMsg(err);
}
}

useEffect(() => {

if (isApplyFilterClicked || initialRender) {
fetchDeviceDetails();
setInitialRender(false);
setIsApplyFilterClicked(false);
}
fetch();
}, [sortFieldName, sortType, pageNo, pageSize, filterAttributes]);
}, [sortFieldName, sortType, pageNo, pageSize, isApplyFilterClicked]);

const onApplyFilter = (filters) => {
onClickApplyFilter(filters, setApplyFilter, setResetPageNo, setFetchData, setFilterAttributes);
onClickApplyFilter(filters, setApplyFilter, setResetPageNo, setFetchData, setFilterAttributes, setIsApplyFilterClicked);
};

const getPaginationValues = (recordsPerPage, pageIndex) => {
Expand Down
Loading

0 comments on commit 50b11b9

Please sign in to comment.