Skip to content

Commit

Permalink
[frontend] Remove EndpointStore, AssetGroupStore & ArticleStore
Browse files Browse the repository at this point in the history
  • Loading branch information
RomuDeuxfois committed Dec 9, 2024
1 parent 8b7f64d commit 71172aa
Show file tree
Hide file tree
Showing 27 changed files with 82 additions and 104 deletions.
8 changes: 4 additions & 4 deletions openbas-front/src/actions/asset_groups/assetgroup-helper.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { AssetGroupStore } from '../../admin/components/assets/asset_groups/AssetGroup';
import type { AssetGroup } from '../../utils/api-types';

export interface AssetGroupsHelper {
getAssetGroups: () => AssetGroupStore[];
getAssetGroupMaps: () => Record<string, AssetGroupStore>;
getAssetGroup: (assetGroupId: string) => AssetGroupStore | undefined;
getAssetGroups: () => AssetGroup[];
getAssetGroupMaps: () => Record<string, AssetGroup>;
getAssetGroup: (assetGroupId: string) => AssetGroup | undefined;
}
6 changes: 3 additions & 3 deletions openbas-front/src/actions/assets/asset-helper.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { EndpointStore } from '../../admin/components/assets/endpoints/Endpoint';
import type { SecurityPlatformStore } from '../../admin/components/assets/security_platforms/SecurityPlatform';
import { Endpoint } from '../../utils/api-types';

export interface EndpointHelper {
getEndpoints: () => EndpointStore[];
getEndpointsMap: () => Record<string, EndpointStore>;
getEndpoints: () => Endpoint[];
getEndpointsMap: () => Record<string, Endpoint>;
}

export interface SecurityPlatformHelper {
Expand Down
7 changes: 1 addition & 6 deletions openbas-front/src/actions/channels/Article.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import type { Article, Channel } from '../../utils/api-types';

export type ArticleStore = Omit<Article, 'article_channel' | 'article_documents'> & {
article_channel: string | undefined;
article_documents: string[] | undefined;
};

export type FullArticleStore = ArticleStore & {
export type FullArticleStore = Article & {
article_fullchannel: Channel;
};
5 changes: 2 additions & 3 deletions openbas-front/src/actions/channels/article-helper.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import type { Article, Exercise } from '../../utils/api-types';
import type { ScenarioStore } from '../scenarios/Scenario';
import type { ArticleStore } from './Article';

export interface ArticlesHelper {
getArticlesMap: () => Record<string, Article>;
getExerciseArticles: (exerciseId: Exercise['exercise_id']) => ArticleStore[];
getScenarioArticles: (scenarioId: ScenarioStore['scenario_id']) => ArticleStore[];
getExerciseArticles: (exerciseId: Exercise['exercise_id']) => Article[];
getScenarioArticles: (scenarioId: ScenarioStore['scenario_id']) => Article[];
}
7 changes: 3 additions & 4 deletions openbas-front/src/admin/components/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,19 @@ import Chart from 'react-apexcharts';
import { fetchStatistics } from '../../actions/Application';
import type { AttackPatternHelper } from '../../actions/attack_patterns/attackpattern-helper';
import { searchExercises } from '../../actions/Exercise';
import type { InjectExpectationResultsByAttackPatternStore } from '../../actions/exercises/Exercise';
import type { ExerciseStore, InjectExpectationResultsByAttackPatternStore } from '../../actions/exercises/Exercise';
import type { StatisticsHelper } from '../../actions/statistics/statistics-helper';
import { initSorting, type Page } from '../../components/common/queryable/Page';
import Empty from '../../components/Empty';
import { useFormatter } from '../../components/i18n';
import Loader from '../../components/Loader';
import type { Theme } from '../../components/Theme';
import { useHelper } from '../../store';
import type { AttackPattern, ExerciseSimple, PlatformStatistic } from '../../utils/api-types';
import { AttackPattern, ExerciseSimple, PlatformStatistic } from '../../utils/api-types';
import { horizontalBarsChartOptions, polarAreaChartOptions, verticalBarsChartOptions } from '../../utils/Charts';
import { attackPatternsFakeData, categoriesDataFakeData, categoriesLabelsFakeData, exercisesTimeSeriesFakeData } from '../../utils/fakeData';
import { useAppDispatch } from '../../utils/hooks';
import useDataLoader from '../../utils/hooks/useDataLoader';
import type { EndpointStore } from './assets/endpoints/Endpoint';
import ResponsePie from './common/injects/ResponsePie';
import MitreMatrix from './common/matrix/MitreMatrix';
import PaperMetric from './common/simulate/PaperMetric';
Expand Down Expand Up @@ -70,7 +69,7 @@ const Dashboard = () => {

// Exercises
const [loadingExercises, setLoadingExercises] = useState(true);
const [exercises, setExercises] = useState<EndpointStore[]>([]);
const [exercises, setExercises] = useState<ExerciseStore[]>([]);
const searchPaginationInput = {
sorts: initSorting('exercise_updated_at', 'DESC'),
page: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import { FunctionComponent, useState } from 'react';
import { updateAssetsOnAssetGroup } from '../../../../actions/asset_groups/assetgroup-action';
import ButtonCreate from '../../../../components/common/ButtonCreate';
import { useFormatter } from '../../../../components/i18n';
import type { AssetGroup } from '../../../../utils/api-types';
import { useAppDispatch } from '../../../../utils/hooks';
import type { UserStore } from '../../teams/players/Player';
import EndpointsDialogAdding from '../endpoints/EndpointsDialogAdding';
import type { AssetGroupStore } from './AssetGroup';

interface Props {
assetGroupId: string;
assetGroupEndpointIds: string[];
onUpdate?: (result: AssetGroupStore) => void;
onUpdate?: (result: AssetGroup) => void;
}

const AssetGroupAddEndpoints: FunctionComponent<Props> = ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ import ButtonCreate from '../../../../components/common/ButtonCreate';
import Dialog from '../../../../components/common/Dialog';
import Drawer from '../../../../components/common/Drawer';
import { useFormatter } from '../../../../components/i18n';
import type { AssetGroupInput } from '../../../../utils/api-types';
import type { AssetGroup, AssetGroupInput } from '../../../../utils/api-types';
import { useAppDispatch } from '../../../../utils/hooks';
import type { UserStore } from '../../teams/players/Player';
import type { AssetGroupStore } from './AssetGroup';
import AssetGroupForm from './AssetGroupForm';

const useStyles = makeStyles((theme: Theme) => ({
Expand All @@ -24,7 +23,7 @@ const useStyles = makeStyles((theme: Theme) => ({

interface Props {
inline?: boolean;
onCreate?: (result: AssetGroupStore) => void;
onCreate?: (result: AssetGroup) => void;
}

const AssetGroupCreation: FunctionComponent<Props> = ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import type { UserHelper } from '../../../../actions/helper';
import SearchFilter from '../../../../components/SearchFilter';
import type { Theme } from '../../../../components/Theme';
import { useHelper } from '../../../../store';
import type { AssetGroup, Endpoint } from '../../../../utils/api-types';
import type { Asset } from '../../../../utils/api-types';
import { useAppDispatch } from '../../../../utils/hooks';
import useDataLoader from '../../../../utils/hooks/useDataLoader';
import useSearchAnFilter from '../../../../utils/SortingFiltering';
import TagsFilter from '../../common/filters/TagsFilter';
import EndpointPopover from '../endpoints/EndpointPopover';
import EndpointsList, { EndpointStoreWithType } from '../endpoints/EndpointsList';
import type { AssetGroupStore } from './AssetGroup';
import AssetGroupAddEndpoints from './AssetGroupAddEndpoints';

const useStyles = makeStyles((theme: Theme) => ({
Expand Down Expand Up @@ -54,7 +54,7 @@ const useStyles = makeStyles((theme: Theme) => ({
interface Props {
assetGroupId: string;
handleClose: () => void;
onUpdate?: (result: AssetGroupStore) => void;
onUpdate?: (result: AssetGroup) => void;
onRemoveEndpointFromAssetGroup?: (assetId: Asset['asset_id']) => void;
}

Expand Down Expand Up @@ -131,7 +131,6 @@ const AssetGroupManagement: FunctionComponent<Props> = ({
inline
assetGroupId={assetGroup?.asset_group_id}
assetGroupEndpointIds={assetGroup?.asset_group_assets ?? []}
onUpdate={onUpdate}
onRemoveEndpointFromAssetGroup={onRemoveEndpointFromAssetGroup}
/>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ import DialogDelete from '../../../../components/common/DialogDelete';
import Drawer from '../../../../components/common/Drawer';
import { emptyFilterGroup } from '../../../../components/common/queryable/filter/FilterUtils';
import { useFormatter } from '../../../../components/i18n';
import type { AssetGroupInput, AssetGroupOutput } from '../../../../utils/api-types';
import type { AssetGroup, AssetGroupInput, AssetGroupOutput } from '../../../../utils/api-types';
import { useAppDispatch } from '../../../../utils/hooks';
import EndpointsDialogAdding from '../endpoints/EndpointsDialogAdding';
import type { AssetGroupStore } from './AssetGroup';
import AssetGroupForm from './AssetGroupForm';
import AssetGroupManagement from './AssetGroupManagement';

Expand All @@ -26,11 +25,11 @@ const useStyles = makeStyles(() => ({

interface Props {
inline?: boolean;
assetGroup: AssetGroupStore | AssetGroupOutput;
assetGroup: AssetGroup | AssetGroupOutput;
onRemoveAssetGroupFromInject?: (assetGroupId: string) => void;
onRemoveEndpointFromAssetGroup?: (assetId: string) => void;
openEditOnInit?: boolean;
onUpdate?: (result: AssetGroupStore) => void;
onUpdate?: (result: AssetGroup) => void;
onDelete?: (result: string) => void;
}

Expand Down Expand Up @@ -72,7 +71,7 @@ const AssetGroupPopover: FunctionComponent<Props> = ({
};
const submitEdit = (data: AssetGroupInput) => {
dispatch(updateAssetGroup(assetGroup.asset_group_id, data)).then(
(result: { result: string; entities: { asset_groups: Record<string, AssetGroupStore> } }) => {
(result: { result: string; entities: { asset_groups: Record<string, AssetGroup> } }) => {
if (result.entities) {
if (onUpdate) {
const updated = result.entities.asset_groups[result.result];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ import { Header } from '../../../../components/common/SortHeadersList';
import { useFormatter } from '../../../../components/i18n';
import ItemTags from '../../../../components/ItemTags';
import { useHelper } from '../../../../store';
import type { AssetGroupOutput } from '../../../../utils/api-types';
import type { AssetGroupStore } from './AssetGroup';
import type { AssetGroup, AssetGroupOutput } from '../../../../utils/api-types';
import AssetGroupCreation from './AssetGroupCreation';
import AssetGroupManagement from './AssetGroupManagement';
import AssetGroupPopover from './AssetGroupPopover';
Expand Down Expand Up @@ -133,7 +132,7 @@ const AssetGroups = () => {
const classes = useStyles();
const { t } = useFormatter();

const [selectedAssetGroupId, setSelectedAssetGroupId] = useState<AssetGroupStore['asset_group_id'] | undefined>(undefined);
const [selectedAssetGroupId, setSelectedAssetGroupId] = useState<AssetGroup['asset_group_id'] | undefined>(undefined);

// Query param
const [searchParams] = useSearchParams();
Expand Down Expand Up @@ -181,7 +180,7 @@ const AssetGroups = () => {
'asset_group_tags',
];

const [assetGroups, setAssetGroups] = useState<AssetGroupStore[]>([]);
const [assetGroups, setAssetGroups] = useState<AssetGroup[]>([]);
const { queryableHelpers, searchPaginationInput } = useQueryableWithLocalStorage('asset-groups', buildSearchPagination({
sorts: initSorting('asset_group_name'),
textSearch: search,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ import ButtonCreate from '../../../../components/common/ButtonCreate';
import Dialog from '../../../../components/common/Dialog';
import Drawer from '../../../../components/common/Drawer';
import { useFormatter } from '../../../../components/i18n';
import type { EndpointInput } from '../../../../utils/api-types';
import { Endpoint, EndpointInput } from '../../../../utils/api-types';
import { useAppDispatch } from '../../../../utils/hooks';
import type { EndpointStore } from './Endpoint';
import EndpointForm from './EndpointForm';

const useStyles = makeStyles((theme: Theme) => ({
Expand All @@ -23,7 +22,7 @@ const useStyles = makeStyles((theme: Theme) => ({

interface Props {
inline?: boolean;
onCreate?: (result: EndpointStore) => void;
onCreate?: (result: Endpoint) => void;
}

const EndpointCreation: FunctionComponent<Props> = ({
Expand All @@ -38,7 +37,7 @@ const EndpointCreation: FunctionComponent<Props> = ({
const dispatch = useAppDispatch();
const onSubmit = (data: EndpointInput) => {
dispatch(addEndpoint(data)).then(
(result: { result: string; entities: { endpoints: Record<string, EndpointStore> } }) => {
(result: { result: string; entities: { endpoints: Record<string, Endpoint> } }) => {
if (result.entities) {
if (onCreate) {
const endpointCreated = result.entities.endpoints[result.result];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ import Dialog from '../../../../components/common/Dialog';
import DialogDelete from '../../../../components/common/DialogDelete';
import Drawer from '../../../../components/common/Drawer';
import { useFormatter } from '../../../../components/i18n';
import type { EndpointInput } from '../../../../utils/api-types';
import type { Endpoint, EndpointInput } from '../../../../utils/api-types';
import { useAppDispatch } from '../../../../utils/hooks';
import type { EndpointStore } from './Endpoint';
import EndpointForm from './EndpointForm';
import { EndpointStoreWithType } from './EndpointsList';

Expand All @@ -23,7 +22,7 @@ interface Props {
onRemoveEndpointFromInject?: (assetId: string) => void;
onRemoveEndpointFromAssetGroup?: (assetId: string) => void;
openEditOnInit?: boolean;
onUpdate?: (result: EndpointStore) => void;
onUpdate?: (result: Endpoint) => void;
onDelete?: (result: string) => void;
}

Expand Down Expand Up @@ -65,7 +64,7 @@ const EndpointPopover: React.FC<Props> = ({
};
const submitEdit = (data: EndpointInput) => {
dispatch(updateEndpoint(endpoint.asset_id, data)).then(
(result: { result: string; entities: { endpoints: Record<string, EndpointStore> } }) => {
(result: { result: string; entities: { endpoints: Record<string, Endpoint> } }) => {
if (result.entities) {
if (onUpdate) {
const endpointUpdated = result.entities.endpoints[result.result];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ import { useFormatter } from '../../../../components/i18n';
import ItemTags from '../../../../components/ItemTags';
import PlatformIcon from '../../../../components/PlatformIcon';
import { useHelper } from '../../../../store';
import type { SearchPaginationInput } from '../../../../utils/api-types';
import type { Endpoint, SearchPaginationInput } from '../../../../utils/api-types';
import { useAppDispatch } from '../../../../utils/hooks';
import useDataLoader from '../../../../utils/hooks/useDataLoader';
import AssetStatus from '../AssetStatus';
import type { EndpointStore } from './Endpoint';
import EndpointCreation from './EndpointCreation';
import EndpointPopover from './EndpointPopover';

Expand Down Expand Up @@ -107,7 +106,7 @@ const Endpoints = () => {
{ field: 'asset_status', label: 'Status', isSortable: false },
];

const [endpoints, setEndpoints] = useState<EndpointStore[]>([]);
const [endpoints, setEndpoints] = useState<Endpoint[]>([]);
const [searchPaginationInput, setSearchPaginationInput] = useState<SearchPaginationInput>(buildSearchPagination({
sorts: initSorting('asset_name'),
textSearch: search,
Expand Down Expand Up @@ -158,7 +157,7 @@ const Endpoints = () => {
/>
<ListItemSecondaryAction />
</ListItem>
{endpoints.map((endpoint: EndpointStore) => {
{endpoints.map((endpoint: Endpoint) => {
const executor = executorsMap[endpoint.asset_executor ?? 'Unknown'];
return (
<ListItem
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ import { useFormatter } from '../../../../components/i18n';
import ItemTags from '../../../../components/ItemTags';
import PlatformIcon from '../../../../components/PlatformIcon';
import { useHelper } from '../../../../store';
import type { FilterGroup } from '../../../../utils/api-types';
import type { Endpoint, FilterGroup } from '../../../../utils/api-types';
import { useAppDispatch } from '../../../../utils/hooks';
import useDataLoader from '../../../../utils/hooks/useDataLoader';
import type { EndpointStore } from './Endpoint';

interface Props {
initialState: string[];
Expand Down Expand Up @@ -51,7 +50,7 @@ const EndpointsDialogAdding: FunctionComponent<Props> = ({
dispatch(fetchEndpoints());
});

const [endpointValues, setEndpointValues] = useState<EndpointStore[]>(initialState.map(id => endpointsMap[id]));
const [endpointValues, setEndpointValues] = useState<Endpoint[]>(initialState.map(id => endpointsMap[id]));
useEffect(() => {
setEndpointValues(initialState.map(id => endpointsMap[id]));
}, [open, initialState]);
Expand All @@ -75,19 +74,19 @@ const EndpointsDialogAdding: FunctionComponent<Props> = ({
};

// Headers
const elements: SelectListElements<EndpointStore> = useMemo(() => ({
const elements: SelectListElements<Endpoint> = useMemo(() => ({
icon: {
value: () => <DevicesOtherOutlined color="primary" />,
},
headers: [
{
field: 'asset_name',
value: (endpoint: EndpointStore) => endpoint.asset_name,
value: (endpoint: Endpoint) => endpoint.asset_name,
width: 50,
},
{
field: 'endpoint_platform',
value: (endpoint: EndpointStore) => (
value: (endpoint: Endpoint) => (
<div style={{ display: 'flex', alignItems: 'center' }}>
<PlatformIcon platform={endpoint.endpoint_platform} width={20} marginRight={10} />
{endpoint.endpoint_platform}
Expand All @@ -97,19 +96,19 @@ const EndpointsDialogAdding: FunctionComponent<Props> = ({
},
{
field: 'endpoint_arch',
value: (endpoint: EndpointStore) => endpoint.endpoint_arch,
value: (endpoint: Endpoint) => endpoint.endpoint_arch,
width: 20,
},
{
field: 'asset_tags',
value: (endpoint: EndpointStore) => <ItemTags variant="reduced-view" tags={endpoint.asset_tags} />,
value: (endpoint: Endpoint) => <ItemTags variant="reduced-view" tags={endpoint.asset_tags} />,
width: 30,
},
],
}), []);

// Pagination
const [endpoints, setEndpoints] = useState<EndpointStore[]>([]);
const [endpoints, setEndpoints] = useState<Endpoint[]>([]);

const availableFilterNames = [
'asset_tags',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as React from 'react';

import ItemTags from '../../../../components/ItemTags';
import PlatformIcon from '../../../../components/PlatformIcon';
import type { EndpointStore } from './Endpoint';
import { Endpoint } from '../../../../utils/api-types';

const useStyles = makeStyles(() => ({
item: {
Expand Down Expand Up @@ -45,7 +45,7 @@ const inlineStyles: Record<string, CSSProperties> = {
},
};

export type EndpointStoreWithType = EndpointStore & { type: string };
export type EndpointStoreWithType = Endpoint & { type: string };

interface Props {
endpoints: EndpointStoreWithType[];
Expand All @@ -59,7 +59,7 @@ const EndpointsList: FunctionComponent<Props> = ({
// Standard hooks
const classes = useStyles();

const component = (endpoint: EndpointStore) => {
const component = (endpoint: Endpoint) => {
return React.cloneElement(actions as React.ReactElement, { endpoint });
};

Expand Down
Loading

0 comments on commit 71172aa

Please sign in to comment.