Skip to content

Commit

Permalink
feat: sonarcloud issue in connection list
Browse files Browse the repository at this point in the history
Signed-off-by: pranalidhanavade <[email protected]>
  • Loading branch information
pranalidhanavade committed Dec 5, 2024
1 parent f7e7e2c commit 8fdf426
Showing 1 changed file with 61 additions and 70 deletions.
131 changes: 61 additions & 70 deletions src/components/Verification/ConnectionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,77 +106,68 @@ const ConnectionList = (props: {
);
};


const selectOrganization = async (
item: IConnectionList,
checked: boolean,
) => {
try {
const index =
localOrgs?.length > 0
? localOrgs.findIndex((ele) => ele.connectionId === item.connectionId)
: -1;

const { connectionId, theirLabel, createDateTime } = item || {};
if (index === -1) {
setLocalOrgs((prev: LocalOrgs[]) => [
...prev,
{
connectionId,
theirLabel,
createDateTime,
},
]);
} else {
const updateLocalOrgs = [...localOrgs];
if (!checked) {
updateLocalOrgs.splice(index, 1);
}
setLocalOrgs(updateLocalOrgs);
}
} catch (error) {
console.error('SELECTED ORGANIZATION:::', error);
}
};


const generateTable = async (connections: IConnectionList[]) => {
try {
const connectionsData =
connections?.length > 0 &&
connections?.map((ele: IConnectionList) => {
const createdOn = ele?.createDateTime
? ele?.createDateTime
: 'Not available';
const connectionId = ele.connectionId
? ele.connectionId
: 'Not available';
const userName = ele?.theirLabel ? ele.theirLabel : 'Not available';

const isChecked = localOrgs
.map((item) => item.connectionId)
.includes(ele.connectionId);

return {
data: [
{ data: renderCheckbox(ele, isChecked, connections) },
{ data: userName },
{ data: connectionId },
{
data: (
<DateTooltip date={createdOn} id="verification_connecetion_list">
{' '}
{dateConversion(createdOn)}{' '}
</DateTooltip>
),
},
],
};
});
const extractConnectionFields = (item: IConnectionList) => {
const connectionId = item?.connectionId || 'Not available';
const theirLabel = item?.theirLabel || 'Not available';
const createDateTime = item?.createDateTime || 'Not available';
return { connectionId, theirLabel, createDateTime };
};

const isConnectionChecked = (connectionId: string) =>
localOrgs.map((item) => item.connectionId).includes(connectionId);


const selectOrganization = async (item: IConnectionList, checked: boolean) => {
try {
const { connectionId, theirLabel, createDateTime } = extractConnectionFields(item);
const index = localOrgs?.findIndex((ele) => ele.connectionId === connectionId) ?? -1;

if (index === -1) {
setLocalOrgs((prev: LocalOrgs[]) => [
...prev,
{ connectionId, theirLabel, createDateTime },
]);
} else if (!checked) {
const updateLocalOrgs = [...localOrgs];
updateLocalOrgs.splice(index, 1);
setLocalOrgs(updateLocalOrgs);
}
} catch (error) {
console.error('SELECTED ORGANIZATION:::', error);
}
};


const generateTable = async (connections: IConnectionList[]) => {
try {
const connectionsData =
connections?.length > 0 &&
connections.map((ele: IConnectionList) => {
const { connectionId, theirLabel, createDateTime } = extractConnectionFields(ele);
const isChecked = isConnectionChecked(connectionId);

return {
data: [
{ data: renderCheckbox(ele, isChecked, connections) },
{ data: theirLabel },
{ data: connectionId },
{
data: (
<DateTooltip date={createDateTime} id="verification_connecetion_list">
{dateConversion(createDateTime)}
</DateTooltip>
),
},
],
};
});

setTableData(connectionsData);
} catch (err) {
console.error('Error generating table:', err);
}
};

setTableData(connectionsData);
} catch (err) {}
};
useEffect(() => {
props.selectConnection(localOrgs);
}, [localOrgs]);
Expand Down

0 comments on commit 8fdf426

Please sign in to comment.