Skip to content

Commit

Permalink
[frontend] Remove double fetch (#1184)
Browse files Browse the repository at this point in the history
Co-authored-by: Guillaume Paris <guillaume.paris@filigran.io>
  • Loading branch information
RomuDeuxfois and guillaumejparis authored Aug 28, 2024
1 parent be0b0f4 commit 2224367
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions openbas-front/src/admin/components/atomic_testings/InjectList.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { CSSProperties, FunctionComponent, useEffect, useState } from 'react';
import React, { CSSProperties, FunctionComponent, useMemo, useState } from 'react';
import { makeStyles } from '@mui/styles';
import { List, ListItem, ListItemButton, ListItemIcon, ListItemText } from '@mui/material';
import { useFormatter } from '../../../components/i18n';
Expand Down Expand Up @@ -84,18 +84,12 @@ const InjectList: FunctionComponent<Props> = ({
sorts: initSorting('inject_updated_at', 'DESC'),
}));

// Fetch injects on initial render and when pagination input changes
useEffect(() => {
fetchInjects(searchPaginationInput)
.then((response) => setInjects(response.data.content));
}, [fetchInjects, searchPaginationInput]);

// Headers
const headers = [
const headers = useMemo(() => [
{
field: 'inject_type',
label: 'Type',
isSortable: true,
isSortable: false,
value: (injectDto: InjectResultDTO) => {
if (injectDto.inject_injector_contract) {
return (
Expand All @@ -120,9 +114,9 @@ const InjectList: FunctionComponent<Props> = ({
{
field: 'inject_status',
label: 'Status',
isSortable: true,
isSortable: false,
value: (injectDto: InjectResultDTO) => {
return (<ItemStatus isInject={true} status={injectDto.inject_status?.status_name} label={t(injectDto.inject_status?.status_name)} variant="inList" />);
return (<ItemStatus isInject status={injectDto.inject_status?.status_name} label={t(injectDto.inject_status?.status_name)} variant="inList" />);
},
},
{
Expand All @@ -149,7 +143,7 @@ const InjectList: FunctionComponent<Props> = ({
isSortable: true,
value: (injectDto: InjectResultDTO) => nsdt(injectDto.inject_updated_at),
},
];
], []);

return (
<>
Expand Down

0 comments on commit 2224367

Please sign in to comment.