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] Fix warnings and fix linter #915

Merged
merged 6 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ const AssetGroupForm: React.FC<Props> = ({
</Tooltip>
</div>
<FilterField
labelId="dynamic-asset-filter"
clazz="Endpoint"
initialValue={value}
onChange={onChange}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,11 @@ const inlineStyles: Record<string, CSSProperties> = {
inject_title: {
width: '20%',
},
inject_status: {
width: '20%',
'inject_status.tracking_sent_date': {
width: '15%',
},
'inject_status.status_name': {
width: '15%',
},
inject_targets: {
width: '20%',
Expand Down Expand Up @@ -104,7 +107,7 @@ const InjectList: FunctionComponent<Props> = ({
value: (injectDto: InjectResultDTO) => injectDto.inject_title,
},
{
field: 'inject_status',
field: 'inject_status.tracking_sent_date',
guillaumejparis marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This filter is not working
We need to modify the back-end for that

label: 'Execution Date',
isSortable: true,
value: (injectDto: InjectResultDTO) => fldt(injectDto.inject_status?.tracking_sent_date),
Expand All @@ -118,7 +121,7 @@ const InjectList: FunctionComponent<Props> = ({
},
},
{
field: 'inject_status',
field: 'inject_status.status_name',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This filter is not working
We need to modify the back-end for that

label: 'Status',
isSortable: true,
value: (injectDto: InjectResultDTO) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ const AtomicTesting = () => {
</Typography>
<div style={{ display: 'flex' }}>
{injectResultDto.inject_injector_contract.injector_contract_platforms?.map((platform: string) => (
<div key="platform" style={{ display: 'flex', marginRight: 15 }}>
<div key={platform} style={{ display: 'flex', marginRight: 15 }}>
<PlatformIcon width={20} platform={platform} marginRight={5} />
{platform}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ const TargetResultsDetailFlow: FunctionComponent<Props> = ({
})));
setEdges([...Array(steps.length - 1)].map((_, i) => ({
id: `result-${i}->result-${i + 1}`,
type: 'result',
source: `result-${i}`,
target: `result-${i + 1}`,
label: i === 0 ? nsdt(lastExecutionStartDate) : nsdt(lastExecutionEndDate),
Expand Down Expand Up @@ -297,7 +296,6 @@ const TargetResultsDetailFlow: FunctionComponent<Props> = ({
})));
setEdges([...Array(mergedSteps.length - 1)].map((_, i) => ({
id: `result-${i}->result-${i + 1}`,
type: 'result',
source: `result-${i}`,
target: `result-${i + 1}`,
label: i === 0 ? nsdt(lastExecutionStartDate) : nsdt(lastExecutionEndDate),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -996,7 +996,7 @@ class InjectDefinition extends Component {
.map((f) => f.key)
.includes('assets');
const assets = assetIds
.map((a) => ({ ...endpointsMap[a], type: 'static' }))
.map((a) => ({ asset_id: a, ...endpointsMap[a], type: 'static' }))
.filter((a) => a !== undefined);
// -- ASSET GROUPS --
const hasAssetGroups = injectorContract.fields
Expand Down
8 changes: 4 additions & 4 deletions openbas-front/src/admin/components/common/injects/Injects.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ const Injects = (props) => {
style={{ float: 'right' }}
aria-label="Change view mode"
>
<>
<div>
{sortedInjects.length > 0 ? (
<CSVLink
data={exportData(
Expand Down Expand Up @@ -263,7 +263,7 @@ const Injects = (props) => {
<FileDownloadOutlined fontSize="small" color="primary" />
</ToggleButton>
)}
</>
</div>
<Tooltip title={t('List view')}>
<ToggleButton
value='list'
Expand All @@ -284,7 +284,7 @@ const Injects = (props) => {
</Tooltip>
</ToggleButtonGroup>
) : (
<>
<div>
{sortedInjects.length > 0 ? (
<CSVLink
data={exportData(
Expand Down Expand Up @@ -315,7 +315,7 @@ const Injects = (props) => {
<FileDownloadOutlined />
</IconButton>
)}
</>
</div>
)}
</div>
<div className="clearfix" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { makeStyles } from '@mui/styles';
import { Chip, List, ListItem, ListItemIcon, ListItemSecondaryAction, ListItemText, Tooltip } from '@mui/material';
import { useDispatch } from 'react-redux';
import { DescriptionOutlined, RowingOutlined } from '@mui/icons-material';
import { Link } from 'react-router-dom';
import { useNavigate } from 'react-router-dom';
import { useFormatter } from '../../../../components/i18n';
import { searchDocuments } from '../../../../actions/Document';
import { fetchTags } from '../../../../actions/Tag';
Expand Down Expand Up @@ -85,6 +85,7 @@ const Documents = () => {
// Standard hooks
const classes = useStyles();
const dispatch = useDispatch();
const navigate = useNavigate();
const { t } = useFormatter();
const { exercisesMap, scenariosMap, userAdmin } = useHelper((helper) => ({
exercisesMap: helper.getExercisesMap(),
Expand Down Expand Up @@ -206,9 +207,15 @@ const Documents = () => {
classes={{ root: classes.exercise }}
variant="outlined"
label={exercise.exercise_name}
component={Link}
clickable={true}
to={`/admin/exercises/${exercise.exercise_id}`}
onClick={
(event) => {
// prevent parent link from triggering
event.stopPropagation();
event.preventDefault();
navigate(`/admin/exercises/${exercise.exercise_id}`);
}
}
/>
</Tooltip>
);
Expand All @@ -231,9 +238,15 @@ const Documents = () => {
classes={{ root: classes.scenario }}
variant="outlined"
label={scenario.scenario_name}
component={Link}
clickable={true}
to={`/admin/scenarios/${scenario.scenario_id}`}
onClick={
(event) => {
// prevent parent link from triggering
event.stopPropagation();
event.preventDefault();
navigate(`/admin/scenarios/${scenario.scenario_id}`);
}
}
/>
</Tooltip>
);
Expand Down
1 change: 1 addition & 0 deletions openbas-front/src/admin/components/scenarios/Scenarios.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ const Scenarios = () => {
<Breadcrumbs variant="list" elements={[{ label: t('Scenarios'), current: true }]} />
<div style={{ display: 'flex', marginBottom: 30 }}>
<Card
key="all"
classes={{ root: classes.card }} variant="outlined"
onClick={() => handleOnClickCategory()}
className={classNames({ [classes.cardSelected]: noCategory() })}
Expand Down
18 changes: 10 additions & 8 deletions openbas-front/src/components/common/filter/FilterChip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,16 @@ const FilterChip: FunctionComponent<Props> = ({
ref={chipRef}
/>
</Tooltip>
<FilterChipPopover
filter={filter}
helpers={helpers}
open={open}
onClose={handleClose}
anchorEl={chipRef.current || undefined}
propertySchema={propertySchema}
/>
{chipRef?.current
&& <FilterChipPopover
filter={filter}
helpers={helpers}
open={open}
onClose={handleClose}
anchorEl={chipRef.current}
propertySchema={propertySchema}
/>
}
</>
);
};
Expand Down
5 changes: 3 additions & 2 deletions openbas-front/src/components/common/filter/FilterChips.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const FilterChips: FunctionComponent<Props> = ({
return (<></>);
}
return (
<>
<React.Fragment key={filter.key}>
{idx !== 0
&& <div
onClick={handleSwitchMode}
Expand All @@ -74,11 +74,12 @@ const FilterChips: FunctionComponent<Props> = ({
helpers={helpers}
propertySchema={property}
/>
</>
</React.Fragment>
);
})
}
</Box>
);
};

export default FilterChips;
4 changes: 0 additions & 4 deletions openbas-front/src/components/common/filter/FilterField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@ const useStyles = makeStyles(() => ({
type OptionPropertySchema = Option & { operator: Filter['operator'] };

interface Props {
labelId: string;
clazz: string;
initialValue?: FilterGroup;
onChange: (value: FilterGroup) => void;
style: CSSProperties;
}

const FilterField: FunctionComponent<Props> = ({
labelId,
clazz,
initialValue,
onChange,
Expand Down Expand Up @@ -69,8 +67,6 @@ const FilterField: FunctionComponent<Props> = ({
<>
<div className={classes.container}>
<MuiAutocomplete
// @ts-expect-error: labelId
labelId={labelId}
options={computeOptions()}
sx={{ width: 200 }}
value={null}
Expand Down
Loading