Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[frontend] When I select injects and export them, the entire list is exported #2113

Merged
merged 2 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion openbas-front/src/admin/components/common/injects/Injects.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,13 @@ const Injects: FunctionComponent<Props> = ({
});
};

const selectedInjects = () => {
const selectedInjectIds = Object.keys(selectedElements);
return injects.filter(inject => selectedInjectIds.includes(inject.inject_id));
};

const atLeastOneValidInject = injects.some(inject => !inject.inject_injector_contract?.injector_contract_content_parsed);

return (
<>
<PaginationComponentV2
Expand All @@ -495,10 +502,11 @@ const Injects: FunctionComponent<Props> = ({
reloadContentCount={reloadInjectCount}
topBarButtons={(
<InjectsListButtons
injects={injects}
selectedInjects={selectedInjects()}
availableButtons={availableButtons}
setViewMode={setViewMode}
onImportedInjects={() => setReloadInjectCount(prev => prev + 1)}
isAtLeastOneValidInject={atLeastOneValidInject}
/>
)}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,19 @@ const useStyles = makeStyles(() => ({
}));

interface Props {
injects: InjectOutputType[];
selectedInjects: InjectOutputType[];
setViewMode?: (mode: string) => void;
availableButtons: string[];
onImportedInjects?: () => void;
isAtLeastOneValidInject: boolean;
}

const InjectsListButtons: FunctionComponent<Props> = ({
injects,
selectedInjects,
setViewMode,
availableButtons,
onImportedInjects,
isAtLeastOneValidInject,
}) => {
// Standard hooks
const classes = useStyles();
Expand All @@ -47,8 +49,6 @@ const InjectsListButtons: FunctionComponent<Props> = ({
tagsMap: helper.getTagsMap(),
}));

const isAtLeastOneValidInject = injects.some(inject => !inject.inject_injector_contract?.injector_contract_content_parsed);

const exportInjects = exportData(
'inject',
[
Expand All @@ -60,7 +60,7 @@ const InjectsListButtons: FunctionComponent<Props> = ({
'inject_tags',
'inject_content',
],
injects,
selectedInjects,
tagsMap,
);
const exportInjectsToXLS = useExportToXLS({ data: exportInjects, fileName: `${t('Injects')}` });
Expand Down
Loading