From 71172aabc4ca3954b070a5f5949a9dd1eb531dc5 Mon Sep 17 00:00:00 2001 From: Romuald Lemesle Date: Thu, 5 Dec 2024 11:14:28 +0100 Subject: [PATCH] [frontend] Remove EndpointStore, AssetGroupStore & ArticleStore --- .../actions/asset_groups/assetgroup-helper.d.ts | 8 ++++---- .../src/actions/assets/asset-helper.d.ts | 6 +++--- openbas-front/src/actions/channels/Article.d.ts | 7 +------ .../src/actions/channels/article-helper.d.ts | 5 ++--- .../src/admin/components/Dashboard.tsx | 7 +++---- .../asset_groups/AssetGroupAddEndpoints.tsx | 4 ++-- .../assets/asset_groups/AssetGroupCreation.tsx | 5 ++--- .../asset_groups/AssetGroupManagement.tsx | 5 ++--- .../assets/asset_groups/AssetGroupPopover.tsx | 9 ++++----- .../assets/asset_groups/AssetGroups.tsx | 7 +++---- .../assets/endpoints/EndpointCreation.tsx | 7 +++---- .../assets/endpoints/EndpointPopover.tsx | 7 +++---- .../components/assets/endpoints/Endpoints.tsx | 7 +++---- .../assets/endpoints/EndpointsDialogAdding.tsx | 17 ++++++++--------- .../assets/endpoints/EndpointsList.tsx | 6 +++--- .../src/admin/components/common/Context.ts | 11 ++++++----- .../components/common/articles/Articles.tsx | 5 +++-- .../common/injects/InjectAddArticles.tsx | 5 +++-- .../common/injects/InjectAddTeams.tsx | 8 +++----- .../admin/components/common/injects/Injects.tsx | 5 ++--- .../components/components/teams/UpdateTeams.tsx | 7 +++---- .../components/scenarios/scenario/Scenario.tsx | 3 +-- .../articles/articleContextForScenario.ts | 8 ++++---- .../admin/components/simulations/Exercises.tsx | 3 +-- .../articles/articleContextForExercise.ts | 8 ++++---- .../validation/common/TeamOrAssetLine.tsx | 8 +++----- .../TechnicalExpectationAssetGroup.tsx | 8 +++----- 27 files changed, 82 insertions(+), 104 deletions(-) diff --git a/openbas-front/src/actions/asset_groups/assetgroup-helper.d.ts b/openbas-front/src/actions/asset_groups/assetgroup-helper.d.ts index 9a39d00ca8..bfe837b031 100644 --- a/openbas-front/src/actions/asset_groups/assetgroup-helper.d.ts +++ b/openbas-front/src/actions/asset_groups/assetgroup-helper.d.ts @@ -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; - getAssetGroup: (assetGroupId: string) => AssetGroupStore | undefined; + getAssetGroups: () => AssetGroup[]; + getAssetGroupMaps: () => Record; + getAssetGroup: (assetGroupId: string) => AssetGroup | undefined; } diff --git a/openbas-front/src/actions/assets/asset-helper.d.ts b/openbas-front/src/actions/assets/asset-helper.d.ts index 3bd5de544d..a53824cb16 100644 --- a/openbas-front/src/actions/assets/asset-helper.d.ts +++ b/openbas-front/src/actions/assets/asset-helper.d.ts @@ -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; + getEndpoints: () => Endpoint[]; + getEndpointsMap: () => Record; } export interface SecurityPlatformHelper { diff --git a/openbas-front/src/actions/channels/Article.d.ts b/openbas-front/src/actions/channels/Article.d.ts index 55172ec364..2ef646e86f 100644 --- a/openbas-front/src/actions/channels/Article.d.ts +++ b/openbas-front/src/actions/channels/Article.d.ts @@ -1,10 +1,5 @@ import type { Article, Channel } from '../../utils/api-types'; -export type ArticleStore = Omit & { - article_channel: string | undefined; - article_documents: string[] | undefined; -}; - -export type FullArticleStore = ArticleStore & { +export type FullArticleStore = Article & { article_fullchannel: Channel; }; diff --git a/openbas-front/src/actions/channels/article-helper.d.ts b/openbas-front/src/actions/channels/article-helper.d.ts index 5ec8d84935..2c91f8c1a8 100644 --- a/openbas-front/src/actions/channels/article-helper.d.ts +++ b/openbas-front/src/actions/channels/article-helper.d.ts @@ -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; - getExerciseArticles: (exerciseId: Exercise['exercise_id']) => ArticleStore[]; - getScenarioArticles: (scenarioId: ScenarioStore['scenario_id']) => ArticleStore[]; + getExerciseArticles: (exerciseId: Exercise['exercise_id']) => Article[]; + getScenarioArticles: (scenarioId: ScenarioStore['scenario_id']) => Article[]; } diff --git a/openbas-front/src/admin/components/Dashboard.tsx b/openbas-front/src/admin/components/Dashboard.tsx index 5a216816fa..2c7d895db2 100644 --- a/openbas-front/src/admin/components/Dashboard.tsx +++ b/openbas-front/src/admin/components/Dashboard.tsx @@ -7,7 +7,7 @@ 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'; @@ -15,12 +15,11 @@ 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'; @@ -70,7 +69,7 @@ const Dashboard = () => { // Exercises const [loadingExercises, setLoadingExercises] = useState(true); - const [exercises, setExercises] = useState([]); + const [exercises, setExercises] = useState([]); const searchPaginationInput = { sorts: initSorting('exercise_updated_at', 'DESC'), page: 0, diff --git a/openbas-front/src/admin/components/assets/asset_groups/AssetGroupAddEndpoints.tsx b/openbas-front/src/admin/components/assets/asset_groups/AssetGroupAddEndpoints.tsx index df36a9188d..c879a99832 100644 --- a/openbas-front/src/admin/components/assets/asset_groups/AssetGroupAddEndpoints.tsx +++ b/openbas-front/src/admin/components/assets/asset_groups/AssetGroupAddEndpoints.tsx @@ -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 = ({ diff --git a/openbas-front/src/admin/components/assets/asset_groups/AssetGroupCreation.tsx b/openbas-front/src/admin/components/assets/asset_groups/AssetGroupCreation.tsx index b1b88d1d33..16a93b16c0 100644 --- a/openbas-front/src/admin/components/assets/asset_groups/AssetGroupCreation.tsx +++ b/openbas-front/src/admin/components/assets/asset_groups/AssetGroupCreation.tsx @@ -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) => ({ @@ -24,7 +23,7 @@ const useStyles = makeStyles((theme: Theme) => ({ interface Props { inline?: boolean; - onCreate?: (result: AssetGroupStore) => void; + onCreate?: (result: AssetGroup) => void; } const AssetGroupCreation: FunctionComponent = ({ diff --git a/openbas-front/src/admin/components/assets/asset_groups/AssetGroupManagement.tsx b/openbas-front/src/admin/components/assets/asset_groups/AssetGroupManagement.tsx index 325d23e6c9..4f3c90402d 100644 --- a/openbas-front/src/admin/components/assets/asset_groups/AssetGroupManagement.tsx +++ b/openbas-front/src/admin/components/assets/asset_groups/AssetGroupManagement.tsx @@ -11,6 +11,7 @@ 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'; @@ -18,7 +19,6 @@ 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) => ({ @@ -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; } @@ -131,7 +131,6 @@ const AssetGroupManagement: FunctionComponent = ({ inline assetGroupId={assetGroup?.asset_group_id} assetGroupEndpointIds={assetGroup?.asset_group_assets ?? []} - onUpdate={onUpdate} onRemoveEndpointFromAssetGroup={onRemoveEndpointFromAssetGroup} /> ) diff --git a/openbas-front/src/admin/components/assets/asset_groups/AssetGroupPopover.tsx b/openbas-front/src/admin/components/assets/asset_groups/AssetGroupPopover.tsx index d47c92dba3..ff2ce5c4d5 100644 --- a/openbas-front/src/admin/components/assets/asset_groups/AssetGroupPopover.tsx +++ b/openbas-front/src/admin/components/assets/asset_groups/AssetGroupPopover.tsx @@ -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'; @@ -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; } @@ -72,7 +71,7 @@ const AssetGroupPopover: FunctionComponent = ({ }; const submitEdit = (data: AssetGroupInput) => { dispatch(updateAssetGroup(assetGroup.asset_group_id, data)).then( - (result: { result: string; entities: { asset_groups: Record } }) => { + (result: { result: string; entities: { asset_groups: Record } }) => { if (result.entities) { if (onUpdate) { const updated = result.entities.asset_groups[result.result]; diff --git a/openbas-front/src/admin/components/assets/asset_groups/AssetGroups.tsx b/openbas-front/src/admin/components/assets/asset_groups/AssetGroups.tsx index 0355d235f4..41e3fb3ad7 100644 --- a/openbas-front/src/admin/components/assets/asset_groups/AssetGroups.tsx +++ b/openbas-front/src/admin/components/assets/asset_groups/AssetGroups.tsx @@ -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'; @@ -133,7 +132,7 @@ const AssetGroups = () => { const classes = useStyles(); const { t } = useFormatter(); - const [selectedAssetGroupId, setSelectedAssetGroupId] = useState(undefined); + const [selectedAssetGroupId, setSelectedAssetGroupId] = useState(undefined); // Query param const [searchParams] = useSearchParams(); @@ -181,7 +180,7 @@ const AssetGroups = () => { 'asset_group_tags', ]; - const [assetGroups, setAssetGroups] = useState([]); + const [assetGroups, setAssetGroups] = useState([]); const { queryableHelpers, searchPaginationInput } = useQueryableWithLocalStorage('asset-groups', buildSearchPagination({ sorts: initSorting('asset_group_name'), textSearch: search, diff --git a/openbas-front/src/admin/components/assets/endpoints/EndpointCreation.tsx b/openbas-front/src/admin/components/assets/endpoints/EndpointCreation.tsx index 1b6afa3c85..89d755fa7c 100644 --- a/openbas-front/src/admin/components/assets/endpoints/EndpointCreation.tsx +++ b/openbas-front/src/admin/components/assets/endpoints/EndpointCreation.tsx @@ -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) => ({ @@ -23,7 +22,7 @@ const useStyles = makeStyles((theme: Theme) => ({ interface Props { inline?: boolean; - onCreate?: (result: EndpointStore) => void; + onCreate?: (result: Endpoint) => void; } const EndpointCreation: FunctionComponent = ({ @@ -38,7 +37,7 @@ const EndpointCreation: FunctionComponent = ({ const dispatch = useAppDispatch(); const onSubmit = (data: EndpointInput) => { dispatch(addEndpoint(data)).then( - (result: { result: string; entities: { endpoints: Record } }) => { + (result: { result: string; entities: { endpoints: Record } }) => { if (result.entities) { if (onCreate) { const endpointCreated = result.entities.endpoints[result.result]; diff --git a/openbas-front/src/admin/components/assets/endpoints/EndpointPopover.tsx b/openbas-front/src/admin/components/assets/endpoints/EndpointPopover.tsx index 98aa83ce8a..60cd1e37d3 100644 --- a/openbas-front/src/admin/components/assets/endpoints/EndpointPopover.tsx +++ b/openbas-front/src/admin/components/assets/endpoints/EndpointPopover.tsx @@ -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'; @@ -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; } @@ -65,7 +64,7 @@ const EndpointPopover: React.FC = ({ }; const submitEdit = (data: EndpointInput) => { dispatch(updateEndpoint(endpoint.asset_id, data)).then( - (result: { result: string; entities: { endpoints: Record } }) => { + (result: { result: string; entities: { endpoints: Record } }) => { if (result.entities) { if (onUpdate) { const endpointUpdated = result.entities.endpoints[result.result]; diff --git a/openbas-front/src/admin/components/assets/endpoints/Endpoints.tsx b/openbas-front/src/admin/components/assets/endpoints/Endpoints.tsx index 2cdc4043f9..39be9da63d 100644 --- a/openbas-front/src/admin/components/assets/endpoints/Endpoints.tsx +++ b/openbas-front/src/admin/components/assets/endpoints/Endpoints.tsx @@ -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'; @@ -107,7 +106,7 @@ const Endpoints = () => { { field: 'asset_status', label: 'Status', isSortable: false }, ]; - const [endpoints, setEndpoints] = useState([]); + const [endpoints, setEndpoints] = useState([]); const [searchPaginationInput, setSearchPaginationInput] = useState(buildSearchPagination({ sorts: initSorting('asset_name'), textSearch: search, @@ -158,7 +157,7 @@ const Endpoints = () => { /> - {endpoints.map((endpoint: EndpointStore) => { + {endpoints.map((endpoint: Endpoint) => { const executor = executorsMap[endpoint.asset_executor ?? 'Unknown']; return ( = ({ dispatch(fetchEndpoints()); }); - const [endpointValues, setEndpointValues] = useState(initialState.map(id => endpointsMap[id])); + const [endpointValues, setEndpointValues] = useState(initialState.map(id => endpointsMap[id])); useEffect(() => { setEndpointValues(initialState.map(id => endpointsMap[id])); }, [open, initialState]); @@ -75,19 +74,19 @@ const EndpointsDialogAdding: FunctionComponent = ({ }; // Headers - const elements: SelectListElements = useMemo(() => ({ + const elements: SelectListElements = useMemo(() => ({ icon: { value: () => , }, 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) => (
{endpoint.endpoint_platform} @@ -97,19 +96,19 @@ const EndpointsDialogAdding: FunctionComponent = ({ }, { field: 'endpoint_arch', - value: (endpoint: EndpointStore) => endpoint.endpoint_arch, + value: (endpoint: Endpoint) => endpoint.endpoint_arch, width: 20, }, { field: 'asset_tags', - value: (endpoint: EndpointStore) => , + value: (endpoint: Endpoint) => , width: 30, }, ], }), []); // Pagination - const [endpoints, setEndpoints] = useState([]); + const [endpoints, setEndpoints] = useState([]); const availableFilterNames = [ 'asset_tags', diff --git a/openbas-front/src/admin/components/assets/endpoints/EndpointsList.tsx b/openbas-front/src/admin/components/assets/endpoints/EndpointsList.tsx index 5691b8ca01..7c266be820 100644 --- a/openbas-front/src/admin/components/assets/endpoints/EndpointsList.tsx +++ b/openbas-front/src/admin/components/assets/endpoints/EndpointsList.tsx @@ -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: { @@ -45,7 +45,7 @@ const inlineStyles: Record = { }, }; -export type EndpointStoreWithType = EndpointStore & { type: string }; +export type EndpointStoreWithType = Endpoint & { type: string }; interface Props { endpoints: EndpointStoreWithType[]; @@ -59,7 +59,7 @@ const EndpointsList: FunctionComponent = ({ // Standard hooks const classes = useStyles(); - const component = (endpoint: EndpointStore) => { + const component = (endpoint: Endpoint) => { return React.cloneElement(actions as React.ReactElement, { endpoint }); }; diff --git a/openbas-front/src/admin/components/common/Context.ts b/openbas-front/src/admin/components/common/Context.ts index b87b4b5fd0..25a12cbce4 100644 --- a/openbas-front/src/admin/components/common/Context.ts +++ b/openbas-front/src/admin/components/common/Context.ts @@ -1,10 +1,11 @@ import { createContext, ReactElement } from 'react'; -import type { ArticleStore, FullArticleStore } from '../../../actions/channels/Article'; +import type { FullArticleStore } from '../../../actions/channels/Article'; import type { InjectOutputType, InjectStore } from '../../../actions/injects/Inject'; import type { TeamStore } from '../../../actions/teams/Team'; import { Page } from '../../../components/common/queryable/Page'; import type { + Article, ArticleCreateInput, ArticleUpdateInput, Evaluation, @@ -43,8 +44,8 @@ export type PermissionsContextType = { export type ArticleContextType = { previewArticleUrl: (article: FullArticleStore) => string; onAddArticle: (data: ArticleCreateInput) => Promise<{ result: string }>; - onUpdateArticle: (article: ArticleStore, data: ArticleUpdateInput) => string; - onDeleteArticle: (article: ArticleStore) => string; + onUpdateArticle: (article: Article, data: ArticleUpdateInput) => string; + onDeleteArticle: (article: Article) => string; }; export type ChallengeContextType = { @@ -133,10 +134,10 @@ export const ArticleContext = createContext({ onAddArticle(_data: ArticleCreateInput): Promise<{ result: string }> { return Promise.resolve({ result: '' }); }, - onDeleteArticle(_article: ArticleStore): string { + onDeleteArticle(_article: Article): string { return ''; }, - onUpdateArticle(_article: ArticleStore, _data: ArticleUpdateInput): string { + onUpdateArticle(_article: Article, _data: ArticleUpdateInput): string { return ''; }, previewArticleUrl(_article: FullArticleStore): string { diff --git a/openbas-front/src/admin/components/common/articles/Articles.tsx b/openbas-front/src/admin/components/common/articles/Articles.tsx index f8160fd8c2..2247778c1e 100644 --- a/openbas-front/src/admin/components/common/articles/Articles.tsx +++ b/openbas-front/src/admin/components/common/articles/Articles.tsx @@ -6,7 +6,7 @@ import * as R from 'ramda'; import { Fragment, FunctionComponent, useContext, useState } from 'react'; import { Link } from 'react-router-dom'; -import type { ArticleStore, FullArticleStore } from '../../../../actions/channels/Article'; +import type { FullArticleStore } from '../../../../actions/channels/Article'; import { fetchChannels } from '../../../../actions/channels/channel-action'; import type { ChannelsHelper } from '../../../../actions/channels/channel-helper'; import { fetchDocuments } from '../../../../actions/Document'; @@ -16,6 +16,7 @@ import ExpandableMarkdown from '../../../../components/ExpandableMarkdown'; import { useFormatter } from '../../../../components/i18n'; import ChannelColor from '../../../../public/components/channels/ChannelColor'; import { useHelper } from '../../../../store'; +import { Article } from '../../../../utils/api-types'; import { useAppDispatch } from '../../../../utils/hooks'; import useDataLoader from '../../../../utils/hooks/useDataLoader'; import useSearchAnFilter from '../../../../utils/SortingFiltering'; @@ -50,7 +51,7 @@ const useStyles = makeStyles(() => ({ })); interface Props { - articles: ArticleStore[]; + articles: Article[]; } const Articles: FunctionComponent = ({ articles }) => { diff --git a/openbas-front/src/admin/components/common/injects/InjectAddArticles.tsx b/openbas-front/src/admin/components/common/injects/InjectAddArticles.tsx index 177f74b67e..ac414ab004 100644 --- a/openbas-front/src/admin/components/common/injects/InjectAddArticles.tsx +++ b/openbas-front/src/admin/components/common/injects/InjectAddArticles.tsx @@ -16,7 +16,7 @@ import { makeStyles } from '@mui/styles'; import * as R from 'ramda'; import { FunctionComponent, useContext, useState } from 'react'; -import type { ArticleStore, FullArticleStore } from '../../../../actions/channels/Article'; +import type { FullArticleStore } from '../../../../actions/channels/Article'; import type { ArticlesHelper } from '../../../../actions/channels/article-helper'; import { fetchChannels } from '../../../../actions/channels/channel-action'; import type { ChannelsHelper } from '../../../../actions/channels/channel-helper'; @@ -25,6 +25,7 @@ import { useFormatter } from '../../../../components/i18n'; import SearchFilter from '../../../../components/SearchFilter'; import type { Theme } from '../../../../components/Theme'; import { useHelper } from '../../../../store'; +import { Article } from '../../../../utils/api-types'; import { useAppDispatch } from '../../../../utils/hooks'; import useDataLoader from '../../../../utils/hooks/useDataLoader'; import { truncate } from '../../../../utils/String'; @@ -54,7 +55,7 @@ const useStyles = makeStyles((theme: Theme) => ({ })); interface Props { - articles: ArticleStore[]; + articles: Article[]; handleAddArticles: (articleIds: string[]) => void; injectArticlesIds: string[]; } diff --git a/openbas-front/src/admin/components/common/injects/InjectAddTeams.tsx b/openbas-front/src/admin/components/common/injects/InjectAddTeams.tsx index 2659a2c21c..a332909c32 100644 --- a/openbas-front/src/admin/components/common/injects/InjectAddTeams.tsx +++ b/openbas-front/src/admin/components/common/injects/InjectAddTeams.tsx @@ -13,7 +13,6 @@ import { import { makeStyles } from '@mui/styles'; import { FunctionComponent, useContext, useEffect, useMemo, useState } from 'react'; -import type { TeamStore } from '../../../../actions/teams/Team'; import { findTeams } from '../../../../actions/teams/team-actions'; import PaginationComponentV2 from '../../../../components/common/queryable/pagination/PaginationComponentV2'; import { buildSearchPagination } from '../../../../components/common/queryable/QueryableUtils'; @@ -24,7 +23,6 @@ import { useFormatter } from '../../../../components/i18n'; import ItemTags from '../../../../components/ItemTags'; import type { Theme } from '../../../../components/Theme'; import type { TeamOutput } from '../../../../utils/api-types'; -import type { EndpointStore } from '../../assets/endpoints/Endpoint'; import CreateTeam from '../../components/teams/CreateTeam'; import { PermissionsContext, TeamContext } from '../Context'; @@ -82,19 +80,19 @@ const InjectAddTeams: FunctionComponent = ({ const removeTeam = (teamId: string) => setSelectedTeamValues(selectedTeamValues.filter(v => v.team_id !== teamId)); // Headers - const elements: SelectListElements = useMemo(() => ({ + const elements: SelectListElements = useMemo(() => ({ icon: { value: () => , }, headers: [ { field: 'team_name', - value: (team: TeamStore) => team.team_name, + value: (team: TeamOutput) => team.team_name, width: 70, }, { field: 'team_tags', - value: (team: TeamStore) => , + value: (team: TeamOutput) => , width: 30, }, ], diff --git a/openbas-front/src/admin/components/common/injects/Injects.tsx b/openbas-front/src/admin/components/common/injects/Injects.tsx index 087032fca3..1a834b1f06 100644 --- a/openbas-front/src/admin/components/common/injects/Injects.tsx +++ b/openbas-front/src/admin/components/common/injects/Injects.tsx @@ -5,7 +5,6 @@ import { CSSProperties, FunctionComponent, useContext, useMemo, useState } from import * as React from 'react'; import { Link } from 'react-router-dom'; -import type { ArticleStore } from '../../../../actions/channels/Article'; import type { InjectorContractConvertedContent, InjectOutputType, InjectStore } from '../../../../actions/injects/Inject'; import type { TeamStore } from '../../../../actions/teams/Team'; import ChainedTimeline from '../../../../components/ChainedTimeline'; @@ -20,7 +19,7 @@ import { useFormatter } from '../../../../components/i18n'; import ItemBoolean from '../../../../components/ItemBoolean'; import ItemTags from '../../../../components/ItemTags'; import PlatformIcon from '../../../../components/PlatformIcon'; -import type { FilterGroup, Inject, InjectTestStatus, Variable } from '../../../../utils/api-types'; +import type { Article, FilterGroup, Inject, InjectTestStatus, Variable } from '../../../../utils/api-types'; import { MESSAGING$ } from '../../../../utils/Environment'; import useEntityToggle from '../../../../utils/hooks/useEntityToggle'; import { splitDuration } from '../../../../utils/Time'; @@ -96,7 +95,7 @@ interface Props { setViewMode?: (mode: string) => void; availableButtons: string[]; teams: TeamStore[]; - articles: ArticleStore[]; + articles: Article[]; variables: Variable[]; uriVariable: string; allUsersNumber?: number; diff --git a/openbas-front/src/admin/components/components/teams/UpdateTeams.tsx b/openbas-front/src/admin/components/components/teams/UpdateTeams.tsx index e6cf33b35e..7703abfa92 100644 --- a/openbas-front/src/admin/components/components/teams/UpdateTeams.tsx +++ b/openbas-front/src/admin/components/components/teams/UpdateTeams.tsx @@ -14,7 +14,6 @@ import Transition from '../../../../components/common/Transition'; import { useFormatter } from '../../../../components/i18n'; import ItemTags from '../../../../components/ItemTags'; import type { Team, TeamOutput } from '../../../../utils/api-types'; -import type { EndpointStore } from '../../assets/endpoints/Endpoint'; import { TeamContext } from '../../common/Context'; import CreateTeam from './CreateTeam'; @@ -72,19 +71,19 @@ const UpdateTeams: React.FC = ({ const removeTeam = (teamId: string) => setSelectedTeamValues(selectedTeamValues.filter(v => v.team_id !== teamId)); // Headers - const elements: SelectListElements = useMemo(() => ({ + const elements: SelectListElements = useMemo(() => ({ icon: { value: () => , }, headers: [ { field: 'team_name', - value: (team: TeamStore) => team.team_name, + value: (team: TeamOutput) => team.team_name, width: 70, }, { field: 'team_tags', - value: (team: TeamStore) => , + value: (team: TeamOutput) => , width: 30, }, ], diff --git a/openbas-front/src/admin/components/scenarios/scenario/Scenario.tsx b/openbas-front/src/admin/components/scenarios/scenario/Scenario.tsx index 27f991f1a6..0ccc3f6a35 100644 --- a/openbas-front/src/admin/components/scenarios/scenario/Scenario.tsx +++ b/openbas-front/src/admin/components/scenarios/scenario/Scenario.tsx @@ -31,7 +31,6 @@ import type { KillChainPhase, SearchPaginationInput } from '../../../../utils/ap import { useAppDispatch } from '../../../../utils/hooks'; import useDataLoader from '../../../../utils/hooks/useDataLoader'; import { isEmptyField } from '../../../../utils/utils'; -import type { EndpointStore } from '../../assets/endpoints/Endpoint'; import ExerciseList from '../../simulations/ExerciseList'; import ExercisePopover from '../../simulations/simulation/ExercisePopover'; import ScenarioDistributionByExercise from './ScenarioDistributionByExercise'; @@ -81,7 +80,7 @@ const Scenario = ({ setOpenInstantiateSimulationAndStart }: { setOpenInstantiate // Exercises const [loadingExercises, setLoadingExercises] = useState(true); - const [exercises, setExercises] = useState([]); + const [exercises, setExercises] = useState([]); const { queryableHelpers, searchPaginationInput } = useQueryableWithLocalStorage(`scenario-${scenarioId}-simulations`, buildSearchPagination({ sorts: initSorting('exercise_start_date'), })); diff --git a/openbas-front/src/admin/components/scenarios/scenario/articles/articleContextForScenario.ts b/openbas-front/src/admin/components/scenarios/scenario/articles/articleContextForScenario.ts index e4b7ce548a..1ac8713893 100644 --- a/openbas-front/src/admin/components/scenarios/scenario/articles/articleContextForScenario.ts +++ b/openbas-front/src/admin/components/scenarios/scenario/articles/articleContextForScenario.ts @@ -1,7 +1,7 @@ -import type { ArticleStore, FullArticleStore } from '../../../../../actions/channels/Article'; +import type { FullArticleStore } from '../../../../../actions/channels/Article'; import { addScenarioArticle, deleteScenarioArticle, updateScenarioArticle } from '../../../../../actions/channels/article-action'; import type { ScenarioStore } from '../../../../../actions/scenarios/Scenario'; -import type { ArticleCreateInput, ArticleUpdateInput } from '../../../../../utils/api-types'; +import { Article, ArticleCreateInput, ArticleUpdateInput } from '../../../../../utils/api-types'; import { useAppDispatch } from '../../../../../utils/hooks'; const articleContextForScenario = (scenarioId: ScenarioStore['scenario_id']) => { @@ -9,10 +9,10 @@ const articleContextForScenario = (scenarioId: ScenarioStore['scenario_id']) => return { previewArticleUrl: (article: FullArticleStore) => `/channels/${scenarioId}/${article.article_fullchannel?.channel_id}?preview=true`, onAddArticle: (data: ArticleCreateInput) => dispatch(addScenarioArticle(scenarioId, data)), - onUpdateArticle: (article: ArticleStore, data: ArticleUpdateInput) => dispatch( + onUpdateArticle: (article: Article, data: ArticleUpdateInput) => dispatch( updateScenarioArticle(scenarioId, article.article_id, data), ), - onDeleteArticle: (article: ArticleStore) => dispatch( + onDeleteArticle: (article: Article) => dispatch( deleteScenarioArticle(scenarioId, article.article_id), ), }; diff --git a/openbas-front/src/admin/components/simulations/Exercises.tsx b/openbas-front/src/admin/components/simulations/Exercises.tsx index a7e7187e14..a55a6f3291 100644 --- a/openbas-front/src/admin/components/simulations/Exercises.tsx +++ b/openbas-front/src/admin/components/simulations/Exercises.tsx @@ -15,7 +15,6 @@ import { useQueryableWithLocalStorage } from '../../../components/common/queryab import { useFormatter } from '../../../components/i18n'; import { useHelper } from '../../../store'; import type { FilterGroup, SearchPaginationInput } from '../../../utils/api-types'; -import type { EndpointStore } from '../assets/endpoints/Endpoint'; import ExerciseList from './ExerciseList'; import ImportUploaderExercise from './ImportUploaderExercise'; import ExerciseCreation from './simulation/ExerciseCreation'; @@ -31,7 +30,7 @@ const Exercises = () => { })); const [loading, setLoading] = useState(true); - const [exercises, setExercises] = useState([]); + const [exercises, setExercises] = useState([]); // Filters const availableFilterNames = [ diff --git a/openbas-front/src/admin/components/simulations/simulation/articles/articleContextForExercise.ts b/openbas-front/src/admin/components/simulations/simulation/articles/articleContextForExercise.ts index bcbc0e6d36..9b67e18d25 100644 --- a/openbas-front/src/admin/components/simulations/simulation/articles/articleContextForExercise.ts +++ b/openbas-front/src/admin/components/simulations/simulation/articles/articleContextForExercise.ts @@ -1,7 +1,7 @@ -import type { ArticleStore, FullArticleStore } from '../../../../../actions/channels/Article'; +import type { FullArticleStore } from '../../../../../actions/channels/Article'; import { addExerciseArticle, deleteExerciseArticle, updateExerciseArticle } from '../../../../../actions/channels/article-action'; import type { ExerciseStore } from '../../../../../actions/exercises/Exercise'; -import type { ArticleCreateInput, ArticleUpdateInput } from '../../../../../utils/api-types'; +import { Article, ArticleCreateInput, ArticleUpdateInput } from '../../../../../utils/api-types'; import { useAppDispatch } from '../../../../../utils/hooks'; const articleContextForExercise = (exerciseId: ExerciseStore['exercise_id']) => { @@ -9,10 +9,10 @@ const articleContextForExercise = (exerciseId: ExerciseStore['exercise_id']) => return { previewArticleUrl: (article: FullArticleStore) => `/channels/${exerciseId}/${article.article_fullchannel?.channel_id}?preview=true`, onAddArticle: (data: ArticleCreateInput) => dispatch(addExerciseArticle(exerciseId, data)), - onUpdateArticle: (article: ArticleStore, data: ArticleUpdateInput) => dispatch( + onUpdateArticle: (article: Article, data: ArticleUpdateInput) => dispatch( updateExerciseArticle(exerciseId, article.article_id, data), ), - onDeleteArticle: (article: ArticleStore) => dispatch( + onDeleteArticle: (article: Article) => dispatch( deleteExerciseArticle(exerciseId, article.article_id), ), }; diff --git a/openbas-front/src/admin/components/simulations/simulation/validation/common/TeamOrAssetLine.tsx b/openbas-front/src/admin/components/simulations/simulation/validation/common/TeamOrAssetLine.tsx index cbcbb9726e..49fde17948 100644 --- a/openbas-front/src/admin/components/simulations/simulation/validation/common/TeamOrAssetLine.tsx +++ b/openbas-front/src/admin/components/simulations/simulation/validation/common/TeamOrAssetLine.tsx @@ -17,11 +17,9 @@ import { fetchExerciseTeams } from '../../../../../../actions/Exercise'; import type { ChallengeHelper } from '../../../../../../actions/helper'; import type { TeamsHelper } from '../../../../../../actions/teams/team-helper'; import { useHelper } from '../../../../../../store'; -import type { Inject, Team } from '../../../../../../utils/api-types'; +import type { AssetGroup, Endpoint, Inject, Team } from '../../../../../../utils/api-types'; import { useAppDispatch } from '../../../../../../utils/hooks'; import useDataLoader from '../../../../../../utils/hooks/useDataLoader'; -import type { AssetGroupStore } from '../../../../assets/asset_groups/AssetGroup'; -import type { EndpointStore } from '../../../../assets/endpoints/Endpoint'; import type { InjectExpectationsStore } from '../../../../common/injects/expectations/Expectation'; import ChallengeExpectation from '../expectations/ChallengeExpectation'; import ChannelExpectation from '../expectations/ChannelExpectation'; @@ -89,8 +87,8 @@ const TeamOrAssetLine: FunctionComponent = ({ }); const team: Team = teamsMap[id]; - const asset: EndpointStore = assetsMap[id]; - const assetGroup: AssetGroupStore = assetGroupsMap[id]; + const asset: Endpoint = assetsMap[id]; + const assetGroup: AssetGroup = assetGroupsMap[id]; const groupByExpectationName = (es: InjectExpectationsStore[]) => { return es.reduce((group, expectation) => { diff --git a/openbas-front/src/admin/components/simulations/simulation/validation/expectations/TechnicalExpectationAssetGroup.tsx b/openbas-front/src/admin/components/simulations/simulation/validation/expectations/TechnicalExpectationAssetGroup.tsx index 4ca5060a88..a86c35cc36 100644 --- a/openbas-front/src/admin/components/simulations/simulation/validation/expectations/TechnicalExpectationAssetGroup.tsx +++ b/openbas-front/src/admin/components/simulations/simulation/validation/expectations/TechnicalExpectationAssetGroup.tsx @@ -6,9 +6,7 @@ import { FunctionComponent } from 'react'; import type { EndpointHelper } from '../../../../../../actions/assets/asset-helper'; import type { Contract } from '../../../../../../actions/contract/contract'; import { useHelper } from '../../../../../../store'; -import type { Team } from '../../../../../../utils/api-types'; -import type { AssetGroupStore } from '../../../../assets/asset_groups/AssetGroup'; -import type { EndpointStore } from '../../../../assets/endpoints/Endpoint'; +import type { AssetGroup, Endpoint, Team } from '../../../../../../utils/api-types'; import type { InjectExpectationsStore } from '../../../../common/injects/expectations/Expectation'; import { typeIcon } from '../../../../common/injects/expectations/ExpectationUtils'; import ExpectationLine from './ExpectationLine'; @@ -31,7 +29,7 @@ interface Props { injectContract: Contract; relatedExpectations: InjectExpectationsStore[]; team: Team; - assetGroup: AssetGroupStore; + assetGroup: AssetGroup; } const TechnicalExpectationAssetGroup: FunctionComponent = ({ @@ -62,7 +60,7 @@ const TechnicalExpectationAssetGroup: FunctionComponent = ({ icon={typeIcon(expectation.inject_expectation_type)} /> {Array.from(groupedByAsset(relatedExpectations)).map(([groupedId, groupedExpectations]) => { - const relatedAsset: EndpointStore = assetsMap[groupedId]; + const relatedAsset: Endpoint = assetsMap[groupedId]; return (