Skip to content

Commit 1966bcb

Browse files
FWF-4550:[Feature] - Sonar cloud fixes
1 parent 2bdd970 commit 1966bcb

File tree

3 files changed

+111
-66
lines changed

3 files changed

+111
-66
lines changed

forms-flow-submissions/src/Routes/SubmissionListing.tsx

Lines changed: 75 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ import { push } from "connected-react-router";
66

77
import { getSubmissionList } from "../api/queryServices/analyzeSubmissionServices";
88
import { formatDate } from "../helper/helper";
9-
import { setAnalizeSubmissionSort, setAnalyzeSubmissionPage } from "../actions/analyzeSubmissionActions";
9+
import {
10+
setAnalizeSubmissionSort,
11+
setAnalyzeSubmissionPage,
12+
} from "../actions/analyzeSubmissionActions";
1013
import {
1114
ReusableResizableTable,
1215
TableFooter,
@@ -38,43 +41,66 @@ const TaskSubmissionList: React.FC = () => {
3841
const scrollWrapperRef = useRef<HTMLDivElement>(null);
3942
const [limit, setLimit] = useState(10);
4043

41-
const sortParams = useSelector((state: any) => state?.analyzeSubmission.analyzeSubmissionSortParams || {});
42-
const {page} = useSelector((state: any) => state?.analyzeSubmission.page || 1 );
43-
const tenantKey = useSelector((state: any) => state.tenants?.tenantData?.tenantkey);
44+
const sortParams = useSelector(
45+
(state: any) => state?.analyzeSubmission.analyzeSubmissionSortParams ?? {}
46+
);
47+
const { page } = useSelector(
48+
(state: any) => state?.analyzeSubmission.page ?? 1
49+
);
50+
const tenantKey = useSelector(
51+
(state: any) => state.tenants?.tenantData?.tenantkey
52+
);
4453
const redirectUrl = MULTITENANCY_ENABLED ? `/tenant/${tenantKey}/` : "/";
4554

46-
const columns: Column[] = useMemo(() => [
47-
{ name: "Submission ID", sortKey: "id", width: 200, resizable: true },
48-
{ name: "Form Name", sortKey: "formName", width: 200, resizable: true },
49-
{ name: "Submitter", sortKey: "createdBy", width: 200, resizable: true },
50-
{ name: "Submission Date", sortKey: "submissionDate", width: 180, resizable: true },
51-
{ name: "Status", sortKey: "applicationStatus", width: 160, resizable: true },
52-
{ name: "", sortKey: "actions", width: 100 },
53-
], []);
55+
const columns: Column[] = useMemo(
56+
() => [
57+
{ name: "Submission ID", sortKey: "id", width: 200, resizable: true },
58+
{ name: "Form Name", sortKey: "formName", width: 200, resizable: true },
59+
{ name: "Submitter", sortKey: "createdBy", width: 200, resizable: true },
60+
{
61+
name: "Submission Date",
62+
sortKey: "submissionDate",
63+
width: 180,
64+
resizable: true,
65+
},
66+
{
67+
name: "Status",
68+
sortKey: "applicationStatus",
69+
width: 160,
70+
resizable: true,
71+
},
72+
{ name: "", sortKey: "actions", width: 100 },
73+
],
74+
[]
75+
);
5476

5577
const activeSortKey = sortParams.activeKey;
56-
const activeSortOrder = sortParams?.[activeSortKey]?.sortOrder || "asc";
78+
const activeSortOrder = sortParams?.[activeSortKey]?.sortOrder ?? "asc";
5779

5880
const { data } = useQuery({
5981
queryKey: ["submissions", page, limit, activeSortKey, activeSortOrder],
60-
queryFn: () => getSubmissionList(limit, page, activeSortOrder, activeSortKey),
82+
queryFn: () =>
83+
getSubmissionList(limit, page, activeSortOrder, activeSortKey),
6184
keepPreviousData: true,
6285
staleTime: 0,
6386
});
6487

65-
const submissions = data?.submissions || [];
66-
const totalCount = data?.totalCount || 0;
88+
const submissions = data?.submissions ?? [];
89+
const totalCount = data?.totalCount ?? 0;
6790

68-
const handleSort = useCallback((key: string) => {
69-
const newOrder = sortParams[key]?.sortOrder === "asc" ? "desc" : "asc";
70-
const updatedSort = Object.fromEntries(
71-
Object.keys(sortParams).map((k) => [
72-
k,
73-
{ sortOrder: k === key ? newOrder : "asc" },
74-
])
75-
);
76-
dispatch(setAnalizeSubmissionSort({ ...updatedSort, activeKey: key }));
77-
}, [dispatch, sortParams]);
91+
const handleSort = useCallback(
92+
(key: string) => {
93+
const newOrder = sortParams[key]?.sortOrder === "asc" ? "desc" : "asc";
94+
const updatedSort = Object.fromEntries(
95+
Object.keys(sortParams).map((k) => [
96+
k,
97+
{ sortOrder: k === key ? newOrder : "asc" },
98+
])
99+
);
100+
dispatch(setAnalizeSubmissionSort({ ...updatedSort, activeKey: key }));
101+
},
102+
[dispatch, sortParams]
103+
);
78104

79105
const handlePageChange = useCallback(
80106
(pageNumber) => {
@@ -83,7 +109,6 @@ const TaskSubmissionList: React.FC = () => {
83109
[dispatch, limit]
84110
);
85111

86-
87112
const renderRow = (row: Submission) => (
88113
<tr key={row.id}>
89114
<td>{row.id}</td>
@@ -112,7 +137,11 @@ const TaskSubmissionList: React.FC = () => {
112137
index: number,
113138
columnsLength: number,
114139
currentResizingColumn: any,
115-
handleMouseDown: (index: number, column: Column, e: React.MouseEvent) => void
140+
handleMouseDown: (
141+
index: number,
142+
column: Column,
143+
e: React.MouseEvent
144+
) => void
116145
) => {
117146
const isLast = index === columnsLength - 1;
118147
const headerKey = column.sortKey || `col-${index}`;
@@ -140,11 +169,17 @@ const TaskSubmissionList: React.FC = () => {
140169
) : (
141170
column.name && t(column.name)
142171
)}
143-
144172
{column.resizable && (
145173
<div
146-
className={`column-resizer ${currentResizingColumn?.sortKey === column.sortKey ? "resizing" : ""}`}
174+
className={`column-resizer ${
175+
currentResizingColumn?.sortKey === column.sortKey
176+
? "resizing"
177+
: ""
178+
}`}
147179
onMouseDown={(e) => handleMouseDown(index, column, e)}
180+
tabIndex={0}
181+
role="separator"
182+
aria-orientation="horizontal"
148183
data-testid={`column-resizer-${column.sortKey}`}
149184
aria-label={t("Resize {{columnName}} column", {
150185
columnName: t(column.name),
@@ -165,15 +200,22 @@ const TaskSubmissionList: React.FC = () => {
165200
return (
166201
<div className="container-wrapper" data-testid="table-container-wrapper">
167202
<div className="table-outer-container">
168-
<div className="table-scroll-wrapper resizable-scroll" ref={scrollWrapperRef}>
203+
<div
204+
className="table-scroll-wrapper resizable-scroll"
205+
ref={scrollWrapperRef}
206+
>
169207
<div className="resizable-table-container">
170208
<ReusableResizableTable
171209
columns={columns}
172210
data={submissions}
173211
renderRow={renderRow}
174212
renderHeaderCell={renderHeaderCell}
175-
emptyMessage={t("No submissions have been found. Try a different filter combination or contact your admin.")}
176-
onColumnResize={(newWidths) => console.log("Column resized:", newWidths)}
213+
emptyMessage={t(
214+
"No submissions have been found. Try a different filter combination or contact your admin."
215+
)}
216+
onColumnResize={(newWidths) =>
217+
console.log("Column resized:", newWidths)
218+
}
177219
tableClassName="resizable-table"
178220
headerClassName="resizable-header"
179221
containerClassName="resizable-table-container"

forms-flow-submissions/src/index.tsx

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useEffect, useState } from "react";
2-
import { Route, Switch, Redirect, useHistory, useParams } from "react-router-dom";
2+
import { Route, Switch, Redirect, useParams } from "react-router-dom";
33
import { KeycloakService, StorageService } from "@formsflow/service";
44
import {
55
KEYCLOAK_URL_AUTH,
@@ -11,6 +11,7 @@ import i18n from "./config/i18n";
1111
import "./index.scss";
1212
import Loading from "./components/Loading";
1313
import SubmissionsList from "./Routes/SubmissionListing";
14+
1415
const authorizedRoles = new Set(["create_submissions", "view_submissions"]);
1516

1617
interface SubmissionsProps {
@@ -21,62 +22,64 @@ interface SubmissionsProps {
2122

2223
const Submissions: React.FC<SubmissionsProps> = React.memo((props) => {
2324
const { publish = () => {}, subscribe = () => {} } = props;
24-
const history = useHistory();
2525
const { tenantId } = useParams<{ tenantId?: string }>();
26-
const [instance, setInstance] = useState(props.getKcInstance());
27-
const [isAuth, setIsAuth] = useState(instance?.isAuthenticated());
28-
const [isClient, setClient] = useState(false);
26+
const [isAuth, setIsAuth] = useState(false);
27+
const [isClient, setIsClient] = useState(false);
2928

3029
const baseUrl = MULTITENANCY_ENABLED ? `/tenant/${tenantId}/` : "/";
3130

3231
useEffect(() => {
3332
publish("ES_ROUTE", { pathname: `${baseUrl}submissions` });
34-
subscribe("ES_CHANGE_LANGUAGE", (msg, data) => {
33+
subscribe("ES_CHANGE_LANGUAGE", (_msg, data) => {
3534
i18n.changeLanguage(data);
36-
})
35+
});
3736
}, []);
3837

3938
useEffect(() => {
40-
StorageService.save("tenantKey", tenantId || "");
39+
StorageService.save("tenantKey", tenantId ?? "");
4140
}, [tenantId]);
4241

4342
useEffect(() => {
44-
if (!isAuth) {
45-
46-
let instance = KeycloakService.getInstance(
47-
KEYCLOAK_URL_AUTH,
48-
KEYCLOAK_URL_REALM,
49-
KEYCLOAK_CLIENT,
50-
tenantId
51-
);
52-
instance.initKeycloak(() => {
53-
setIsAuth(instance.isAuthenticated());
54-
publish("FF_AUTH", instance);
55-
});
56-
}
43+
const kcInstance = KeycloakService.getInstance(
44+
KEYCLOAK_URL_AUTH,
45+
KEYCLOAK_URL_REALM,
46+
KEYCLOAK_CLIENT,
47+
tenantId
48+
);
49+
50+
kcInstance.initKeycloak(() => {
51+
setIsAuth(kcInstance.isAuthenticated());
52+
publish("FF_AUTH", kcInstance);
53+
});
5754
}, []);
5855

5956
useEffect(() => {
6057
if (!isAuth) return;
6158

62-
const roles = JSON.parse(StorageService.get(StorageService.User.USER_ROLE) || "[]");
59+
const roles = JSON.parse(StorageService.get(StorageService.User.USER_ROLE) ?? "[]");
6360
if (roles.some((role: any) => authorizedRoles.has(role))) {
64-
setClient(true);
61+
setIsClient(true);
6562
}
66-
const locale = localStorage.getItem("i18nextLng")
67-
if (locale) i18n.changeLanguage(locale);
68-
publish("ES_ROUTE", { pathname: `${baseUrl}submissions` });
69-
subscribe("ES_CHANGE_LANGUAGE", (msg, data) => {
70-
i18n.changeLanguage(data);
71-
})
7263

73-
}, [isAuth])
64+
const locale = localStorage.getItem("i18nextLng");
65+
if (locale) {
66+
i18n.changeLanguage(locale);
67+
}
7468

69+
publish("ES_ROUTE", { pathname: `${baseUrl}submissions` });
70+
subscribe("ES_CHANGE_LANGUAGE", (_msg, data) => {
71+
i18n.changeLanguage(data);
72+
});
73+
}, [isAuth]);
7574

7675
if (!isAuth) {
77-
return <Loading />
76+
return <Loading />;
7877
}
79-
if(!isClient) return <p>unauthorized</p>
78+
79+
if (!isClient) {
80+
return <p>unauthorized</p>;
81+
}
82+
8083
return (
8184
<div className="main-container" tabIndex={0}>
8285
<div className="container mt-5">

forms-flow-submissions/src/services/StoreServices.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ interface PreloadedState {
1313
function configureStore(preloadedState?: PreloadedState) {
1414
const enhancers: Middleware[] = [routerMiddleware(history)];
1515

16-
const node_env = window._env_?.NODE_ENV || process.env?.NODE_ENV;
16+
const node_env = window._env_?.NODE_ENV ?? process.env?.NODE_ENV;
1717
if (node_env === "development") {
1818
enhancers.push(logger);
1919
}

0 commit comments

Comments
 (0)