From 41dfeaaae2f4df0dca627df2c0219dbf3fcce511 Mon Sep 17 00:00:00 2001 From: Laurent Bonnet Date: Tue, 12 Mar 2024 16:21:31 +0100 Subject: [PATCH 01/14] [backend] expand entity resolution when converting aggregate distribution (#6319) --- .../opencti-graphql/src/database/middleware.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/opencti-platform/opencti-graphql/src/database/middleware.js b/opencti-platform/opencti-graphql/src/database/middleware.js index cf0ecd89a94e..a90bdc9c3296 100644 --- a/opencti-platform/opencti-graphql/src/database/middleware.js +++ b/opencti-platform/opencti-graphql/src/database/middleware.js @@ -449,11 +449,16 @@ export const stixLoadByFilters = async (context, user, types, args) => { // region Graphics const convertAggregateDistributions = async (context, user, limit, orderingFunction, distribution) => { - const data = R.take(limit, R.sortWith([orderingFunction(R.prop('value'))])(distribution)); + const data = R.sortWith([orderingFunction(R.prop('value'))])(distribution); + // we try to resolve the complete batch of 100 results const resolveLabels = await elFindByIds(context, user, data.map((d) => d.label), { toMap: true }); - return data // Depending of user access, info can be empty, must be filtered + // Depending of user access, info can be empty, must be filtered + const filteredEntities = data .filter((n) => isNotEmptyField(resolveLabels[n.label.toLowerCase()])) .map((n) => R.assoc('entity', resolveLabels[n.label.toLowerCase()], n)); + // take only the 'limit' first match + // TODO: integrate data access restriction into aggregation query, and directly return 'limit' element instead of 100 + return R.take(limit, filteredEntities); }; export const timeSeriesHistory = async (context, user, types, args) => { const { startDate, endDate, interval } = args; From cbf4290700ab16a830c8f7e492bc9c468f60ce85 Mon Sep 17 00:00:00 2001 From: Laurent Bonnet Date: Mon, 25 Mar 2024 11:01:14 +0100 Subject: [PATCH 02/14] Revert "[backend] expand entity resolution when converting aggregate distribution (#6319)" This reverts commit 1c304d5d14043c4a5206d27c0a167dbdf1201e3f. --- .../opencti-graphql/src/database/middleware.js | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/opencti-platform/opencti-graphql/src/database/middleware.js b/opencti-platform/opencti-graphql/src/database/middleware.js index a90bdc9c3296..cf0ecd89a94e 100644 --- a/opencti-platform/opencti-graphql/src/database/middleware.js +++ b/opencti-platform/opencti-graphql/src/database/middleware.js @@ -449,16 +449,11 @@ export const stixLoadByFilters = async (context, user, types, args) => { // region Graphics const convertAggregateDistributions = async (context, user, limit, orderingFunction, distribution) => { - const data = R.sortWith([orderingFunction(R.prop('value'))])(distribution); - // we try to resolve the complete batch of 100 results + const data = R.take(limit, R.sortWith([orderingFunction(R.prop('value'))])(distribution)); const resolveLabels = await elFindByIds(context, user, data.map((d) => d.label), { toMap: true }); - // Depending of user access, info can be empty, must be filtered - const filteredEntities = data + return data // Depending of user access, info can be empty, must be filtered .filter((n) => isNotEmptyField(resolveLabels[n.label.toLowerCase()])) .map((n) => R.assoc('entity', resolveLabels[n.label.toLowerCase()], n)); - // take only the 'limit' first match - // TODO: integrate data access restriction into aggregation query, and directly return 'limit' element instead of 100 - return R.take(limit, filteredEntities); }; export const timeSeriesHistory = async (context, user, types, args) => { const { startDate, endDate, interval } = args; From 298408c85108121466540f1d879bd2750a6fb06d Mon Sep 17 00:00:00 2001 From: Laurent Bonnet Date: Tue, 26 Mar 2024 11:17:43 +0100 Subject: [PATCH 03/14] [backend] do not send restricted entities with distributions --- .../opencti-graphql/src/database/middleware.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/opencti-platform/opencti-graphql/src/database/middleware.js b/opencti-platform/opencti-graphql/src/database/middleware.js index cf0ecd89a94e..8e4aca07afa0 100644 --- a/opencti-platform/opencti-graphql/src/database/middleware.js +++ b/opencti-platform/opencti-graphql/src/database/middleware.js @@ -450,10 +450,19 @@ export const stixLoadByFilters = async (context, user, types, args) => { // region Graphics const convertAggregateDistributions = async (context, user, limit, orderingFunction, distribution) => { const data = R.take(limit, R.sortWith([orderingFunction(R.prop('value'))])(distribution)); - const resolveLabels = await elFindByIds(context, user, data.map((d) => d.label), { toMap: true }); - return data // Depending of user access, info can be empty, must be filtered - .filter((n) => isNotEmptyField(resolveLabels[n.label.toLowerCase()])) - .map((n) => R.assoc('entity', resolveLabels[n.label.toLowerCase()], n)); + // resolve all of them, limited to ids for comparison in next step + const allResolveLabels = await elFindByIds(context, SYSTEM_USER, data.map((d) => d.label), { toMap: true }); + const grantedResolveLabels = await elFindByIds(context, user, data.map((d) => d.label), { toMap: true }); + // entities not granted shall be sent as "restricted" with limited information + return data + .filter((n) => isNotEmptyField(allResolveLabels[n.label.toLowerCase()])) + .map((n) => { + if (grantedResolveLabels[n.label.toLowerCase()]) { + return R.assoc('entity', grantedResolveLabels[n.label.toLowerCase()], n); + } + // return R.assoc('entity', { id: n.label, entity_type: n.entity_type, name: 'Restricted' }, n); + return n; // no entity details + }); }; export const timeSeriesHistory = async (context, user, types, args) => { const { startDate, endDate, interval } = args; From 1b62695dd98a90c616b184d99c2a0cc7d2c660cb Mon Sep 17 00:00:00 2001 From: Laurent Bonnet Date: Tue, 26 Mar 2024 11:19:16 +0100 Subject: [PATCH 04/14] [frontend] handle Distribution.entity that might be null --- .../src/components/dashboard/WidgetDonut.tsx | 15 +++++++-------- .../dashboard/WidgetListCoreObjects.tsx | 2 +- .../dashboard/WidgetListRelationships.tsx | 2 +- .../src/components/dashboard/WidgetRadar.tsx | 2 +- .../components/dashboard/WidgetTimeline.tsx | 2 +- .../src/components/dashboard/WidgetTree.tsx | 2 +- .../analyses/groupings/GroupingsDonut.jsx | 2 +- .../groupings/GroupingsHorizontalBars.jsx | 2 +- .../groupings/StixCoreObjectGroupingsDonut.jsx | 2 +- .../StixCoreObjectGroupingsHorizontalBars.jsx | 2 +- .../analyses/reports/ReportsDonut.jsx | 2 +- .../analyses/reports/ReportsHorizontalBars.jsx | 2 +- .../StixCoreObjectReportsHorizontalBars.jsx | 2 +- .../common/audits/AuditsDistributionList.jsx | 4 ++-- .../common/audits/AuditsHorizontalBars.jsx | 10 +++++----- .../common/location/GlobalVictimologyMap.jsx | 4 ++-- .../StixCoreObjectsDistributionList.jsx | 2 +- .../StixCoreObjectsHorizontalBars.jsx | 10 +++++----- .../StixCoreObjectsMultiHorizontalBars.jsx | 8 ++++---- ...tityStixCoreRelationshipsHorizontalBars.jsx | 6 +++--- .../StixRelationshipsDistributionList.jsx | 4 ++-- .../StixRelationshipsHorizontalBars.jsx | 18 +++++++++--------- .../StixRelationshipsMultiHorizontalBars.jsx | 16 ++++++++-------- .../StixRelationshipsPolarArea.jsx | 2 +- .../EntityStixSightingRelationshipsDonut.jsx | 9 ++++----- .../indicators/IndicatorsDonut.jsx | 2 +- .../opencti-front/src/utils/Graph.js | 2 +- 27 files changed, 67 insertions(+), 69 deletions(-) diff --git a/opencti-platform/opencti-front/src/components/dashboard/WidgetDonut.tsx b/opencti-platform/opencti-front/src/components/dashboard/WidgetDonut.tsx index 4a4beee20b63..0795e8fcd548 100644 --- a/opencti-platform/opencti-front/src/components/dashboard/WidgetDonut.tsx +++ b/opencti-platform/opencti-front/src/components/dashboard/WidgetDonut.tsx @@ -27,27 +27,26 @@ const WidgetDonut = ({ const chartData = data.map((n) => n.value); // eslint-disable-next-line no-nested-ternary const labels = data.map((n) => (groupBy.endsWith('_id') - ? defaultValue(n.entity) + ? defaultValue(n.entity, 'Restricted') : groupBy === 'entity_type' && t_i18n(`entity_${n.label}`) !== `entity_${n.label}` ? t_i18n(`entity_${n.label}`) : n.label)); let chartColors = []; if (data.at(0)?.entity?.color) { - chartColors = data.map((n) => (theme.palette.mode === 'light' && n.entity.color === '#ffffff' + chartColors = data.map((n) => (theme.palette.mode === 'light' && n.entity?.color === '#ffffff' ? '#000000' - : n.entity.color)); + : n.entity?.color)); } if (data.at(0)?.entity?.x_opencti_color) { - chartColors = data.map((n) => (theme.palette.mode === 'light' - && n.entity.x_opencti_color === '#ffffff' + chartColors = data.map((n) => (theme.palette.mode === 'light' && n.entity?.x_opencti_color === '#ffffff' ? '#000000' - : n.entity.x_opencti_color)); + : n.entity?.x_opencti_color)); } if (data.at(0)?.entity?.template?.color) { - chartColors = data.map((n) => (theme.palette.mode === 'light' && n.entity.template.color === '#ffffff' + chartColors = data.map((n) => (theme.palette.mode === 'light' && n.entity?.template.color === '#ffffff' ? '#000000' - : n.entity.template.color)); + : n.entity?.template.color)); } return ( diff --git a/opencti-platform/opencti-front/src/components/dashboard/WidgetListCoreObjects.tsx b/opencti-platform/opencti-front/src/components/dashboard/WidgetListCoreObjects.tsx index d79fa4fc0537..4ad4e18ec03d 100644 --- a/opencti-platform/opencti-front/src/components/dashboard/WidgetListCoreObjects.tsx +++ b/opencti-platform/opencti-front/src/components/dashboard/WidgetListCoreObjects.tsx @@ -72,7 +72,7 @@ const WidgetListCoreObjects = ({ primary={ <>
- {defaultValue(stixCoreObject)} + {defaultValue(stixCoreObject, 'Restricted')}
{fsd(date)} diff --git a/opencti-platform/opencti-front/src/components/dashboard/WidgetListRelationships.tsx b/opencti-platform/opencti-front/src/components/dashboard/WidgetListRelationships.tsx index 244b9a374045..ae138fd867b2 100644 --- a/opencti-platform/opencti-front/src/components/dashboard/WidgetListRelationships.tsx +++ b/opencti-platform/opencti-front/src/components/dashboard/WidgetListRelationships.tsx @@ -149,7 +149,7 @@ const WidgetListRelationships = ({
{stixRelationship.to - ? defaultValue(stixRelationship.to) + ? defaultValue(stixRelationship.to, t_i18n('Restricted')) : t_i18n('Restricted')}
diff --git a/opencti-platform/opencti-front/src/components/dashboard/WidgetRadar.tsx b/opencti-platform/opencti-front/src/components/dashboard/WidgetRadar.tsx index c2d6b8148bf0..d6bd661a2b8f 100644 --- a/opencti-platform/opencti-front/src/components/dashboard/WidgetRadar.tsx +++ b/opencti-platform/opencti-front/src/components/dashboard/WidgetRadar.tsx @@ -33,7 +33,7 @@ const WidgetRadar = ({ // eslint-disable-next-line no-nested-ternary,implicit-arrow-linebreak const labels = data.map((n) => (groupBy.endsWith('_id') - ? defaultValue(n.entity) + ? defaultValue(n.entity, 'Restricted') : groupBy === 'entity_type' && t_i18n(`entity_${n.label}`) !== `entity_${n.label}` ? t_i18n(`entity_${n.label}`) : n.label)); diff --git a/opencti-platform/opencti-front/src/components/dashboard/WidgetTimeline.tsx b/opencti-platform/opencti-front/src/components/dashboard/WidgetTimeline.tsx index 6f76d7a43d5f..2a28f9d0f072 100644 --- a/opencti-platform/opencti-front/src/components/dashboard/WidgetTimeline.tsx +++ b/opencti-platform/opencti-front/src/components/dashboard/WidgetTimeline.tsx @@ -67,7 +67,7 @@ const WidgetTimeline = ({ data }: WidgetTimelineProps) => { - {defaultValue(value)} + {defaultValue(value, 'Restricted')}
({ // eslint-disable-next-line no-nested-ternary x: groupBy.endsWith('_id') - ? defaultValue(n.entity) + ? defaultValue(n.entity, 'Restricted') : groupBy === 'entity_type' && t_i18n(`entity_${n.label}`) !== `entity_${n.label}` ? t_i18n(`entity_${n.label}`) : n.label, diff --git a/opencti-platform/opencti-front/src/private/components/analyses/groupings/GroupingsDonut.jsx b/opencti-platform/opencti-front/src/private/components/analyses/groupings/GroupingsDonut.jsx index f6c69364d4ad..9ce408c2fc32 100644 --- a/opencti-platform/opencti-front/src/private/components/analyses/groupings/GroupingsDonut.jsx +++ b/opencti-platform/opencti-front/src/private/components/analyses/groupings/GroupingsDonut.jsx @@ -70,7 +70,7 @@ const GroupingsDonut = (props) => { let data = resultProps.groupingsDistribution; if (field && field.includes('internal_id')) { data = R.map( - (n) => R.assoc('label', n.entity.name, n), + (n) => R.assoc('label', n.entity?.name ?? 'Restricted', n), resultProps.groupingsDistribution, ); } diff --git a/opencti-platform/opencti-front/src/private/components/analyses/groupings/GroupingsHorizontalBars.jsx b/opencti-platform/opencti-front/src/private/components/analyses/groupings/GroupingsHorizontalBars.jsx index f5edae6aff11..6a2059d8f74e 100644 --- a/opencti-platform/opencti-front/src/private/components/analyses/groupings/GroupingsHorizontalBars.jsx +++ b/opencti-platform/opencti-front/src/private/components/analyses/groupings/GroupingsHorizontalBars.jsx @@ -71,7 +71,7 @@ class GroupingsHorizontalBars extends Component { && props.groupingsDistribution.length > 0 ) { const data = props.groupingsDistribution.map((n) => ({ - x: n.entity.name, + x: n.entity?.name ?? 'Restricted', y: n.value, })); const chartData = [{ name: t('Number of groupings'), data }]; diff --git a/opencti-platform/opencti-front/src/private/components/analyses/groupings/StixCoreObjectGroupingsDonut.jsx b/opencti-platform/opencti-front/src/private/components/analyses/groupings/StixCoreObjectGroupingsDonut.jsx index 15c6a291c4e6..9bdffb91f192 100644 --- a/opencti-platform/opencti-front/src/private/components/analyses/groupings/StixCoreObjectGroupingsDonut.jsx +++ b/opencti-platform/opencti-front/src/private/components/analyses/groupings/StixCoreObjectGroupingsDonut.jsx @@ -72,7 +72,7 @@ class StixCoreObjectGroupingsDonut extends Component { let data = props.groupingsDistribution; if (field && field.includes('internal_id')) { data = R.map( - (n) => R.assoc('label', n.entity.name, n), + (n) => R.assoc('label', n.entity?.name ?? 'Restricted', n), props.groupingsDistribution, ); } diff --git a/opencti-platform/opencti-front/src/private/components/analyses/groupings/StixCoreObjectGroupingsHorizontalBars.jsx b/opencti-platform/opencti-front/src/private/components/analyses/groupings/StixCoreObjectGroupingsHorizontalBars.jsx index 5063739ddfd0..98565e839ed2 100644 --- a/opencti-platform/opencti-front/src/private/components/analyses/groupings/StixCoreObjectGroupingsHorizontalBars.jsx +++ b/opencti-platform/opencti-front/src/private/components/analyses/groupings/StixCoreObjectGroupingsHorizontalBars.jsx @@ -68,7 +68,7 @@ class StixCoreObjectGroupingsHorizontalBars extends Component { && props.groupingsDistribution.length > 0 ) { const data = props.groupingsDistribution.map((n) => ({ - x: n.entity.name, + x: n.entity?.name ?? 'Restricted', y: n.value, })); const chartData = [{ name: t('Number of groupings'), data }]; diff --git a/opencti-platform/opencti-front/src/private/components/analyses/reports/ReportsDonut.jsx b/opencti-platform/opencti-front/src/private/components/analyses/reports/ReportsDonut.jsx index 6dca43294782..67890589f33f 100644 --- a/opencti-platform/opencti-front/src/private/components/analyses/reports/ReportsDonut.jsx +++ b/opencti-platform/opencti-front/src/private/components/analyses/reports/ReportsDonut.jsx @@ -73,7 +73,7 @@ class ReportsDonut extends Component { let data = props.reportsDistribution; if (field && field.includes('internal_id')) { data = R.map( - (n) => R.assoc('label', n.entity.name, n), + (n) => R.assoc('label', n.entity?.name ?? 'Restricted', n), props.reportsDistribution, ); } diff --git a/opencti-platform/opencti-front/src/private/components/analyses/reports/ReportsHorizontalBars.jsx b/opencti-platform/opencti-front/src/private/components/analyses/reports/ReportsHorizontalBars.jsx index df5822db5aa2..029e10698407 100644 --- a/opencti-platform/opencti-front/src/private/components/analyses/reports/ReportsHorizontalBars.jsx +++ b/opencti-platform/opencti-front/src/private/components/analyses/reports/ReportsHorizontalBars.jsx @@ -71,7 +71,7 @@ class ReportsHorizontalBars extends Component { && props.reportsDistribution.length > 0 ) { const data = props.reportsDistribution.map((n) => ({ - x: n.entity.name, + x: n.entity?.name ?? 'Restricted', y: n.value, })); const chartData = [{ name: t('Number of reports'), data }]; diff --git a/opencti-platform/opencti-front/src/private/components/analyses/reports/StixCoreObjectReportsHorizontalBars.jsx b/opencti-platform/opencti-front/src/private/components/analyses/reports/StixCoreObjectReportsHorizontalBars.jsx index 25c91e5d2971..8c87df94f5ba 100644 --- a/opencti-platform/opencti-front/src/private/components/analyses/reports/StixCoreObjectReportsHorizontalBars.jsx +++ b/opencti-platform/opencti-front/src/private/components/analyses/reports/StixCoreObjectReportsHorizontalBars.jsx @@ -68,7 +68,7 @@ class StixCoreObjectReportsHorizontalBars extends Component { && props.reportsDistribution.length > 0 ) { const data = props.reportsDistribution.map((n) => ({ - x: n.entity.name, + x: n.entity?.name ?? 'Restricted', y: n.value, })); const chartData = [{ name: t('Number of reports'), data }]; diff --git a/opencti-platform/opencti-front/src/private/components/common/audits/AuditsDistributionList.jsx b/opencti-platform/opencti-front/src/private/components/common/audits/AuditsDistributionList.jsx index 4ee8c0a11c2f..efc5d1c53a71 100644 --- a/opencti-platform/opencti-front/src/private/components/common/audits/AuditsDistributionList.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/audits/AuditsDistributionList.jsx @@ -273,13 +273,13 @@ const AuditsDistributionList = ({ selection.attribute.endsWith('.id') || selection.attribute.endsWith('_id') || selection.attribute.endsWith('_ids') - ? o.entity.id + ? o.entity?.id : null, type: selection.attribute.endsWith('.id') || selection.attribute.endsWith('_id') || selection.attribute.endsWith('_ids') - ? o.entity.entity_type + ? o.entity?.entity_type : o.label, })); return ; diff --git a/opencti-platform/opencti-front/src/private/components/common/audits/AuditsHorizontalBars.jsx b/opencti-platform/opencti-front/src/private/components/common/audits/AuditsHorizontalBars.jsx index d9a57376d9a7..3100d0216fb4 100644 --- a/opencti-platform/opencti-front/src/private/components/common/audits/AuditsHorizontalBars.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/audits/AuditsHorizontalBars.jsx @@ -292,7 +292,7 @@ const AuditsHorizontalBars = ({ selection.attribute.endsWith('.id') || selection.attribute.endsWith('_id') || selection.attribute.endsWith('_ids') - ? itemColor(n.entity.entity_type) + ? itemColor(n.entity?.entity_type) : itemColor(n.label), })); const chartData = [ @@ -305,11 +305,11 @@ const AuditsHorizontalBars = ({ || selection.attribute.endsWith('_id') || selection.attribute.endsWith('_ids') ? props.auditsDistribution.map((n) => ({ - id: n.entity.id, + id: n.entity?.id, entity_type: - n.entity.entity_type === 'Workspace' - ? n.entity.type - : n.entity.entity_type, + n.entity?.entity_type === 'Workspace' + ? n.entity.type + : n.entity?.entity_type, })) : null; return ( diff --git a/opencti-platform/opencti-front/src/private/components/common/location/GlobalVictimologyMap.jsx b/opencti-platform/opencti-front/src/private/components/common/location/GlobalVictimologyMap.jsx index bb5344b4acc7..f39d0c3e40de 100644 --- a/opencti-platform/opencti-front/src/private/components/common/location/GlobalVictimologyMap.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/location/GlobalVictimologyMap.jsx @@ -96,14 +96,14 @@ class GlobalVictimologyMap extends Component { x.entity, ), R.filter( - (n) => n.entity.entity_type === 'Country', + (n) => n.entity?.entity_type === 'Country', props.stixCoreRelationshipsDistribution, ), ); const cities = R.map( (x) => x.entity, R.filter( - (n) => n.entity.entity_type === 'City', + (n) => n.entity?.entity_type === 'City', props.stixCoreRelationshipsDistribution, ), ); diff --git a/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectsDistributionList.jsx b/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectsDistributionList.jsx index f45782f5159a..dfd3927d7e35 100644 --- a/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectsDistributionList.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectsDistributionList.jsx @@ -131,7 +131,7 @@ const StixCoreObjectsDistributionList = ({ : o.label, value: o.value, color: o.entity?.color ?? o.entity?.x_opencti_color, - id: selection.attribute.endsWith('_id') ? o.entity.id : null, + id: selection.attribute.endsWith('_id') ? o.entity?.id : null, type: o.entity?.entity_type ?? o.label, })); return ; diff --git a/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectsHorizontalBars.jsx b/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectsHorizontalBars.jsx index fc5db087e43d..cc3135e2d658 100644 --- a/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectsHorizontalBars.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectsHorizontalBars.jsx @@ -241,7 +241,7 @@ const StixCoreObjectsHorizontalBars = ({ ) { const data = props.stixCoreObjectsDistribution.map((n) => { let color = selection.attribute.endsWith('_id') - ? itemColor(n.entity.entity_type) + ? itemColor(n.entity?.entity_type) : itemColor(n.label); if (n.entity?.color) { color = theme.palette.mode === 'light' && n.entity.color === '#ffffff' @@ -250,13 +250,13 @@ const StixCoreObjectsHorizontalBars = ({ } if (n.entity?.x_opencti_color) { color = theme.palette.mode === 'light' - && n.entity.x_opencti_color === '#ffffff' + && n.entity.x_opencti_color === '#ffffff' ? '#000000' : n.entity.x_opencti_color; } if (n.entity?.template?.color) { color = theme.palette.mode === 'light' - && n.entity.template.color === '#ffffff' + && n.entity.template.color === '#ffffff' ? '#000000' : n.entity.template.color; } @@ -279,8 +279,8 @@ const StixCoreObjectsHorizontalBars = ({ ]; const redirectionUtils = selection.attribute === 'name' ? props.stixCoreObjectsDistribution.map((n) => ({ - id: n.entity.id, - entity_type: n.entity.entity_type, + id: n.entity?.id, + entity_type: n.entity?.entity_type, })) : undefined; return ( diff --git a/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectsMultiHorizontalBars.jsx b/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectsMultiHorizontalBars.jsx index 36b6ff1dbbe1..ee61bd280ef3 100644 --- a/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectsMultiHorizontalBars.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectsMultiHorizontalBars.jsx @@ -444,7 +444,7 @@ const stixCoreObjectsMultiHorizontalBars = ({ ) { const data = props.stixCoreObjectsDistribution.map((n) => { let color = selection.attribute.endsWith('_id') - ? itemColor(n.entity.entity_type) + ? itemColor(n.entity?.entity_type) : itemColor(n.label); if (n.entity?.color) { color = theme.palette.mode === 'light' && n.entity.color === '#ffffff' @@ -467,7 +467,7 @@ const stixCoreObjectsMultiHorizontalBars = ({ x: // eslint-disable-next-line no-nested-ternary selection.attribute.endsWith('_id') - ? defaultValue(n.entity) + ? defaultValue(n.entity, 'Restricted') : selection.attribute === 'entity_type' ? t_i18n(`entity_${n.label}`) : n.label, @@ -483,8 +483,8 @@ const stixCoreObjectsMultiHorizontalBars = ({ ]; const redirectionUtils = selection.attribute === 'name' ? props.stixCoreObjectsDistribution.map((n) => ({ - id: n.entity.id, - entity_type: n.entity.entity_type, + id: n.entity?.id, + entity_type: n.entity?.entity_type, })) : null; return ( diff --git a/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/EntityStixCoreRelationshipsHorizontalBars.jsx b/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/EntityStixCoreRelationshipsHorizontalBars.jsx index 0fadaafa4d30..ed018f1efaae 100644 --- a/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/EntityStixCoreRelationshipsHorizontalBars.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/EntityStixCoreRelationshipsHorizontalBars.jsx @@ -238,14 +238,14 @@ const EntityStixCoreRelationshipsHorizontalBars = ( x: // eslint-disable-next-line no-nested-ternary field === 'internal_id' - ? defaultValue(n.entity) + ? defaultValue(n.entity, 'Restricted') : field === 'entity_type' ? t_i18n(`entity_${n.label}`) : n.label, y: n.value, fillColor: field === 'internal_id' - ? itemColor(n.entity.entity_type) + ? itemColor(n.entity?.entity_type) : itemColor(n.label), })); const chartData = [ @@ -257,7 +257,7 @@ const EntityStixCoreRelationshipsHorizontalBars = ( const redirectionUtils = (field === 'internal_id') ? props.stixCoreRelationshipsDistribution.map( (n) => ({ id: n.label, - entity_type: n.entity.entity_type, + entity_type: n.entity?.entity_type, }), ) : null; return ( diff --git a/opencti-platform/opencti-front/src/private/components/common/stix_relationships/StixRelationshipsDistributionList.jsx b/opencti-platform/opencti-front/src/private/components/common/stix_relationships/StixRelationshipsDistributionList.jsx index 8bd34a11e185..3203f7c5a502 100644 --- a/opencti-platform/opencti-front/src/private/components/common/stix_relationships/StixRelationshipsDistributionList.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/stix_relationships/StixRelationshipsDistributionList.jsx @@ -257,8 +257,8 @@ const StixRelationshipsDistributionList = ({ ? defaultValue(o.entity) : o.label, value: o.value, - id: finalField.endsWith('_id') ? o.entity.id : null, - type: finalField.endsWith('_id') ? o.entity.entity_type : o.label, + id: finalField.endsWith('_id') ? o.entity?.id : null, + type: finalField.endsWith('_id') ? o.entity?.entity_type : o.label, })); return ( { let color = selection.attribute.endsWith('_id') - ? itemColor(n.entity.entity_type) + ? itemColor(n.entity?.entity_type) : itemColor(n.label); if (n.entity?.color) { - color = theme.palette.mode === 'light' && n.entity.color === '#ffffff' + color = theme.palette.mode === 'light' && n.entity?.color === '#ffffff' ? '#000000' - : n.entity.color; + : n.entity?.color; } if (n.entity?.x_opencti_color) { color = theme.palette.mode === 'light' - && n.entity.x_opencti_color === '#ffffff' + && n.entity?.x_opencti_color === '#ffffff' ? '#000000' - : n.entity.x_opencti_color; + : n.entity?.x_opencti_color; } if (n.entity?.template?.color) { color = theme.palette.mode === 'light' - && n.entity.template.color === '#ffffff' + && n.entity?.template.color === '#ffffff' ? '#000000' - : n.entity.template.color; + : n.entity?.template.color; } return { x: finalField.endsWith('_id') - ? defaultValue(n.entity) + ? defaultValue(n.entity, 'Restricted') : n.label, y: n.value, fillColor: color, @@ -291,7 +291,7 @@ const StixRelationshipsHorizontalBars = ({ const redirectionUtils = finalField.endsWith('_id') ? props.stixRelationshipsDistribution.map((n) => ({ id: n.label, - entity_type: n.entity.entity_type, + entity_type: n.entity?.entity_type, })) : undefined; return ( diff --git a/opencti-platform/opencti-front/src/private/components/common/stix_relationships/StixRelationshipsMultiHorizontalBars.jsx b/opencti-platform/opencti-front/src/private/components/common/stix_relationships/StixRelationshipsMultiHorizontalBars.jsx index 042a33d1eb95..0f6edb2db8ed 100644 --- a/opencti-platform/opencti-front/src/private/components/common/stix_relationships/StixRelationshipsMultiHorizontalBars.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/stix_relationships/StixRelationshipsMultiHorizontalBars.jsx @@ -826,17 +826,17 @@ const StixRelationshipsMultiHorizontalBars = ({ && props.stixRelationshipsDistribution && props.stixRelationshipsDistribution.length > 0 ) { - const categories = props.stixRelationshipsDistribution.map((n) => defaultValue(n.entity)); + const categories = props.stixRelationshipsDistribution.map((n) => defaultValue(n.entity, 'Restricted')); const entitiesMapping = {}; for (const distrib of props.stixRelationshipsDistribution) { for (const subDistrib of distrib.entity[key]) { entitiesMapping[ finalSubDistributionField === 'internal_id' - ? defaultValue(subDistrib.entity) + ? defaultValue(subDistrib.entity, 'Restricted') : subDistrib.label ] = (entitiesMapping[ finalSubDistributionField === 'internal_id' - ? defaultValue(subDistrib.entity) + ? defaultValue(subDistrib.entity, 'Restricted') : subDistrib.label ] || 0) + subDistrib.value; } @@ -849,7 +849,7 @@ const StixRelationshipsMultiHorizontalBars = ({ for (const distrib of props.stixRelationshipsDistribution) { for (const sortedEntity of sortedEntityMapping) { const entityData = R.head( - distrib.entity[key].filter( + distrib.entity?.[key].filter( (n) => (finalSubDistributionField === 'internal_id' ? defaultValue(n.entity) : n.label) === sortedEntity[0], @@ -907,14 +907,14 @@ const StixRelationshipsMultiHorizontalBars = ({ const redirectionUtils = finalField === 'internal_id' ? props.stixRelationshipsDistribution.map((n) => ({ id: n.label, - entity_type: n.entity.entity_type, + entity_type: n.entity?.entity_type, series: subSectionIdsOrder.map((subSectionId) => { - const [entity] = n.entity[key].filter( + const [entity] = n.entity[key]?.filter( (e) => e.label === subSectionId, - ); + ) ?? []; return { id: subSectionId, - entity_type: entity ? entity.entity.entity_type : null, + entity_type: entity ? entity.entity?.entity_type : null, }; }), })) diff --git a/opencti-platform/opencti-front/src/private/components/common/stix_relationships/StixRelationshipsPolarArea.jsx b/opencti-platform/opencti-front/src/private/components/common/stix_relationships/StixRelationshipsPolarArea.jsx index 6a645cca8527..b833247c526f 100644 --- a/opencti-platform/opencti-front/src/private/components/common/stix_relationships/StixRelationshipsPolarArea.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/stix_relationships/StixRelationshipsPolarArea.jsx @@ -247,7 +247,7 @@ const StixRelationshipsPolarArea = ({ data = R.map( (n) => R.assoc( 'label', - defaultValue(n.entity), + defaultValue(n.entity, 'Restricted'), n, ), props.stixRelationshipsDistribution, diff --git a/opencti-platform/opencti-front/src/private/components/events/stix_sighting_relationships/EntityStixSightingRelationshipsDonut.jsx b/opencti-platform/opencti-front/src/private/components/events/stix_sighting_relationships/EntityStixSightingRelationshipsDonut.jsx index 51433ed4008c..770f5b0d5032 100644 --- a/opencti-platform/opencti-front/src/private/components/events/stix_sighting_relationships/EntityStixSightingRelationshipsDonut.jsx +++ b/opencti-platform/opencti-front/src/private/components/events/stix_sighting_relationships/EntityStixSightingRelationshipsDonut.jsx @@ -12,6 +12,7 @@ import Chart from '../../common/charts/Chart'; import { QueryRenderer } from '../../../../relay/environment'; import inject18n from '../../../../components/i18n'; import { donutChartOptions } from '../../../../utils/Charts'; +import { defaultValue } from '../../../../utils/Graph'; const styles = () => ({ paper: { @@ -219,11 +220,9 @@ class EntityStixSightingRelationshipsDonut extends Component { (n) => R.assoc( 'label', `${ - toTypes.length > 1 - ? `[${t(`entity_${n.entity.entity_type}`)}] ${ - n.entity.name - }` - : `${n.entity.name}` + toTypes.length > 1 && n.entity + ? `[${t(`entity_${n.entity.entity_type}`)}] ${n.entity.name}` + : `${defaultValue(n.entity, 'Restricted')}` }`, n, ), diff --git a/opencti-platform/opencti-front/src/private/components/observations/indicators/IndicatorsDonut.jsx b/opencti-platform/opencti-front/src/private/components/observations/indicators/IndicatorsDonut.jsx index 948f73e259a2..e2c10865d517 100644 --- a/opencti-platform/opencti-front/src/private/components/observations/indicators/IndicatorsDonut.jsx +++ b/opencti-platform/opencti-front/src/private/components/observations/indicators/IndicatorsDonut.jsx @@ -72,7 +72,7 @@ class IndicatorsDonut extends Component { let data = props.indicatorsDistribution; if (field && field.includes('internal_id')) { data = map( - (n) => assoc('label', n.entity.name, n), + (n) => assoc('label', n.entity?.name ?? 'Restricted', n), props.indicatorsDistribution, ); } diff --git a/opencti-platform/opencti-front/src/utils/Graph.js b/opencti-platform/opencti-front/src/utils/Graph.js index 125f5a8a6f2f..873b3d5b5c63 100644 --- a/opencti-platform/opencti-front/src/utils/Graph.js +++ b/opencti-platform/opencti-front/src/utils/Graph.js @@ -382,7 +382,7 @@ export const defaultKey = (n) => { }; export const defaultValue = (n, fallback = 'Unknown') => { - if (!n) return ''; + if (!n) return fallback; if (typeof n.definition === 'object') { return defaultValueMarking(n); } From c94ed197bf9cd7113db8da1e2e53984c7c95ff94 Mon Sep 17 00:00:00 2001 From: Laurent Bonnet Date: Wed, 27 Mar 2024 16:37:30 +0100 Subject: [PATCH 05/14] [backend] use isUserCanAccessStoreElement with cache instead of request --- opencti-platform/opencti-graphql/src/database/middleware.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/opencti-platform/opencti-graphql/src/database/middleware.js b/opencti-platform/opencti-graphql/src/database/middleware.js index 8e4aca07afa0..77f92c67dee5 100644 --- a/opencti-platform/opencti-graphql/src/database/middleware.js +++ b/opencti-platform/opencti-graphql/src/database/middleware.js @@ -452,13 +452,13 @@ const convertAggregateDistributions = async (context, user, limit, orderingFunct const data = R.take(limit, R.sortWith([orderingFunction(R.prop('value'))])(distribution)); // resolve all of them, limited to ids for comparison in next step const allResolveLabels = await elFindByIds(context, SYSTEM_USER, data.map((d) => d.label), { toMap: true }); - const grantedResolveLabels = await elFindByIds(context, user, data.map((d) => d.label), { toMap: true }); // entities not granted shall be sent as "restricted" with limited information return data .filter((n) => isNotEmptyField(allResolveLabels[n.label.toLowerCase()])) .map((n) => { - if (grantedResolveLabels[n.label.toLowerCase()]) { - return R.assoc('entity', grantedResolveLabels[n.label.toLowerCase()], n); + const element = allResolveLabels[n.label.toLowerCase()]; + if (isUserCanAccessStoreElement(context, user, element)) { + return R.assoc('entity', element, n); } // return R.assoc('entity', { id: n.label, entity_type: n.entity_type, name: 'Restricted' }, n); return n; // no entity details From 8fa74ce04dc3be8161b2bf59c135d143ace8d3da Mon Sep 17 00:00:00 2001 From: Laurent Bonnet Date: Wed, 27 Mar 2024 16:41:11 +0100 Subject: [PATCH 06/14] [frontend] refactor usage of defaultValue for Distributions --- .../src/components/dashboard/WidgetDonut.tsx | 2 +- .../src/components/dashboard/WidgetListCoreObjects.tsx | 2 +- .../src/components/dashboard/WidgetListRelationships.tsx | 8 ++------ .../src/components/dashboard/WidgetRadar.tsx | 2 +- .../src/components/dashboard/WidgetTimeline.tsx | 2 +- .../opencti-front/src/components/dashboard/WidgetTree.tsx | 2 +- .../components/common/audits/AuditsDistributionList.jsx | 2 +- .../components/common/audits/AuditsHorizontalBars.jsx | 2 +- .../stix_core_objects/StixCoreObjectsHorizontalBars.jsx | 2 +- .../StixCoreObjectsMultiHorizontalBars.jsx | 2 +- .../EntityStixCoreRelationshipsHorizontalBars.jsx | 2 +- .../StixRelationshipsHorizontalBars.jsx | 2 +- .../StixRelationshipsMultiHorizontalBars.jsx | 6 +++--- .../stix_relationships/StixRelationshipsPolarArea.jsx | 2 +- .../RelationshipsStixCoreRelationshipLine.jsx | 4 ++-- .../EntityStixSightingRelationshipsDonut.jsx | 2 +- .../PublicStixCoreObjectsHorizontalBars.tsx | 2 +- .../PublicStixRelationshipsDistributionList.tsx | 4 +++- .../PublicStixRelationshipsHorizontalBars.tsx | 2 +- .../PublicStixRelationshipsMultiHorizontalBars.tsx | 6 ++++-- .../PublicStixRelationshipsPolarArea.tsx | 6 +++++- 21 files changed, 34 insertions(+), 30 deletions(-) diff --git a/opencti-platform/opencti-front/src/components/dashboard/WidgetDonut.tsx b/opencti-platform/opencti-front/src/components/dashboard/WidgetDonut.tsx index 0795e8fcd548..89c10959bc2a 100644 --- a/opencti-platform/opencti-front/src/components/dashboard/WidgetDonut.tsx +++ b/opencti-platform/opencti-front/src/components/dashboard/WidgetDonut.tsx @@ -27,7 +27,7 @@ const WidgetDonut = ({ const chartData = data.map((n) => n.value); // eslint-disable-next-line no-nested-ternary const labels = data.map((n) => (groupBy.endsWith('_id') - ? defaultValue(n.entity, 'Restricted') + ? defaultValue(n.entity, t_i18n('Restricted')) : groupBy === 'entity_type' && t_i18n(`entity_${n.label}`) !== `entity_${n.label}` ? t_i18n(`entity_${n.label}`) : n.label)); diff --git a/opencti-platform/opencti-front/src/components/dashboard/WidgetListCoreObjects.tsx b/opencti-platform/opencti-front/src/components/dashboard/WidgetListCoreObjects.tsx index 4ad4e18ec03d..8c9c5a48d1c5 100644 --- a/opencti-platform/opencti-front/src/components/dashboard/WidgetListCoreObjects.tsx +++ b/opencti-platform/opencti-front/src/components/dashboard/WidgetListCoreObjects.tsx @@ -72,7 +72,7 @@ const WidgetListCoreObjects = ({ primary={ <>
- {defaultValue(stixCoreObject, 'Restricted')} + {defaultValue(stixCoreObject, t_i18n('Restricted'))}
{fsd(date)} diff --git a/opencti-platform/opencti-front/src/components/dashboard/WidgetListRelationships.tsx b/opencti-platform/opencti-front/src/components/dashboard/WidgetListRelationships.tsx index ae138fd867b2..ea8dd58f50ef 100644 --- a/opencti-platform/opencti-front/src/components/dashboard/WidgetListRelationships.tsx +++ b/opencti-platform/opencti-front/src/components/dashboard/WidgetListRelationships.tsx @@ -115,9 +115,7 @@ const WidgetListRelationships = ({
- {stixRelationship.from - ? defaultValue(stixRelationship.from) - : t_i18n('Restricted')} + {defaultValue(stixRelationship.from, t_i18n('Restricted')}
@@ -148,9 +146,7 @@ const WidgetListRelationships = ({
- {stixRelationship.to - ? defaultValue(stixRelationship.to, t_i18n('Restricted')) - : t_i18n('Restricted')} + {defaultValue(stixRelationship.to, t_i18n('Restricted')}
diff --git a/opencti-platform/opencti-front/src/components/dashboard/WidgetRadar.tsx b/opencti-platform/opencti-front/src/components/dashboard/WidgetRadar.tsx index d6bd661a2b8f..c35a26ee4bc6 100644 --- a/opencti-platform/opencti-front/src/components/dashboard/WidgetRadar.tsx +++ b/opencti-platform/opencti-front/src/components/dashboard/WidgetRadar.tsx @@ -33,7 +33,7 @@ const WidgetRadar = ({ // eslint-disable-next-line no-nested-ternary,implicit-arrow-linebreak const labels = data.map((n) => (groupBy.endsWith('_id') - ? defaultValue(n.entity, 'Restricted') + ? defaultValue(n.entity, t_i18n('Restricted')) : groupBy === 'entity_type' && t_i18n(`entity_${n.label}`) !== `entity_${n.label}` ? t_i18n(`entity_${n.label}`) : n.label)); diff --git a/opencti-platform/opencti-front/src/components/dashboard/WidgetTimeline.tsx b/opencti-platform/opencti-front/src/components/dashboard/WidgetTimeline.tsx index 2a28f9d0f072..728a92dd773f 100644 --- a/opencti-platform/opencti-front/src/components/dashboard/WidgetTimeline.tsx +++ b/opencti-platform/opencti-front/src/components/dashboard/WidgetTimeline.tsx @@ -67,7 +67,7 @@ const WidgetTimeline = ({ data }: WidgetTimelineProps) => { - {defaultValue(value, 'Restricted')} + {defaultValue(value, t_i18n('Restricted'))}
({ // eslint-disable-next-line no-nested-ternary x: groupBy.endsWith('_id') - ? defaultValue(n.entity, 'Restricted') + ? defaultValue(n.entity, t_i18n('Restricted')) : groupBy === 'entity_type' && t_i18n(`entity_${n.label}`) !== `entity_${n.label}` ? t_i18n(`entity_${n.label}`) : n.label, diff --git a/opencti-platform/opencti-front/src/private/components/common/audits/AuditsDistributionList.jsx b/opencti-platform/opencti-front/src/private/components/common/audits/AuditsDistributionList.jsx index efc5d1c53a71..f715debc71e2 100644 --- a/opencti-platform/opencti-front/src/private/components/common/audits/AuditsDistributionList.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/audits/AuditsDistributionList.jsx @@ -264,7 +264,7 @@ const AuditsDistributionList = ({ selection.attribute.endsWith('.id') || selection.attribute.endsWith('_id') || selection.attribute.endsWith('_ids') - ? defaultValue(o.entity) + ? defaultValue(o.entity, t_i18n('Restricted')) : selection.attribute === 'entity_type' ? t_i18n(`entity_${o.label}`) : o.label, diff --git a/opencti-platform/opencti-front/src/private/components/common/audits/AuditsHorizontalBars.jsx b/opencti-platform/opencti-front/src/private/components/common/audits/AuditsHorizontalBars.jsx index 3100d0216fb4..f60c6520fdf0 100644 --- a/opencti-platform/opencti-front/src/private/components/common/audits/AuditsHorizontalBars.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/audits/AuditsHorizontalBars.jsx @@ -283,7 +283,7 @@ const AuditsHorizontalBars = ({ selection.attribute.endsWith('.id') || selection.attribute.endsWith('_id') || selection.attribute.endsWith('_ids') - ? defaultValue(n.entity) + ? defaultValue(n.entity, t_i18n('Restricted')) : selection.attribute === 'entity_type' ? t_i18n(`entity_${n.label}`) : n.label, diff --git a/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectsHorizontalBars.jsx b/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectsHorizontalBars.jsx index cc3135e2d658..a1278da7ad39 100644 --- a/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectsHorizontalBars.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectsHorizontalBars.jsx @@ -263,7 +263,7 @@ const StixCoreObjectsHorizontalBars = ({ return { // eslint-disable-next-line no-nested-ternary x: selection.attribute.endsWith('_id') - ? defaultValue(n.entity) + ? defaultValue(n.entity, t_i18n('Restricted')) : selection.attribute === 'entity_type' ? t_i18n(`entity_${n.label}`) : n.label, diff --git a/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectsMultiHorizontalBars.jsx b/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectsMultiHorizontalBars.jsx index ee61bd280ef3..7eb366f53823 100644 --- a/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectsMultiHorizontalBars.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectsMultiHorizontalBars.jsx @@ -467,7 +467,7 @@ const stixCoreObjectsMultiHorizontalBars = ({ x: // eslint-disable-next-line no-nested-ternary selection.attribute.endsWith('_id') - ? defaultValue(n.entity, 'Restricted') + ? defaultValue(n.entity, t_i18n('Restricted')) : selection.attribute === 'entity_type' ? t_i18n(`entity_${n.label}`) : n.label, diff --git a/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/EntityStixCoreRelationshipsHorizontalBars.jsx b/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/EntityStixCoreRelationshipsHorizontalBars.jsx index ed018f1efaae..0e62e6312da9 100644 --- a/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/EntityStixCoreRelationshipsHorizontalBars.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/EntityStixCoreRelationshipsHorizontalBars.jsx @@ -238,7 +238,7 @@ const EntityStixCoreRelationshipsHorizontalBars = ( x: // eslint-disable-next-line no-nested-ternary field === 'internal_id' - ? defaultValue(n.entity, 'Restricted') + ? defaultValue(n.entity, t_i18n('Restricted')) : field === 'entity_type' ? t_i18n(`entity_${n.label}`) : n.label, diff --git a/opencti-platform/opencti-front/src/private/components/common/stix_relationships/StixRelationshipsHorizontalBars.jsx b/opencti-platform/opencti-front/src/private/components/common/stix_relationships/StixRelationshipsHorizontalBars.jsx index a699b996aa8f..cf755aea5763 100644 --- a/opencti-platform/opencti-front/src/private/components/common/stix_relationships/StixRelationshipsHorizontalBars.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/stix_relationships/StixRelationshipsHorizontalBars.jsx @@ -281,7 +281,7 @@ const StixRelationshipsHorizontalBars = ({ } return { x: finalField.endsWith('_id') - ? defaultValue(n.entity, 'Restricted') + ? defaultValue(n.entity, t_i18n('Restricted')) : n.label, y: n.value, fillColor: color, diff --git a/opencti-platform/opencti-front/src/private/components/common/stix_relationships/StixRelationshipsMultiHorizontalBars.jsx b/opencti-platform/opencti-front/src/private/components/common/stix_relationships/StixRelationshipsMultiHorizontalBars.jsx index 0f6edb2db8ed..61b478cd232e 100644 --- a/opencti-platform/opencti-front/src/private/components/common/stix_relationships/StixRelationshipsMultiHorizontalBars.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/stix_relationships/StixRelationshipsMultiHorizontalBars.jsx @@ -826,17 +826,17 @@ const StixRelationshipsMultiHorizontalBars = ({ && props.stixRelationshipsDistribution && props.stixRelationshipsDistribution.length > 0 ) { - const categories = props.stixRelationshipsDistribution.map((n) => defaultValue(n.entity, 'Restricted')); + const categories = props.stixRelationshipsDistribution.map((n) => defaultValue(n.entity, t_i18n('Restricted'))); const entitiesMapping = {}; for (const distrib of props.stixRelationshipsDistribution) { for (const subDistrib of distrib.entity[key]) { entitiesMapping[ finalSubDistributionField === 'internal_id' - ? defaultValue(subDistrib.entity, 'Restricted') + ? defaultValue(subDistrib.entity, t_i18n('Restricted')) : subDistrib.label ] = (entitiesMapping[ finalSubDistributionField === 'internal_id' - ? defaultValue(subDistrib.entity, 'Restricted') + ? defaultValue(subDistrib.entity, t_i18n('Restricted')) : subDistrib.label ] || 0) + subDistrib.value; } diff --git a/opencti-platform/opencti-front/src/private/components/common/stix_relationships/StixRelationshipsPolarArea.jsx b/opencti-platform/opencti-front/src/private/components/common/stix_relationships/StixRelationshipsPolarArea.jsx index b833247c526f..6d54bb573942 100644 --- a/opencti-platform/opencti-front/src/private/components/common/stix_relationships/StixRelationshipsPolarArea.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/stix_relationships/StixRelationshipsPolarArea.jsx @@ -247,7 +247,7 @@ const StixRelationshipsPolarArea = ({ data = R.map( (n) => R.assoc( 'label', - defaultValue(n.entity, 'Restricted'), + defaultValue(n.entity, t_i18n('Restricted')), n, ), props.stixRelationshipsDistribution, diff --git a/opencti-platform/opencti-front/src/private/components/data/relationships/RelationshipsStixCoreRelationshipLine.jsx b/opencti-platform/opencti-front/src/private/components/data/relationships/RelationshipsStixCoreRelationshipLine.jsx index 41ac713234aa..6324053cf935 100644 --- a/opencti-platform/opencti-front/src/private/components/data/relationships/RelationshipsStixCoreRelationshipLine.jsx +++ b/opencti-platform/opencti-front/src/private/components/data/relationships/RelationshipsStixCoreRelationshipLine.jsx @@ -150,7 +150,7 @@ const RelationshipsStixCoreRelationshipLineComponent = ({ className={classes.bodyItem} style={{ width: dataColumns.fromName.width }} > - {node.from ? defaultValue(node.from) : t_i18n('Restricted')} + {defaultValue(node.from, t_i18n('Restricted'))}
- {node.to ? defaultValue(node.to) : t_i18n('Restricted')} + {defaultValue(node.to, t_i18n('Restricted')}
1 && n.entity ? `[${t(`entity_${n.entity.entity_type}`)}] ${n.entity.name}` - : `${defaultValue(n.entity, 'Restricted')}` + : `${defaultValue(n.entity, t_i18n('Restricted'))}` }`, n, ), diff --git a/opencti-platform/opencti-front/src/public/components/dashboard/stix_core_objects/PublicStixCoreObjectsHorizontalBars.tsx b/opencti-platform/opencti-front/src/public/components/dashboard/stix_core_objects/PublicStixCoreObjectsHorizontalBars.tsx index bf05a5b6a007..12f1f7a3773d 100644 --- a/opencti-platform/opencti-front/src/public/components/dashboard/stix_core_objects/PublicStixCoreObjectsHorizontalBars.tsx +++ b/opencti-platform/opencti-front/src/public/components/dashboard/stix_core_objects/PublicStixCoreObjectsHorizontalBars.tsx @@ -231,7 +231,7 @@ const PublicStixCoreObjectsHorizontalBarsComponent = ({ return { // eslint-disable-next-line no-nested-ternary x: selection.attribute?.endsWith('_id') - ? defaultValue(n?.entity) + ? defaultValue(n?.entity, t_i18n('Restricted')) : selection.attribute === 'entity_type' ? t_i18n(`entity_${n?.label}`) : n?.label, diff --git a/opencti-platform/opencti-front/src/public/components/dashboard/stix_relationships/PublicStixRelationshipsDistributionList.tsx b/opencti-platform/opencti-front/src/public/components/dashboard/stix_relationships/PublicStixRelationshipsDistributionList.tsx index 1ad6c301c21d..c143f427adb4 100644 --- a/opencti-platform/opencti-front/src/public/components/dashboard/stix_relationships/PublicStixRelationshipsDistributionList.tsx +++ b/opencti-platform/opencti-front/src/public/components/dashboard/stix_relationships/PublicStixRelationshipsDistributionList.tsx @@ -188,13 +188,15 @@ const PublicStixRelationshipsDistributionListComponent = ({ queryRef, ); + const { t_i18n } = useFormatter(); + if (publicStixRelationshipsDistribution && publicStixRelationshipsDistribution.length > 0) { const finalField = dataSelection[0].attribute || 'entity_type'; const data = publicStixRelationshipsDistribution.flatMap((o) => { if (!o) return []; return { label: finalField.endsWith('_id') - ? defaultValue(o.entity) + ? defaultValue(o.entity, t_i18n('Restricted')) : o.label, value: o.value, id: o.entity?.id ?? null, diff --git a/opencti-platform/opencti-front/src/public/components/dashboard/stix_relationships/PublicStixRelationshipsHorizontalBars.tsx b/opencti-platform/opencti-front/src/public/components/dashboard/stix_relationships/PublicStixRelationshipsHorizontalBars.tsx index 39fa5e1d5b99..484db2131feb 100644 --- a/opencti-platform/opencti-front/src/public/components/dashboard/stix_relationships/PublicStixRelationshipsHorizontalBars.tsx +++ b/opencti-platform/opencti-front/src/public/components/dashboard/stix_relationships/PublicStixRelationshipsHorizontalBars.tsx @@ -219,7 +219,7 @@ const PublicStixRelationshipsHorizontalBarsComponent = ({ } return { x: finalField.endsWith('_id') - ? defaultValue(n?.entity) + ? defaultValue(n?.entity, t_i18n('Restricted')) : n?.label, y: n?.value, fillColor: color, diff --git a/opencti-platform/opencti-front/src/public/components/dashboard/stix_relationships/PublicStixRelationshipsMultiHorizontalBars.tsx b/opencti-platform/opencti-front/src/public/components/dashboard/stix_relationships/PublicStixRelationshipsMultiHorizontalBars.tsx index 7f188259539c..abf89fd1c833 100644 --- a/opencti-platform/opencti-front/src/public/components/dashboard/stix_relationships/PublicStixRelationshipsMultiHorizontalBars.tsx +++ b/opencti-platform/opencti-front/src/public/components/dashboard/stix_relationships/PublicStixRelationshipsMultiHorizontalBars.tsx @@ -349,6 +349,8 @@ const PublicStixRelationshipsMultiHorizontalBarsComponent = ({ queryRef, ); + const { t_i18n } = useFormatter(); + if ( publicStixRelationshipsDistribution && publicStixRelationshipsDistribution.length > 0 @@ -358,7 +360,7 @@ const PublicStixRelationshipsMultiHorizontalBarsComponent = ({ const subSelection = dataSelection[1]; const finalSubDistributionField = subSelection.attribute || 'entity_type'; - const categories = publicStixRelationshipsDistribution.map((n) => defaultValue(n?.entity)); + const categories = publicStixRelationshipsDistribution.map((n) => defaultValue(n?.entity, t_i18n('Restricted'))); const entitiesMapping: Record = {}; for (const distrib of publicStixRelationshipsDistribution) { for (const subDistrib of distrib?.breakdownDistribution ?? []) { @@ -383,7 +385,7 @@ const PublicStixRelationshipsMultiHorizontalBarsComponent = ({ const entityData = R.head( (distrib?.breakdownDistribution ?? []).filter( (n) => (finalSubDistributionField === 'internal_id' - ? defaultValue(n?.entity) + ? defaultValue(n?.entity, t_i18n('Restricted')) : n?.label) === sortedEntity[0], ), ); diff --git a/opencti-platform/opencti-front/src/public/components/dashboard/stix_relationships/PublicStixRelationshipsPolarArea.tsx b/opencti-platform/opencti-front/src/public/components/dashboard/stix_relationships/PublicStixRelationshipsPolarArea.tsx index 670105bf8f05..b2d63a111fed 100644 --- a/opencti-platform/opencti-front/src/public/components/dashboard/stix_relationships/PublicStixRelationshipsPolarArea.tsx +++ b/opencti-platform/opencti-front/src/public/components/dashboard/stix_relationships/PublicStixRelationshipsPolarArea.tsx @@ -182,6 +182,8 @@ const PublicStixRelationshipsPolarAreaComponent = ({ queryRef, ); + const { t_i18n } = useFormatter(); + if ( publicStixRelationshipsDistribution && publicStixRelationshipsDistribution.length > 0 @@ -195,7 +197,9 @@ const PublicStixRelationshipsPolarAreaComponent = ({ return []; } return { - label: attributeField.endsWith('_id') ? defaultValue(item.entity) : item.label, + label: attributeField.endsWith('_id') + ? defaultValue(item.entity, t_i18n('Restricted')) + : item.label, value: item.value ?? 0, }; })} From 37c65bf03ffc5bc0168b11c65fa1a3e4140ab73d Mon Sep 17 00:00:00 2001 From: Laurent Bonnet Date: Thu, 28 Mar 2024 14:25:13 +0100 Subject: [PATCH 07/14] [frontend] move defaultValue and co. to new utils file --- .../src/components/dashboard/WidgetDonut.tsx | 2 +- .../dashboard/WidgetListCoreObjects.tsx | 4 +- .../dashboard/WidgetListRelationships.tsx | 10 +- .../src/components/dashboard/WidgetRadar.tsx | 2 +- .../components/dashboard/WidgetTimeline.tsx | 4 +- .../src/components/dashboard/WidgetTree.tsx | 2 +- .../src/private/components/SearchBulk.jsx | 2 +- .../groupings/GroupingKnowledgeGraph.jsx | 3 +- .../analyses/malware_analyses/Root.tsx | 2 +- .../analyses/reports/ReportKnowledgeGraph.jsx | 3 +- .../reports/ReportKnowledgeTimeLine.jsx | 2 +- .../case_incidents/IncidentKnowledgeGraph.jsx | 3 +- .../IncidentKnowledgeTimeLine.jsx | 2 +- .../cases/case_rfis/CaseRfiKnowledgeGraph.jsx | 3 +- .../case_rfis/CaseRfiKnowledgeTimeLine.jsx | 2 +- .../cases/case_rfts/CaseRftKnowledgeGraph.jsx | 3 +- .../case_rfts/CaseRftKnowledgeTimeLine.jsx | 2 +- .../common/audits/AuditsDistributionList.jsx | 2 +- .../common/audits/AuditsHorizontalBars.jsx | 2 +- .../ContainerAddStixCoreObjectsLine.jsx | 2 +- .../common/containers/ContainerHeader.jsx | 2 +- .../ContainerStixCoreObjectsMappingLine.jsx | 2 +- .../ContainerStixDomainObjectLine.jsx | 2 +- ...tainerStixObjectOrStixRelationshipLine.jsx | 2 +- ...ectOrStixCoreRelationshipContainerLine.tsx | 2 +- ...tOrStixCoreRelationshipContainersGraph.jsx | 3 +- .../files/workbench/WorkbenchFileContent.jsx | 2 +- .../common/form/DynamicResolutionField.jsx | 2 +- .../common/form/StixCoreObjectsField.jsx | 2 +- .../common/form/StixDomainObjectsField.jsx | 2 +- .../StixCoreObjectsHorizontalBars.jsx | 2 +- .../StixCoreObjectsMultiHorizontalBars.jsx | 2 +- .../EntityStixCoreRelationshipLineAll.jsx | 2 +- .../EntityStixCoreRelationshipLineFrom.jsx | 2 +- .../EntityStixCoreRelationshipLineTo.jsx | 2 +- ...ityStixCoreRelationshipsHorizontalBars.jsx | 2 +- ...ixRelationshipStixCoreRelationshipLine.jsx | 2 +- .../StixCoreRelationshipCreationForm.js | 2 +- ...pCreationFromEntityStixCoreObjectsLine.jsx | 2 +- .../StixCoreRelationshipOverview.jsx | 2 +- ...ityStixCoreRelationshipsContextualView.tsx | 2 +- ...yStixCoreRelationshipsEntitiesViewLine.tsx | 2 +- ...eRelationshipsIndicatorsContextualView.tsx | 2 +- .../StixDomainObjectHeader.jsx | 2 +- .../StixDomainObjectNestedEntitiesLines.jsx | 2 +- .../StixDomainObjectTimeline.jsx | 2 +- .../StixDomainObjectsTimeline.jsx | 2 +- ...estedRefRelationshipCreationFromEntity.jsx | 2 +- ...dRefRelationshipCreationFromEntityLine.tsx | 2 +- .../StixRelationshipsDistributionList.jsx | 2 +- .../StixRelationshipsHorizontalBars.jsx | 2 +- .../StixRelationshipsMultiHorizontalBars.jsx | 2 +- .../StixRelationshipsPolarArea.jsx | 2 +- .../src/private/components/data/ToolBar.jsx | 2 +- .../entities/EntitiesStixDomainObjectLine.jsx | 2 +- .../RelationshipsStixCoreRelationshipLine.jsx | 2 +- .../EntityStixSightingRelationshipsDonut.jsx | 2 +- .../StixSightingRelationshipCreation.jsx | 2 +- .../StixCyberObservableEntitiesLines.jsx | 2 +- ...StixCyberObservableNestedEntitiesLines.jsx | 2 +- .../notifications/NotificationsToolBar.tsx | 2 +- .../search/SearchStixCoreObjectLine.jsx | 2 +- .../InvestigationAddStixCoreObjectsLine.tsx | 2 +- .../investigations/InvestigationGraph.jsx | 3 +- .../PublicStixCoreObjectsHorizontalBars.tsx | 2 +- ...ublicStixRelationshipsDistributionList.tsx | 2 +- .../PublicStixRelationshipsHorizontalBars.tsx | 2 +- ...icStixRelationshipsMultiHorizontalBars.tsx | 4 +- .../PublicStixRelationshipsPolarArea.tsx | 2 +- .../opencti-front/src/utils/Graph.js | 129 ---------------- .../src/utils/defaultRepresentatives.ts | 142 ++++++++++++++++++ .../src/utils/filters/useSearchEntities.tsx | 2 +- .../src/utils/graph/EntityDetails.tsx | 2 +- .../src/utils/graph/RelationShipFromAndTo.tsx | 2 +- .../src/utils/graph/StixMetaObjectDetails.tsx | 2 +- 75 files changed, 224 insertions(+), 214 deletions(-) create mode 100644 opencti-platform/opencti-front/src/utils/defaultRepresentatives.ts diff --git a/opencti-platform/opencti-front/src/components/dashboard/WidgetDonut.tsx b/opencti-platform/opencti-front/src/components/dashboard/WidgetDonut.tsx index 89c10959bc2a..c55c5e598a21 100644 --- a/opencti-platform/opencti-front/src/components/dashboard/WidgetDonut.tsx +++ b/opencti-platform/opencti-front/src/components/dashboard/WidgetDonut.tsx @@ -2,7 +2,7 @@ import Chart from '@components/common/charts/Chart'; import React from 'react'; import { useTheme } from '@mui/styles'; import type { ApexOptions } from 'apexcharts'; -import { defaultValue } from '../../utils/Graph'; +import { defaultValue, isFieldForIdentifier } from '../../utils/defaultRepresentatives'; import { donutChartOptions } from '../../utils/Charts'; import { useFormatter } from '../i18n'; import type { Theme } from '../Theme'; diff --git a/opencti-platform/opencti-front/src/components/dashboard/WidgetListCoreObjects.tsx b/opencti-platform/opencti-front/src/components/dashboard/WidgetListCoreObjects.tsx index 8c9c5a48d1c5..3c194f4170d1 100644 --- a/opencti-platform/opencti-front/src/components/dashboard/WidgetListCoreObjects.tsx +++ b/opencti-platform/opencti-front/src/components/dashboard/WidgetListCoreObjects.tsx @@ -8,7 +8,7 @@ import StixCoreObjectLabels from '@components/common/stix_core_objects/StixCoreO import React, { CSSProperties } from 'react'; import { resolveLink } from '../../utils/Entity'; import ItemIcon from '../ItemIcon'; -import { defaultValue } from '../../utils/Graph'; +import { defaultValue } from '../../utils/defaultRepresentatives'; import ItemStatus from '../ItemStatus'; import ItemMarkings from '../ItemMarkings'; import { useFormatter } from '../i18n'; @@ -72,7 +72,7 @@ const WidgetListCoreObjects = ({ primary={ <>
- {defaultValue(stixCoreObject, t_i18n('Restricted'))} + {defaultValue(stixCoreObject)}
{fsd(date)} diff --git a/opencti-platform/opencti-front/src/components/dashboard/WidgetListRelationships.tsx b/opencti-platform/opencti-front/src/components/dashboard/WidgetListRelationships.tsx index ea8dd58f50ef..d46372f7aebb 100644 --- a/opencti-platform/opencti-front/src/components/dashboard/WidgetListRelationships.tsx +++ b/opencti-platform/opencti-front/src/components/dashboard/WidgetListRelationships.tsx @@ -7,7 +7,7 @@ import React, { CSSProperties } from 'react'; import { useTheme } from '@mui/styles'; import { ListItemButton } from '@mui/material'; import ItemIcon from '../ItemIcon'; -import { defaultValue } from '../../utils/Graph'; +import { defaultValue } from '../../utils/defaultRepresentatives'; import ItemMarkings from '../ItemMarkings'; import { computeLink } from '../../utils/Entity'; import type { Theme } from '../Theme'; @@ -115,7 +115,9 @@ const WidgetListRelationships = ({
- {defaultValue(stixRelationship.from, t_i18n('Restricted')} + {stixRelationship.from + ? defaultValue(stixRelationship.from) + : t_i18n('Restricted')}
@@ -146,7 +148,9 @@ const WidgetListRelationships = ({
- {defaultValue(stixRelationship.to, t_i18n('Restricted')} + {stixRelationship.to + ? defaultValue(stixRelationship.to) + : t_i18n('Restricted')}
diff --git a/opencti-platform/opencti-front/src/components/dashboard/WidgetRadar.tsx b/opencti-platform/opencti-front/src/components/dashboard/WidgetRadar.tsx index c35a26ee4bc6..204796983400 100644 --- a/opencti-platform/opencti-front/src/components/dashboard/WidgetRadar.tsx +++ b/opencti-platform/opencti-front/src/components/dashboard/WidgetRadar.tsx @@ -3,7 +3,7 @@ import React from 'react'; import { useTheme } from '@mui/styles'; import { ApexOptions } from 'apexcharts'; import { radarChartOptions } from '../../utils/Charts'; -import { defaultValue } from '../../utils/Graph'; +import { defaultValue } from '../../utils/defaultRepresentatives'; import { useFormatter } from '../i18n'; import type { Theme } from '../Theme'; diff --git a/opencti-platform/opencti-front/src/components/dashboard/WidgetTimeline.tsx b/opencti-platform/opencti-front/src/components/dashboard/WidgetTimeline.tsx index 728a92dd773f..84f56d8909e7 100644 --- a/opencti-platform/opencti-front/src/components/dashboard/WidgetTimeline.tsx +++ b/opencti-platform/opencti-front/src/components/dashboard/WidgetTimeline.tsx @@ -9,7 +9,7 @@ import TimelineContent from '@mui/lab/TimelineContent'; import Paper from '@mui/material/Paper'; import Typography from '@mui/material/Typography'; import React from 'react'; -import { defaultValue } from '../../utils/Graph'; +import { defaultValue } from '../../utils/defaultRepresentatives'; import MarkdownDisplay from '../MarkdownDisplay'; import ItemIcon from '../ItemIcon'; import { itemColor } from '../../utils/Colors'; @@ -67,7 +67,7 @@ const WidgetTimeline = ({ data }: WidgetTimelineProps) => { - {defaultValue(value, t_i18n('Restricted'))} + {defaultValue(value)}
({ diff --git a/opencti-platform/opencti-front/src/private/components/common/containers/ContainerHeader.jsx b/opencti-platform/opencti-front/src/private/components/common/containers/ContainerHeader.jsx index 69ee0b5a0f37..fd06ba7df5a5 100644 --- a/opencti-platform/opencti-front/src/private/components/common/containers/ContainerHeader.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/containers/ContainerHeader.jsx @@ -33,7 +33,7 @@ import Security from '../../../../utils/Security'; import { useFormatter } from '../../../../components/i18n'; import { truncate } from '../../../../utils/String'; import { commitMutation, MESSAGING$, QueryRenderer } from '../../../../relay/environment'; -import { defaultValue } from '../../../../utils/Graph'; +import { defaultValue } from '../../../../utils/defaultRepresentatives'; import { stixCoreRelationshipCreationMutation } from '../stix_core_relationships/StixCoreRelationshipCreation'; import { containerAddStixCoreObjectsLinesRelationAddMutation } from './ContainerAddStixCoreObjectsLines'; import StixCoreObjectSharing from '../stix_core_objects/StixCoreObjectSharing'; diff --git a/opencti-platform/opencti-front/src/private/components/common/containers/ContainerStixCoreObjectsMappingLine.jsx b/opencti-platform/opencti-front/src/private/components/common/containers/ContainerStixCoreObjectsMappingLine.jsx index 34f894aa2694..b7a2331fe02e 100644 --- a/opencti-platform/opencti-front/src/private/components/common/containers/ContainerStixCoreObjectsMappingLine.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/containers/ContainerStixCoreObjectsMappingLine.jsx @@ -16,7 +16,7 @@ import IconButton from '@mui/material/IconButton'; import { useFormatter } from '../../../../components/i18n'; import ItemIcon from '../../../../components/ItemIcon'; import { resolveLink } from '../../../../utils/Entity'; -import { defaultValue } from '../../../../utils/Graph'; +import { defaultValue } from '../../../../utils/defaultRepresentatives'; import ItemMarkings from '../../../../components/ItemMarkings'; import { hexToRGB, itemColor } from '../../../../utils/Colors'; import ContainerStixCoreObjectPopover from './ContainerStixCoreObjectPopover'; diff --git a/opencti-platform/opencti-front/src/private/components/common/containers/ContainerStixDomainObjectLine.jsx b/opencti-platform/opencti-front/src/private/components/common/containers/ContainerStixDomainObjectLine.jsx index cd011e45be2c..2b8fbcb36402 100644 --- a/opencti-platform/opencti-front/src/private/components/common/containers/ContainerStixDomainObjectLine.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/containers/ContainerStixDomainObjectLine.jsx @@ -19,7 +19,7 @@ import ItemIcon from '../../../../components/ItemIcon'; import ContainerStixCoreObjectPopover from './ContainerStixCoreObjectPopover'; import { resolveLink } from '../../../../utils/Entity'; import StixCoreObjectLabels from '../stix_core_objects/StixCoreObjectLabels'; -import { defaultValue } from '../../../../utils/Graph'; +import { defaultValue } from '../../../../utils/defaultRepresentatives'; import ItemMarkings from '../../../../components/ItemMarkings'; import { hexToRGB, itemColor } from '../../../../utils/Colors'; diff --git a/opencti-platform/opencti-front/src/private/components/common/containers/ContainerStixObjectOrStixRelationshipLine.jsx b/opencti-platform/opencti-front/src/private/components/common/containers/ContainerStixObjectOrStixRelationshipLine.jsx index 17d49e89130e..37dbacd54350 100644 --- a/opencti-platform/opencti-front/src/private/components/common/containers/ContainerStixObjectOrStixRelationshipLine.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/containers/ContainerStixObjectOrStixRelationshipLine.jsx @@ -17,7 +17,7 @@ import ContainerStixCoreObjectPopover from './ContainerStixCoreObjectPopover'; import { resolveLink } from '../../../../utils/Entity'; import ItemMarkings from '../../../../components/ItemMarkings'; import { hexToRGB, itemColor } from '../../../../utils/Colors'; -import { defaultValue } from '../../../../utils/Graph'; +import { defaultValue } from '../../../../utils/defaultRepresentatives'; import StixCoreObjectLabels from '../stix_core_objects/StixCoreObjectLabels'; const useStyles = makeStyles((theme) => ({ diff --git a/opencti-platform/opencti-front/src/private/components/common/containers/StixCoreObjectOrStixCoreRelationshipContainerLine.tsx b/opencti-platform/opencti-front/src/private/components/common/containers/StixCoreObjectOrStixCoreRelationshipContainerLine.tsx index 40a6cab8440b..641a2be277e3 100644 --- a/opencti-platform/opencti-front/src/private/components/common/containers/StixCoreObjectOrStixCoreRelationshipContainerLine.tsx +++ b/opencti-platform/opencti-front/src/private/components/common/containers/StixCoreObjectOrStixCoreRelationshipContainerLine.tsx @@ -12,7 +12,7 @@ import { useFormatter } from '../../../../components/i18n'; import StixCoreObjectLabels from '../stix_core_objects/StixCoreObjectLabels'; import ItemIcon from '../../../../components/ItemIcon'; import { resolveLink } from '../../../../utils/Entity'; -import { defaultValue } from '../../../../utils/Graph'; +import { defaultValue } from '../../../../utils/defaultRepresentatives'; import ItemStatus from '../../../../components/ItemStatus'; import ItemMarkings from '../../../../components/ItemMarkings'; import type { Theme } from '../../../../components/Theme'; diff --git a/opencti-platform/opencti-front/src/private/components/common/containers/StixCoreObjectOrStixCoreRelationshipContainersGraph.jsx b/opencti-platform/opencti-front/src/private/components/common/containers/StixCoreObjectOrStixCoreRelationshipContainersGraph.jsx index ebb45ac0701a..e931eef5e6f0 100644 --- a/opencti-platform/opencti-front/src/private/components/common/containers/StixCoreObjectOrStixCoreRelationshipContainersGraph.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/containers/StixCoreObjectOrStixCoreRelationshipContainersGraph.jsx @@ -15,14 +15,13 @@ import { computeTimeRangeInterval, computeTimeRangeValues, decodeGraphData, - defaultSecondaryValue, - defaultValue, encodeGraphData, linkPaint, nodeAreaPaint, nodePaint, nodeThreePaint, } from '../../../../utils/Graph'; +import { defaultSecondaryValue, defaultValue } from '../../../../utils/defaultRepresentatives'; import { commitMutation, MESSAGING$ } from '../../../../relay/environment'; import inject18n from '../../../../components/i18n'; import { stixDomainObjectMutationFieldPatch } from '../stix_domain_objects/StixDomainObjectEditionOverview'; diff --git a/opencti-platform/opencti-front/src/private/components/common/files/workbench/WorkbenchFileContent.jsx b/opencti-platform/opencti-front/src/private/components/common/files/workbench/WorkbenchFileContent.jsx index d37f1b0bee26..332aea431aa5 100644 --- a/opencti-platform/opencti-front/src/private/components/common/files/workbench/WorkbenchFileContent.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/files/workbench/WorkbenchFileContent.jsx @@ -40,7 +40,7 @@ import SwitchField from '../../../../../components/SwitchField'; import TextField from '../../../../../components/TextField'; import { APP_BASE_PATH, commitMutation, handleError, MESSAGING$, QueryRenderer } from '../../../../../relay/environment'; import { observableValue, resolveIdentityClass, resolveIdentityType, resolveLink, resolveLocationType, resolveThreatActorType } from '../../../../../utils/Entity'; -import { defaultKey, defaultValue } from '../../../../../utils/Graph'; +import { defaultKey, defaultValue } from '../../../../../utils/defaultRepresentatives'; import useAttributes from '../../../../../utils/hooks/useAttributes'; import useVocabularyCategory from '../../../../../utils/hooks/useVocabularyCategory'; import { computeDuplicates, convertFromStixType, convertToStixType, truncate, uniqWithByFields } from '../../../../../utils/String'; diff --git a/opencti-platform/opencti-front/src/private/components/common/form/DynamicResolutionField.jsx b/opencti-platform/opencti-front/src/private/components/common/form/DynamicResolutionField.jsx index 943e6577cc66..0a59c2734a58 100644 --- a/opencti-platform/opencti-front/src/private/components/common/form/DynamicResolutionField.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/form/DynamicResolutionField.jsx @@ -17,7 +17,7 @@ import ItemIcon from '../../../../components/ItemIcon'; import ItemBoolean from '../../../../components/ItemBoolean'; import { convertFromStixType, convertToStixType } from '../../../../utils/String'; import { useFormatter } from '../../../../components/i18n'; -import { defaultValue } from '../../../../utils/Graph'; +import { defaultValue } from '../../../../utils/defaultRepresentatives'; import { isEmptyField } from '../../../../utils/utils'; const inlineStyles = { diff --git a/opencti-platform/opencti-front/src/private/components/common/form/StixCoreObjectsField.jsx b/opencti-platform/opencti-front/src/private/components/common/form/StixCoreObjectsField.jsx index 17bf2c0618b1..be258daa77ff 100644 --- a/opencti-platform/opencti-front/src/private/components/common/form/StixCoreObjectsField.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/form/StixCoreObjectsField.jsx @@ -12,7 +12,7 @@ import ListItemText from '@mui/material/ListItemText'; import makeStyles from '@mui/styles/makeStyles'; import IconButton from '@mui/material/IconButton'; import ItemIcon from '../../../../components/ItemIcon'; -import { defaultValue } from '../../../../utils/Graph'; +import { defaultValue } from '../../../../utils/defaultRepresentatives'; import { useFormatter } from '../../../../components/i18n'; import AutocompleteField from '../../../../components/AutocompleteField'; import { fetchQuery } from '../../../../relay/environment'; diff --git a/opencti-platform/opencti-front/src/private/components/common/form/StixDomainObjectsField.jsx b/opencti-platform/opencti-front/src/private/components/common/form/StixDomainObjectsField.jsx index dcfa7bf25466..a002ed987730 100644 --- a/opencti-platform/opencti-front/src/private/components/common/form/StixDomainObjectsField.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/form/StixDomainObjectsField.jsx @@ -8,7 +8,7 @@ import { graphql } from 'react-relay'; import { fetchQuery } from '../../../../relay/environment'; import AutocompleteField from '../../../../components/AutocompleteField'; import inject18n from '../../../../components/i18n'; -import { defaultValue } from '../../../../utils/Graph'; +import { defaultValue } from '../../../../utils/defaultRepresentatives'; import ItemIcon from '../../../../components/ItemIcon'; const SEARCH$ = new Subject().pipe(debounce(() => timer(1500))); diff --git a/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectsHorizontalBars.jsx b/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectsHorizontalBars.jsx index a1278da7ad39..ec3ad875e95d 100644 --- a/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectsHorizontalBars.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectsHorizontalBars.jsx @@ -4,7 +4,7 @@ import { useTheme } from '@mui/styles'; import { QueryRenderer } from '../../../../relay/environment'; import { useFormatter } from '../../../../components/i18n'; import { itemColor } from '../../../../utils/Colors'; -import { defaultValue } from '../../../../utils/Graph'; +import { defaultValue } from '../../../../utils/defaultRepresentatives'; import { buildFiltersAndOptionsForWidgets } from '../../../../utils/filters/filtersUtils'; import WidgetContainer from '../../../../components/dashboard/WidgetContainer'; import WidgetNoData from '../../../../components/dashboard/WidgetNoData'; diff --git a/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectsMultiHorizontalBars.jsx b/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectsMultiHorizontalBars.jsx index 7eb366f53823..d490068e59ad 100644 --- a/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectsMultiHorizontalBars.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectsMultiHorizontalBars.jsx @@ -11,7 +11,7 @@ import { QueryRenderer } from '../../../../relay/environment'; import { useFormatter } from '../../../../components/i18n'; import { horizontalBarsChartOptions } from '../../../../utils/Charts'; import { simpleNumberFormat } from '../../../../utils/Number'; -import { defaultValue } from '../../../../utils/Graph'; +import { defaultValue } from '../../../../utils/defaultRepresentatives'; import { itemColor } from '../../../../utils/Colors'; import { buildFiltersAndOptionsForWidgets } from '../../../../utils/filters/filtersUtils'; diff --git a/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/EntityStixCoreRelationshipLineAll.jsx b/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/EntityStixCoreRelationshipLineAll.jsx index 9984954f6bea..dc30ad9de8bd 100644 --- a/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/EntityStixCoreRelationshipLineAll.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/EntityStixCoreRelationshipLineAll.jsx @@ -18,7 +18,7 @@ import inject18n from '../../../../components/i18n'; import ItemIcon from '../../../../components/ItemIcon'; import ItemConfidence from '../../../../components/ItemConfidence'; import StixCoreRelationshipPopover from './StixCoreRelationshipPopover'; -import { defaultValue } from '../../../../utils/Graph'; +import { defaultValue } from '../../../../utils/defaultRepresentatives'; import { hexToRGB, itemColor } from '../../../../utils/Colors'; import ItemMarkings from '../../../../components/ItemMarkings'; diff --git a/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/EntityStixCoreRelationshipLineFrom.jsx b/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/EntityStixCoreRelationshipLineFrom.jsx index c3a2bca8d709..648c3420ea4f 100644 --- a/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/EntityStixCoreRelationshipLineFrom.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/EntityStixCoreRelationshipLineFrom.jsx @@ -18,7 +18,7 @@ import inject18n from '../../../../components/i18n'; import ItemIcon from '../../../../components/ItemIcon'; import ItemConfidence from '../../../../components/ItemConfidence'; import StixCoreRelationshipPopover from './StixCoreRelationshipPopover'; -import { defaultValue } from '../../../../utils/Graph'; +import { defaultValue } from '../../../../utils/defaultRepresentatives'; import { hexToRGB, itemColor } from '../../../../utils/Colors'; import ItemMarkings from '../../../../components/ItemMarkings'; diff --git a/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/EntityStixCoreRelationshipLineTo.jsx b/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/EntityStixCoreRelationshipLineTo.jsx index 18c8d74787a7..350e466c8098 100644 --- a/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/EntityStixCoreRelationshipLineTo.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/EntityStixCoreRelationshipLineTo.jsx @@ -18,7 +18,7 @@ import inject18n from '../../../../components/i18n'; import ItemIcon from '../../../../components/ItemIcon'; import ItemConfidence from '../../../../components/ItemConfidence'; import StixCoreRelationshipPopover from './StixCoreRelationshipPopover'; -import { defaultValue } from '../../../../utils/Graph'; +import { defaultValue } from '../../../../utils/defaultRepresentatives'; import { hexToRGB, itemColor } from '../../../../utils/Colors'; import ItemMarkings from '../../../../components/ItemMarkings'; diff --git a/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/EntityStixCoreRelationshipsHorizontalBars.jsx b/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/EntityStixCoreRelationshipsHorizontalBars.jsx index 0e62e6312da9..50f559776ad9 100644 --- a/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/EntityStixCoreRelationshipsHorizontalBars.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/EntityStixCoreRelationshipsHorizontalBars.jsx @@ -12,7 +12,7 @@ import { useFormatter } from '../../../../components/i18n'; import { itemColor } from '../../../../utils/Colors'; import { horizontalBarsChartOptions } from '../../../../utils/Charts'; import { simpleNumberFormat } from '../../../../utils/Number'; -import { defaultValue } from '../../../../utils/Graph'; +import { defaultValue } from '../../../../utils/defaultRepresentatives'; const useStyles = makeStyles(() => ({ paper: { diff --git a/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/SimpleStixObjectOrStixRelationshipStixCoreRelationshipLine.jsx b/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/SimpleStixObjectOrStixRelationshipStixCoreRelationshipLine.jsx index 045866fb4f9a..8461521e91b2 100644 --- a/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/SimpleStixObjectOrStixRelationshipStixCoreRelationshipLine.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/SimpleStixObjectOrStixRelationshipStixCoreRelationshipLine.jsx @@ -21,7 +21,7 @@ import Security from '../../../../utils/Security'; import { KNOWLEDGE_KNUPDATE } from '../../../../utils/hooks/useGranted'; import ItemIcon from '../../../../components/ItemIcon'; import { hexToRGB, itemColor } from '../../../../utils/Colors'; -import { defaultValue } from '../../../../utils/Graph'; +import { defaultValue } from '../../../../utils/defaultRepresentatives'; import ItemMarkings from '../../../../components/ItemMarkings'; const styles = (theme) => ({ diff --git a/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/StixCoreRelationshipCreationForm.js b/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/StixCoreRelationshipCreationForm.js index 9b7607f13893..4f3d51febb31 100644 --- a/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/StixCoreRelationshipCreationForm.js +++ b/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/StixCoreRelationshipCreationForm.js @@ -21,7 +21,7 @@ import { itemColor } from '../../../../utils/Colors'; import ItemIcon from '../../../../components/ItemIcon'; import { useSchemaCreationValidation } from '../../../../utils/hooks/useEntitySettings'; import useDefaultValues from '../../../../utils/hooks/useDefaultValues'; -import { defaultValue } from '../../../../utils/Graph'; +import { defaultValue } from '../../../../utils/defaultRepresentatives'; const useStyles = makeStyles((theme) => ({ containerRelation: { diff --git a/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/StixCoreRelationshipCreationFromEntityStixCoreObjectsLine.jsx b/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/StixCoreRelationshipCreationFromEntityStixCoreObjectsLine.jsx index 8f87501e460b..ff671682eef4 100644 --- a/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/StixCoreRelationshipCreationFromEntityStixCoreObjectsLine.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/StixCoreRelationshipCreationFromEntityStixCoreObjectsLine.jsx @@ -13,7 +13,7 @@ import { useFormatter } from '../../../../components/i18n'; import StixCoreObjectLabels from '../stix_core_objects/StixCoreObjectLabels'; import ItemIcon from '../../../../components/ItemIcon'; import ItemMarkings from '../../../../components/ItemMarkings'; -import { defaultValue } from '../../../../utils/Graph'; +import { defaultValue } from '../../../../utils/defaultRepresentatives'; import { hexToRGB, itemColor } from '../../../../utils/Colors'; import { APP_BASE_PATH } from '../../../../relay/environment'; diff --git a/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/StixCoreRelationshipOverview.jsx b/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/StixCoreRelationshipOverview.jsx index 0b38db981c9e..90ff0cd01e60 100644 --- a/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/StixCoreRelationshipOverview.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/StixCoreRelationshipOverview.jsx @@ -34,7 +34,7 @@ import StixCoreRelationshipExternalReferences from '../../analyses/external_refe import StixCoreRelationshipLatestHistory from './StixCoreRelationshipLatestHistory'; import Security from '../../../../utils/Security'; import { KNOWLEDGE_KNUPDATE } from '../../../../utils/hooks/useGranted'; -import { defaultValue } from '../../../../utils/Graph'; +import { defaultValue } from '../../../../utils/defaultRepresentatives'; import ItemStatus from '../../../../components/ItemStatus'; import ItemCreators from '../../../../components/ItemCreators'; import StixCoreRelationshipSharing from './StixCoreRelationshipSharing'; diff --git a/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/views/EntityStixCoreRelationshipsContextualView.tsx b/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/views/EntityStixCoreRelationshipsContextualView.tsx index 6d393bc1dc3e..1ae789a4b909 100644 --- a/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/views/EntityStixCoreRelationshipsContextualView.tsx +++ b/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/views/EntityStixCoreRelationshipsContextualView.tsx @@ -11,7 +11,7 @@ import useEntityToggle from '../../../../../utils/hooks/useEntityToggle'; import EntityStixCoreRelationshipsContextualViewLines from './EntityStixCoreRelationshipsContextualViewLines'; import { hexToRGB, itemColor } from '../../../../../utils/Colors'; import { useFormatter } from '../../../../../components/i18n'; -import { defaultValue } from '../../../../../utils/Graph'; +import { defaultValue } from '../../../../../utils/defaultRepresentatives'; import StixCoreObjectLabels from '../../stix_core_objects/StixCoreObjectLabels'; import ItemMarkings from '../../../../../components/ItemMarkings'; import { DataColumns, PaginationOptions } from '../../../../../components/list_lines'; diff --git a/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/views/EntityStixCoreRelationshipsEntitiesViewLine.tsx b/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/views/EntityStixCoreRelationshipsEntitiesViewLine.tsx index 26e0c27ce8d3..a5d3e64118bd 100644 --- a/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/views/EntityStixCoreRelationshipsEntitiesViewLine.tsx +++ b/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/views/EntityStixCoreRelationshipsEntitiesViewLine.tsx @@ -18,7 +18,7 @@ import { useFormatter } from '../../../../../components/i18n'; import { DataColumns } from '../../../../../components/list_lines'; import { UseEntityToggle } from '../../../../../utils/hooks/useEntityToggle'; import ItemIcon from '../../../../../components/ItemIcon'; -import { defaultValue } from '../../../../../utils/Graph'; +import { defaultValue } from '../../../../../utils/defaultRepresentatives'; import { hexToRGB, itemColor } from '../../../../../utils/Colors'; import { EntityStixCoreRelationshipsEntitiesViewLine_node$data, diff --git a/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/views/indicators/EntityStixCoreRelationshipsIndicatorsContextualView.tsx b/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/views/indicators/EntityStixCoreRelationshipsIndicatorsContextualView.tsx index 40dbc26dc04a..116e4714fb1f 100644 --- a/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/views/indicators/EntityStixCoreRelationshipsIndicatorsContextualView.tsx +++ b/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/views/indicators/EntityStixCoreRelationshipsIndicatorsContextualView.tsx @@ -20,7 +20,7 @@ import { import useEntityToggle from '../../../../../../utils/hooks/useEntityToggle'; import { EntityStixCoreRelationshipsIndicatorsContextualViewLine_node$data } from './__generated__/EntityStixCoreRelationshipsIndicatorsContextualViewLine_node.graphql'; import useAuth from '../../../../../../utils/hooks/useAuth'; -import { defaultValue } from '../../../../../../utils/Graph'; +import { defaultValue } from '../../../../../../utils/defaultRepresentatives'; import StixCoreObjectLabels from '../../../stix_core_objects/StixCoreObjectLabels'; import ItemMarkings from '../../../../../../components/ItemMarkings'; import ListLines from '../../../../../../components/list_lines/ListLines'; diff --git a/opencti-platform/opencti-front/src/private/components/common/stix_domain_objects/StixDomainObjectHeader.jsx b/opencti-platform/opencti-front/src/private/components/common/stix_domain_objects/StixDomainObjectHeader.jsx index 8a9fa3166e26..d806afddd008 100644 --- a/opencti-platform/opencti-front/src/private/components/common/stix_domain_objects/StixDomainObjectHeader.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/stix_domain_objects/StixDomainObjectHeader.jsx @@ -39,7 +39,7 @@ import StixCoreObjectSharing from '../stix_core_objects/StixCoreObjectSharing'; import { truncate } from '../../../../utils/String'; import { useIsEnforceReference } from '../../../../utils/hooks/useEntitySettings'; import StixCoreObjectQuickSubscription from '../stix_core_objects/StixCoreObjectQuickSubscription'; -import { defaultValue } from '../../../../utils/Graph'; +import { defaultValue } from '../../../../utils/defaultRepresentatives'; import Transition from '../../../../components/Transition'; import Loader, { LoaderVariant } from '../../../../components/Loader'; diff --git a/opencti-platform/opencti-front/src/private/components/common/stix_domain_objects/StixDomainObjectNestedEntitiesLines.jsx b/opencti-platform/opencti-front/src/private/components/common/stix_domain_objects/StixDomainObjectNestedEntitiesLines.jsx index 4b3fa9801a9d..073d58243808 100644 --- a/opencti-platform/opencti-front/src/private/components/common/stix_domain_objects/StixDomainObjectNestedEntitiesLines.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/stix_domain_objects/StixDomainObjectNestedEntitiesLines.jsx @@ -13,7 +13,7 @@ import inject18n from '../../../../components/i18n'; import ItemIcon from '../../../../components/ItemIcon'; import StixNestedRefRelationshipPopover from '../stix_nested_ref_relationships/StixNestedRefRelationshipPopover'; import { resolveLink } from '../../../../utils/Entity'; -import { defaultValue } from '../../../../utils/Graph'; +import { defaultValue } from '../../../../utils/defaultRepresentatives'; import { hexToRGB, itemColor } from '../../../../utils/Colors'; const styles = (theme) => ({ diff --git a/opencti-platform/opencti-front/src/private/components/common/stix_domain_objects/StixDomainObjectTimeline.jsx b/opencti-platform/opencti-front/src/private/components/common/stix_domain_objects/StixDomainObjectTimeline.jsx index a58947806fb1..05bbc2aa24be 100644 --- a/opencti-platform/opencti-front/src/private/components/common/stix_domain_objects/StixDomainObjectTimeline.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/stix_domain_objects/StixDomainObjectTimeline.jsx @@ -20,7 +20,7 @@ import ItemIcon from '../../../../components/ItemIcon'; import inject18n from '../../../../components/i18n'; import { stixDomainObjectThreatKnowledgeStixRelationshipsQuery } from './StixDomainObjectThreatKnowledgeQuery'; import { truncate } from '../../../../utils/String'; -import { defaultSecondaryValue, defaultValue } from '../../../../utils/Graph'; +import { defaultSecondaryValue, defaultValue } from '../../../../utils/defaultRepresentatives'; import { itemColor } from '../../../../utils/Colors'; const Transition = React.forwardRef((props, ref) => ( diff --git a/opencti-platform/opencti-front/src/private/components/common/stix_domain_objects/StixDomainObjectsTimeline.jsx b/opencti-platform/opencti-front/src/private/components/common/stix_domain_objects/StixDomainObjectsTimeline.jsx index 021a80ac8c0e..f10416541e9c 100644 --- a/opencti-platform/opencti-front/src/private/components/common/stix_domain_objects/StixDomainObjectsTimeline.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/stix_domain_objects/StixDomainObjectsTimeline.jsx @@ -17,7 +17,7 @@ import CircularProgress from '@mui/material/CircularProgress'; import { QueryRenderer } from '../../../../relay/environment'; import ItemIcon from '../../../../components/ItemIcon'; import inject18n from '../../../../components/i18n'; -import { defaultValue } from '../../../../utils/Graph'; +import { defaultValue } from '../../../../utils/defaultRepresentatives'; import { resolveLink } from '../../../../utils/Entity'; import { itemColor } from '../../../../utils/Colors'; import MarkdownDisplay from '../../../../components/MarkdownDisplay'; diff --git a/opencti-platform/opencti-front/src/private/components/common/stix_nested_ref_relationships/StixNestedRefRelationshipCreationFromEntity.jsx b/opencti-platform/opencti-front/src/private/components/common/stix_nested_ref_relationships/StixNestedRefRelationshipCreationFromEntity.jsx index e316f5a33866..a2546fbd299b 100644 --- a/opencti-platform/opencti-front/src/private/components/common/stix_nested_ref_relationships/StixNestedRefRelationshipCreationFromEntity.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/stix_nested_ref_relationships/StixNestedRefRelationshipCreationFromEntity.jsx @@ -27,7 +27,7 @@ import SelectField from '../../../../components/SelectField'; import StixNestedRefRelationCreationFromEntityLines, { stixNestedRefRelationshipCreationFromEntityLinesQuery } from './StixNestedRefRelationshipCreationFromEntityLines'; import StixCyberObservableCreation from '../../observations/stix_cyber_observables/StixCyberObservableCreation'; import { truncate } from '../../../../utils/String'; -import { defaultValue } from '../../../../utils/Graph'; +import { defaultValue } from '../../../../utils/defaultRepresentatives'; import StixDomainObjectCreation from '../stix_domain_objects/StixDomainObjectCreation'; import DateTimePickerField from '../../../../components/DateTimePickerField'; import { onlyLinkedTo } from '../../../../utils/Relation'; diff --git a/opencti-platform/opencti-front/src/private/components/common/stix_nested_ref_relationships/StixNestedRefRelationshipCreationFromEntityLine.tsx b/opencti-platform/opencti-front/src/private/components/common/stix_nested_ref_relationships/StixNestedRefRelationshipCreationFromEntityLine.tsx index 0625fe8c880b..9664bf829001 100644 --- a/opencti-platform/opencti-front/src/private/components/common/stix_nested_ref_relationships/StixNestedRefRelationshipCreationFromEntityLine.tsx +++ b/opencti-platform/opencti-front/src/private/components/common/stix_nested_ref_relationships/StixNestedRefRelationshipCreationFromEntityLine.tsx @@ -16,7 +16,7 @@ import StixCoreObjectLabels from '../stix_core_objects/StixCoreObjectLabels'; import { APP_BASE_PATH } from '../../../../relay/environment'; import ItemIcon from '../../../../components/ItemIcon'; import { hexToRGB, itemColor } from '../../../../utils/Colors'; -import { defaultValue } from '../../../../utils/Graph'; +import { defaultValue } from '../../../../utils/defaultRepresentatives'; import ItemMarkings from '../../../../components/ItemMarkings'; import { useFormatter } from '../../../../components/i18n'; import type { Theme } from '../../../../components/Theme'; diff --git a/opencti-platform/opencti-front/src/private/components/common/stix_relationships/StixRelationshipsDistributionList.jsx b/opencti-platform/opencti-front/src/private/components/common/stix_relationships/StixRelationshipsDistributionList.jsx index 3203f7c5a502..fc321db3d096 100644 --- a/opencti-platform/opencti-front/src/private/components/common/stix_relationships/StixRelationshipsDistributionList.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/stix_relationships/StixRelationshipsDistributionList.jsx @@ -2,7 +2,7 @@ import React from 'react'; import { graphql } from 'react-relay'; import { QueryRenderer } from '../../../../relay/environment'; import { useFormatter } from '../../../../components/i18n'; -import { defaultValue } from '../../../../utils/Graph'; +import { defaultValue } from '../../../../utils/defaultRepresentatives'; import useGranted, { SETTINGS_SETACCESSES } from '../../../../utils/hooks/useGranted'; import { buildFiltersAndOptionsForWidgets } from '../../../../utils/filters/filtersUtils'; import WidgetNoData from '../../../../components/dashboard/WidgetNoData'; diff --git a/opencti-platform/opencti-front/src/private/components/common/stix_relationships/StixRelationshipsHorizontalBars.jsx b/opencti-platform/opencti-front/src/private/components/common/stix_relationships/StixRelationshipsHorizontalBars.jsx index cf755aea5763..1e2dae42b374 100644 --- a/opencti-platform/opencti-front/src/private/components/common/stix_relationships/StixRelationshipsHorizontalBars.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/stix_relationships/StixRelationshipsHorizontalBars.jsx @@ -4,7 +4,7 @@ import { useTheme } from '@mui/styles'; import { QueryRenderer } from '../../../../relay/environment'; import { useFormatter } from '../../../../components/i18n'; import { itemColor } from '../../../../utils/Colors'; -import { defaultValue } from '../../../../utils/Graph'; +import { defaultValue } from '../../../../utils/defaultRepresentatives'; import { buildFiltersAndOptionsForWidgets } from '../../../../utils/filters/filtersUtils'; import WidgetContainer from '../../../../components/dashboard/WidgetContainer'; import WidgetNoData from '../../../../components/dashboard/WidgetNoData'; diff --git a/opencti-platform/opencti-front/src/private/components/common/stix_relationships/StixRelationshipsMultiHorizontalBars.jsx b/opencti-platform/opencti-front/src/private/components/common/stix_relationships/StixRelationshipsMultiHorizontalBars.jsx index 61b478cd232e..b541ecaeff36 100644 --- a/opencti-platform/opencti-front/src/private/components/common/stix_relationships/StixRelationshipsMultiHorizontalBars.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/stix_relationships/StixRelationshipsMultiHorizontalBars.jsx @@ -3,7 +3,7 @@ import { graphql } from 'react-relay'; import * as R from 'ramda'; import { QueryRenderer } from '../../../../relay/environment'; import { useFormatter } from '../../../../components/i18n'; -import { defaultValue } from '../../../../utils/Graph'; +import { defaultValue } from '../../../../utils/defaultRepresentatives'; import { buildFiltersAndOptionsForWidgets } from '../../../../utils/filters/filtersUtils'; import WidgetContainer from '../../../../components/dashboard/WidgetContainer'; import WidgetNoData from '../../../../components/dashboard/WidgetNoData'; diff --git a/opencti-platform/opencti-front/src/private/components/common/stix_relationships/StixRelationshipsPolarArea.jsx b/opencti-platform/opencti-front/src/private/components/common/stix_relationships/StixRelationshipsPolarArea.jsx index 6d54bb573942..ff147f88cdc9 100644 --- a/opencti-platform/opencti-front/src/private/components/common/stix_relationships/StixRelationshipsPolarArea.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/stix_relationships/StixRelationshipsPolarArea.jsx @@ -3,7 +3,7 @@ import * as R from 'ramda'; import { graphql } from 'react-relay'; import { QueryRenderer } from '../../../../relay/environment'; import { useFormatter } from '../../../../components/i18n'; -import { defaultValue } from '../../../../utils/Graph'; +import { defaultValue } from '../../../../utils/defaultRepresentatives'; import { buildFiltersAndOptionsForWidgets } from '../../../../utils/filters/filtersUtils'; import WidgetNoData from '../../../../components/dashboard/WidgetNoData'; import WidgetLoader from '../../../../components/dashboard/WidgetLoader'; diff --git a/opencti-platform/opencti-front/src/private/components/data/ToolBar.jsx b/opencti-platform/opencti-front/src/private/components/data/ToolBar.jsx index 28de51bec2f7..778820de78ac 100644 --- a/opencti-platform/opencti-front/src/private/components/data/ToolBar.jsx +++ b/opencti-platform/opencti-front/src/private/components/data/ToolBar.jsx @@ -64,7 +64,7 @@ import { truncate } from '../../../utils/String'; import { commitMutation, fetchQuery, MESSAGING$ } from '../../../relay/environment'; import ItemIcon from '../../../components/ItemIcon'; import { objectMarkingFieldAllowedMarkingsQuery } from '../common/form/ObjectMarkingField'; -import { defaultValue } from '../../../utils/Graph'; +import { defaultValue } from '../../../utils/defaultRepresentatives'; import { identitySearchIdentitiesSearchQuery } from '../common/identities/IdentitySearch'; import { labelsSearchQuery } from '../settings/LabelsQuery'; import Security from '../../../utils/Security'; diff --git a/opencti-platform/opencti-front/src/private/components/data/entities/EntitiesStixDomainObjectLine.jsx b/opencti-platform/opencti-front/src/private/components/data/entities/EntitiesStixDomainObjectLine.jsx index d0287ab2179b..bc56594271b3 100644 --- a/opencti-platform/opencti-front/src/private/components/data/entities/EntitiesStixDomainObjectLine.jsx +++ b/opencti-platform/opencti-front/src/private/components/data/entities/EntitiesStixDomainObjectLine.jsx @@ -16,7 +16,7 @@ import ItemIcon from '../../../../components/ItemIcon'; import ItemMarkings from '../../../../components/ItemMarkings'; import { resolveLink } from '../../../../utils/Entity'; import { hexToRGB, itemColor } from '../../../../utils/Colors'; -import { defaultValue } from '../../../../utils/Graph'; +import { defaultValue } from '../../../../utils/defaultRepresentatives'; const useStyles = makeStyles((theme) => ({ item: { diff --git a/opencti-platform/opencti-front/src/private/components/data/relationships/RelationshipsStixCoreRelationshipLine.jsx b/opencti-platform/opencti-front/src/private/components/data/relationships/RelationshipsStixCoreRelationshipLine.jsx index 6324053cf935..316797114862 100644 --- a/opencti-platform/opencti-front/src/private/components/data/relationships/RelationshipsStixCoreRelationshipLine.jsx +++ b/opencti-platform/opencti-front/src/private/components/data/relationships/RelationshipsStixCoreRelationshipLine.jsx @@ -16,7 +16,7 @@ import makeStyles from '@mui/styles/makeStyles'; import { useFormatter } from '../../../../components/i18n'; import ItemIcon from '../../../../components/ItemIcon'; import ItemMarkings from '../../../../components/ItemMarkings'; -import { defaultValue } from '../../../../utils/Graph'; +import { defaultValue } from '../../../../utils/defaultRepresentatives'; import { computeLink } from '../../../../utils/Entity'; import { hexToRGB, itemColor } from '../../../../utils/Colors'; diff --git a/opencti-platform/opencti-front/src/private/components/events/stix_sighting_relationships/EntityStixSightingRelationshipsDonut.jsx b/opencti-platform/opencti-front/src/private/components/events/stix_sighting_relationships/EntityStixSightingRelationshipsDonut.jsx index 23ca0c2b4055..55e343839135 100644 --- a/opencti-platform/opencti-front/src/private/components/events/stix_sighting_relationships/EntityStixSightingRelationshipsDonut.jsx +++ b/opencti-platform/opencti-front/src/private/components/events/stix_sighting_relationships/EntityStixSightingRelationshipsDonut.jsx @@ -12,7 +12,7 @@ import Chart from '../../common/charts/Chart'; import { QueryRenderer } from '../../../../relay/environment'; import inject18n from '../../../../components/i18n'; import { donutChartOptions } from '../../../../utils/Charts'; -import { defaultValue } from '../../../../utils/Graph'; +import { defaultValue } from '../../../../utils/defaultRepresentatives'; const styles = () => ({ paper: { diff --git a/opencti-platform/opencti-front/src/private/components/events/stix_sighting_relationships/StixSightingRelationshipCreation.jsx b/opencti-platform/opencti-front/src/private/components/events/stix_sighting_relationships/StixSightingRelationshipCreation.jsx index 6c69cbd92587..26a7e982a817 100644 --- a/opencti-platform/opencti-front/src/private/components/events/stix_sighting_relationships/StixSightingRelationshipCreation.jsx +++ b/opencti-platform/opencti-front/src/private/components/events/stix_sighting_relationships/StixSightingRelationshipCreation.jsx @@ -16,7 +16,7 @@ import { itemColor } from '../../../../utils/Colors'; import { formatDate } from '../../../../utils/Time'; import ItemIcon from '../../../../components/ItemIcon'; import { truncate } from '../../../../utils/String'; -import { defaultValue } from '../../../../utils/Graph'; +import { defaultValue } from '../../../../utils/defaultRepresentatives'; import StixSightingRelationshipCreationForm from './StixSightingRelationshipCreationForm'; const styles = (theme) => ({ diff --git a/opencti-platform/opencti-front/src/private/components/observations/stix_cyber_observables/StixCyberObservableEntitiesLines.jsx b/opencti-platform/opencti-front/src/private/components/observations/stix_cyber_observables/StixCyberObservableEntitiesLines.jsx index bfb7fa590585..ba2721e0b37a 100644 --- a/opencti-platform/opencti-front/src/private/components/observations/stix_cyber_observables/StixCyberObservableEntitiesLines.jsx +++ b/opencti-platform/opencti-front/src/private/components/observations/stix_cyber_observables/StixCyberObservableEntitiesLines.jsx @@ -14,7 +14,7 @@ import * as R from 'ramda'; import { AutoFix } from 'mdi-material-ui'; import Chip from '@mui/material/Chip'; import ItemIcon from '../../../../components/ItemIcon'; -import { defaultValue } from '../../../../utils/Graph'; +import { defaultValue } from '../../../../utils/defaultRepresentatives'; import inject18n from '../../../../components/i18n'; import { resolveLink } from '../../../../utils/Entity'; import { TEN_SECONDS } from '../../../../utils/Time'; diff --git a/opencti-platform/opencti-front/src/private/components/observations/stix_cyber_observables/StixCyberObservableNestedEntitiesLines.jsx b/opencti-platform/opencti-front/src/private/components/observations/stix_cyber_observables/StixCyberObservableNestedEntitiesLines.jsx index 9e986e044ef5..f5d7c6fe4c10 100644 --- a/opencti-platform/opencti-front/src/private/components/observations/stix_cyber_observables/StixCyberObservableNestedEntitiesLines.jsx +++ b/opencti-platform/opencti-front/src/private/components/observations/stix_cyber_observables/StixCyberObservableNestedEntitiesLines.jsx @@ -14,7 +14,7 @@ import inject18n from '../../../../components/i18n'; import ItemIcon from '../../../../components/ItemIcon'; import StixNestedRefRelationshipPopover from '../../common/stix_nested_ref_relationships/StixNestedRefRelationshipPopover'; import { resolveLink } from '../../../../utils/Entity'; -import { defaultValue } from '../../../../utils/Graph'; +import { defaultValue } from '../../../../utils/defaultRepresentatives'; import { hexToRGB, itemColor } from '../../../../utils/Colors'; import { TEN_SECONDS } from '../../../../utils/Time'; import { stixCyberObservableEntitiesLinesQuery } from './StixCyberObservableEntitiesLines'; diff --git a/opencti-platform/opencti-front/src/private/components/profile/notifications/NotificationsToolBar.tsx b/opencti-platform/opencti-front/src/private/components/profile/notifications/NotificationsToolBar.tsx index 45674e8e5853..a2e082ea9077 100644 --- a/opencti-platform/opencti-front/src/private/components/profile/notifications/NotificationsToolBar.tsx +++ b/opencti-platform/opencti-front/src/private/components/profile/notifications/NotificationsToolBar.tsx @@ -23,7 +23,7 @@ import Alert from '@mui/material/Alert'; import makeStyles from '@mui/styles/makeStyles'; import { truncate } from '../../../../utils/String'; import { MESSAGING$ } from '../../../../relay/environment'; -import { defaultValue } from '../../../../utils/Graph'; +import { defaultValue } from '../../../../utils/defaultRepresentatives'; import { useFormatter } from '../../../../components/i18n'; import type { Theme } from '../../../../components/Theme'; import { NotificationLine_node$data } from './__generated__/NotificationLine_node.graphql'; diff --git a/opencti-platform/opencti-front/src/private/components/search/SearchStixCoreObjectLine.jsx b/opencti-platform/opencti-front/src/private/components/search/SearchStixCoreObjectLine.jsx index ae7fc8d4717f..fc29a3b3bfa5 100644 --- a/opencti-platform/opencti-front/src/private/components/search/SearchStixCoreObjectLine.jsx +++ b/opencti-platform/opencti-front/src/private/components/search/SearchStixCoreObjectLine.jsx @@ -15,7 +15,7 @@ import StixCoreObjectLabels from '../common/stix_core_objects/StixCoreObjectLabe import ItemIcon from '../../../components/ItemIcon'; import ItemMarkings from '../../../components/ItemMarkings'; import { resolveLink } from '../../../utils/Entity'; -import { defaultValue } from '../../../utils/Graph'; +import { defaultValue } from '../../../utils/defaultRepresentatives'; import ItemEntityType from '../../../components/ItemEntityType'; const useStyles = makeStyles((theme) => ({ diff --git a/opencti-platform/opencti-front/src/private/components/workspaces/investigations/InvestigationAddStixCoreObjectsLine.tsx b/opencti-platform/opencti-front/src/private/components/workspaces/investigations/InvestigationAddStixCoreObjectsLine.tsx index f73a5ff1eb7c..13496a76dd5a 100644 --- a/opencti-platform/opencti-front/src/private/components/workspaces/investigations/InvestigationAddStixCoreObjectsLine.tsx +++ b/opencti-platform/opencti-front/src/private/components/workspaces/investigations/InvestigationAddStixCoreObjectsLine.tsx @@ -12,7 +12,7 @@ import StixCoreObjectLabels from '../../common/stix_core_objects/StixCoreObjectL import { useFormatter } from '../../../../components/i18n'; import ItemIcon from '../../../../components/ItemIcon'; import ItemMarkings from '../../../../components/ItemMarkings'; -import { defaultValue } from '../../../../utils/Graph'; +import { defaultValue } from '../../../../utils/defaultRepresentatives'; import { hexToRGB, itemColor } from '../../../../utils/Colors'; import type { Theme } from '../../../../components/Theme'; import { DataColumns } from '../../../../components/list_lines'; diff --git a/opencti-platform/opencti-front/src/private/components/workspaces/investigations/InvestigationGraph.jsx b/opencti-platform/opencti-front/src/private/components/workspaces/investigations/InvestigationGraph.jsx index 1c3a3ba21977..21a34241ef3d 100644 --- a/opencti-platform/opencti-front/src/private/components/workspaces/investigations/InvestigationGraph.jsx +++ b/opencti-platform/opencti-front/src/private/components/workspaces/investigations/InvestigationGraph.jsx @@ -21,14 +21,13 @@ import { computeTimeRangeInterval, computeTimeRangeValues, decodeGraphData, - defaultSecondaryValue, - defaultValue, encodeGraphData, linkPaint, nodeAreaPaint, nodePaint, nodeThreePaint, } from '../../../../utils/Graph'; +import { defaultSecondaryValue, defaultValue } from '../../../../utils/defaultRepresentatives'; import EntitiesDetailsRightsBar from '../../../../utils/graph/EntitiesDetailsRightBar'; import LassoSelection from '../../../../utils/graph/LassoSelection'; import { buildViewParamsFromUrlAndStorage, saveViewParameters } from '../../../../utils/ListParameters'; diff --git a/opencti-platform/opencti-front/src/public/components/dashboard/stix_core_objects/PublicStixCoreObjectsHorizontalBars.tsx b/opencti-platform/opencti-front/src/public/components/dashboard/stix_core_objects/PublicStixCoreObjectsHorizontalBars.tsx index 12f1f7a3773d..8a44145839a5 100644 --- a/opencti-platform/opencti-front/src/public/components/dashboard/stix_core_objects/PublicStixCoreObjectsHorizontalBars.tsx +++ b/opencti-platform/opencti-front/src/public/components/dashboard/stix_core_objects/PublicStixCoreObjectsHorizontalBars.tsx @@ -5,7 +5,7 @@ import type { PublicManifestWidget } from '../PublicManifest'; import { useFormatter } from '../../../../components/i18n'; import WidgetNoData from '../../../../components/dashboard/WidgetNoData'; import { itemColor } from '../../../../utils/Colors'; -import { defaultValue } from '../../../../utils/Graph'; +import { defaultValue } from '../../../../utils/defaultRepresentatives'; import WidgetHorizontalBars from '../../../../components/dashboard/WidgetHorizontalBars'; import type { Theme } from '../../../../components/Theme'; import type { PublicWidgetContainerProps } from '../PublicWidgetContainerProps'; diff --git a/opencti-platform/opencti-front/src/public/components/dashboard/stix_relationships/PublicStixRelationshipsDistributionList.tsx b/opencti-platform/opencti-front/src/public/components/dashboard/stix_relationships/PublicStixRelationshipsDistributionList.tsx index c143f427adb4..d8620947500a 100644 --- a/opencti-platform/opencti-front/src/public/components/dashboard/stix_relationships/PublicStixRelationshipsDistributionList.tsx +++ b/opencti-platform/opencti-front/src/public/components/dashboard/stix_relationships/PublicStixRelationshipsDistributionList.tsx @@ -9,7 +9,7 @@ import WidgetContainer from '../../../../components/dashboard/WidgetContainer'; import WidgetLoader from '../../../../components/dashboard/WidgetLoader'; import { PublicStixRelationshipsDistributionListQuery } from './__generated__/PublicStixRelationshipsDistributionListQuery.graphql'; import type { PublicManifestWidget } from '../PublicManifest'; -import { defaultValue } from '../../../../utils/Graph'; +import { defaultValue } from '../../../../utils/defaultRepresentatives'; const publicStixRelationshipsDistributionListQuery = graphql` query PublicStixRelationshipsDistributionListQuery( diff --git a/opencti-platform/opencti-front/src/public/components/dashboard/stix_relationships/PublicStixRelationshipsHorizontalBars.tsx b/opencti-platform/opencti-front/src/public/components/dashboard/stix_relationships/PublicStixRelationshipsHorizontalBars.tsx index 484db2131feb..318a240e1661 100644 --- a/opencti-platform/opencti-front/src/public/components/dashboard/stix_relationships/PublicStixRelationshipsHorizontalBars.tsx +++ b/opencti-platform/opencti-front/src/public/components/dashboard/stix_relationships/PublicStixRelationshipsHorizontalBars.tsx @@ -5,7 +5,7 @@ import type { PublicManifestWidget } from '../PublicManifest'; import type { Theme } from '../../../../components/Theme'; import { useFormatter } from '../../../../components/i18n'; import { itemColor } from '../../../../utils/Colors'; -import { defaultValue } from '../../../../utils/Graph'; +import { defaultValue } from '../../../../utils/defaultRepresentatives'; import WidgetHorizontalBars from '../../../../components/dashboard/WidgetHorizontalBars'; import WidgetNoData from '../../../../components/dashboard/WidgetNoData'; import type { PublicWidgetContainerProps } from '../PublicWidgetContainerProps'; diff --git a/opencti-platform/opencti-front/src/public/components/dashboard/stix_relationships/PublicStixRelationshipsMultiHorizontalBars.tsx b/opencti-platform/opencti-front/src/public/components/dashboard/stix_relationships/PublicStixRelationshipsMultiHorizontalBars.tsx index abf89fd1c833..888b99911397 100644 --- a/opencti-platform/opencti-front/src/public/components/dashboard/stix_relationships/PublicStixRelationshipsMultiHorizontalBars.tsx +++ b/opencti-platform/opencti-front/src/public/components/dashboard/stix_relationships/PublicStixRelationshipsMultiHorizontalBars.tsx @@ -3,7 +3,7 @@ import React from 'react'; import * as R from 'ramda'; import type { PublicManifestWidget } from '../PublicManifest'; import { useFormatter } from '../../../../components/i18n'; -import { defaultValue } from '../../../../utils/Graph'; +import { defaultValue } from '../../../../utils/defaultRepresentatives'; import WidgetHorizontalBars from '../../../../components/dashboard/WidgetHorizontalBars'; import WidgetNoData from '../../../../components/dashboard/WidgetNoData'; import type { PublicWidgetContainerProps } from '../PublicWidgetContainerProps'; @@ -360,7 +360,7 @@ const PublicStixRelationshipsMultiHorizontalBarsComponent = ({ const subSelection = dataSelection[1]; const finalSubDistributionField = subSelection.attribute || 'entity_type'; - const categories = publicStixRelationshipsDistribution.map((n) => defaultValue(n?.entity, t_i18n('Restricted'))); + const categories = publicStixRelationshipsDistribution.map((n) => defaultValue(n?.entity)); const entitiesMapping: Record = {}; for (const distrib of publicStixRelationshipsDistribution) { for (const subDistrib of distrib?.breakdownDistribution ?? []) { diff --git a/opencti-platform/opencti-front/src/public/components/dashboard/stix_relationships/PublicStixRelationshipsPolarArea.tsx b/opencti-platform/opencti-front/src/public/components/dashboard/stix_relationships/PublicStixRelationshipsPolarArea.tsx index b2d63a111fed..57ba64aafb65 100644 --- a/opencti-platform/opencti-front/src/public/components/dashboard/stix_relationships/PublicStixRelationshipsPolarArea.tsx +++ b/opencti-platform/opencti-front/src/public/components/dashboard/stix_relationships/PublicStixRelationshipsPolarArea.tsx @@ -9,7 +9,7 @@ import WidgetContainer from '../../../../components/dashboard/WidgetContainer'; import WidgetLoader from '../../../../components/dashboard/WidgetLoader'; import { PublicStixRelationshipsPolarAreaQuery } from './__generated__/PublicStixRelationshipsPolarAreaQuery.graphql'; import WidgetPolarArea from '../../../../components/dashboard/WidgetPolarArea'; -import { defaultValue } from '../../../../utils/Graph'; +import { defaultValue } from '../../../../utils/defaultRepresentatives'; const publicStixRelationshipsPolarAreaQuery = graphql` query PublicStixRelationshipsPolarAreaQuery( diff --git a/opencti-platform/opencti-front/src/utils/Graph.js b/opencti-platform/opencti-front/src/utils/Graph.js index 873b3d5b5c63..a59a08489e0c 100644 --- a/opencti-platform/opencti-front/src/utils/Graph.js +++ b/opencti-platform/opencti-front/src/utils/Graph.js @@ -306,135 +306,6 @@ export const decodeMappingData = (encodedMappingData) => { return {}; }; -export const defaultDate = (n) => { - if (!n) return ''; - if (!isDateStringNone(n.start_time)) { - return n.start_time; - } - if (!isDateStringNone(n.first_seen)) { - return n.first_seen; - } - if (!isDateStringNone(n.first_observed)) { - return n.first_observed; - } - if (!isDateStringNone(n.valid_from)) { - return n.valid_from; - } - if (!isDateStringNone(n.published)) { - return n.published; - } - if (!isDateStringNone(n.created)) { - return n.created; - } - if (!isDateStringNone(n.created_at)) { - return n.created_at; - } - return null; -}; - -export const defaultType = (n, t) => { - if (n.parent_types.includes('basic-relationship')) { - return t(`relationship_${n.entity_type}`); - } - return t(`entity_${n.entity_type}`); -}; - -export const defaultValueMarking = (n) => { - let def = 'Unknown'; - if (n.definition) { - const definition = R.toPairs(n.definition); - if (definition[0]) { - if (definition[0][1].includes(':')) { - // eslint-disable-next-line prefer-destructuring - def = definition[0][1]; - } else { - def = `${definition[0][0]}:${definition[0][1]}`; - } - } - } - return def; -}; - -export const defaultKey = (n) => { - if (!n) return null; - if (n.hashes) { - return 'hashes'; - } - if (n.name) { - return 'name'; - } - if (n.value) { - return 'value'; - } - if (n.observable_value) { - return 'observable_value'; - } - if (n.attribute_abstract) { - return 'attribute_abstract'; - } - if (n.opinion) { - return null; - } - if (n.abstract) { - return 'abstract'; - } - return null; -}; - -export const defaultValue = (n, fallback = 'Unknown') => { - if (!n) return fallback; - if (typeof n.definition === 'object') { - return defaultValueMarking(n); - } - const mainValue = n.name - || n.label - || n.observableName - || n.observable_value - || n.pattern - || n.attribute_abstract - || n.opinion - || n.value - || n.definition - || n.source_name - || n.phase_name - || n.result_name - || n.country - || n.key - || (n.template && n.template.name) - || (n.content && truncate(n.content, 30)) - || (n.hashes - && (n.hashes.MD5 - || n.hashes['SHA-1'] - || n.hashes['SHA-256'] - || n.hashes['SHA-512'])) - || (n.source_ref_name - && n.target_ref_name - && `${truncate(n.source_ref_name, 20)} ➡️ ${truncate( - n.target_ref_name, - 20, - )}`) - || defaultValue(R.head(R.pathOr([], ['objects', 'edges'], n))?.node) - || (n.from - && n.to - && `${truncate(defaultValue(n.from), 20)} ➡️ ${truncate( - defaultValue(n.to), - 20, - )}`) - || fallback; - return n.x_mitre_id ? `[${n.x_mitre_id}] ${mainValue}` : mainValue; -}; - -export const defaultSecondaryValue = (n) => { - if (!n) return ''; - return ( - n.description - || n.x_opencti_description - || n.content - || n.entity_type - || dateFormat(n.created_at) - ); -}; - export const computeTimeRangeInterval = (objects) => { const filteredDates = objects .filter( diff --git a/opencti-platform/opencti-front/src/utils/defaultRepresentatives.ts b/opencti-platform/opencti-front/src/utils/defaultRepresentatives.ts new file mode 100644 index 000000000000..d95313460e8b --- /dev/null +++ b/opencti-platform/opencti-front/src/utils/defaultRepresentatives.ts @@ -0,0 +1,142 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ +import * as R from 'ramda'; +import { isDateStringNone } from '../components/i18n'; +import { truncate } from './String'; +import { dateFormat } from './Time'; + +export const isFieldForIdentifier = (fieldName: string) => { + return fieldName === 'id' + || fieldName.endsWith('.id') + || fieldName.endsWith('_id') + || fieldName.endsWith('_ids'); +}; + +export const defaultDate = (n: any) => { + if (!n) return ''; + if (!isDateStringNone(n.start_time)) { + return n.start_time; + } + if (!isDateStringNone(n.first_seen)) { + return n.first_seen; + } + if (!isDateStringNone(n.first_observed)) { + return n.first_observed; + } + if (!isDateStringNone(n.valid_from)) { + return n.valid_from; + } + if (!isDateStringNone(n.published)) { + return n.published; + } + if (!isDateStringNone(n.created)) { + return n.created; + } + if (!isDateStringNone(n.created_at)) { + return n.created_at; + } + return null; +}; + +export const defaultType = (n: any, t: (key: string) => string) => { + if (n.parent_types.includes('basic-relationship')) { + return t(`relationship_${n.entity_type}`); + } + return t(`entity_${n.entity_type}`); +}; + +export const defaultValueMarking = (n: any) => { + let def = 'Unknown'; + if (n.definition) { + const definition = R.toPairs(n.definition); + if (definition[0]) { + if (definition[0][1].includes(':')) { + // eslint-disable-next-line prefer-destructuring + def = definition[0][1]; + } else { + def = `${definition[0][0]}:${definition[0][1]}`; + } + } + } + return def; +}; + +export const defaultKey = (n: any) => { + if (!n) return null; + if (n.hashes) { + return 'hashes'; + } + if (n.name) { + return 'name'; + } + if (n.value) { + return 'value'; + } + if (n.observable_value) { + return 'observable_value'; + } + if (n.attribute_abstract) { + return 'attribute_abstract'; + } + if (n.opinion) { + return null; + } + if (n.abstract) { + return 'abstract'; + } + return null; +}; + +export const defaultValue = (n: any, fallback = 'Unknown') => { + if (!n) return ''; + if (typeof n.definition === 'object') { + return defaultValueMarking(n); + } + const mainValue: string = n.representative?.main + || n.name + || n.label + || n.observableName + || n.observable_value + || n.pattern + || n.attribute_abstract + || n.opinion + || n.value + || n.definition + || n.source_name + || n.phase_name + || n.result_name + || n.country + || n.key + || (n.template && n.template.name) + || (n.content && truncate(n.content, 30)) + || (n.hashes + && (n.hashes.MD5 + || n.hashes['SHA-1'] + || n.hashes['SHA-256'] + || n.hashes['SHA-512'])) + || (n.source_ref_name + && n.target_ref_name + && `${truncate(n.source_ref_name, 20)} ➡️ ${truncate( + n.target_ref_name, + 20, + )}`) + || defaultValue((R.head(R.pathOr([], ['objects', 'edges'], n)) as any)?.node) + || (n.from + && n.to + && `${truncate(defaultValue(n.from), 20)} ➡️ ${truncate( + defaultValue(n.to), + 20, + )}`) + || fallback; + return n.x_mitre_id ? `[${n.x_mitre_id}] ${mainValue}` : mainValue; +}; + +export const defaultSecondaryValue = (n: any) => { + if (!n) return ''; + return ( + n.description + || n.x_opencti_description + || n.content + || n.entity_type + || dateFormat(n.created_at) + ); +}; diff --git a/opencti-platform/opencti-front/src/utils/filters/useSearchEntities.tsx b/opencti-platform/opencti-front/src/utils/filters/useSearchEntities.tsx index aa037089ebd2..a92aca7a451b 100644 --- a/opencti-platform/opencti-front/src/utils/filters/useSearchEntities.tsx +++ b/opencti-platform/opencti-front/src/utils/filters/useSearchEntities.tsx @@ -30,7 +30,7 @@ import { NotifierFieldSearchQuery$data } from '@components/common/form/__generat import useAuth, { FilterDefinition } from '../hooks/useAuth'; import { useSearchEntitiesStixCoreObjectsSearchQuery$data } from './__generated__/useSearchEntitiesStixCoreObjectsSearchQuery.graphql'; import { useFormatter } from '../../components/i18n'; -import { defaultValue } from '../Graph'; +import { defaultValue } from '../defaultRepresentatives'; import { fetchQuery } from '../../relay/environment'; import { useSearchEntitiesSchemaSCOSearchQuery$data } from './__generated__/useSearchEntitiesSchemaSCOSearchQuery.graphql'; import type { Theme } from '../../components/Theme'; diff --git a/opencti-platform/opencti-front/src/utils/graph/EntityDetails.tsx b/opencti-platform/opencti-front/src/utils/graph/EntityDetails.tsx index 4d3a7239dffb..44f6545f2be9 100644 --- a/opencti-platform/opencti-front/src/utils/graph/EntityDetails.tsx +++ b/opencti-platform/opencti-front/src/utils/graph/EntityDetails.tsx @@ -21,7 +21,7 @@ import type { SelectedEntity } from './EntitiesDetailsRightBar'; import ErrorNotFound from '../../components/ErrorNotFound'; import ItemIcon from '../../components/ItemIcon'; import type { Theme } from '../../components/Theme'; -import { defaultValue } from '../Graph'; +import { defaultValue } from '../defaultRepresentatives'; import { hexToRGB, itemColor } from '../Colors'; import { truncate } from '../String'; import ItemCreators from '../../components/ItemCreators'; diff --git a/opencti-platform/opencti-front/src/utils/graph/RelationShipFromAndTo.tsx b/opencti-platform/opencti-front/src/utils/graph/RelationShipFromAndTo.tsx index 43cbda258827..6cfd60da0959 100644 --- a/opencti-platform/opencti-front/src/utils/graph/RelationShipFromAndTo.tsx +++ b/opencti-platform/opencti-front/src/utils/graph/RelationShipFromAndTo.tsx @@ -7,7 +7,7 @@ import { useFormatter } from '../../components/i18n'; import useQueryLoading from '../hooks/useQueryLoading'; import { RelationShipFromAndToQuery } from './__generated__/RelationShipFromAndToQuery.graphql'; import { truncate } from '../String'; -import { defaultValue } from '../Graph'; +import { defaultValue } from '../defaultRepresentatives'; const useStyles = makeStyles(() => ({ label: { diff --git a/opencti-platform/opencti-front/src/utils/graph/StixMetaObjectDetails.tsx b/opencti-platform/opencti-front/src/utils/graph/StixMetaObjectDetails.tsx index ea2c22396fd9..65472ae50eef 100644 --- a/opencti-platform/opencti-front/src/utils/graph/StixMetaObjectDetails.tsx +++ b/opencti-platform/opencti-front/src/utils/graph/StixMetaObjectDetails.tsx @@ -9,7 +9,7 @@ import useQueryLoading from '../hooks/useQueryLoading'; import Loader, { LoaderVariant } from '../../components/Loader'; import type { SelectedEntity } from './EntitiesDetailsRightBar'; import ErrorNotFound from '../../components/ErrorNotFound'; -import { defaultValue } from '../Graph'; +import { defaultValue } from '../defaultRepresentatives'; import { hexToRGB, itemColor } from '../Colors'; import { truncate } from '../String'; import ItemCreators from '../../components/ItemCreators'; From 3950248a18e408069eeccd95cb79fb3f187cf185 Mon Sep 17 00:00:00 2001 From: Laurent Bonnet Date: Thu, 28 Mar 2024 14:26:18 +0100 Subject: [PATCH 08/14] [frontend] refactor distribution widgets --- .../dashboard/WidgetDistributionList.tsx | 5 +- .../src/components/dashboard/WidgetDonut.tsx | 13 +- .../dashboard/WidgetListCoreObjects.tsx | 4 +- .../dashboard/WidgetListRelationships.tsx | 6 +- .../src/components/dashboard/WidgetRadar.tsx | 11 +- .../components/dashboard/WidgetTimeline.tsx | 10 +- .../src/components/dashboard/WidgetTree.tsx | 21 +- .../src/private/components/SearchBulk.jsx | 4 +- .../groupings/GroupingKnowledgeGraph.jsx | 6 +- .../analyses/groupings/GroupingsAreaChart.jsx | 167 ----- .../analyses/groupings/GroupingsDonut.jsx | 143 ---- .../groupings/GroupingsHorizontalBars.jsx | 166 ----- .../groupings/GroupingsVerticalBars.jsx | 167 ----- .../StixCoreObjectGroupingsAreaChart.jsx | 201 ------ .../StixCoreObjectGroupingsDonut.jsx | 162 ----- .../StixCoreObjectGroupingsHorizontalBars.jsx | 162 ----- .../StixCoreObjectGroupingsVerticalBars.jsx | 200 ------ .../analyses/malware_analyses/Root.tsx | 4 +- .../analyses/reports/ReportKnowledgeGraph.jsx | 6 +- .../reports/ReportKnowledgeTimeLine.jsx | 6 +- .../analyses/reports/ReportsAreaChart.jsx | 167 ----- .../analyses/reports/ReportsDonut.jsx | 160 ----- .../reports/ReportsHorizontalBars.jsx | 166 ----- .../analyses/reports/ReportsVerticalBars.jsx | 167 ----- .../case_incidents/IncidentKnowledgeGraph.jsx | 6 +- .../IncidentKnowledgeTimeLine.jsx | 6 +- .../cases/case_rfis/CaseRfiKnowledgeGraph.jsx | 6 +- .../case_rfis/CaseRfiKnowledgeTimeLine.jsx | 6 +- .../cases/case_rfts/CaseRftKnowledgeGraph.jsx | 6 +- .../case_rfts/CaseRftKnowledgeTimeLine.jsx | 6 +- .../common/audits/AuditsDistributionList.jsx | 186 +----- .../components/common/audits/AuditsDonut.jsx | 120 +--- .../common/audits/AuditsHorizontalBars.jsx | 181 +----- .../components/common/audits/AuditsRadar.jsx | 121 +--- .../common/audits/AuditsTreeMap.jsx | 127 +--- .../ContainerAddStixCoreObjectsLine.jsx | 4 +- .../common/containers/ContainerHeader.jsx | 8 +- .../ContainerStixCoreObjectsMappingLine.jsx | 4 +- .../ContainerStixDomainObjectLine.jsx | 4 +- ...tainerStixObjectOrStixRelationshipLine.jsx | 4 +- ...ectOrStixCoreRelationshipContainerLine.tsx | 4 +- ...tOrStixCoreRelationshipContainersGraph.jsx | 6 +- .../files/workbench/WorkbenchFileContent.jsx | 34 +- .../common/form/DynamicResolutionField.jsx | 4 +- .../common/form/StixCoreObjectsField.jsx | 4 +- .../common/form/StixDomainObjectsField.jsx | 4 +- .../StixCoreObjectsDistributionList.jsx | 52 +- .../StixCoreObjectsDonut.jsx | 132 +--- .../StixCoreObjectsHorizontalBars.jsx | 238 ++----- .../StixCoreObjectsMultiHorizontalBars.jsx | 6 +- .../StixCoreObjectsRadar.jsx | 134 +--- .../StixCoreObjectsTimeline.jsx | 160 +---- .../StixCoreObjectsTreeMap.jsx | 127 +--- ...xCoreObjectOrCoreRelationshipLabelsView.js | 2 +- .../EntityStixCoreRelationshipLineAll.jsx | 4 +- .../EntityStixCoreRelationshipLineFrom.jsx | 4 +- .../EntityStixCoreRelationshipLineTo.jsx | 4 +- ...ityStixCoreRelationshipsHorizontalBars.jsx | 4 +- ...ixRelationshipStixCoreRelationshipLine.jsx | 4 +- .../StixCoreRelationshipCreationForm.js | 6 +- ...pCreationFromEntityStixCoreObjectsLine.jsx | 4 +- .../StixCoreRelationshipOverview.jsx | 10 +- ...ityStixCoreRelationshipsContextualView.tsx | 4 +- ...yStixCoreRelationshipsEntitiesViewLine.tsx | 4 +- ...eRelationshipsIndicatorsContextualView.tsx | 4 +- .../StixDomainObjectHeader.jsx | 10 +- .../StixDomainObjectNestedEntitiesLines.jsx | 4 +- .../StixDomainObjectTimeline.jsx | 10 +- .../StixDomainObjectsTimeline.jsx | 4 +- ...estedRefRelationshipCreationFromEntity.jsx | 6 +- ...dRefRelationshipCreationFromEntityLine.tsx | 4 +- .../StixRelationshipsDistributionList.jsx | 164 +---- .../StixRelationshipsDonut.jsx | 144 +--- .../StixRelationshipsHorizontalBars.jsx | 190 +----- .../StixRelationshipsMultiHorizontalBars.jsx | 613 ++++-------------- .../StixRelationshipsPolarArea.jsx | 160 +---- .../StixRelationshipsRadar.jsx | 144 +--- .../StixRelationshipsTimeline.jsx | 220 +++---- .../StixRelationshipsTreeMap.jsx | 137 +--- .../src/private/components/data/ToolBar.jsx | 12 +- .../entities/EntitiesStixDomainObjectLine.jsx | 4 +- .../RelationshipsStixCoreRelationshipLine.jsx | 6 +- .../EntityStixSightingRelationshipsDonut.jsx | 4 +- .../StixSightingRelationshipCreation.jsx | 6 +- .../StixCyberObservableEntitiesLines.jsx | 6 +- ...StixCyberObservableNestedEntitiesLines.jsx | 4 +- .../notifications/NotificationsToolBar.tsx | 6 +- .../search/SearchStixCoreObjectLine.jsx | 4 +- .../InvestigationAddStixCoreObjectsLine.tsx | 4 +- .../investigations/InvestigationGraph.jsx | 6 +- .../PublicStixCoreObjectsDistributionList.tsx | 57 +- .../PublicStixCoreObjectsDonut.tsx | 132 +--- .../PublicStixCoreObjectsHorizontalBars.tsx | 202 +----- .../PublicStixCoreObjectsRadar.tsx | 134 +--- .../PublicStixCoreObjectsTimeline.tsx | 160 +---- .../PublicStixCoreObjectsTreeMap.tsx | 127 +--- ...ublicStixRelationshipsDistributionList.tsx | 139 +--- .../PublicStixRelationshipsDonut.tsx | 146 +---- .../PublicStixRelationshipsHorizontalBars.tsx | 196 +----- ...icStixRelationshipsMultiHorizontalBars.tsx | 345 ++-------- .../PublicStixRelationshipsPolarArea.tsx | 151 +---- .../PublicStixRelationshipsRadar.tsx | 147 +---- .../PublicStixRelationshipsTimeline.tsx | 218 +++---- .../PublicStixRelationshipsTreeMap.tsx | 137 +--- .../opencti-front/src/utils/Graph.js | 9 +- .../src/utils/defaultRepresentatives.ts | 20 +- .../src/utils/filters/useSearchEntities.tsx | 4 +- .../src/utils/graph/EntityDetails.tsx | 6 +- .../src/utils/graph/RelationShipFromAndTo.tsx | 11 +- .../src/utils/graph/StixMetaObjectDetails.tsx | 8 +- .../utils/hooks/useDistributionGraphData.ts | 133 ++++ .../opencti-graphql/src/database/engine.js | 2 +- .../src/database/middleware.js | 10 +- 113 files changed, 1273 insertions(+), 6971 deletions(-) delete mode 100644 opencti-platform/opencti-front/src/private/components/analyses/groupings/GroupingsAreaChart.jsx delete mode 100644 opencti-platform/opencti-front/src/private/components/analyses/groupings/GroupingsDonut.jsx delete mode 100644 opencti-platform/opencti-front/src/private/components/analyses/groupings/GroupingsHorizontalBars.jsx delete mode 100644 opencti-platform/opencti-front/src/private/components/analyses/groupings/GroupingsVerticalBars.jsx delete mode 100644 opencti-platform/opencti-front/src/private/components/analyses/groupings/StixCoreObjectGroupingsAreaChart.jsx delete mode 100644 opencti-platform/opencti-front/src/private/components/analyses/groupings/StixCoreObjectGroupingsDonut.jsx delete mode 100644 opencti-platform/opencti-front/src/private/components/analyses/groupings/StixCoreObjectGroupingsHorizontalBars.jsx delete mode 100644 opencti-platform/opencti-front/src/private/components/analyses/groupings/StixCoreObjectGroupingsVerticalBars.jsx delete mode 100644 opencti-platform/opencti-front/src/private/components/analyses/reports/ReportsAreaChart.jsx delete mode 100644 opencti-platform/opencti-front/src/private/components/analyses/reports/ReportsDonut.jsx delete mode 100644 opencti-platform/opencti-front/src/private/components/analyses/reports/ReportsHorizontalBars.jsx delete mode 100644 opencti-platform/opencti-front/src/private/components/analyses/reports/ReportsVerticalBars.jsx create mode 100644 opencti-platform/opencti-front/src/utils/hooks/useDistributionGraphData.ts diff --git a/opencti-platform/opencti-front/src/components/dashboard/WidgetDistributionList.tsx b/opencti-platform/opencti-front/src/components/dashboard/WidgetDistributionList.tsx index 6b281b7ef0dc..0e5917dee8e5 100644 --- a/opencti-platform/opencti-front/src/components/dashboard/WidgetDistributionList.tsx +++ b/opencti-platform/opencti-front/src/components/dashboard/WidgetDistributionList.tsx @@ -9,6 +9,7 @@ import ItemIcon from '../ItemIcon'; import { computeLink } from '../../utils/Entity'; import type { Theme } from '../Theme'; import { useFormatter } from '../i18n'; +import { getMainRepresentative } from '../../utils/defaultRepresentatives'; interface WidgetDistributionListProps { // eslint-disable-next-line @typescript-eslint/no-explicit-any @@ -38,6 +39,8 @@ const WidgetDistributionList = ({ > {data.map((entry, key) => { + const label = getMainRepresentative(entry.entity) || entry.label; + let link: string | null = null; if (entry.type !== 'User' || hasSettingAccess) { const node: { @@ -94,7 +97,7 @@ const WidgetDistributionList = ({ paddingRight: 10, }} > - {entry.label} + {label}
} /> diff --git a/opencti-platform/opencti-front/src/components/dashboard/WidgetDonut.tsx b/opencti-platform/opencti-front/src/components/dashboard/WidgetDonut.tsx index c55c5e598a21..f8267b446288 100644 --- a/opencti-platform/opencti-front/src/components/dashboard/WidgetDonut.tsx +++ b/opencti-platform/opencti-front/src/components/dashboard/WidgetDonut.tsx @@ -2,10 +2,9 @@ import Chart from '@components/common/charts/Chart'; import React from 'react'; import { useTheme } from '@mui/styles'; import type { ApexOptions } from 'apexcharts'; -import { defaultValue, isFieldForIdentifier } from '../../utils/defaultRepresentatives'; import { donutChartOptions } from '../../utils/Charts'; -import { useFormatter } from '../i18n'; import type { Theme } from '../Theme'; +import useDistributionGraphData from '../../utils/hooks/useDistributionGraphData'; interface WidgetDonutProps { // eslint-disable-next-line @typescript-eslint/no-explicit-any @@ -22,16 +21,10 @@ const WidgetDonut = ({ readonly = false, }: WidgetDonutProps) => { const theme = useTheme(); - const { t_i18n } = useFormatter(); + const { buildWidgetLabelsOption } = useDistributionGraphData(); const chartData = data.map((n) => n.value); - // eslint-disable-next-line no-nested-ternary - const labels = data.map((n) => (groupBy.endsWith('_id') - ? defaultValue(n.entity, t_i18n('Restricted')) - : groupBy === 'entity_type' && t_i18n(`entity_${n.label}`) !== `entity_${n.label}` - ? t_i18n(`entity_${n.label}`) - : n.label)); - + const labels = buildWidgetLabelsOption(data, groupBy); let chartColors = []; if (data.at(0)?.entity?.color) { chartColors = data.map((n) => (theme.palette.mode === 'light' && n.entity?.color === '#ffffff' diff --git a/opencti-platform/opencti-front/src/components/dashboard/WidgetListCoreObjects.tsx b/opencti-platform/opencti-front/src/components/dashboard/WidgetListCoreObjects.tsx index 3c194f4170d1..45c7bcfeaa51 100644 --- a/opencti-platform/opencti-front/src/components/dashboard/WidgetListCoreObjects.tsx +++ b/opencti-platform/opencti-front/src/components/dashboard/WidgetListCoreObjects.tsx @@ -8,7 +8,7 @@ import StixCoreObjectLabels from '@components/common/stix_core_objects/StixCoreO import React, { CSSProperties } from 'react'; import { resolveLink } from '../../utils/Entity'; import ItemIcon from '../ItemIcon'; -import { defaultValue } from '../../utils/defaultRepresentatives'; +import { getMainRepresentative } from '../../utils/defaultRepresentatives'; import ItemStatus from '../ItemStatus'; import ItemMarkings from '../ItemMarkings'; import { useFormatter } from '../i18n'; @@ -72,7 +72,7 @@ const WidgetListCoreObjects = ({ primary={ <>
- {defaultValue(stixCoreObject)} + {getMainRepresentative(stixCoreObject)}
{fsd(date)} diff --git a/opencti-platform/opencti-front/src/components/dashboard/WidgetListRelationships.tsx b/opencti-platform/opencti-front/src/components/dashboard/WidgetListRelationships.tsx index d46372f7aebb..b302a4157db7 100644 --- a/opencti-platform/opencti-front/src/components/dashboard/WidgetListRelationships.tsx +++ b/opencti-platform/opencti-front/src/components/dashboard/WidgetListRelationships.tsx @@ -7,7 +7,7 @@ import React, { CSSProperties } from 'react'; import { useTheme } from '@mui/styles'; import { ListItemButton } from '@mui/material'; import ItemIcon from '../ItemIcon'; -import { defaultValue } from '../../utils/defaultRepresentatives'; +import { getMainRepresentative } from '../../utils/defaultRepresentatives'; import ItemMarkings from '../ItemMarkings'; import { computeLink } from '../../utils/Entity'; import type { Theme } from '../Theme'; @@ -116,7 +116,7 @@ const WidgetListRelationships = ({
{stixRelationship.from - ? defaultValue(stixRelationship.from) + ? getMainRepresentative(stixRelationship.from) : t_i18n('Restricted')}
@@ -149,7 +149,7 @@ const WidgetListRelationships = ({
{stixRelationship.to - ? defaultValue(stixRelationship.to) + ? getMainRepresentative(stixRelationship.to) : t_i18n('Restricted')}
diff --git a/opencti-platform/opencti-front/src/components/dashboard/WidgetRadar.tsx b/opencti-platform/opencti-front/src/components/dashboard/WidgetRadar.tsx index 204796983400..d494fd8757f2 100644 --- a/opencti-platform/opencti-front/src/components/dashboard/WidgetRadar.tsx +++ b/opencti-platform/opencti-front/src/components/dashboard/WidgetRadar.tsx @@ -3,9 +3,9 @@ import React from 'react'; import { useTheme } from '@mui/styles'; import { ApexOptions } from 'apexcharts'; import { radarChartOptions } from '../../utils/Charts'; -import { defaultValue } from '../../utils/defaultRepresentatives'; import { useFormatter } from '../i18n'; import type { Theme } from '../Theme'; +import useDistributionGraphData from '../../utils/hooks/useDistributionGraphData'; interface WidgetRadarProps { // eslint-disable-next-line @typescript-eslint/no-explicit-any @@ -25,19 +25,14 @@ const WidgetRadar = ({ }: WidgetRadarProps) => { const theme = useTheme(); const { t_i18n } = useFormatter(); + const { buildWidgetLabelsOption } = useDistributionGraphData(); const chartData = [{ name: label || t_i18n('Number of relationships'), data: data.map((n) => n.value), }]; - // eslint-disable-next-line no-nested-ternary,implicit-arrow-linebreak - const labels = data.map((n) => (groupBy.endsWith('_id') - ? defaultValue(n.entity, t_i18n('Restricted')) - : groupBy === 'entity_type' && t_i18n(`entity_${n.label}`) !== `entity_${n.label}` - ? t_i18n(`entity_${n.label}`) - : n.label)); - + const labels = buildWidgetLabelsOption(data, groupBy); return ( { }} > - {data.map(({ value, link }) => { + {data.map(({ value, link }, index) => { return ( - + { - {defaultValue(value)} + {getMainRepresentative(value)}
diff --git a/opencti-platform/opencti-front/src/components/dashboard/WidgetTree.tsx b/opencti-platform/opencti-front/src/components/dashboard/WidgetTree.tsx index 1e5ae67ce67d..24746df78b48 100644 --- a/opencti-platform/opencti-front/src/components/dashboard/WidgetTree.tsx +++ b/opencti-platform/opencti-front/src/components/dashboard/WidgetTree.tsx @@ -4,7 +4,7 @@ import { useTheme } from '@mui/styles'; import { ApexOptions } from 'apexcharts'; import { useFormatter } from '../i18n'; import { treeMapOptions } from '../../utils/Charts'; -import { defaultValue } from '../../utils/defaultRepresentatives'; +import { getMainRepresentative, isFieldForIdentifier } from '../../utils/defaultRepresentatives'; interface WidgetTreeProps { // eslint-disable-next-line @typescript-eslint/no-explicit-any @@ -25,15 +25,16 @@ const WidgetTree = ({ const theme = useTheme(); const { t_i18n } = useFormatter(); - const chartData = data.map((n) => ({ - // eslint-disable-next-line no-nested-ternary - x: groupBy.endsWith('_id') - ? defaultValue(n.entity, t_i18n('Restricted')) - : groupBy === 'entity_type' && t_i18n(`entity_${n.label}`) !== `entity_${n.label}` - ? t_i18n(`entity_${n.label}`) - : n.label, - y: n.value, - })); + const chartData = data.map((n) => { + const item = { x: n.label, y: n.value }; + if (isFieldForIdentifier(groupBy)) { + item.x = getMainRepresentative(n.entity); + } else if (groupBy === 'entity_type' && t_i18n(`entity_${n.label}`) !== `entity_${n.label}`) { + item.x = t_i18n(`entity_${n.label}`); + } + return item; + }); + const series = [{ data: chartData }]; return ( diff --git a/opencti-platform/opencti-front/src/private/components/SearchBulk.jsx b/opencti-platform/opencti-front/src/private/components/SearchBulk.jsx index 0c8061b7b540..214f2b8f8c40 100644 --- a/opencti-platform/opencti-front/src/private/components/SearchBulk.jsx +++ b/opencti-platform/opencti-front/src/private/components/SearchBulk.jsx @@ -21,7 +21,7 @@ import ItemIcon from '../../components/ItemIcon'; import { searchStixCoreObjectsLinesSearchQuery } from './search/SearchStixCoreObjectsLines'; import { fetchQuery } from '../../relay/environment'; import { useFormatter } from '../../components/i18n'; -import { defaultValue } from '../../utils/defaultRepresentatives'; +import { getMainRepresentative } from '../../utils/defaultRepresentatives'; import { resolveLink } from '../../utils/Entity'; import StixCoreObjectLabels from './common/stix_core_objects/StixCoreObjectLabels'; import StixCoreObjectsExports from './common/stix_core_objects/StixCoreObjectsExports'; @@ -340,7 +340,7 @@ const SearchBulk = () => { (resolvedStixCoreObject) => ({ id: resolvedStixCoreObject.id, type: resolvedStixCoreObject.entity_type, - value: defaultValue(resolvedStixCoreObject), + value: getMainRepresentative(resolvedStixCoreObject), labels: resolvedStixCoreObject.objectLabel, markings: resolvedStixCoreObject.objectMarking, containersNumber: resolvedStixCoreObject.containersNumber, diff --git a/opencti-platform/opencti-front/src/private/components/analyses/groupings/GroupingKnowledgeGraph.jsx b/opencti-platform/opencti-front/src/private/components/analyses/groupings/GroupingKnowledgeGraph.jsx index 910b6d775fb7..c9f066d715b9 100644 --- a/opencti-platform/opencti-front/src/private/components/analyses/groupings/GroupingKnowledgeGraph.jsx +++ b/opencti-platform/opencti-front/src/private/components/analyses/groupings/GroupingKnowledgeGraph.jsx @@ -31,7 +31,7 @@ import { nodePaint, nodeThreePaint, } from '../../../../utils/Graph'; -import { defaultSecondaryValue, defaultValue } from '../../../../utils/defaultRepresentatives'; +import { getSecondaryRepresentative, getMainRepresentative } from '../../../../utils/defaultRepresentatives'; import { buildViewParamsFromUrlAndStorage, saveViewParameters } from '../../../../utils/ListParameters'; import GroupingKnowledgeGraphBar from './GroupingKnowledgeGraphBar'; import { groupingMutationFieldPatch } from './GroupingEditionOverview'; @@ -954,9 +954,9 @@ class GroupingKnowledgeGraphComponent extends Component { this.selectedNodes.clear(); if (isNotEmptyField(keyword)) { const filterByKeyword = (n) => keyword === '' - || (defaultValue(n) || '').toLowerCase().indexOf(keyword.toLowerCase()) + || (getMainRepresentative(n) || '').toLowerCase().indexOf(keyword.toLowerCase()) !== -1 - || (defaultSecondaryValue(n) || '') + || (getSecondaryRepresentative(n) || '') .toLowerCase() .indexOf(keyword.toLowerCase()) !== -1 || (n.entity_type || '').toLowerCase().indexOf(keyword.toLowerCase()) diff --git a/opencti-platform/opencti-front/src/private/components/analyses/groupings/GroupingsAreaChart.jsx b/opencti-platform/opencti-front/src/private/components/analyses/groupings/GroupingsAreaChart.jsx deleted file mode 100644 index c048bc638a59..000000000000 --- a/opencti-platform/opencti-front/src/private/components/analyses/groupings/GroupingsAreaChart.jsx +++ /dev/null @@ -1,167 +0,0 @@ -import React, { Component } from 'react'; -import * as PropTypes from 'prop-types'; -import { compose } from 'ramda'; -import { graphql } from 'react-relay'; -import withStyles from '@mui/styles/withStyles'; -import withTheme from '@mui/styles/withTheme'; -import CircularProgress from '@mui/material/CircularProgress'; -import Paper from '@mui/material/Paper'; -import Typography from '@mui/material/Typography'; -import Chart from '../../common/charts/Chart'; -import { QueryRenderer } from '../../../../relay/environment'; -import inject18n from '../../../../components/i18n'; -import { monthsAgo, now } from '../../../../utils/Time'; -import { areaChartOptions } from '../../../../utils/Charts'; -import { simpleNumberFormat } from '../../../../utils/Number'; - -const styles = () => ({ - paper: { - minHeight: 280, - height: '100%', - margin: '4px 0 0 0', - padding: '0 0 10px 0', - borderRadius: 4, - }, - chip: { - fontSize: 10, - height: 20, - marginLeft: 10, - }, -}); - -const groupingsAreaChartTimeSeriesQuery = graphql` - query GroupingsAreaChartTimeSeriesQuery( - $field: String! - $operation: StatsOperation! - $startDate: DateTime! - $endDate: DateTime! - $interval: String! - ) { - groupingsTimeSeries( - field: $field - operation: $operation - startDate: $startDate - endDate: $endDate - interval: $interval - ) { - date - value - } - } -`; - -class GroupingsAreaChart extends Component { - renderContent() { - const { t, fsd, groupingType, startDate, endDate, theme } = this.props; - const interval = 'day'; - const finalStartDate = startDate || monthsAgo(12); - const finalEndDate = endDate || now(); - const groupingsTimeSeriesVariables = { - groupingType: groupingType || null, - field: 'created_at', - operation: 'count', - startDate: finalStartDate, - endDate: finalEndDate, - interval, - }; - return ( - { - if (props && props.groupingsTimeSeries) { - const chartData = props.groupingsTimeSeries.map((entry) => ({ - x: new Date(entry.date), - y: entry.value, - })); - return ( - - ); - } - if (props) { - return ( -
- - {t('No entities of this type has been found.')} - -
- ); - } - return ( -
- - - -
- ); - }} - /> - ); - } - - render() { - const { t, classes, title, variant, height } = this.props; - return ( -
- - {title || t('Groupings distribution')} - - {variant !== 'inLine' ? ( - - {this.renderContent()} - - ) : ( - this.renderContent() - )} -
- ); - } -} - -GroupingsAreaChart.propTypes = { - classes: PropTypes.object, - theme: PropTypes.object, - t: PropTypes.func, - md: PropTypes.func, -}; - -export default compose( - inject18n, - withTheme, - withStyles(styles), -)(GroupingsAreaChart); diff --git a/opencti-platform/opencti-front/src/private/components/analyses/groupings/GroupingsDonut.jsx b/opencti-platform/opencti-front/src/private/components/analyses/groupings/GroupingsDonut.jsx deleted file mode 100644 index 9ce408c2fc32..000000000000 --- a/opencti-platform/opencti-front/src/private/components/analyses/groupings/GroupingsDonut.jsx +++ /dev/null @@ -1,143 +0,0 @@ -import React from 'react'; -import { graphql } from 'react-relay'; -import CircularProgress from '@mui/material/CircularProgress'; -import Paper from '@mui/material/Paper'; -import Typography from '@mui/material/Typography'; -import * as R from 'ramda'; -import makeStyles from '@mui/styles/makeStyles'; -import Chart from '../../common/charts/Chart'; -import { QueryRenderer } from '../../../../relay/environment'; -import { donutChartOptions } from '../../../../utils/Charts'; - -const useStyles = makeStyles(() => ({ - paper: { - height: 300, - minHeight: 300, - maxHeight: 300, - margin: '10px 0 0 0', - padding: 0, - borderRadius: 4, - }, -})); - -const groupingsDonutDistributionQuery = graphql` - query GroupingsDonutDistributionQuery( - $field: String! - $operation: StatsOperation! - $limit: Int - $startDate: DateTime - $endDate: DateTime - ) { - groupingsDistribution( - field: $field - operation: $operation - limit: $limit - startDate: $startDate - endDate: $endDate - ) { - label - value - entity { - ... on Identity { - name - } - } - } - } -`; - -const GroupingsDonut = (props) => { - const { t, field, startDate, endDate, theme, height, title, variant } = props; - const classes = useStyles(); - const renderContent = () => { - const groupingsDistributionVariables = { - field: field || 'grouping_types', - operation: 'count', - limit: 8, - startDate, - endDate, - }; - return ( - { - if ( - resultProps - && resultProps.groupingsDistribution - && resultProps.groupingsDistribution.length > 0 - ) { - let data = resultProps.groupingsDistribution; - if (field && field.includes('internal_id')) { - data = R.map( - (n) => R.assoc('label', n.entity?.name ?? 'Restricted', n), - resultProps.groupingsDistribution, - ); - } - const chartData = data.map((n) => n.value); - const labels = data.map((n) => n.label); - return ( - - ); - } - if (props) { - return ( -
- - {t('No entities of this type has been found.')} - -
- ); - } - return ( -
- - - -
- ); - }} - /> - ); - }; - return ( -
- - {title || t('Groupings distribution')} - - {variant !== 'inLine' ? ( - - {renderContent()} - - ) : ( - renderContent() - )} -
- ); -}; - -export default GroupingsDonut; diff --git a/opencti-platform/opencti-front/src/private/components/analyses/groupings/GroupingsHorizontalBars.jsx b/opencti-platform/opencti-front/src/private/components/analyses/groupings/GroupingsHorizontalBars.jsx deleted file mode 100644 index 6a2059d8f74e..000000000000 --- a/opencti-platform/opencti-front/src/private/components/analyses/groupings/GroupingsHorizontalBars.jsx +++ /dev/null @@ -1,166 +0,0 @@ -import React, { Component } from 'react'; -import * as PropTypes from 'prop-types'; -import { compose } from 'ramda'; -import { graphql } from 'react-relay'; -import withTheme from '@mui/styles/withTheme'; -import withStyles from '@mui/styles/withStyles'; -import CircularProgress from '@mui/material/CircularProgress'; -import Paper from '@mui/material/Paper'; -import Typography from '@mui/material/Typography'; -import Chart from '../../common/charts/Chart'; -import { QueryRenderer } from '../../../../relay/environment'; -import inject18n from '../../../../components/i18n'; -import { horizontalBarsChartOptions } from '../../../../utils/Charts'; -import { simpleNumberFormat } from '../../../../utils/Number'; - -const styles = () => ({ - paper: { - height: 300, - minHeight: 300, - maxHeight: 300, - margin: '10px 0 0 0', - padding: 0, - borderRadius: 4, - }, -}); - -const groupingsHorizontalBarsDistributionQuery = graphql` - query GroupingsHorizontalBarsDistributionQuery( - $field: String! - $operation: StatsOperation! - $limit: Int - $startDate: DateTime - $endDate: DateTime - ) { - groupingsDistribution( - field: $field - operation: $operation - limit: $limit - startDate: $startDate - endDate: $endDate - ) { - label - value - entity { - ... on Identity { - name - } - } - } - } -`; - -class GroupingsHorizontalBars extends Component { - renderContent() { - const { t, field, startDate, endDate, theme } = this.props; - const groupingsDistributionVariables = { - field: field || 'grouping_types', - operation: 'count', - limit: 8, - startDate, - endDate, - }; - return ( - { - if ( - props - && props.groupingsDistribution - && props.groupingsDistribution.length > 0 - ) { - const data = props.groupingsDistribution.map((n) => ({ - x: n.entity?.name ?? 'Restricted', - y: n.value, - })); - const chartData = [{ name: t('Number of groupings'), data }]; - return ( - - ); - } - if (props) { - return ( -
- - {t('No entities of this type has been found.')} - -
- ); - } - return ( -
- - - -
- ); - }} - /> - ); - } - - render() { - const { t, classes, title, variant, height } = this.props; - return ( -
- - {title || t('Groupings distribution')} - - {variant !== 'inLine' ? ( - - {this.renderContent()} - - ) : ( - this.renderContent() - )} -
- ); - } -} - -GroupingsHorizontalBars.propTypes = { - title: PropTypes.string, - field: PropTypes.string, - startDate: PropTypes.string, - endDate: PropTypes.string, - classes: PropTypes.object, - theme: PropTypes.object, - t: PropTypes.func, -}; - -export default compose( - inject18n, - withTheme, - withStyles(styles), -)(GroupingsHorizontalBars); diff --git a/opencti-platform/opencti-front/src/private/components/analyses/groupings/GroupingsVerticalBars.jsx b/opencti-platform/opencti-front/src/private/components/analyses/groupings/GroupingsVerticalBars.jsx deleted file mode 100644 index 5d956c870fcb..000000000000 --- a/opencti-platform/opencti-front/src/private/components/analyses/groupings/GroupingsVerticalBars.jsx +++ /dev/null @@ -1,167 +0,0 @@ -import React, { Component } from 'react'; -import * as PropTypes from 'prop-types'; -import { compose } from 'ramda'; -import { graphql } from 'react-relay'; -import withTheme from '@mui/styles/withTheme'; -import withStyles from '@mui/styles/withStyles'; -import CircularProgress from '@mui/material/CircularProgress'; -import Paper from '@mui/material/Paper'; -import Typography from '@mui/material/Typography'; -import Chart from '../../common/charts/Chart'; -import { QueryRenderer } from '../../../../relay/environment'; -import inject18n from '../../../../components/i18n'; -import { monthsAgo, now } from '../../../../utils/Time'; -import { verticalBarsChartOptions } from '../../../../utils/Charts'; -import { simpleNumberFormat } from '../../../../utils/Number'; - -const styles = () => ({ - paper: { - minHeight: 280, - height: '100%', - margin: '4px 0 0 0', - padding: '0 0 10px 0', - borderRadius: 4, - }, - chip: { - fontSize: 10, - height: 20, - marginLeft: 10, - }, -}); - -const reporstVerticalBarsTimeSeriesQuery = graphql` - query GroupingsVerticalBarsTimeSeriesQuery( - $field: String! - $operation: StatsOperation! - $startDate: DateTime! - $endDate: DateTime! - $interval: String! - ) { - groupingsTimeSeries( - field: $field - operation: $operation - startDate: $startDate - endDate: $endDate - interval: $interval - ) { - date - value - } - } -`; - -class GroupingsVerticalBars extends Component { - renderContent() { - const { t, fsd, groupingType, startDate, endDate, theme } = this.props; - const interval = 'day'; - const finalStartDate = startDate || monthsAgo(12); - const finalEndDate = endDate || now(); - const groupingsTimeSeriesVariables = { - groupingType: groupingType || null, - field: 'created_at', - operation: 'count', - startDate: finalStartDate, - endDate: finalEndDate, - interval, - }; - return ( - { - if (props && props.groupingsTimeSeries) { - const chartData = props.groupingsTimeSeries.map((entry) => ({ - x: new Date(entry.date), - y: entry.value, - })); - return ( - - ); - } - if (props) { - return ( -
- - {t('No entities of this type has been found.')} - -
- ); - } - return ( -
- - - -
- ); - }} - /> - ); - } - - render() { - const { t, classes, title, variant, height } = this.props; - return ( -
- - {title || t('Groupings history')} - - {variant !== 'inLine' ? ( - - {this.renderContent()} - - ) : ( - this.renderContent() - )} -
- ); - } -} - -GroupingsVerticalBars.propTypes = { - classes: PropTypes.object, - theme: PropTypes.object, - t: PropTypes.func, - md: PropTypes.func, -}; - -export default compose( - inject18n, - withTheme, - withStyles(styles), -)(GroupingsVerticalBars); diff --git a/opencti-platform/opencti-front/src/private/components/analyses/groupings/StixCoreObjectGroupingsAreaChart.jsx b/opencti-platform/opencti-front/src/private/components/analyses/groupings/StixCoreObjectGroupingsAreaChart.jsx deleted file mode 100644 index 3fd365a2790a..000000000000 --- a/opencti-platform/opencti-front/src/private/components/analyses/groupings/StixCoreObjectGroupingsAreaChart.jsx +++ /dev/null @@ -1,201 +0,0 @@ -import React, { Component } from 'react'; -import * as PropTypes from 'prop-types'; -import { compose } from 'ramda'; -import { graphql } from 'react-relay'; -import withStyles from '@mui/styles/withStyles'; -import withTheme from '@mui/styles/withTheme'; -import CircularProgress from '@mui/material/CircularProgress'; -import Paper from '@mui/material/Paper'; -import Typography from '@mui/material/Typography'; -import Chart from '../../common/charts/Chart'; -import { QueryRenderer } from '../../../../relay/environment'; -import inject18n from '../../../../components/i18n'; -import { monthsAgo, now } from '../../../../utils/Time'; -import { areaChartOptions } from '../../../../utils/Charts'; -import { simpleNumberFormat } from '../../../../utils/Number'; - -const styles = () => ({ - paper: { - minHeight: 280, - height: '100%', - margin: '4px 0 0 0', - padding: '0 0 10px 0', - borderRadius: 4, - }, - chip: { - fontSize: 10, - height: 20, - marginLeft: 10, - }, -}); - -const stixCoreObjectGroupingsAreaChartTimeSeriesQuery = graphql` - query StixCoreObjectGroupingsAreaChartTimeSeriesQuery( - $objectId: String - $authorId: String - $groupingClass: String - $field: String! - $operation: StatsOperation! - $startDate: DateTime! - $endDate: DateTime! - $interval: String! - ) { - groupingsTimeSeries( - objectId: $objectId - authorId: $authorId - groupingType: $groupingClass - field: $field - operation: $operation - startDate: $startDate - endDate: $endDate - interval: $interval - ) { - date - value - } - } -`; - -class StixCoreObjectGroupingsAreaChart extends Component { - renderContent() { - const { - t, - fsd, - groupingType, - startDate, - endDate, - stixCoreObjectId, - authorId, - theme, - } = this.props; - const interval = 'day'; - const finalStartDate = startDate || monthsAgo(12); - const finalEndDate = endDate || now(); - let groupingsTimeSeriesVariables; - if (authorId) { - groupingsTimeSeriesVariables = { - authorId, - objectId: null, - groupingType: groupingType || null, - field: 'created_at', - operation: 'count', - startDate: finalStartDate, - endDate: finalEndDate, - interval, - }; - } else { - groupingsTimeSeriesVariables = { - authorId: null, - objectId: stixCoreObjectId, - groupingType: groupingType || null, - field: 'created_at', - operation: 'count', - startDate: finalStartDate, - endDate: finalEndDate, - interval, - }; - } - return ( - { - if (props && props.groupingsTimeSeries) { - const chartData = props.groupingsTimeSeries.map((entry) => ({ - x: new Date(entry.date), - y: entry.value, - })); - return ( - - ); - } - if (props) { - return ( -
- - {t('No entities of this type has been found.')} - -
- ); - } - return ( -
- - - -
- ); - }} - /> - ); - } - - render() { - const { t, classes, title, variant, height } = this.props; - return ( -
- - {title || t('Groupings history')} - - {variant !== 'inLine' ? ( - - {this.renderContent()} - - ) : ( - this.renderContent() - )} -
- ); - } -} - -StixCoreObjectGroupingsAreaChart.propTypes = { - classes: PropTypes.object, - theme: PropTypes.object, - stixCoreObjectId: PropTypes.string, - authorId: PropTypes.string, - t: PropTypes.func, - md: PropTypes.func, - nsd: PropTypes.func, -}; - -export default compose( - inject18n, - withTheme, - withStyles(styles), -)(StixCoreObjectGroupingsAreaChart); diff --git a/opencti-platform/opencti-front/src/private/components/analyses/groupings/StixCoreObjectGroupingsDonut.jsx b/opencti-platform/opencti-front/src/private/components/analyses/groupings/StixCoreObjectGroupingsDonut.jsx deleted file mode 100644 index 9bdffb91f192..000000000000 --- a/opencti-platform/opencti-front/src/private/components/analyses/groupings/StixCoreObjectGroupingsDonut.jsx +++ /dev/null @@ -1,162 +0,0 @@ -import React, { Component } from 'react'; -import * as PropTypes from 'prop-types'; -import * as R from 'ramda'; -import { graphql } from 'react-relay'; -import withTheme from '@mui/styles/withTheme'; -import withStyles from '@mui/styles/withStyles'; -import CircularProgress from '@mui/material/CircularProgress'; -import Paper from '@mui/material/Paper'; -import Typography from '@mui/material/Typography'; -import Chart from '../../common/charts/Chart'; -import { QueryRenderer } from '../../../../relay/environment'; -import inject18n from '../../../../components/i18n'; -import { donutChartOptions } from '../../../../utils/Charts'; - -const styles = () => ({ - paper: { - height: 300, - minHeight: 300, - maxHeight: 300, - margin: '10px 0 0 0', - padding: 0, - borderRadius: 4, - }, -}); - -const stixCoreObjectGroupingsDonutDistributionQuery = graphql` - query StixCoreObjectGroupingsDonutDistributionQuery( - $objectId: String - $field: String! - $operation: StatsOperation! - $limit: Int - ) { - groupingsDistribution( - objectId: $objectId - field: $field - operation: $operation - limit: $limit - ) { - label - value - entity { - ... on Identity { - name - } - ... on Malware { - name - } - } - } - } -`; - -class StixCoreObjectGroupingsDonut extends Component { - renderContent() { - const { t, stixCoreObjectId, field, theme } = this.props; - const groupingsDistributionVariables = { - objectId: stixCoreObjectId, - field: field || 'grouping_types', - operation: 'count', - limit: 8, - }; - return ( - { - if ( - props - && props.groupingsDistribution - && props.groupingsDistribution.length > 0 - ) { - let data = props.groupingsDistribution; - if (field && field.includes('internal_id')) { - data = R.map( - (n) => R.assoc('label', n.entity?.name ?? 'Restricted', n), - props.groupingsDistribution, - ); - } - const chartData = data.map((n) => n.value); - const labels = data.map((n) => n.label); - return ( - - ); - } - if (props) { - return ( -
- - {t('No entities of this type has been found.')} - -
- ); - } - return ( -
- - - -
- ); - }} - /> - ); - } - - render() { - const { t, classes, title, variant, height } = this.props; - return ( -
- - {title || t('Groupings distribution')} - - {variant !== 'inLine' ? ( - - {this.renderContent()} - - ) : ( - this.renderContent() - )} -
- ); - } -} - -StixCoreObjectGroupingsDonut.propTypes = { - stixCoreObjectId: PropTypes.string, - title: PropTypes.string, - field: PropTypes.string, - classes: PropTypes.object, - theme: PropTypes.object, - t: PropTypes.func, -}; - -export default R.compose( - inject18n, - withTheme, - withStyles(styles), -)(StixCoreObjectGroupingsDonut); diff --git a/opencti-platform/opencti-front/src/private/components/analyses/groupings/StixCoreObjectGroupingsHorizontalBars.jsx b/opencti-platform/opencti-front/src/private/components/analyses/groupings/StixCoreObjectGroupingsHorizontalBars.jsx deleted file mode 100644 index 98565e839ed2..000000000000 --- a/opencti-platform/opencti-front/src/private/components/analyses/groupings/StixCoreObjectGroupingsHorizontalBars.jsx +++ /dev/null @@ -1,162 +0,0 @@ -import React, { Component } from 'react'; -import * as PropTypes from 'prop-types'; -import { compose } from 'ramda'; -import { graphql } from 'react-relay'; -import withTheme from '@mui/styles/withTheme'; -import withStyles from '@mui/styles/withStyles'; -import CircularProgress from '@mui/material/CircularProgress'; -import Paper from '@mui/material/Paper'; -import Typography from '@mui/material/Typography'; -import Chart from '../../common/charts/Chart'; -import { QueryRenderer } from '../../../../relay/environment'; -import inject18n from '../../../../components/i18n'; -import { horizontalBarsChartOptions } from '../../../../utils/Charts'; -import { simpleNumberFormat } from '../../../../utils/Number'; - -const styles = () => ({ - paper: { - height: 300, - minHeight: 300, - maxHeight: 300, - margin: '10px 0 0 0', - padding: '0 10px 0 0', - borderRadius: 4, - }, -}); - -const stixCoreObjectGroupingsHorizontalBarsDistributionQuery = graphql` - query StixCoreObjectGroupingsHorizontalBarsDistributionQuery( - $objectId: String - $field: String! - $operation: StatsOperation! - $limit: Int - ) { - groupingsDistribution( - objectId: $objectId - field: $field - operation: $operation - limit: $limit - ) { - label - value - entity { - ... on Identity { - name - } - } - } - } -`; - -class StixCoreObjectGroupingsHorizontalBars extends Component { - renderContent() { - const { t, stixCoreObjectId, field, theme } = this.props; - const groupingsDistributionVariables = { - objectId: stixCoreObjectId, - field: field || 'context', - operation: 'count', - limit: 8, - }; - return ( - { - if ( - props - && props.groupingsDistribution - && props.groupingsDistribution.length > 0 - ) { - const data = props.groupingsDistribution.map((n) => ({ - x: n.entity?.name ?? 'Restricted', - y: n.value, - })); - const chartData = [{ name: t('Number of groupings'), data }]; - return ( - - ); - } - if (props) { - return ( -
- - {t('No entities of this type has been found.')} - -
- ); - } - return ( -
- - - -
- ); - }} - /> - ); - } - - render() { - const { t, classes, title, variant, height } = this.props; - return ( -
- - {title || t('Groupings distribution')} - - {variant !== 'inLine' ? ( - - {this.renderContent()} - - ) : ( - this.renderContent() - )} -
- ); - } -} - -StixCoreObjectGroupingsHorizontalBars.propTypes = { - stixCoreObjectId: PropTypes.string, - title: PropTypes.string, - field: PropTypes.string, - theme: PropTypes.object, - classes: PropTypes.object, - t: PropTypes.func, -}; - -export default compose( - inject18n, - withTheme, - withStyles(styles), -)(StixCoreObjectGroupingsHorizontalBars); diff --git a/opencti-platform/opencti-front/src/private/components/analyses/groupings/StixCoreObjectGroupingsVerticalBars.jsx b/opencti-platform/opencti-front/src/private/components/analyses/groupings/StixCoreObjectGroupingsVerticalBars.jsx deleted file mode 100644 index 169a8c5af91c..000000000000 --- a/opencti-platform/opencti-front/src/private/components/analyses/groupings/StixCoreObjectGroupingsVerticalBars.jsx +++ /dev/null @@ -1,200 +0,0 @@ -import React, { Component } from 'react'; -import * as PropTypes from 'prop-types'; -import { compose } from 'ramda'; -import { graphql } from 'react-relay'; -import withStyles from '@mui/styles/withStyles'; -import withTheme from '@mui/styles/withTheme'; -import CircularProgress from '@mui/material/CircularProgress'; -import Paper from '@mui/material/Paper'; -import Typography from '@mui/material/Typography'; -import Chart from '../../common/charts/Chart'; -import { QueryRenderer } from '../../../../relay/environment'; -import inject18n from '../../../../components/i18n'; -import { monthsAgo, now } from '../../../../utils/Time'; -import { verticalBarsChartOptions } from '../../../../utils/Charts'; -import { simpleNumberFormat } from '../../../../utils/Number'; - -const styles = () => ({ - paper: { - minHeight: 280, - height: '100%', - margin: '4px 0 0 0', - padding: '0 0 10px 0', - borderRadius: 4, - }, - chip: { - fontSize: 10, - height: 20, - marginLeft: 10, - }, -}); - -const stixCoreObjectReporstVerticalBarsTimeSeriesQuery = graphql` - query StixCoreObjectGroupingsVerticalBarsTimeSeriesQuery( - $objectId: String - $authorId: String - $groupingClass: String - $field: String! - $operation: StatsOperation! - $startDate: DateTime! - $endDate: DateTime! - $interval: String! - ) { - groupingsTimeSeries( - objectId: $objectId - authorId: $authorId - groupingType: $groupingClass - field: $field - operation: $operation - startDate: $startDate - endDate: $endDate - interval: $interval - ) { - date - value - } - } -`; - -class GroupingsVerticalBars extends Component { - renderContent() { - const { - t, - fsd, - groupingType, - startDate, - endDate, - stixCoreObjectId, - authorId, - theme, - } = this.props; - const interval = 'day'; - const finalStartDate = startDate || monthsAgo(12); - const finalEndDate = endDate || now(); - let groupingsTimeSeriesVariables; - if (authorId) { - groupingsTimeSeriesVariables = { - authorId, - objectId: null, - groupingType: groupingType || null, - field: 'created_at', - operation: 'count', - startDate: finalStartDate, - endDate: finalEndDate, - interval, - }; - } else { - groupingsTimeSeriesVariables = { - authorId: null, - objectId: stixCoreObjectId, - groupingType: groupingType || null, - field: 'created_at', - operation: 'count', - startDate: finalStartDate, - endDate: finalEndDate, - interval, - }; - } - return ( - { - if (props && props.groupingsTimeSeries) { - const chartData = props.groupingsTimeSeries.map((entry) => ({ - x: new Date(entry.date), - y: entry.value, - })); - return ( - - ); - } - if (props) { - return ( -
- - {t('No entities of this type has been found.')} - -
- ); - } - return ( -
- - - -
- ); - }} - /> - ); - } - - render() { - const { t, classes, title, variant, height } = this.props; - return ( -
- - {title || t('Groupings history')} - - {variant !== 'inLine' ? ( - - {this.renderContent()} - - ) : ( - this.renderContent() - )} -
- ); - } -} - -GroupingsVerticalBars.propTypes = { - classes: PropTypes.object, - theme: PropTypes.object, - stixCoreObjectId: PropTypes.string, - authorId: PropTypes.string, - t: PropTypes.func, - md: PropTypes.func, -}; - -export default compose( - inject18n, - withTheme, - withStyles(styles), -)(GroupingsVerticalBars); diff --git a/opencti-platform/opencti-front/src/private/components/analyses/malware_analyses/Root.tsx b/opencti-platform/opencti-front/src/private/components/analyses/malware_analyses/Root.tsx index 9b491aa603bb..9fb80ca704b0 100644 --- a/opencti-platform/opencti-front/src/private/components/analyses/malware_analyses/Root.tsx +++ b/opencti-platform/opencti-front/src/private/components/analyses/malware_analyses/Root.tsx @@ -24,7 +24,7 @@ import StixCoreObjectHistory from '../../common/stix_core_objects/StixCoreObject import StixCoreRelationship from '../../common/stix_core_relationships/StixCoreRelationship'; import { useFormatter } from '../../../../components/i18n'; import Breadcrumbs from '../../../../components/Breadcrumbs'; -import { defaultValue } from '../../../../utils/defaultRepresentatives'; +import { getMainRepresentative } from '../../../../utils/defaultRepresentatives'; const subscription = graphql` subscription RootMalwareAnalysisSubscription($id: ID!) { @@ -92,7 +92,7 @@ const RootMalwareAnalysis = () => { keyword === '' - || (defaultValue(n) || '').toLowerCase().indexOf(keyword.toLowerCase()) + || (getMainRepresentative(n) || '').toLowerCase().indexOf(keyword.toLowerCase()) !== -1 - || (defaultSecondaryValue(n) || '') + || (getSecondaryRepresentative(n) || '') .toLowerCase() .indexOf(keyword.toLowerCase()) !== -1 || (n.entity_type || '').toLowerCase().indexOf(keyword.toLowerCase()) diff --git a/opencti-platform/opencti-front/src/private/components/analyses/reports/ReportKnowledgeTimeLine.jsx b/opencti-platform/opencti-front/src/private/components/analyses/reports/ReportKnowledgeTimeLine.jsx index f47421161694..e2da68fd10a7 100644 --- a/opencti-platform/opencti-front/src/private/components/analyses/reports/ReportKnowledgeTimeLine.jsx +++ b/opencti-platform/opencti-front/src/private/components/analyses/reports/ReportKnowledgeTimeLine.jsx @@ -11,7 +11,7 @@ import TimelineConnector from '@mui/lab/TimelineConnector'; import TimelineContent from '@mui/lab/TimelineContent'; import Paper from '@mui/material/Paper'; import Typography from '@mui/material/Typography'; -import { defaultSecondaryValue, defaultValue } from '../../../../utils/defaultRepresentatives'; +import { getSecondaryRepresentative, getMainRepresentative } from '../../../../utils/defaultRepresentatives'; import ItemIcon from '../../../../components/ItemIcon'; import { resolveLink } from '../../../../utils/Entity'; import { useFormatter } from '../../../../components/i18n'; @@ -99,10 +99,10 @@ const ReportKnowledgeTimeLineComponent = ({ - {defaultValue(node)} + {getMainRepresentative(node)}
diff --git a/opencti-platform/opencti-front/src/private/components/analyses/reports/ReportsAreaChart.jsx b/opencti-platform/opencti-front/src/private/components/analyses/reports/ReportsAreaChart.jsx deleted file mode 100644 index 051097c87690..000000000000 --- a/opencti-platform/opencti-front/src/private/components/analyses/reports/ReportsAreaChart.jsx +++ /dev/null @@ -1,167 +0,0 @@ -import React, { Component } from 'react'; -import * as PropTypes from 'prop-types'; -import { compose } from 'ramda'; -import { graphql } from 'react-relay'; -import withStyles from '@mui/styles/withStyles'; -import withTheme from '@mui/styles/withTheme'; -import CircularProgress from '@mui/material/CircularProgress'; -import Paper from '@mui/material/Paper'; -import Typography from '@mui/material/Typography'; -import Chart from '../../common/charts/Chart'; -import { QueryRenderer } from '../../../../relay/environment'; -import inject18n from '../../../../components/i18n'; -import { monthsAgo, now } from '../../../../utils/Time'; -import { areaChartOptions } from '../../../../utils/Charts'; -import { simpleNumberFormat } from '../../../../utils/Number'; - -const styles = () => ({ - paper: { - minHeight: 280, - height: '100%', - margin: '4px 0 0 0', - padding: '0 0 10px 0', - borderRadius: 4, - }, - chip: { - fontSize: 10, - height: 20, - marginLeft: 10, - }, -}); - -const reportsAreaChartTimeSeriesQuery = graphql` - query ReportsAreaChartTimeSeriesQuery( - $field: String! - $operation: StatsOperation! - $startDate: DateTime! - $endDate: DateTime! - $interval: String! - ) { - reportsTimeSeries( - field: $field - operation: $operation - startDate: $startDate - endDate: $endDate - interval: $interval - ) { - date - value - } - } -`; - -class ReportsAreaChart extends Component { - renderContent() { - const { t, fsd, reportType, startDate, endDate, theme } = this.props; - const interval = 'day'; - const finalStartDate = startDate || monthsAgo(12); - const finalEndDate = endDate || now(); - const reportsTimeSeriesVariables = { - reportType: reportType || null, - field: 'created_at', - operation: 'count', - startDate: finalStartDate, - endDate: finalEndDate, - interval, - }; - return ( - { - if (props && props.reportsTimeSeries) { - const chartData = props.reportsTimeSeries.map((entry) => ({ - x: new Date(entry.date), - y: entry.value, - })); - return ( - - ); - } - if (props) { - return ( -
- - {t('No entities of this type has been found.')} - -
- ); - } - return ( -
- - - -
- ); - }} - /> - ); - } - - render() { - const { t, classes, title, variant, height } = this.props; - return ( -
- - {title || t('Reports distribution')} - - {variant !== 'inLine' ? ( - - {this.renderContent()} - - ) : ( - this.renderContent() - )} -
- ); - } -} - -ReportsAreaChart.propTypes = { - classes: PropTypes.object, - theme: PropTypes.object, - t: PropTypes.func, - md: PropTypes.func, -}; - -export default compose( - inject18n, - withTheme, - withStyles(styles), -)(ReportsAreaChart); diff --git a/opencti-platform/opencti-front/src/private/components/analyses/reports/ReportsDonut.jsx b/opencti-platform/opencti-front/src/private/components/analyses/reports/ReportsDonut.jsx deleted file mode 100644 index 67890589f33f..000000000000 --- a/opencti-platform/opencti-front/src/private/components/analyses/reports/ReportsDonut.jsx +++ /dev/null @@ -1,160 +0,0 @@ -import React, { Component } from 'react'; -import * as PropTypes from 'prop-types'; -import { compose } from 'ramda'; -import { graphql } from 'react-relay'; -import withTheme from '@mui/styles/withTheme'; -import withStyles from '@mui/styles/withStyles'; -import CircularProgress from '@mui/material/CircularProgress'; -import Paper from '@mui/material/Paper'; -import Typography from '@mui/material/Typography'; -import * as R from 'ramda'; -import Chart from '../../common/charts/Chart'; -import { QueryRenderer } from '../../../../relay/environment'; -import inject18n from '../../../../components/i18n'; -import { donutChartOptions } from '../../../../utils/Charts'; - -const styles = () => ({ - paper: { - height: 300, - minHeight: 300, - maxHeight: 300, - margin: '10px 0 0 0', - padding: 0, - borderRadius: 4, - }, -}); - -const reportsDonutDistributionQuery = graphql` - query ReportsDonutDistributionQuery( - $field: String! - $operation: StatsOperation! - $limit: Int - $startDate: DateTime - $endDate: DateTime - ) { - reportsDistribution( - field: $field - operation: $operation - limit: $limit - startDate: $startDate - endDate: $endDate - ) { - label - value - entity { - ... on Identity { - name - } - } - } - } -`; - -class ReportsDonut extends Component { - renderContent() { - const { t, field, startDate, endDate, theme } = this.props; - const reportsDistributionVariables = { - field: field || 'report_types', - operation: 'count', - limit: 8, - startDate, - endDate, - }; - return ( - { - if ( - props - && props.reportsDistribution - && props.reportsDistribution.length > 0 - ) { - let data = props.reportsDistribution; - if (field && field.includes('internal_id')) { - data = R.map( - (n) => R.assoc('label', n.entity?.name ?? 'Restricted', n), - props.reportsDistribution, - ); - } - const chartData = data.map((n) => n.value); - const labels = data.map((n) => n.label); - return ( - - ); - } - if (props) { - return ( -
- - {t('No entities of this type has been found.')} - -
- ); - } - return ( -
- - - -
- ); - }} - /> - ); - } - - render() { - const { t, classes, title, variant, height } = this.props; - return ( -
- - {title || t('Reports distribution')} - - {variant !== 'inLine' ? ( - - {this.renderContent()} - - ) : ( - this.renderContent() - )} -
- ); - } -} - -ReportsDonut.propTypes = { - title: PropTypes.string, - field: PropTypes.string, - startDate: PropTypes.string, - endDate: PropTypes.string, - classes: PropTypes.object, - theme: PropTypes.object, - t: PropTypes.func, -}; - -export default compose(inject18n, withTheme, withStyles(styles))(ReportsDonut); diff --git a/opencti-platform/opencti-front/src/private/components/analyses/reports/ReportsHorizontalBars.jsx b/opencti-platform/opencti-front/src/private/components/analyses/reports/ReportsHorizontalBars.jsx deleted file mode 100644 index 029e10698407..000000000000 --- a/opencti-platform/opencti-front/src/private/components/analyses/reports/ReportsHorizontalBars.jsx +++ /dev/null @@ -1,166 +0,0 @@ -import React, { Component } from 'react'; -import * as PropTypes from 'prop-types'; -import { compose } from 'ramda'; -import { graphql } from 'react-relay'; -import withTheme from '@mui/styles/withTheme'; -import withStyles from '@mui/styles/withStyles'; -import CircularProgress from '@mui/material/CircularProgress'; -import Paper from '@mui/material/Paper'; -import Typography from '@mui/material/Typography'; -import Chart from '../../common/charts/Chart'; -import { QueryRenderer } from '../../../../relay/environment'; -import inject18n from '../../../../components/i18n'; -import { horizontalBarsChartOptions } from '../../../../utils/Charts'; -import { simpleNumberFormat } from '../../../../utils/Number'; - -const styles = () => ({ - paper: { - height: 300, - minHeight: 300, - maxHeight: 300, - margin: '10px 0 0 0', - padding: 0, - borderRadius: 4, - }, -}); - -const reportsHorizontalBarsDistributionQuery = graphql` - query ReportsHorizontalBarsDistributionQuery( - $field: String! - $operation: StatsOperation! - $limit: Int - $startDate: DateTime - $endDate: DateTime - ) { - reportsDistribution( - field: $field - operation: $operation - limit: $limit - startDate: $startDate - endDate: $endDate - ) { - label - value - entity { - ... on Identity { - name - } - } - } - } -`; - -class ReportsHorizontalBars extends Component { - renderContent() { - const { t, field, startDate, endDate, theme } = this.props; - const reportsDistributionVariables = { - field: field || 'report_types', - operation: 'count', - limit: 8, - startDate, - endDate, - }; - return ( - { - if ( - props - && props.reportsDistribution - && props.reportsDistribution.length > 0 - ) { - const data = props.reportsDistribution.map((n) => ({ - x: n.entity?.name ?? 'Restricted', - y: n.value, - })); - const chartData = [{ name: t('Number of reports'), data }]; - return ( - - ); - } - if (props) { - return ( -
- - {t('No entities of this type has been found.')} - -
- ); - } - return ( -
- - - -
- ); - }} - /> - ); - } - - render() { - const { t, classes, title, variant, height } = this.props; - return ( -
- - {title || t('Reports distribution')} - - {variant !== 'inLine' ? ( - - {this.renderContent()} - - ) : ( - this.renderContent() - )} -
- ); - } -} - -ReportsHorizontalBars.propTypes = { - title: PropTypes.string, - field: PropTypes.string, - startDate: PropTypes.string, - endDate: PropTypes.string, - classes: PropTypes.object, - theme: PropTypes.object, - t: PropTypes.func, -}; - -export default compose( - inject18n, - withTheme, - withStyles(styles), -)(ReportsHorizontalBars); diff --git a/opencti-platform/opencti-front/src/private/components/analyses/reports/ReportsVerticalBars.jsx b/opencti-platform/opencti-front/src/private/components/analyses/reports/ReportsVerticalBars.jsx deleted file mode 100644 index 631e10388e7a..000000000000 --- a/opencti-platform/opencti-front/src/private/components/analyses/reports/ReportsVerticalBars.jsx +++ /dev/null @@ -1,167 +0,0 @@ -import React, { Component } from 'react'; -import * as PropTypes from 'prop-types'; -import { compose } from 'ramda'; -import { graphql } from 'react-relay'; -import withTheme from '@mui/styles/withTheme'; -import withStyles from '@mui/styles/withStyles'; -import CircularProgress from '@mui/material/CircularProgress'; -import Paper from '@mui/material/Paper'; -import Typography from '@mui/material/Typography'; -import Chart from '../../common/charts/Chart'; -import { QueryRenderer } from '../../../../relay/environment'; -import inject18n from '../../../../components/i18n'; -import { monthsAgo, now } from '../../../../utils/Time'; -import { verticalBarsChartOptions } from '../../../../utils/Charts'; -import { simpleNumberFormat } from '../../../../utils/Number'; - -const styles = () => ({ - paper: { - minHeight: 280, - height: '100%', - margin: '4px 0 0 0', - padding: '0 0 10px 0', - borderRadius: 4, - }, - chip: { - fontSize: 10, - height: 20, - marginLeft: 10, - }, -}); - -const reporstVerticalBarsTimeSeriesQuery = graphql` - query ReportsVerticalBarsTimeSeriesQuery( - $field: String! - $operation: StatsOperation! - $startDate: DateTime! - $endDate: DateTime! - $interval: String! - ) { - reportsTimeSeries( - field: $field - operation: $operation - startDate: $startDate - endDate: $endDate - interval: $interval - ) { - date - value - } - } -`; - -class ReportsVerticalBars extends Component { - renderContent() { - const { t, fsd, reportType, startDate, endDate, theme } = this.props; - const interval = 'day'; - const finalStartDate = startDate || monthsAgo(12); - const finalEndDate = endDate || now(); - const reportsTimeSeriesVariables = { - reportType: reportType || null, - field: 'created_at', - operation: 'count', - startDate: finalStartDate, - endDate: finalEndDate, - interval, - }; - return ( - { - if (props && props.reportsTimeSeries) { - const chartData = props.reportsTimeSeries.map((entry) => ({ - x: new Date(entry.date), - y: entry.value, - })); - return ( - - ); - } - if (props) { - return ( -
- - {t('No entities of this type has been found.')} - -
- ); - } - return ( -
- - - -
- ); - }} - /> - ); - } - - render() { - const { t, classes, title, variant, height } = this.props; - return ( -
- - {title || t('Reports history')} - - {variant !== 'inLine' ? ( - - {this.renderContent()} - - ) : ( - this.renderContent() - )} -
- ); - } -} - -ReportsVerticalBars.propTypes = { - classes: PropTypes.object, - theme: PropTypes.object, - t: PropTypes.func, - md: PropTypes.func, -}; - -export default compose( - inject18n, - withTheme, - withStyles(styles), -)(ReportsVerticalBars); diff --git a/opencti-platform/opencti-front/src/private/components/cases/case_incidents/IncidentKnowledgeGraph.jsx b/opencti-platform/opencti-front/src/private/components/cases/case_incidents/IncidentKnowledgeGraph.jsx index fffdcd8223cb..09d7ddf8ef03 100644 --- a/opencti-platform/opencti-front/src/private/components/cases/case_incidents/IncidentKnowledgeGraph.jsx +++ b/opencti-platform/opencti-front/src/private/components/cases/case_incidents/IncidentKnowledgeGraph.jsx @@ -32,7 +32,7 @@ import { nodePaint, nodeThreePaint, } from '../../../../utils/Graph'; -import { defaultSecondaryValue, defaultValue } from '../../../../utils/defaultRepresentatives'; +import { getSecondaryRepresentative, getMainRepresentative } from '../../../../utils/defaultRepresentatives'; import EntitiesDetailsRightsBar from '../../../../utils/graph/EntitiesDetailsRightBar'; import LassoSelection from '../../../../utils/graph/LassoSelection'; import { buildViewParamsFromUrlAndStorage, saveViewParameters } from '../../../../utils/ListParameters'; @@ -957,9 +957,9 @@ class IncidentKnowledgeGraphComponent extends Component { this.selectedNodes.clear(); if (isNotEmptyField(keyword)) { const filterByKeyword = (n) => keyword === '' - || (defaultValue(n) || '').toLowerCase().indexOf(keyword.toLowerCase()) + || (getMainRepresentative(n) || '').toLowerCase().indexOf(keyword.toLowerCase()) !== -1 - || (defaultSecondaryValue(n) || '') + || (getSecondaryRepresentative(n) || '') .toLowerCase() .indexOf(keyword.toLowerCase()) !== -1 || (n.entity_type || '').toLowerCase().indexOf(keyword.toLowerCase()) diff --git a/opencti-platform/opencti-front/src/private/components/cases/case_incidents/IncidentKnowledgeTimeLine.jsx b/opencti-platform/opencti-front/src/private/components/cases/case_incidents/IncidentKnowledgeTimeLine.jsx index bc4ac389351e..d0f96270d9d9 100644 --- a/opencti-platform/opencti-front/src/private/components/cases/case_incidents/IncidentKnowledgeTimeLine.jsx +++ b/opencti-platform/opencti-front/src/private/components/cases/case_incidents/IncidentKnowledgeTimeLine.jsx @@ -11,7 +11,7 @@ import TimelineConnector from '@mui/lab/TimelineConnector'; import TimelineContent from '@mui/lab/TimelineContent'; import Paper from '@mui/material/Paper'; import Typography from '@mui/material/Typography'; -import { defaultSecondaryValue, defaultValue } from '../../../../utils/defaultRepresentatives'; +import { getSecondaryRepresentative, getMainRepresentative } from '../../../../utils/defaultRepresentatives'; import ItemIcon from '../../../../components/ItemIcon'; import { resolveLink } from '../../../../utils/Entity'; import { useFormatter } from '../../../../components/i18n'; @@ -99,10 +99,10 @@ const IncidentKnowledgeTimeLineComponent = ({ - {defaultValue(node)} + {getMainRepresentative(node)}
diff --git a/opencti-platform/opencti-front/src/private/components/cases/case_rfis/CaseRfiKnowledgeGraph.jsx b/opencti-platform/opencti-front/src/private/components/cases/case_rfis/CaseRfiKnowledgeGraph.jsx index 7fc6b04de6b1..1a6d9abaee5b 100644 --- a/opencti-platform/opencti-front/src/private/components/cases/case_rfis/CaseRfiKnowledgeGraph.jsx +++ b/opencti-platform/opencti-front/src/private/components/cases/case_rfis/CaseRfiKnowledgeGraph.jsx @@ -32,7 +32,7 @@ import { nodePaint, nodeThreePaint, } from '../../../../utils/Graph'; -import { defaultSecondaryValue, defaultValue } from '../../../../utils/defaultRepresentatives'; +import { getSecondaryRepresentative, getMainRepresentative } from '../../../../utils/defaultRepresentatives'; import EntitiesDetailsRightsBar from '../../../../utils/graph/EntitiesDetailsRightBar'; import LassoSelection from '../../../../utils/graph/LassoSelection'; import { buildViewParamsFromUrlAndStorage, saveViewParameters } from '../../../../utils/ListParameters'; @@ -957,9 +957,9 @@ class CaseRfiKnowledgeGraphComponent extends Component { this.selectedNodes.clear(); if (isNotEmptyField(keyword)) { const filterByKeyword = (n) => keyword === '' - || (defaultValue(n) || '').toLowerCase().indexOf(keyword.toLowerCase()) + || (getMainRepresentative(n) || '').toLowerCase().indexOf(keyword.toLowerCase()) !== -1 - || (defaultSecondaryValue(n) || '') + || (getSecondaryRepresentative(n) || '') .toLowerCase() .indexOf(keyword.toLowerCase()) !== -1 || (n.entity_type || '').toLowerCase().indexOf(keyword.toLowerCase()) diff --git a/opencti-platform/opencti-front/src/private/components/cases/case_rfis/CaseRfiKnowledgeTimeLine.jsx b/opencti-platform/opencti-front/src/private/components/cases/case_rfis/CaseRfiKnowledgeTimeLine.jsx index 25da13300f05..9d90f6063690 100644 --- a/opencti-platform/opencti-front/src/private/components/cases/case_rfis/CaseRfiKnowledgeTimeLine.jsx +++ b/opencti-platform/opencti-front/src/private/components/cases/case_rfis/CaseRfiKnowledgeTimeLine.jsx @@ -11,7 +11,7 @@ import TimelineConnector from '@mui/lab/TimelineConnector'; import TimelineContent from '@mui/lab/TimelineContent'; import Paper from '@mui/material/Paper'; import Typography from '@mui/material/Typography'; -import { defaultSecondaryValue, defaultValue } from '../../../../utils/defaultRepresentatives'; +import { getSecondaryRepresentative, getMainRepresentative } from '../../../../utils/defaultRepresentatives'; import ItemIcon from '../../../../components/ItemIcon'; import { resolveLink } from '../../../../utils/Entity'; import { useFormatter } from '../../../../components/i18n'; @@ -99,10 +99,10 @@ const CaseRfiKnowledgeTimeLineComponent = ({ - {defaultValue(node)} + {getMainRepresentative(node)}
diff --git a/opencti-platform/opencti-front/src/private/components/cases/case_rfts/CaseRftKnowledgeGraph.jsx b/opencti-platform/opencti-front/src/private/components/cases/case_rfts/CaseRftKnowledgeGraph.jsx index e2c1e7561a20..3ee5bc05ddbf 100644 --- a/opencti-platform/opencti-front/src/private/components/cases/case_rfts/CaseRftKnowledgeGraph.jsx +++ b/opencti-platform/opencti-front/src/private/components/cases/case_rfts/CaseRftKnowledgeGraph.jsx @@ -32,7 +32,7 @@ import { nodePaint, nodeThreePaint, } from '../../../../utils/Graph'; -import { defaultSecondaryValue, defaultValue } from '../../../../utils/defaultRepresentatives'; +import { getSecondaryRepresentative, getMainRepresentative } from '../../../../utils/defaultRepresentatives'; import EntitiesDetailsRightsBar from '../../../../utils/graph/EntitiesDetailsRightBar'; import LassoSelection from '../../../../utils/graph/LassoSelection'; import { buildViewParamsFromUrlAndStorage, saveViewParameters } from '../../../../utils/ListParameters'; @@ -956,9 +956,9 @@ class CaseRftKnowledgeGraphComponent extends Component { this.selectedNodes.clear(); if (isNotEmptyField(keyword)) { const filterByKeyword = (n) => keyword === '' - || (defaultValue(n) || '').toLowerCase().indexOf(keyword.toLowerCase()) + || (getMainRepresentative(n) || '').toLowerCase().indexOf(keyword.toLowerCase()) !== -1 - || (defaultSecondaryValue(n) || '') + || (getSecondaryRepresentative(n) || '') .toLowerCase() .indexOf(keyword.toLowerCase()) !== -1 || (n.entity_type || '').toLowerCase().indexOf(keyword.toLowerCase()) diff --git a/opencti-platform/opencti-front/src/private/components/cases/case_rfts/CaseRftKnowledgeTimeLine.jsx b/opencti-platform/opencti-front/src/private/components/cases/case_rfts/CaseRftKnowledgeTimeLine.jsx index 54971fd113d5..81a972e4b790 100644 --- a/opencti-platform/opencti-front/src/private/components/cases/case_rfts/CaseRftKnowledgeTimeLine.jsx +++ b/opencti-platform/opencti-front/src/private/components/cases/case_rfts/CaseRftKnowledgeTimeLine.jsx @@ -11,7 +11,7 @@ import TimelineConnector from '@mui/lab/TimelineConnector'; import TimelineContent from '@mui/lab/TimelineContent'; import Paper from '@mui/material/Paper'; import Typography from '@mui/material/Typography'; -import { defaultSecondaryValue, defaultValue } from '../../../../utils/defaultRepresentatives'; +import { getSecondaryRepresentative, getMainRepresentative } from '../../../../utils/defaultRepresentatives'; import ItemIcon from '../../../../components/ItemIcon'; import { resolveLink } from '../../../../utils/Entity'; import { useFormatter } from '../../../../components/i18n'; @@ -99,10 +99,10 @@ const CaseRftKnowledgeTimeLineComponent = ({ - {defaultValue(node)} + {getMainRepresentative(node)}
diff --git a/opencti-platform/opencti-front/src/private/components/common/audits/AuditsDistributionList.jsx b/opencti-platform/opencti-front/src/private/components/common/audits/AuditsDistributionList.jsx index dd280209abbc..858474f1f332 100644 --- a/opencti-platform/opencti-front/src/private/components/common/audits/AuditsDistributionList.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/audits/AuditsDistributionList.jsx @@ -17,7 +17,7 @@ import React from 'react'; import { graphql } from 'react-relay'; import { QueryRenderer } from '../../../../relay/environment'; import { useFormatter } from '../../../../components/i18n'; -import { defaultValue } from '../../../../utils/defaultRepresentatives'; +import { getMainRepresentative, isFieldForIdentifier } from '../../../../utils/defaultRepresentatives'; import useGranted, { SETTINGS, SETTINGS_SETACCESSES } from '../../../../utils/hooks/useGranted'; import useEnterpriseEdition from '../../../../utils/hooks/useEnterpriseEdition'; import WidgetContainer from '../../../../components/dashboard/WidgetContainer'; @@ -54,147 +54,27 @@ const auditsDistributionListDistributionQuery = graphql` value entity { ... on BasicObject { - entity_type id + entity_type } ... on BasicRelationship { - entity_type id + entity_type } - ... on AttackPattern { - name - description - } - ... on Campaign { - name - description - } - ... on CourseOfAction { - name - description - } - ... on Individual { - name - description - } - ... on Organization { - name - description - } - ... on Sector { - name - description - } - ... on System { - name - description - } - ... on Indicator { - name - description - } - ... on Infrastructure { - name - description - } - ... on IntrusionSet { - name - description - } - ... on Position { - name - description - } - ... on City { - name - description - } - ... on AdministrativeArea { - name - description - } - ... on Country { - name - description - } - ... on Region { - name - description - } - ... on Malware { - name - description - } - ... on MalwareAnalysis { - result_name - } - ... on ThreatActor { - name - description - } - ... on Tool { - name - description - } - ... on Vulnerability { - name - description - } - ... on Incident { - name - description - } - ... on Event { - name - description - } - ... on Channel { - name - description - } - ... on Narrative { - name - description - } - ... on Language { - name - } - ... on DataComponent { - name - } - ... on DataSource { - name - } - ... on Case { - name - } - ... on Task { - name - } - ... on StixCyberObservable { - observable_value + ... on StixObject { + representative { + main + } } - ... on MarkingDefinition { - definition_type - definition + ... on StixRelationship { + representative { + main + } } + # objects without representative ... on Creator { - entity_type - name - } - ... on Report { name } - ... on Grouping { - name - } - ... on Note { - attribute_abstract - content - } - ... on Opinion { - opinion - } ... on Group { name } @@ -258,30 +138,24 @@ const AuditsDistributionList = ({ && props.auditsDistribution && props.auditsDistribution.length > 0 ) { - const data = props.auditsDistribution.map((o) => ({ - label: - // eslint-disable-next-line no-nested-ternary - selection.attribute.endsWith('.id') - || selection.attribute.endsWith('_id') - || selection.attribute.endsWith('_ids') - ? defaultValue(o.entity, t_i18n('Restricted')) - : selection.attribute === 'entity_type' - ? t_i18n(`entity_${o.label}`) - : o.label, - value: o.value, - id: - selection.attribute.endsWith('.id') - || selection.attribute.endsWith('_id') - || selection.attribute.endsWith('_ids') - ? o.entity?.id - : null, - type: - selection.attribute.endsWith('.id') - || selection.attribute.endsWith('_id') - || selection.attribute.endsWith('_ids') - ? o.entity?.entity_type - : o.label, - })); + const data = props.auditsDistribution.map((n) => { + let { label } = n; + let id = null; + let type = n.label; + if (isFieldForIdentifier(selection.attribute)) { + label = getMainRepresentative(n.entity) || n.label; + id = n.entity?.id; + type = n.entity?.entity_type; + } else if (selection.attribute === 'entity_type' && t_i18n(`entity_${n.label}`) !== `entity_${n.label}`) { + label = t_i18n(`entity_${n.label}`); + } + return { + label, + value: n.value, + id, + type, + }; + }); return ; } if (props) { diff --git a/opencti-platform/opencti-front/src/private/components/common/audits/AuditsDonut.jsx b/opencti-platform/opencti-front/src/private/components/common/audits/AuditsDonut.jsx index f610b07e1a98..34d06faaffdb 100644 --- a/opencti-platform/opencti-front/src/private/components/common/audits/AuditsDonut.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/audits/AuditsDonut.jsx @@ -54,125 +54,19 @@ const auditsDonutDistributionQuery = graphql` value entity { ... on BasicObject { + id entity_type } ... on BasicRelationship { + id entity_type } - ... on AttackPattern { - name - description - } - ... on Campaign { - name - description - } - ... on CourseOfAction { - name - description - } - ... on Individual { - name - description - } - ... on Organization { - name - description - } - ... on Sector { - name - description - } - ... on System { - name - description - } - ... on Indicator { - name - description - } - ... on Infrastructure { - name - description - } - ... on IntrusionSet { - name - description - } - ... on Position { - name - description - } - ... on City { - name - description - } - ... on AdministrativeArea { - name - description - } - ... on Country { - name - description - } - ... on Region { - name - description - } - ... on Malware { - name - description - } - ... on MalwareAnalysis { - result_name - } - ... on ThreatActor { - name - description - } - ... on Tool { - name - description - } - ... on Vulnerability { - name - description - } - ... on Incident { - name - description - } - ... on Event { - name - description - } - ... on Channel { - name - description - } - ... on Narrative { - name - description - } - ... on Language { - name - } - ... on DataComponent { - name - } - ... on DataSource { - name - } - ... on Case { - name - } - ... on StixCyberObservable { - observable_value - } - ... on MarkingDefinition { - definition_type - definition + ... on StixObject { + representative { + main + } } + # objects without representative ... on Creator { name } diff --git a/opencti-platform/opencti-front/src/private/components/common/audits/AuditsHorizontalBars.jsx b/opencti-platform/opencti-front/src/private/components/common/audits/AuditsHorizontalBars.jsx index 1b1664659436..43c4ca955482 100644 --- a/opencti-platform/opencti-front/src/private/components/common/audits/AuditsHorizontalBars.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/audits/AuditsHorizontalBars.jsx @@ -25,11 +25,10 @@ import Chart from '../charts/Chart'; import { QueryRenderer } from '../../../../relay/environment'; import { useFormatter } from '../../../../components/i18n'; import { horizontalBarsChartOptions } from '../../../../utils/Charts'; -import { itemColor } from '../../../../utils/Colors'; import { simpleNumberFormat } from '../../../../utils/Number'; -import { defaultValue } from '../../../../utils/defaultRepresentatives'; import useGranted, { SETTINGS } from '../../../../utils/hooks/useGranted'; import useEnterpriseEdition from '../../../../utils/hooks/useEnterpriseEdition'; +import useDistributionGraphData from '../../../../utils/hooks/useDistributionGraphData'; const useStyles = makeStyles(() => ({ paper: { @@ -69,143 +68,27 @@ const auditsHorizontalBarsDistributionQuery = graphql` value entity { ... on BasicObject { - entity_type id + entity_type } ... on BasicRelationship { - entity_type id + entity_type } - ... on AttackPattern { - name - description - } - ... on Campaign { - name - description - } - ... on CourseOfAction { - name - description - } - ... on Individual { - name - description - } - ... on Organization { - name - description - } - ... on Sector { - name - description - } - ... on System { - name - description - } - ... on Indicator { - name - description - } - ... on Infrastructure { - name - description - } - ... on IntrusionSet { - name - description - } - ... on Position { - name - description - } - ... on City { - name - description - } - ... on AdministrativeArea { - name - description - } - ... on Country { - name - description - } - ... on Region { - name - description - } - ... on Malware { - name - description - } - ... on MalwareAnalysis { - result_name - } - ... on ThreatActor { - name - description - } - ... on Tool { - name - description - } - ... on Vulnerability { - name - description - } - ... on Incident { - name - description - } - ... on Event { - name - description - } - ... on Channel { - name - description - } - ... on Narrative { - name - description - } - ... on Language { - name - } - ... on DataComponent { - name - } - ... on DataSource { - name - } - ... on Case { - name - } - ... on StixCyberObservable { - observable_value + ... on StixObject { + representative { + main + } } - ... on MarkingDefinition { - definition_type - definition + ... on StixRelationship { + representative { + main + } } + # objects without representative ... on Creator { name } - ... on Report { - name - } - ... on Grouping { - name - } - ... on Note { - attribute_abstract - content - } - ... on Opinion { - opinion - } ... on Group { name } @@ -234,6 +117,8 @@ const AuditsHorizontalBars = ({ const navigate = useNavigate(); const isGrantedToSettings = useGranted([SETTINGS]); const isEnterpriseEdition = useEnterpriseEdition(); + const { buildWidgetProps } = useDistributionGraphData(); + const renderContent = () => { if (!isGrantedToSettings || !isEnterpriseEdition) { return ( @@ -277,41 +162,7 @@ const AuditsHorizontalBars = ({ && props.auditsDistribution && props.auditsDistribution.length > 0 ) { - const data = props.auditsDistribution.map((n) => ({ - x: - // eslint-disable-next-line no-nested-ternary - selection.attribute.endsWith('.id') - || selection.attribute.endsWith('_id') - || selection.attribute.endsWith('_ids') - ? defaultValue(n.entity, t_i18n('Restricted')) - : selection.attribute === 'entity_type' - ? t_i18n(`entity_${n.label}`) - : n.label, - y: n.value, - fillColor: - selection.attribute.endsWith('.id') - || selection.attribute.endsWith('_id') - || selection.attribute.endsWith('_ids') - ? itemColor(n.entity?.entity_type) - : itemColor(n.label), - })); - const chartData = [ - { - name: selection.label || t_i18n('Number of history entries'), - data, - }, - ]; - const redirectionUtils = selection.attribute.endsWith('.id') - || selection.attribute.endsWith('_id') - || selection.attribute.endsWith('_ids') - ? props.auditsDistribution.map((n) => ({ - id: n.entity?.id, - entity_type: - n.entity?.entity_type === 'Workspace' - ? n.entity.type - : n.entity?.entity_type, - })) - : null; + const { series, redirectionUtils } = buildWidgetProps(props.auditsDistribution, selection, 'Number of history entries'); return ( ({ @@ -102,7 +102,7 @@ const ContainerAddStixCoreObjectsLineComponent = ({ className={classes.bodyItem} style={{ width: dataColumns.value.width }} > - {defaultValue(node)} + {getMainRepresentative(node)}
{ key={object.id} value={object.id} > - {defaultValue(object)} + {getMainRepresentative(object)} ))} @@ -1061,7 +1061,7 @@ const ContainerHeader = (props) => { {enableQuickSubscription && ( @@ -1070,7 +1070,7 @@ const ContainerHeader = (props) => { )} diff --git a/opencti-platform/opencti-front/src/private/components/common/containers/ContainerStixCoreObjectsMappingLine.jsx b/opencti-platform/opencti-front/src/private/components/common/containers/ContainerStixCoreObjectsMappingLine.jsx index b7a2331fe02e..f1f71b497be6 100644 --- a/opencti-platform/opencti-front/src/private/components/common/containers/ContainerStixCoreObjectsMappingLine.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/containers/ContainerStixCoreObjectsMappingLine.jsx @@ -16,7 +16,7 @@ import IconButton from '@mui/material/IconButton'; import { useFormatter } from '../../../../components/i18n'; import ItemIcon from '../../../../components/ItemIcon'; import { resolveLink } from '../../../../utils/Entity'; -import { defaultValue } from '../../../../utils/defaultRepresentatives'; +import { getMainRepresentative } from '../../../../utils/defaultRepresentatives'; import ItemMarkings from '../../../../components/ItemMarkings'; import { hexToRGB, itemColor } from '../../../../utils/Colors'; import ContainerStixCoreObjectPopover from './ContainerStixCoreObjectPopover'; @@ -100,7 +100,7 @@ const ContainerStixCoreObjectLineComponent = (props) => { > {node.x_mitre_id ? `[${node.x_mitre_id}] ${node.name}` - : defaultValue(node)} + : getMainRepresentative(node)}
{ > {node.x_mitre_id ? `[${node.x_mitre_id}] ${node.name}` - : defaultValue(node)} + : getMainRepresentative(node)}
({ @@ -109,7 +109,7 @@ const ContainerStixObjectOrStixRelationshipLineComponent = ({ className={classes.bodyItem} style={{ width: dataColumns.name.width }} > - {defaultValue(node)} + {getMainRepresentative(node)}
- {defaultValue(node)} + {getMainRepresentative(node)}
keyword === '' - || (defaultValue(n) || '').toLowerCase().indexOf(keyword.toLowerCase()) + || (getMainRepresentative(n) || '').toLowerCase().indexOf(keyword.toLowerCase()) !== -1 - || (defaultSecondaryValue(n) || '') + || (getSecondaryRepresentative(n) || '') .toLowerCase() .indexOf(keyword.toLowerCase()) !== -1 || (n.entity_type || '').toLowerCase().indexOf(keyword.toLowerCase()) diff --git a/opencti-platform/opencti-front/src/private/components/common/files/workbench/WorkbenchFileContent.jsx b/opencti-platform/opencti-front/src/private/components/common/files/workbench/WorkbenchFileContent.jsx index 332aea431aa5..a150c96f37c1 100644 --- a/opencti-platform/opencti-front/src/private/components/common/files/workbench/WorkbenchFileContent.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/files/workbench/WorkbenchFileContent.jsx @@ -40,7 +40,7 @@ import SwitchField from '../../../../../components/SwitchField'; import TextField from '../../../../../components/TextField'; import { APP_BASE_PATH, commitMutation, handleError, MESSAGING$, QueryRenderer } from '../../../../../relay/environment'; import { observableValue, resolveIdentityClass, resolveIdentityType, resolveLink, resolveLocationType, resolveThreatActorType } from '../../../../../utils/Entity'; -import { defaultKey, defaultValue } from '../../../../../utils/defaultRepresentatives'; +import { defaultKey, getMainRepresentative } from '../../../../../utils/defaultRepresentatives'; import useAttributes from '../../../../../utils/hooks/useAttributes'; import useVocabularyCategory from '../../../../../utils/hooks/useVocabularyCategory'; import { computeDuplicates, convertFromStixType, convertToStixType, truncate, uniqWithByFields } from '../../../../../utils/String'; @@ -2819,14 +2819,14 @@ const WorkbenchFileContentComponent = ({ n.type === 'relationship' ? t_i18n(`relationship_${n.relationship_type}`) : t_i18n(`entity_${convertFromStixType(n.type)}`), - default_value: defaultValue({ + default_value: getMainRepresentative({ ...n, - source_ref_name: defaultValue( + source_ref_name: getMainRepresentative( indexedStixObjects[n.source_ref] || indexedStixObjects[n.sighting_of_ref] || {}, ), - target_ref_name: defaultValue( + target_ref_name: getMainRepresentative( indexedStixObjects[n.target_ref] || indexedStixObjects[n.where_sighted_refs?.at(0)] || {}, @@ -2998,7 +2998,7 @@ const WorkbenchFileContentComponent = ({ const resolvedStixDomainObjects = stixDomainObjects.map((n) => ({ ...n, ttype: t_i18n(`entity_${convertFromStixType(n.type)}`), - default_value: defaultValue(n, null), + default_value: getMainRepresentative(n, null), markings: resolveMarkings(stixDomainObjects, n.object_marking_refs), })); const sort = R.sortWith( @@ -3241,7 +3241,7 @@ const WorkbenchFileContentComponent = ({ const resolvedStixCyberObservables = stixCyberObservables.map((n) => ({ ...n, ttype: t_i18n(`entity_${convertFromStixType(n.type)}`), - default_value: defaultValue(n, null), + default_value: getMainRepresentative(n, null), markings: resolveMarkings(stixDomainObjects, n.object_marking_refs), })); const sort = R.sortWith( @@ -3481,13 +3481,13 @@ const WorkbenchFileContentComponent = ({ const resolvedStixCoreRelationships = stixCoreRelationships.map((n) => ({ ...n, ttype: t_i18n(`relationship_${n.relationship_type}`), - default_value: defaultValue({ + default_value: getMainRepresentative({ ...n, - source_ref_name: defaultValue(indexedStixObjects[n.source_ref] || {}), - target_ref_name: defaultValue(indexedStixObjects[n.target_ref] || {}), + source_ref_name: getMainRepresentative(indexedStixObjects[n.source_ref] || {}), + target_ref_name: getMainRepresentative(indexedStixObjects[n.target_ref] || {}), }, null), - source_ref_name: defaultValue(indexedStixObjects[n.source_ref] || {}), - target_ref_name: defaultValue(indexedStixObjects[n.target_ref] || {}), + source_ref_name: getMainRepresentative(indexedStixObjects[n.source_ref] || {}), + target_ref_name: getMainRepresentative(indexedStixObjects[n.target_ref] || {}), markings: resolveMarkings(stixDomainObjects, n.object_marking_refs), })); const sort = R.sortWith( @@ -3625,19 +3625,19 @@ const WorkbenchFileContentComponent = ({ const resolvedStixSightings = stixSightings.map((n) => ({ ...n, ttype: t_i18n('Sighting'), - default_value: defaultValue({ + default_value: getMainRepresentative({ ...n, - source_ref_name: defaultValue( + source_ref_name: getMainRepresentative( indexedStixObjects[n.sighting_of_ref] || {}, ), - target_ref_name: defaultValue( + target_ref_name: getMainRepresentative( indexedStixObjects[n.where_sighted_refs?.at(0)] || {}, ), }, null), - source_ref_name: defaultValue( + source_ref_name: getMainRepresentative( indexedStixObjects[n.sighting_of_ref] || {}, ), - target_ref_name: defaultValue( + target_ref_name: getMainRepresentative( indexedStixObjects[n.where_sighted_refs?.at(0)] || {}, ), markings: resolveMarkings(stixDomainObjects, n.object_marking_refs), @@ -3805,7 +3805,7 @@ const WorkbenchFileContentComponent = ({ const resolvedContainers = containers.map((n) => ({ ...n, ttype: t_i18n(`entity_${convertFromStixType(n.type)}`), - default_value: defaultValue(n, null), + default_value: getMainRepresentative(n, null), markings: resolveMarkings(stixDomainObjects, n.object_marking_refs), })); const sort = R.sortWith( diff --git a/opencti-platform/opencti-front/src/private/components/common/form/DynamicResolutionField.jsx b/opencti-platform/opencti-front/src/private/components/common/form/DynamicResolutionField.jsx index 0a59c2734a58..f814de976776 100644 --- a/opencti-platform/opencti-front/src/private/components/common/form/DynamicResolutionField.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/form/DynamicResolutionField.jsx @@ -17,7 +17,7 @@ import ItemIcon from '../../../../components/ItemIcon'; import ItemBoolean from '../../../../components/ItemBoolean'; import { convertFromStixType, convertToStixType } from '../../../../utils/String'; import { useFormatter } from '../../../../components/i18n'; -import { defaultValue } from '../../../../utils/defaultRepresentatives'; +import { getMainRepresentative } from '../../../../utils/defaultRepresentatives'; import { isEmptyField } from '../../../../utils/utils'; const inlineStyles = { @@ -86,7 +86,7 @@ const DynamicResolutionField = ({ return { id: firstStixDomainObject.id, type: targetSelectedType, - name: defaultValue(firstStixDomainObject), + name: getMainRepresentative(firstStixDomainObject), in_platform: null, }; } diff --git a/opencti-platform/opencti-front/src/private/components/common/form/StixCoreObjectsField.jsx b/opencti-platform/opencti-front/src/private/components/common/form/StixCoreObjectsField.jsx index be258daa77ff..8f610e343a33 100644 --- a/opencti-platform/opencti-front/src/private/components/common/form/StixCoreObjectsField.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/form/StixCoreObjectsField.jsx @@ -12,7 +12,7 @@ import ListItemText from '@mui/material/ListItemText'; import makeStyles from '@mui/styles/makeStyles'; import IconButton from '@mui/material/IconButton'; import ItemIcon from '../../../../components/ItemIcon'; -import { defaultValue } from '../../../../utils/defaultRepresentatives'; +import { getMainRepresentative } from '../../../../utils/defaultRepresentatives'; import { useFormatter } from '../../../../components/i18n'; import AutocompleteField from '../../../../components/AutocompleteField'; import { fetchQuery } from '../../../../relay/environment'; @@ -234,7 +234,7 @@ const StixCoreObjectsField = (props) => { const finalStixCoreObjects = R.pipe( R.pathOr([], ['stixCoreObjects', 'edges']), R.map((n) => ({ - label: defaultValue(n.node), + label: getMainRepresentative(n.node), value: n.node.id, type: n.node.entity_type, })), diff --git a/opencti-platform/opencti-front/src/private/components/common/form/StixDomainObjectsField.jsx b/opencti-platform/opencti-front/src/private/components/common/form/StixDomainObjectsField.jsx index a002ed987730..fca6a9cfd79e 100644 --- a/opencti-platform/opencti-front/src/private/components/common/form/StixDomainObjectsField.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/form/StixDomainObjectsField.jsx @@ -8,7 +8,7 @@ import { graphql } from 'react-relay'; import { fetchQuery } from '../../../../relay/environment'; import AutocompleteField from '../../../../components/AutocompleteField'; import inject18n from '../../../../components/i18n'; -import { defaultValue } from '../../../../utils/defaultRepresentatives'; +import { getMainRepresentative } from '../../../../utils/defaultRepresentatives'; import ItemIcon from '../../../../components/ItemIcon'; const SEARCH$ = new Subject().pipe(debounce(() => timer(1500))); @@ -207,7 +207,7 @@ class StixDomainObjectsField extends Component { const labels = pipe( pathOr([], ['stixDomainObjects', 'edges']), map((n) => ({ - label: defaultValue(n.node), + label: getMainRepresentative(n.node), value: n.node.id, type: n.node.entity_type, })), diff --git a/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectsDistributionList.jsx b/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectsDistributionList.jsx index dfd3927d7e35..550cd137c6a4 100644 --- a/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectsDistributionList.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectsDistributionList.jsx @@ -8,6 +8,7 @@ import WidgetContainer from '../../../../components/dashboard/WidgetContainer'; import WidgetNoData from '../../../../components/dashboard/WidgetNoData'; import WidgetLoader from '../../../../components/dashboard/WidgetLoader'; import WidgetDistributionList from '../../../../components/dashboard/WidgetDistributionList'; +import { getMainRepresentative, isFieldForIdentifier } from '../../../../utils/defaultRepresentatives'; const stixCoreObjectsDistributionListDistributionQuery = graphql` query StixCoreObjectsDistributionListDistributionQuery( @@ -43,34 +44,33 @@ const stixCoreObjectsDistributionListDistributionQuery = graphql` label value entity { - ... on StixObject { + ... on BasicObject { id entity_type - representative { - main - } } - ... on StixRelationship { + ... on BasicRelationship { id entity_type - representative { - main - } } - ... on Creator { - id - entity_type + ... on StixObject { representative { main } } + # use colors when available ... on Label { - value color } ... on MarkingDefinition { x_opencti_color } + # objects without representative + ... on Creator { + name + } + ... on Group { + name + } ... on Status { template { name @@ -121,19 +121,21 @@ const StixCoreObjectsDistributionList = ({ && props.stixCoreObjectsDistribution && props.stixCoreObjectsDistribution.length > 0 ) { - const data = props.stixCoreObjectsDistribution.map((o) => ({ - label: - // eslint-disable-next-line no-nested-ternary - selection.attribute.endsWith('_id') - ? o.entity?.representative?.main - : selection.attribute === 'entity_type' - ? t_i18n(`entity_${o.label}`) - : o.label, - value: o.value, - color: o.entity?.color ?? o.entity?.x_opencti_color, - id: selection.attribute.endsWith('_id') ? o.entity?.id : null, - type: o.entity?.entity_type ?? o.label, - })); + const data = props.stixCoreObjectsDistribution.map((n) => { + let { label } = n; + if (isFieldForIdentifier(selection.attribute)) { + label = getMainRepresentative(n.entity); + } else if (selection.attribute === 'entity_type' && t_i18n(`entity_${n.label}`) !== `entity_${n.label}`) { + label = t_i18n(`entity_${n.label}`); + } + return { + label, + value: n.value, + color: n.entity?.color ?? n.entity?.x_opencti_color, + id: selection.attribute.endsWith('_id') ? n.entity?.id : null, + type: n.entity?.entity_type ?? n.label, + }; + }); return ; } if (props) { diff --git a/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectsDonut.jsx b/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectsDonut.jsx index 06b03b5053db..668a8782ad6a 100644 --- a/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectsDonut.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectsDonut.jsx @@ -45,136 +45,36 @@ const stixCoreObjectsDonutDistributionQuery = graphql` value entity { ... on BasicObject { + id entity_type } ... on BasicRelationship { + id entity_type } - ... on AttackPattern { - name - description - } - ... on Campaign { - name - description - } - ... on CourseOfAction { - name - description - } - ... on Individual { - name - description - } - ... on Organization { - name - description - } - ... on Sector { - name - description - } - ... on System { - name - description - } - ... on Indicator { - name - description - } - ... on Infrastructure { - name - description - } - ... on IntrusionSet { - name - description - } - ... on Position { - name - description - } - ... on City { - name - description - } - ... on AdministrativeArea { - name - description - } - ... on Country { - name - description - } - ... on Region { - name - description - } - ... on Malware { - name - description - } - ... on MalwareAnalysis { - result_name - } - ... on ThreatActor { - name - description - } - ... on Tool { - name - description - } - ... on Vulnerability { - name - description - } - ... on Incident { - name - description - } - ... on Event { - name - description - } - ... on Channel { - name - description - } - ... on Narrative { - name - description - } - ... on Language { - name - } - ... on DataComponent { - name - } - ... on DataSource { - name + ... on StixObject { + representative { + main + } } - ... on Case { - name + ... on StixRelationship { + representative { + main + } } - ... on StixCyberObservable { - observable_value + # use colors when available + ... on Label { + color } ... on MarkingDefinition { - definition_type - definition x_opencti_color } - ... on KillChainPhase { - kill_chain_name - phase_name - } + # objects without representative ... on Creator { name } - ... on Label { - value - color + ... on Group { + name } ... on Status { template { diff --git a/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectsHorizontalBars.jsx b/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectsHorizontalBars.jsx index ec3ad875e95d..4dbef617ee58 100644 --- a/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectsHorizontalBars.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectsHorizontalBars.jsx @@ -1,15 +1,13 @@ import React from 'react'; import { graphql } from 'react-relay'; -import { useTheme } from '@mui/styles'; import { QueryRenderer } from '../../../../relay/environment'; import { useFormatter } from '../../../../components/i18n'; -import { itemColor } from '../../../../utils/Colors'; -import { defaultValue } from '../../../../utils/defaultRepresentatives'; import { buildFiltersAndOptionsForWidgets } from '../../../../utils/filters/filtersUtils'; import WidgetContainer from '../../../../components/dashboard/WidgetContainer'; import WidgetNoData from '../../../../components/dashboard/WidgetNoData'; import WidgetLoader from '../../../../components/dashboard/WidgetLoader'; import WidgetHorizontalBars from '../../../../components/dashboard/WidgetHorizontalBars'; +import useDistributionGraphData from '../../../../utils/hooks/useDistributionGraphData'; const stixCoreObjectsHorizontalBarsDistributionQuery = graphql` query StixCoreObjectsHorizontalBarsDistributionQuery( @@ -45,155 +43,47 @@ const stixCoreObjectsHorizontalBarsDistributionQuery = graphql` label value entity { - ... on BasicObject { - entity_type - id - } - ... on BasicRelationship { - entity_type - id - } - ... on AttackPattern { - name - description - } - ... on Campaign { - name - description - } - ... on CourseOfAction { - name - description - } - ... on Individual { - name - description - } - ... on Organization { - name - description - } - ... on Sector { - name - description - } - ... on System { - name - description - } - ... on Indicator { - name - description - } - ... on Infrastructure { - name - description - } - ... on IntrusionSet { - name - description - } - ... on Position { - name - description - } - ... on City { - name - description - } - ... on AdministrativeArea { - name - description - } - ... on Country { - name - description - } - ... on Region { - name - description - } - ... on Malware { - name - description - } - ... on MalwareAnalysis { - result_name - } - ... on ThreatActor { - name - description - } - ... on Tool { - name - description - } - ... on Vulnerability { - name - description - } - ... on Incident { - name - description - } - ... on Event { - name - description - } - ... on Channel { - name - description - } - ... on Narrative { - name - description - } - ... on Language { - name - } - ... on DataComponent { - name - } - ... on DataSource { - name - } - ... on Case { - name - } - ... on StixCyberObservable { - observable_value - } - ... on MarkingDefinition { - definition_type - definition - x_opencti_color - } - ... on Creator { - name - } - ... on Report { - name - } - ... on Grouping { - name - } - ... on Note { - attribute_abstract - content - } - ... on Opinion { - opinion + ... on BasicObject { + id + entity_type + } + ... on BasicRelationship { + id + entity_type + } + ... on StixObject { + representative { + main } - ... on Label { - value - color + } + ... on StixRelationship { + representative { + main } - ... on Status { - template { - name - color - } + } + # internal objects + ... on Creator { + id + name + } + ... on Group { + id + name + } + # need colors when available + ... on Label { + value + color + } + ... on MarkingDefinition { + x_opencti_color + } + ... on Status { + template { + name + color } + } } } } @@ -209,8 +99,9 @@ const StixCoreObjectsHorizontalBars = ({ withExportPopover = false, isReadOnly = false, }) => { - const theme = useTheme(); const { t_i18n } = useFormatter(); + const { buildWidgetProps } = useDistributionGraphData(); + const renderContent = () => { const selection = dataSelection[0]; const dataSelectionTypes = ['Stix-Core-Object']; @@ -239,53 +130,10 @@ const StixCoreObjectsHorizontalBars = ({ && props.stixCoreObjectsDistribution && props.stixCoreObjectsDistribution.length > 0 ) { - const data = props.stixCoreObjectsDistribution.map((n) => { - let color = selection.attribute.endsWith('_id') - ? itemColor(n.entity?.entity_type) - : itemColor(n.label); - if (n.entity?.color) { - color = theme.palette.mode === 'light' && n.entity.color === '#ffffff' - ? '#000000' - : n.entity.color; - } - if (n.entity?.x_opencti_color) { - color = theme.palette.mode === 'light' - && n.entity.x_opencti_color === '#ffffff' - ? '#000000' - : n.entity.x_opencti_color; - } - if (n.entity?.template?.color) { - color = theme.palette.mode === 'light' - && n.entity.template.color === '#ffffff' - ? '#000000' - : n.entity.template.color; - } - return { - // eslint-disable-next-line no-nested-ternary - x: selection.attribute.endsWith('_id') - ? defaultValue(n.entity, t_i18n('Restricted')) - : selection.attribute === 'entity_type' - ? t_i18n(`entity_${n.label}`) - : n.label, - y: n.value, - fillColor: color, - }; - }); - const chartData = [ - { - name: selection.label || t_i18n('Number of relationships'), - data, - }, - ]; - const redirectionUtils = selection.attribute === 'name' - ? props.stixCoreObjectsDistribution.map((n) => ({ - id: n.entity?.id, - entity_type: n.entity?.entity_type, - })) - : undefined; + const { series, redirectionUtils } = buildWidgetProps(props.stixCoreObjectsDistribution, selection, 'Number of relationships'); return ( 0 ) { const data = props.stixCoreObjectsDistribution.map((n) => { - let color = selection.attribute.endsWith('_id') + let color = isFieldForIdentifier(selection.attribute) ? itemColor(n.entity?.entity_type) : itemColor(n.label); if (n.entity?.color) { @@ -467,7 +467,7 @@ const stixCoreObjectsMultiHorizontalBars = ({ x: // eslint-disable-next-line no-nested-ternary selection.attribute.endsWith('_id') - ? defaultValue(n.entity, t_i18n('Restricted')) + ? getMainRepresentative(n.entity, t_i18n('Restricted')) : selection.attribute === 'entity_type' ? t_i18n(`entity_${n.label}`) : n.label, diff --git a/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectsRadar.jsx b/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectsRadar.jsx index bcd9a5ee9a87..541b0e58b69c 100644 --- a/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectsRadar.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectsRadar.jsx @@ -43,139 +43,41 @@ const stixCoreObjectsRadarDistributionQuery = graphql` value entity { ... on BasicObject { + id entity_type } ... on BasicRelationship { + id entity_type } - ... on AttackPattern { - name - description - x_mitre_id - } - ... on Campaign { - name - description - } - ... on CourseOfAction { - name - description - } - ... on Individual { - name - description - } - ... on Organization { - name - description - } - ... on Sector { - name - description - } - ... on System { - name - description - } - ... on Indicator { - name - description - } - ... on Infrastructure { - name - description - } - ... on IntrusionSet { - name - description - } - ... on Position { - name - description - } - ... on City { - name - description - } - ... on AdministrativeArea { - name - description - } - ... on Country { - name - description - } - ... on Region { - name - description - } - ... on Malware { - name - description - } - ... on MalwareAnalysis { - result_name - } - ... on ThreatActor { - name - description - } - ... on Tool { - name - description - } - ... on Vulnerability { - name - description - } - ... on Incident { - name - description - } - ... on Event { - name - description - } - ... on Channel { - name - description - } - ... on Narrative { - name - description - } - ... on Language { - name - } - ... on DataComponent { - name - } - ... on DataSource { - name + ... on StixObject { + representative { + main + } } - ... on Case { - name + ... on StixRelationship { + representative { + main + } } - ... on StixCyberObservable { - observable_value + # use colors when available + ... on Label { + color } ... on MarkingDefinition { - definition_type - definition - } - ... on KillChainPhase { - kill_chain_name - phase_name + x_opencti_color } + # objects without representative ... on Creator { name } - ... on Label { - value + ... on Group { + name } ... on Status { template { name + color } } } diff --git a/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectsTimeline.jsx b/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectsTimeline.jsx index f317def339a9..cf95d5768166 100644 --- a/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectsTimeline.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectsTimeline.jsx @@ -29,149 +29,6 @@ const stixCoreObjectsTimelineQuery = graphql` id entity_type created_at - ... on StixDomainObject { - created - modified - } - ... on AttackPattern { - name - description - } - ... on Campaign { - name - description - } - ... on Note { - attribute_abstract - } - ... on Opinion { - opinion - } - ... on ObservedData { - first_observed - last_observed - } - ... on Opinion { - opinion - } - ... on Report { - name - description - published - } - ... on Grouping { - name - description - } - ... on CourseOfAction { - name - description - } - ... on Individual { - name - description - } - ... on Organization { - name - description - } - ... on Sector { - name - description - } - ... on System { - name - description - } - ... on Indicator { - name - description - } - ... on Infrastructure { - name - description - } - ... on IntrusionSet { - name - description - } - ... on Position { - name - description - } - ... on City { - name - description - } - ... on AdministrativeArea { - name - description - } - ... on Country { - name - description - } - ... on Region { - name - description - } - ... on Malware { - name - description - } - ... on MalwareAnalysis { - result_name - } - ... on ThreatActor { - name - description - } - ... on Tool { - name - description - } - ... on Vulnerability { - name - description - } - ... on Incident { - name - description - } - ... on Event { - name - description - } - ... on Channel { - name - description - } - ... on Narrative { - name - description - } - ... on Language { - name - } - ... on DataComponent { - name - } - ... on DataSource { - name - } - ... on Case { - name - } - ... on Note { - attribute_abstract - content - } - ... on Opinion { - opinion - } - ... on StixCyberObservable { - observable_value - } createdBy { ... on Identity { id @@ -186,6 +43,23 @@ const stixCoreObjectsTimelineQuery = graphql` x_opencti_order x_opencti_color } + ... on BasicObject { + id + entity_type + } + ... on StixObject { + representative { + main + secondary + } + } + ... on StixDomainObject { + created + modified + } + ... on StixCyberObservable { + observable_value + } } } } diff --git a/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectsTreeMap.jsx b/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectsTreeMap.jsx index d04b18dbe9b4..55028a3bca6a 100644 --- a/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectsTreeMap.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectsTreeMap.jsx @@ -43,135 +43,22 @@ const stixCoreObjectsTreeMapDistributionQuery = graphql` value entity { ... on BasicObject { + id entity_type } ... on BasicRelationship { + id entity_type } - ... on AttackPattern { - name - description - } - ... on Campaign { - name - description - } - ... on CourseOfAction { - name - description - } - ... on Individual { - name - description - } - ... on Organization { - name - description - } - ... on Sector { - name - description - } - ... on System { - name - description - } - ... on Indicator { - name - description - } - ... on Infrastructure { - name - description - } - ... on IntrusionSet { - name - description - } - ... on Position { - name - description - } - ... on City { - name - description - } - ... on AdministrativeArea { - name - description - } - ... on Country { - name - description - } - ... on Region { - name - description - } - ... on Malware { - name - description - } - ... on MalwareAnalysis { - result_name - } - ... on ThreatActor { - name - description - } - ... on Tool { - name - description - } - ... on Vulnerability { - name - description - } - ... on Incident { - name - description - } - ... on Event { - name - description - } - ... on Channel { - name - description - } - ... on Narrative { - name - description - } - ... on Language { - name - } - ... on DataComponent { - name - } - ... on DataSource { - name - } - ... on Case { - name - } - ... on StixCyberObservable { - observable_value - } - ... on MarkingDefinition { - definition_type - definition - } - ... on KillChainPhase { - kill_chain_name - phase_name + ... on StixObject { + representative { + main + } } + # objects without representative ... on Creator { name } - ... on Label { - value - } ... on Status { template { name diff --git a/opencti-platform/opencti-front/src/private/components/common/stix_core_objects_or_stix_relationships/StixCoreObjectOrCoreRelationshipLabelsView.js b/opencti-platform/opencti-front/src/private/components/common/stix_core_objects_or_stix_relationships/StixCoreObjectOrCoreRelationshipLabelsView.js index 7b139d1353af..69e21765af37 100644 --- a/opencti-platform/opencti-front/src/private/components/common/stix_core_objects_or_stix_relationships/StixCoreObjectOrCoreRelationshipLabelsView.js +++ b/opencti-platform/opencti-front/src/private/components/common/stix_core_objects_or_stix_relationships/StixCoreObjectOrCoreRelationshipLabelsView.js @@ -325,7 +325,7 @@ const StixCoreObjectOrCoreRelationshipLabelsView = (props) => { StixCoreObjectOrCoreRelationshipLabelsView.propTypes = { id: PropTypes.string, - labels: PropTypes.object, + labels: PropTypes.array, mutationRelationsAdd: PropTypes.object, mutationRelationDelete: PropTypes.object, }; diff --git a/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/EntityStixCoreRelationshipLineAll.jsx b/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/EntityStixCoreRelationshipLineAll.jsx index dc30ad9de8bd..6c04873dbdaf 100644 --- a/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/EntityStixCoreRelationshipLineAll.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/EntityStixCoreRelationshipLineAll.jsx @@ -18,7 +18,7 @@ import inject18n from '../../../../components/i18n'; import ItemIcon from '../../../../components/ItemIcon'; import ItemConfidence from '../../../../components/ItemConfidence'; import StixCoreRelationshipPopover from './StixCoreRelationshipPopover'; -import { defaultValue } from '../../../../utils/defaultRepresentatives'; +import { getMainRepresentative } from '../../../../utils/defaultRepresentatives'; import { hexToRGB, itemColor } from '../../../../utils/Colors'; import ItemMarkings from '../../../../components/ItemMarkings'; @@ -165,7 +165,7 @@ class EntityStixCoreRelationshipLineAllComponent extends Component { : dataColumns.observable_value.width, }} > - {!restricted ? defaultValue(remoteNode) : t('Restricted')} + {!restricted ? getMainRepresentative(remoteNode) : t('Restricted')}
- {!restricted ? defaultValue(node.to) : t('Restricted')} + {!restricted ? getMainRepresentative(node.to) : t('Restricted')}
- {!restricted ? defaultValue(node.from) : t('Restricted')} + {!restricted ? getMainRepresentative(node.from) : t('Restricted')}
({ paper: { @@ -238,7 +238,7 @@ const EntityStixCoreRelationshipsHorizontalBars = ( x: // eslint-disable-next-line no-nested-ternary field === 'internal_id' - ? defaultValue(n.entity, t_i18n('Restricted')) + ? getMainRepresentative(n.entity, t_i18n('Restricted')) : field === 'entity_type' ? t_i18n(`entity_${n.label}`) : n.label, diff --git a/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/SimpleStixObjectOrStixRelationshipStixCoreRelationshipLine.jsx b/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/SimpleStixObjectOrStixRelationshipStixCoreRelationshipLine.jsx index 8461521e91b2..e9b1d328f313 100644 --- a/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/SimpleStixObjectOrStixRelationshipStixCoreRelationshipLine.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/SimpleStixObjectOrStixRelationshipStixCoreRelationshipLine.jsx @@ -21,7 +21,7 @@ import Security from '../../../../utils/Security'; import { KNOWLEDGE_KNUPDATE } from '../../../../utils/hooks/useGranted'; import ItemIcon from '../../../../components/ItemIcon'; import { hexToRGB, itemColor } from '../../../../utils/Colors'; -import { defaultValue } from '../../../../utils/defaultRepresentatives'; +import { getMainRepresentative } from '../../../../utils/defaultRepresentatives'; import ItemMarkings from '../../../../components/ItemMarkings'; const styles = (theme) => ({ @@ -134,7 +134,7 @@ class SimpleStixObjectOrStixRelationshipStixCoreRelationshipLineComponent extend className={classes.bodyItem} style={{ width: dataColumns.name.width }} > - {element.restricted ? element.name : defaultValue(element)} + {element.restricted ? element.name : getMainRepresentative(element)}
({ containerRelation: { @@ -193,7 +193,7 @@ const StixCoreRelationshipCreationForm = ({ {isMultipleFrom ? ({t_i18n('Multiple entities selected')}) - : (defaultValue(fromEntity))} + : (getMainRepresentative(fromEntity))}
@@ -242,7 +242,7 @@ const StixCoreRelationshipCreationForm = ({ {isMultipleTo ? ({t_i18n('Multiple entities selected')}) - : (defaultValue(toEntity))} + : (getMainRepresentative(toEntity))}
diff --git a/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/StixCoreRelationshipCreationFromEntityStixCoreObjectsLine.jsx b/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/StixCoreRelationshipCreationFromEntityStixCoreObjectsLine.jsx index ff671682eef4..7df9b15fd812 100644 --- a/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/StixCoreRelationshipCreationFromEntityStixCoreObjectsLine.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/StixCoreRelationshipCreationFromEntityStixCoreObjectsLine.jsx @@ -13,7 +13,7 @@ import { useFormatter } from '../../../../components/i18n'; import StixCoreObjectLabels from '../stix_core_objects/StixCoreObjectLabels'; import ItemIcon from '../../../../components/ItemIcon'; import ItemMarkings from '../../../../components/ItemMarkings'; -import { defaultValue } from '../../../../utils/defaultRepresentatives'; +import { getMainRepresentative } from '../../../../utils/defaultRepresentatives'; import { hexToRGB, itemColor } from '../../../../utils/Colors'; import { APP_BASE_PATH } from '../../../../relay/environment'; @@ -128,7 +128,7 @@ const StixCoreRelationshipCreationFromEntityStixCoreObjectsLineComponent = ({ className={classes.bodyItem} style={{ width: dataColumns.value.width }} > - {defaultValue(node)} + {getMainRepresentative(node)}
{!fromRestricted ? truncate( - defaultValue(from) !== 'Unknown' - ? defaultValue(from) + getMainRepresentative(from) !== 'Unknown' + ? getMainRepresentative(from) : t(`relationship_${from.entity_type}`), 50, ) @@ -362,8 +362,8 @@ class StixCoreRelationshipContainer extends Component { {!toRestricted ? truncate( - defaultValue(to) !== 'Unknown' - ? defaultValue(to) + getMainRepresentative(to) !== 'Unknown' + ? getMainRepresentative(to) : t(`relationship_${to.entity_type}`), 50, ) diff --git a/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/views/EntityStixCoreRelationshipsContextualView.tsx b/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/views/EntityStixCoreRelationshipsContextualView.tsx index 1ae789a4b909..c1a2f2c712ef 100644 --- a/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/views/EntityStixCoreRelationshipsContextualView.tsx +++ b/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/views/EntityStixCoreRelationshipsContextualView.tsx @@ -11,7 +11,7 @@ import useEntityToggle from '../../../../../utils/hooks/useEntityToggle'; import EntityStixCoreRelationshipsContextualViewLines from './EntityStixCoreRelationshipsContextualViewLines'; import { hexToRGB, itemColor } from '../../../../../utils/Colors'; import { useFormatter } from '../../../../../components/i18n'; -import { defaultValue } from '../../../../../utils/defaultRepresentatives'; +import { getMainRepresentative } from '../../../../../utils/defaultRepresentatives'; import StixCoreObjectLabels from '../../stix_core_objects/StixCoreObjectLabels'; import ItemMarkings from '../../../../../components/ItemMarkings'; import { DataColumns, PaginationOptions } from '../../../../../components/list_lines'; @@ -153,7 +153,7 @@ const EntityStixCoreRelationshipsContextualViewComponent: FunctionComponent defaultValue(stixCoreObject), + render: (stixCoreObject: EntityStixCoreRelationshipsContextualViewLine_node$data) => getMainRepresentative(stixCoreObject), }, createdBy: { label: 'Author', diff --git a/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/views/EntityStixCoreRelationshipsEntitiesViewLine.tsx b/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/views/EntityStixCoreRelationshipsEntitiesViewLine.tsx index a5d3e64118bd..813b24bddcf3 100644 --- a/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/views/EntityStixCoreRelationshipsEntitiesViewLine.tsx +++ b/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/views/EntityStixCoreRelationshipsEntitiesViewLine.tsx @@ -18,7 +18,7 @@ import { useFormatter } from '../../../../../components/i18n'; import { DataColumns } from '../../../../../components/list_lines'; import { UseEntityToggle } from '../../../../../utils/hooks/useEntityToggle'; import ItemIcon from '../../../../../components/ItemIcon'; -import { defaultValue } from '../../../../../utils/defaultRepresentatives'; +import { getMainRepresentative } from '../../../../../utils/defaultRepresentatives'; import { hexToRGB, itemColor } from '../../../../../utils/Colors'; import { EntityStixCoreRelationshipsEntitiesViewLine_node$data, @@ -293,7 +293,7 @@ EntityStixCoreRelationshipsEntitiesLineProps : dataColumns.observable_value.width, }} > - {defaultValue(stixCoreObject)} + {getMainRepresentative(stixCoreObject)}
defaultValue(stixCoreObject), + render: (stixCoreObject: EntityStixCoreRelationshipsIndicatorsContextualViewLine_node$data) => getMainRepresentative(stixCoreObject), }, objectLabel: { label: 'Labels', diff --git a/opencti-platform/opencti-front/src/private/components/common/stix_domain_objects/StixDomainObjectHeader.jsx b/opencti-platform/opencti-front/src/private/components/common/stix_domain_objects/StixDomainObjectHeader.jsx index d806afddd008..249514518952 100644 --- a/opencti-platform/opencti-front/src/private/components/common/stix_domain_objects/StixDomainObjectHeader.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/stix_domain_objects/StixDomainObjectHeader.jsx @@ -39,7 +39,7 @@ import StixCoreObjectSharing from '../stix_core_objects/StixCoreObjectSharing'; import { truncate } from '../../../../utils/String'; import { useIsEnforceReference } from '../../../../utils/hooks/useEntitySettings'; import StixCoreObjectQuickSubscription from '../stix_core_objects/StixCoreObjectQuickSubscription'; -import { defaultValue } from '../../../../utils/defaultRepresentatives'; +import { getMainRepresentative } from '../../../../utils/defaultRepresentatives'; import Transition from '../../../../components/Transition'; import Loader, { LoaderVariant } from '../../../../components/Loader'; @@ -341,13 +341,13 @@ const StixDomainObjectHeader = (props) => { return ( }> - + - {truncate(defaultValue(stixDomainObject), 80)} + {truncate(getMainRepresentative(stixDomainObject), 80)} {typeof onViewAs === 'function' && ( @@ -515,7 +515,7 @@ const StixDomainObjectHeader = (props) => { {enableQuickSubscription && ( @@ -524,7 +524,7 @@ const StixDomainObjectHeader = (props) => { )} diff --git a/opencti-platform/opencti-front/src/private/components/common/stix_domain_objects/StixDomainObjectNestedEntitiesLines.jsx b/opencti-platform/opencti-front/src/private/components/common/stix_domain_objects/StixDomainObjectNestedEntitiesLines.jsx index 073d58243808..b3b7d0776b57 100644 --- a/opencti-platform/opencti-front/src/private/components/common/stix_domain_objects/StixDomainObjectNestedEntitiesLines.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/stix_domain_objects/StixDomainObjectNestedEntitiesLines.jsx @@ -13,7 +13,7 @@ import inject18n from '../../../../components/i18n'; import ItemIcon from '../../../../components/ItemIcon'; import StixNestedRefRelationshipPopover from '../stix_nested_ref_relationships/StixNestedRefRelationshipPopover'; import { resolveLink } from '../../../../utils/Entity'; -import { defaultValue } from '../../../../utils/defaultRepresentatives'; +import { getMainRepresentative } from '../../../../utils/defaultRepresentatives'; import { hexToRGB, itemColor } from '../../../../utils/Colors'; const styles = (theme) => ({ @@ -134,7 +134,7 @@ class StixDomainObjectNestedEntitiesLinesComponent extends Component { className={classes.bodyItem} style={{ width: '40%' }} > - {defaultValue(stixCoreObject)} + {getMainRepresentative(stixCoreObject)}
{fsd(node.start_time)} diff --git a/opencti-platform/opencti-front/src/private/components/common/stix_domain_objects/StixDomainObjectTimeline.jsx b/opencti-platform/opencti-front/src/private/components/common/stix_domain_objects/StixDomainObjectTimeline.jsx index 05bbc2aa24be..9f27cc241bbf 100644 --- a/opencti-platform/opencti-front/src/private/components/common/stix_domain_objects/StixDomainObjectTimeline.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/stix_domain_objects/StixDomainObjectTimeline.jsx @@ -20,7 +20,7 @@ import ItemIcon from '../../../../components/ItemIcon'; import inject18n from '../../../../components/i18n'; import { stixDomainObjectThreatKnowledgeStixRelationshipsQuery } from './StixDomainObjectThreatKnowledgeQuery'; import { truncate } from '../../../../utils/String'; -import { defaultSecondaryValue, defaultValue } from '../../../../utils/defaultRepresentatives'; +import { getSecondaryRepresentative, getMainRepresentative } from '../../../../utils/defaultRepresentatives'; import { itemColor } from '../../../../utils/Colors'; const Transition = React.forwardRef((props, ref) => ( @@ -95,7 +95,7 @@ class StixDomainObjectTimelineComponent extends Component { @@ -123,7 +123,7 @@ class StixDomainObjectTimelineComponent extends Component { @@ -154,7 +154,7 @@ class StixDomainObjectTimelineComponent extends Component { {!restricted ? truncate( - defaultValue(stixRelationship.targetEntity), + getMainRepresentative(stixRelationship.targetEntity), 50, ) : t('Restricted')} @@ -166,7 +166,7 @@ class StixDomainObjectTimelineComponent extends Component { && stixRelationship.description.length > 0 ? stixRelationship.description : !restricted - ? defaultSecondaryValue( + ? getSecondaryRepresentative( stixRelationship.targetEntity, ) : t('Restricted'), diff --git a/opencti-platform/opencti-front/src/private/components/common/stix_domain_objects/StixDomainObjectsTimeline.jsx b/opencti-platform/opencti-front/src/private/components/common/stix_domain_objects/StixDomainObjectsTimeline.jsx index f10416541e9c..e4311e1f8db3 100644 --- a/opencti-platform/opencti-front/src/private/components/common/stix_domain_objects/StixDomainObjectsTimeline.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/stix_domain_objects/StixDomainObjectsTimeline.jsx @@ -17,7 +17,7 @@ import CircularProgress from '@mui/material/CircularProgress'; import { QueryRenderer } from '../../../../relay/environment'; import ItemIcon from '../../../../components/ItemIcon'; import inject18n from '../../../../components/i18n'; -import { defaultValue } from '../../../../utils/defaultRepresentatives'; +import { getMainRepresentative } from '../../../../utils/defaultRepresentatives'; import { resolveLink } from '../../../../utils/Entity'; import { itemColor } from '../../../../utils/Colors'; import MarkdownDisplay from '../../../../components/MarkdownDisplay'; @@ -229,7 +229,7 @@ class StixDomainObjectsTimeline extends Component { - {defaultValue(stixDomainObject)} + {getMainRepresentative(stixDomainObject)}
- {truncate(defaultValue(fromEntity), 20)} + {truncate(getMainRepresentative(fromEntity), 20)}
@@ -773,7 +773,7 @@ const StixNestedRefRelationshipCreationFromEntity = ({
- {truncate(defaultValue(toEntity[0]), 20)} + {truncate(getMainRepresentative(toEntity[0]), 20)}
diff --git a/opencti-platform/opencti-front/src/private/components/common/stix_nested_ref_relationships/StixNestedRefRelationshipCreationFromEntityLine.tsx b/opencti-platform/opencti-front/src/private/components/common/stix_nested_ref_relationships/StixNestedRefRelationshipCreationFromEntityLine.tsx index 9664bf829001..fe7d7e17bf71 100644 --- a/opencti-platform/opencti-front/src/private/components/common/stix_nested_ref_relationships/StixNestedRefRelationshipCreationFromEntityLine.tsx +++ b/opencti-platform/opencti-front/src/private/components/common/stix_nested_ref_relationships/StixNestedRefRelationshipCreationFromEntityLine.tsx @@ -16,7 +16,7 @@ import StixCoreObjectLabels from '../stix_core_objects/StixCoreObjectLabels'; import { APP_BASE_PATH } from '../../../../relay/environment'; import ItemIcon from '../../../../components/ItemIcon'; import { hexToRGB, itemColor } from '../../../../utils/Colors'; -import { defaultValue } from '../../../../utils/defaultRepresentatives'; +import { getMainRepresentative } from '../../../../utils/defaultRepresentatives'; import ItemMarkings from '../../../../components/ItemMarkings'; import { useFormatter } from '../../../../components/i18n'; import type { Theme } from '../../../../components/Theme'; @@ -323,7 +323,7 @@ export const StixNestedRefRelationshipCreationFromEntityLine: FunctionComponent< className={classes.bodyItem} style={{ width: dataColumns.value.width }} > - {defaultValue(data)} + {getMainRepresentative(data)}
0 ) { - const data = props.stixRelationshipsDistribution.map((o) => ({ - label: finalField.endsWith('_id') - ? defaultValue(o.entity) - : o.label, - value: o.value, - id: finalField.endsWith('_id') ? o.entity?.id : null, - type: finalField.endsWith('_id') ? o.entity?.entity_type : o.label, - })); + const data = props.stixRelationshipsDistribution.map((n) => { + let { label } = n; + let id = null; + let type = n.label; + if (isFieldForIdentifier(finalField)) { + label = getMainRepresentative(n.entity); + id = n.entity?.id; + type = n.entity?.entity_type; + } + return { + label, + value: n.value, + id, + type, + }; + }); return ( { - const theme = useTheme(); const { t_i18n } = useFormatter(); + const { buildWidgetProps } = useDistributionGraphData(); const renderContent = () => { let selection = {}; let filtersAndOptions; @@ -258,45 +153,10 @@ const StixRelationshipsHorizontalBars = ({ && props.stixRelationshipsDistribution && props.stixRelationshipsDistribution.length > 0 ) { - const data = props.stixRelationshipsDistribution.map((n) => { - let color = selection.attribute.endsWith('_id') - ? itemColor(n.entity?.entity_type) - : itemColor(n.label); - if (n.entity?.color) { - color = theme.palette.mode === 'light' && n.entity?.color === '#ffffff' - ? '#000000' - : n.entity?.color; - } - if (n.entity?.x_opencti_color) { - color = theme.palette.mode === 'light' - && n.entity?.x_opencti_color === '#ffffff' - ? '#000000' - : n.entity?.x_opencti_color; - } - if (n.entity?.template?.color) { - color = theme.palette.mode === 'light' - && n.entity?.template.color === '#ffffff' - ? '#000000' - : n.entity?.template.color; - } - return { - x: finalField.endsWith('_id') - ? defaultValue(n.entity, t_i18n('Restricted')) - : n.label, - y: n.value, - fillColor: color, - }; - }); - const chartData = [{ name: t_i18n('Number of relationships'), data }]; - const redirectionUtils = finalField.endsWith('_id') - ? props.stixRelationshipsDistribution.map((n) => ({ - id: n.label, - entity_type: n.entity?.entity_type, - })) - : undefined; + const { series, redirectionUtils } = buildWidgetProps(props.stixRelationshipsDistribution, selection, 'Number of relationships'); return ( 0 ) { - const categories = props.stixRelationshipsDistribution.map((n) => defaultValue(n.entity, t_i18n('Restricted'))); + const categories = props.stixRelationshipsDistribution.map((n) => getMainRepresentative(n.entity, t_i18n('Restricted'))); const entitiesMapping = {}; for (const distrib of props.stixRelationshipsDistribution) { for (const subDistrib of distrib.entity[key]) { entitiesMapping[ finalSubDistributionField === 'internal_id' - ? defaultValue(subDistrib.entity, t_i18n('Restricted')) + ? getMainRepresentative(subDistrib.entity, t_i18n('Restricted')) : subDistrib.label ] = (entitiesMapping[ finalSubDistributionField === 'internal_id' - ? defaultValue(subDistrib.entity, t_i18n('Restricted')) + ? getMainRepresentative(subDistrib.entity, t_i18n('Restricted')) : subDistrib.label ] || 0) + subDistrib.value; } @@ -851,7 +470,7 @@ const StixRelationshipsMultiHorizontalBars = ({ const entityData = R.head( distrib.entity?.[key].filter( (n) => (finalSubDistributionField === 'internal_id' - ? defaultValue(n.entity) + ? getMainRepresentative(n.entity) : n.label) === sortedEntity[0], ), ); @@ -859,21 +478,21 @@ const StixRelationshipsMultiHorizontalBars = ({ if (entityData) { value = entityData.value; } - if (categoriesValues[defaultValue(distrib.entity)]) { - categoriesValues[defaultValue(distrib.entity)].push(value); + if (categoriesValues[getMainRepresentative(distrib.entity)]) { + categoriesValues[getMainRepresentative(distrib.entity)].push(value); } else { - categoriesValues[defaultValue(distrib.entity)] = [value]; + categoriesValues[getMainRepresentative(distrib.entity)] = [value]; } } const sum = ( - categoriesValues[defaultValue(distrib.entity)] || [] + categoriesValues[getMainRepresentative(distrib.entity)] || [] ).reduce((partialSum, a) => partialSum + a, 0); - if (categoriesValues[defaultValue(distrib.entity)]) { - categoriesValues[defaultValue(distrib.entity)].push( + if (categoriesValues[getMainRepresentative(distrib.entity)]) { + categoriesValues[getMainRepresentative(distrib.entity)].push( distrib.value - sum, ); } else { - categoriesValues[defaultValue(distrib.entity)] = [ + categoriesValues[getMainRepresentative(distrib.entity)] = [ distrib.value - sum, ]; } diff --git a/opencti-platform/opencti-front/src/private/components/common/stix_relationships/StixRelationshipsPolarArea.jsx b/opencti-platform/opencti-front/src/private/components/common/stix_relationships/StixRelationshipsPolarArea.jsx index ff147f88cdc9..e20d402cd519 100644 --- a/opencti-platform/opencti-front/src/private/components/common/stix_relationships/StixRelationshipsPolarArea.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/stix_relationships/StixRelationshipsPolarArea.jsx @@ -1,9 +1,8 @@ import React from 'react'; -import * as R from 'ramda'; import { graphql } from 'react-relay'; import { QueryRenderer } from '../../../../relay/environment'; import { useFormatter } from '../../../../components/i18n'; -import { defaultValue } from '../../../../utils/defaultRepresentatives'; +import { getMainRepresentative, isFieldForIdentifier } from '../../../../utils/defaultRepresentatives'; import { buildFiltersAndOptionsForWidgets } from '../../../../utils/filters/filtersUtils'; import WidgetNoData from '../../../../components/dashboard/WidgetNoData'; import WidgetLoader from '../../../../components/dashboard/WidgetLoader'; @@ -61,140 +60,42 @@ const stixRelationshipsPolarAreasDistributionQuery = graphql` value entity { ... on BasicObject { + id entity_type } ... on BasicRelationship { + id entity_type } - ... on AttackPattern { - name - description - } - ... on Campaign { - name - description - } - ... on CourseOfAction { - name - description - } - ... on Individual { - name - description - } - ... on Organization { - name - description - } - ... on Sector { - name - description - } - ... on System { - name - description - } - ... on Indicator { - name - description - } - ... on Infrastructure { - name - description - } - ... on IntrusionSet { - name - description - } - ... on Position { - name - description - } - ... on City { - name - description - } - ... on Country { - name - description - } - ... on Region { - name - description - } - ... on Malware { - name - description - } - ... on ThreatActor { - name - description - } - ... on Tool { - name - description - } - ... on Vulnerability { - name - description - } - ... on Incident { - name - description - } - ... on Event { - name - description - } - ... on Channel { - name - description - } - ... on Narrative { - name - description - } - ... on Language { - name - } - ... on DataComponent { - name - description - } - ... on DataSource { - name - description - } - ... on Case { - name - description - } - ... on StixCyberObservable { - observable_value - } - ... on MarkingDefinition { - definition_type - definition + ... on StixObject { + representative { + main + } } - ... on KillChainPhase { - kill_chain_name - phase_name + ... on StixRelationship { + representative { + main + } } + # internal objects ... on Creator { name } - ... on Report { + ... on Group { name } - ... on Grouping { - name + # need colors when available + ... on Label { + color } - ... on Note { - attribute_abstract - content + ... on MarkingDefinition { + x_opencti_color } - ... on Opinion { - opinion + ... on Status { + template { + name + color + } } } } @@ -243,16 +144,13 @@ const StixRelationshipsPolarArea = ({ render={({ props }) => { if (props && props.stixRelationshipsDistribution && props.stixRelationshipsDistribution.length > 0) { let data = props.stixRelationshipsDistribution; - if (finalField.endsWith('_id')) { - data = R.map( - (n) => R.assoc( - 'label', - defaultValue(n.entity, t_i18n('Restricted')), - n, - ), - props.stixRelationshipsDistribution, - ); + if (isFieldForIdentifier(finalField)) { + data = data.map((n) => ({ + ...n, + label: getMainRepresentative(n.entity), + })); } + // TODO: take into account the entity color to send it to the widget (that shall handle it) return ( defaultValue(o), + (o) => getMainRepresentative(o), R.values(selectedElements || {}), ), ), @@ -1704,7 +1704,7 @@ class ToolBar extends Component { R.map( (p) => (typeof p === 'string' ? p - : defaultValue(p)), + : getMainRepresentative(p)), R.pathOr([], ['context', 'values'], o), ), ), @@ -1867,7 +1867,7 @@ class ToolBar extends Component { textOverflow: 'ellipsis', }, }} - primary={defaultValue(element)} + primary={getMainRepresentative(element)} secondary={truncate( element.description || element.x_opencti_description @@ -1920,7 +1920,7 @@ class ToolBar extends Component { {t('Name')}
- {defaultValue(keptElement)} + {getMainRepresentative(keptElement)}
({ item: { @@ -115,7 +115,7 @@ const EntitiesStixDomainObjectLineComponent = ({ className={classes.bodyItem} style={{ width: dataColumns.name.width }} > - {defaultValue(node)} + {getMainRepresentative(node)}
- {defaultValue(node.from, t_i18n('Restricted'))} + {getMainRepresentative(node.from)}
- {defaultValue(node.to, t_i18n('Restricted')} + {getMainRepresentative(node.to)}
({ paper: { @@ -222,7 +222,7 @@ class EntityStixSightingRelationshipsDonut extends Component { `${ toTypes.length > 1 && n.entity ? `[${t(`entity_${n.entity.entity_type}`)}] ${n.entity.name}` - : `${defaultValue(n.entity, t_i18n('Restricted'))}` + : `${getMainRepresentative(n.entity) || n.label}` }`, n, ), diff --git a/opencti-platform/opencti-front/src/private/components/events/stix_sighting_relationships/StixSightingRelationshipCreation.jsx b/opencti-platform/opencti-front/src/private/components/events/stix_sighting_relationships/StixSightingRelationshipCreation.jsx index 26a7e982a817..410d8df9cca7 100644 --- a/opencti-platform/opencti-front/src/private/components/events/stix_sighting_relationships/StixSightingRelationshipCreation.jsx +++ b/opencti-platform/opencti-front/src/private/components/events/stix_sighting_relationships/StixSightingRelationshipCreation.jsx @@ -16,7 +16,7 @@ import { itemColor } from '../../../../utils/Colors'; import { formatDate } from '../../../../utils/Time'; import ItemIcon from '../../../../components/ItemIcon'; import { truncate } from '../../../../utils/String'; -import { defaultValue } from '../../../../utils/defaultRepresentatives'; +import { getMainRepresentative } from '../../../../utils/defaultRepresentatives'; import StixSightingRelationshipCreationForm from './StixSightingRelationshipCreationForm'; const styles = (theme) => ({ @@ -498,7 +498,7 @@ class StixSightingRelationshipCreation extends Component {
- {truncate(defaultValue(toObjects[0]), 20)} + {truncate(getMainRepresentative(toObjects[0]), 20)}
@@ -539,7 +539,7 @@ class StixSightingRelationshipCreation extends Component { {fromObjects.length > 1 ? ( {t('Multiple entities selected')} ) : ( - truncate(defaultValue(fromObjects[0])) + truncate(getMainRepresentative(fromObjects[0])) )} diff --git a/opencti-platform/opencti-front/src/private/components/observations/stix_cyber_observables/StixCyberObservableEntitiesLines.jsx b/opencti-platform/opencti-front/src/private/components/observations/stix_cyber_observables/StixCyberObservableEntitiesLines.jsx index ba2721e0b37a..ceddb8cabd17 100644 --- a/opencti-platform/opencti-front/src/private/components/observations/stix_cyber_observables/StixCyberObservableEntitiesLines.jsx +++ b/opencti-platform/opencti-front/src/private/components/observations/stix_cyber_observables/StixCyberObservableEntitiesLines.jsx @@ -14,7 +14,7 @@ import * as R from 'ramda'; import { AutoFix } from 'mdi-material-ui'; import Chip from '@mui/material/Chip'; import ItemIcon from '../../../../components/ItemIcon'; -import { defaultValue } from '../../../../utils/defaultRepresentatives'; +import { getMainRepresentative } from '../../../../utils/defaultRepresentatives'; import inject18n from '../../../../components/i18n'; import { resolveLink } from '../../../../utils/Entity'; import { TEN_SECONDS } from '../../../../utils/Time'; @@ -229,8 +229,8 @@ class StixCyberObservableEntitiesLinesComponent extends Component { || targetEntity.entity_type === 'stix-relation' ? `${targetEntity.from.name} ${String.fromCharCode( 8594, - )} ${defaultValue(targetEntity.to)}` - : defaultValue(targetEntity) + )} ${getMainRepresentative(targetEntity.to)}` + : getMainRepresentative(targetEntity) : t('Restricted')}
- {defaultValue(stixCoreObject)} + {getMainRepresentative(stixCoreObject)}
= ({ {truncate( Object.values(selectedElements || {}) - .map((o) => defaultValue(o)) + .map((o) => getMainRepresentative(o)) .join(', '), 80, )} @@ -371,7 +371,7 @@ const NotificationsToolBar: FunctionComponent = ({ {truncate( (o.context?.values ?? []) - .map((p) => (typeof p === 'string' ? p : defaultValue(p))) + .map((p) => (typeof p === 'string' ? p : getMainRepresentative(p))) .join(', '), 80, )} diff --git a/opencti-platform/opencti-front/src/private/components/search/SearchStixCoreObjectLine.jsx b/opencti-platform/opencti-front/src/private/components/search/SearchStixCoreObjectLine.jsx index fc29a3b3bfa5..2c5acdaa1186 100644 --- a/opencti-platform/opencti-front/src/private/components/search/SearchStixCoreObjectLine.jsx +++ b/opencti-platform/opencti-front/src/private/components/search/SearchStixCoreObjectLine.jsx @@ -15,7 +15,7 @@ import StixCoreObjectLabels from '../common/stix_core_objects/StixCoreObjectLabe import ItemIcon from '../../../components/ItemIcon'; import ItemMarkings from '../../../components/ItemMarkings'; import { resolveLink } from '../../../utils/Entity'; -import { defaultValue } from '../../../utils/defaultRepresentatives'; +import { getMainRepresentative } from '../../../utils/defaultRepresentatives'; import ItemEntityType from '../../../components/ItemEntityType'; const useStyles = makeStyles((theme) => ({ @@ -118,7 +118,7 @@ const SearchStixCoreObjectLineComponent = ({ className={classes.bodyItem} style={{ width: dataColumns.value.width }} > - {defaultValue(node)} + {getMainRepresentative(node)}
- {defaultValue(node)} + {getMainRepresentative(node)}
keyword === '' - || (defaultValue(n) || '').toLowerCase().indexOf(keyword.toLowerCase()) + || (getMainRepresentative(n) || '').toLowerCase().indexOf(keyword.toLowerCase()) !== -1 - || (defaultSecondaryValue(n) || '') + || (getSecondaryRepresentative(n) || '') .toLowerCase() .indexOf(keyword.toLowerCase()) !== -1 || (n.entity_type || '').toLowerCase().indexOf(keyword.toLowerCase()) diff --git a/opencti-platform/opencti-front/src/public/components/dashboard/stix_core_objects/PublicStixCoreObjectsDistributionList.tsx b/opencti-platform/opencti-front/src/public/components/dashboard/stix_core_objects/PublicStixCoreObjectsDistributionList.tsx index 6074af33abcf..4a42cd3da85d 100644 --- a/opencti-platform/opencti-front/src/public/components/dashboard/stix_core_objects/PublicStixCoreObjectsDistributionList.tsx +++ b/opencti-platform/opencti-front/src/public/components/dashboard/stix_core_objects/PublicStixCoreObjectsDistributionList.tsx @@ -8,6 +8,7 @@ import WidgetContainer from '../../../../components/dashboard/WidgetContainer'; import WidgetLoader from '../../../../components/dashboard/WidgetLoader'; import WidgetDistributionList from '../../../../components/dashboard/WidgetDistributionList'; import { PublicStixCoreObjectsDistributionListQuery } from './__generated__/PublicStixCoreObjectsDistributionListQuery.graphql'; +import { getMainRepresentative } from '../../../../utils/defaultRepresentatives'; const publicStixCoreObjectsDistributionListQuery = graphql` query PublicStixCoreObjectsDistributionListQuery( @@ -25,39 +26,34 @@ const publicStixCoreObjectsDistributionListQuery = graphql` label value entity { - ... on StixObject { + ... on BasicObject { id entity_type - representative { - main - } } - ... on StixRelationship { + ... on BasicRelationship { id entity_type - representative { - main - } } - ... on Creator { - id - entity_type + ... on StixObject { representative { main } } + + # need colors when available ... on Label { - value color } ... on MarkingDefinition { x_opencti_color } - ... on Status { - template { - name - color - } + + # internal objects + ... on Creator { + name + } + ... on Group { + name } } } @@ -78,20 +74,21 @@ const PublicStixCoreObjectsDistributionListComponent = ({ ); if (publicStixCoreObjectsDistribution && publicStixCoreObjectsDistribution.length > 0) { - const data = publicStixCoreObjectsDistribution.flatMap((o) => { - if (!o) return []; + const data = publicStixCoreObjectsDistribution.flatMap((n) => { + if (!n) return []; + let { label } = n; + if (t_i18n(`entity_${n.label}`) !== `entity_${n.label}`) { + label = t_i18n(`entity_${n.label}`); + } + if (n.entity) { + label = getMainRepresentative(n.entity); + } return { - label: - // eslint-disable-next-line no-nested-ternary - o.entity?.representative?.main - ? o.entity?.representative?.main - : t_i18n(`entity_${o.label}`) !== `entity_${o.label}` - ? t_i18n(`entity_${o.label}`) - : o.label, - value: o.value, - color: o.entity?.color ?? o.entity?.x_opencti_color, - id: o.entity?.id ?? null, - type: o.entity?.entity_type ?? o.label, + label, + value: n.value, + color: n.entity?.color ?? n.entity?.x_opencti_color, + id: n.entity?.id ?? null, + type: n.entity?.entity_type ?? n.label, }; }); return ; diff --git a/opencti-platform/opencti-front/src/public/components/dashboard/stix_core_objects/PublicStixCoreObjectsDonut.tsx b/opencti-platform/opencti-front/src/public/components/dashboard/stix_core_objects/PublicStixCoreObjectsDonut.tsx index a9adbf3ce447..4d1253daae57 100644 --- a/opencti-platform/opencti-front/src/public/components/dashboard/stix_core_objects/PublicStixCoreObjectsDonut.tsx +++ b/opencti-platform/opencti-front/src/public/components/dashboard/stix_core_objects/PublicStixCoreObjectsDonut.tsx @@ -27,137 +27,37 @@ const publicStixCoreObjectsDonutQuery = graphql` value entity { ... on BasicObject { + id entity_type } ... on BasicRelationship { + id entity_type } - ... on AttackPattern { - name - description - } - ... on Campaign { - name - description - } - ... on CourseOfAction { - name - description - } - ... on Individual { - name - description - } - ... on Organization { - name - description - } - ... on Sector { - name - description - } - ... on System { - name - description - } - ... on Indicator { - name - description - } - ... on Infrastructure { - name - description - } - ... on IntrusionSet { - name - description - } - ... on Position { - name - description - } - ... on City { - name - description - } - ... on AdministrativeArea { - name - description - } - ... on Country { - name - description - } - ... on Region { - name - description - } - ... on Malware { - name - description - } - ... on MalwareAnalysis { - result_name - } - ... on ThreatActor { - name - description - } - ... on Tool { - name - description - } - ... on Vulnerability { - name - description - } - ... on Incident { - name - description - } - ... on Event { - name - description - } - ... on Channel { - name - description - } - ... on Narrative { - name - description - } - ... on Language { - name + ... on StixObject { + representative { + main + } } - ... on DataComponent { - name + ... on StixRelationship { + representative { + main + } } - ... on DataSource { + # internal objects + ... on Creator { name } - ... on Case { + ... on Group { name } - ... on StixCyberObservable { - observable_value + # need colors when available + ... on Label { + color } ... on MarkingDefinition { - definition_type - definition x_opencti_color } - ... on KillChainPhase { - kill_chain_name - phase_name - } - ... on Creator { - name - } - ... on Label { - value - color - } ... on Status { template { name diff --git a/opencti-platform/opencti-front/src/public/components/dashboard/stix_core_objects/PublicStixCoreObjectsHorizontalBars.tsx b/opencti-platform/opencti-front/src/public/components/dashboard/stix_core_objects/PublicStixCoreObjectsHorizontalBars.tsx index 8a44145839a5..8984bc5a880d 100644 --- a/opencti-platform/opencti-front/src/public/components/dashboard/stix_core_objects/PublicStixCoreObjectsHorizontalBars.tsx +++ b/opencti-platform/opencti-front/src/public/components/dashboard/stix_core_objects/PublicStixCoreObjectsHorizontalBars.tsx @@ -1,18 +1,15 @@ import { graphql, PreloadedQuery, usePreloadedQuery } from 'react-relay'; import React from 'react'; -import { useTheme } from '@mui/styles'; import type { PublicManifestWidget } from '../PublicManifest'; import { useFormatter } from '../../../../components/i18n'; import WidgetNoData from '../../../../components/dashboard/WidgetNoData'; -import { itemColor } from '../../../../utils/Colors'; -import { defaultValue } from '../../../../utils/defaultRepresentatives'; import WidgetHorizontalBars from '../../../../components/dashboard/WidgetHorizontalBars'; -import type { Theme } from '../../../../components/Theme'; import type { PublicWidgetContainerProps } from '../PublicWidgetContainerProps'; import useQueryLoading from '../../../../utils/hooks/useQueryLoading'; import WidgetContainer from '../../../../components/dashboard/WidgetContainer'; import WidgetLoader from '../../../../components/dashboard/WidgetLoader'; import { PublicStixCoreObjectsHorizontalBarsQuery } from './__generated__/PublicStixCoreObjectsHorizontalBarsQuery.graphql'; +import useDistributionGraphData from '../../../../utils/hooks/useDistributionGraphData'; const publicStixCoreObjectsHorizontalBarsQuery = graphql` query PublicStixCoreObjectsHorizontalBarsQuery( @@ -31,148 +28,37 @@ const publicStixCoreObjectsHorizontalBarsQuery = graphql` value entity { ... on BasicObject { - entity_type id + entity_type } ... on BasicRelationship { - entity_type id + entity_type } - ... on AttackPattern { - name - description - } - ... on Campaign { - name - description - } - ... on CourseOfAction { - name - description - } - ... on Individual { - name - description - } - ... on Organization { - name - description - } - ... on Sector { - name - description - } - ... on System { - name - description - } - ... on Indicator { - name - description - } - ... on Infrastructure { - name - description - } - ... on IntrusionSet { - name - description - } - ... on Position { - name - description - } - ... on City { - name - description - } - ... on AdministrativeArea { - name - description - } - ... on Country { - name - description - } - ... on Region { - name - description - } - ... on Malware { - name - description - } - ... on MalwareAnalysis { - result_name - } - ... on ThreatActor { - name - description - } - ... on Tool { - name - description - } - ... on Vulnerability { - name - description - } - ... on Incident { - name - description - } - ... on Event { - name - description - } - ... on Channel { - name - description - } - ... on Narrative { - name - description - } - ... on Language { - name - } - ... on DataComponent { - name - } - ... on DataSource { - name - } - ... on Case { - name - } - ... on StixCyberObservable { - observable_value + ... on StixObject { + representative { + main + } } - ... on MarkingDefinition { - definition_type - definition - x_opencti_color + ... on StixRelationship { + representative { + main + } } + # internal objects ... on Creator { name } - ... on Report { - name - } - ... on Grouping { + ... on Group { name } - ... on Note { - attribute_abstract - content - } - ... on Opinion { - opinion - } + # need colors when available ... on Label { - value color } + ... on MarkingDefinition { + x_opencti_color + } ... on Status { template { name @@ -195,8 +81,7 @@ const PublicStixCoreObjectsHorizontalBarsComponent = ({ dataSelection, queryRef, }: PublicStixCoreObjectsHorizontalBarsComponentProps) => { - const theme = useTheme(); - const { t_i18n } = useFormatter(); + const { buildWidgetProps } = useDistributionGraphData(); const { publicStixCoreObjectsDistribution } = usePreloadedQuery( publicStixCoreObjectsHorizontalBarsQuery, queryRef, @@ -207,57 +92,10 @@ const PublicStixCoreObjectsHorizontalBarsComponent = ({ && publicStixCoreObjectsDistribution.length > 0 ) { const selection = dataSelection[0]; - const data = publicStixCoreObjectsDistribution.map((n) => { - let color = selection.attribute?.endsWith('_id') - ? itemColor(n?.entity?.entity_type) - : itemColor(n?.label); - if (n?.entity?.color) { - color = theme.palette.mode === 'light' && n.entity.color === '#ffffff' - ? '#000000' - : n.entity.color; - } - if (n?.entity?.x_opencti_color) { - color = theme.palette.mode === 'light' - && n.entity.x_opencti_color === '#ffffff' - ? '#000000' - : n.entity.x_opencti_color; - } - if (n?.entity?.template?.color) { - color = theme.palette.mode === 'light' - && n.entity.template.color === '#ffffff' - ? '#000000' - : n.entity.template.color; - } - return { - // eslint-disable-next-line no-nested-ternary - x: selection.attribute?.endsWith('_id') - ? defaultValue(n?.entity, t_i18n('Restricted')) - : selection.attribute === 'entity_type' - ? t_i18n(`entity_${n?.label}`) - : n?.label, - y: n?.value, - fillColor: color, - }; - }); - const chartData = [ - { - name: selection.label || t_i18n('Number of relationships'), - data, - }, - ]; - const redirectionUtils = selection.attribute === 'name' - ? publicStixCoreObjectsDistribution.flatMap((n) => { - if (!n || !n.entity) return []; - return { - id: n.entity.id, - entity_type: n.entity.entity_type, - }; - }) - : undefined; - + const { series, redirectionUtils } = buildWidgetProps(publicStixCoreObjectsDistribution, selection, 'Entities number'); return ( { - const theme = useTheme(); - const { t_i18n } = useFormatter(); + const { buildWidgetProps } = useDistributionGraphData(); const { publicStixRelationshipsDistribution } = usePreloadedQuery( publicStixRelationshipsHorizontalBarsQuery, queryRef, @@ -201,47 +92,10 @@ const PublicStixRelationshipsHorizontalBarsComponent = ({ && publicStixRelationshipsDistribution.length > 0 ) { const selection = dataSelection[0]; - const finalField = selection.attribute || 'entity_type'; - const data = publicStixRelationshipsDistribution.map((n) => { - let color = selection.attribute?.endsWith('_id') - ? itemColor(n?.entity?.entity_type) - : itemColor(n?.label); - if (n?.entity?.color) { - color = theme.palette.mode === 'light' && n.entity.color === '#ffffff' - ? '#000000' - : n.entity.color; - } - if (n?.entity?.x_opencti_color) { - color = theme.palette.mode === 'light' - && n.entity.x_opencti_color === '#ffffff' - ? '#000000' - : n.entity.x_opencti_color; - } - return { - x: finalField.endsWith('_id') - ? defaultValue(n?.entity, t_i18n('Restricted')) - : n?.label, - y: n?.value, - fillColor: color, - }; - }); - const chartData = [{ - name: selection.label || t_i18n('Number of relationships'), - data, - }]; - const redirectionUtils = finalField.endsWith('_id') - ? publicStixRelationshipsDistribution.flatMap((n) => { - if (!n || !n.entity) return []; - return { - id: n.entity.id, - entity_type: n.entity.entity_type, - }; - }) - : undefined; - + const { series, redirectionUtils } = buildWidgetProps(publicStixRelationshipsDistribution, selection, 'Number of relationships'); return ( defaultValue(n?.entity)); + const categories = publicStixRelationshipsDistribution.map((n) => getMainRepresentative(n?.entity)); const entitiesMapping: Record = {}; for (const distrib of publicStixRelationshipsDistribution) { for (const subDistrib of distrib?.breakdownDistribution ?? []) { - entitiesMapping[ - finalSubDistributionField === 'internal_id' - ? defaultValue(subDistrib?.entity) - : subDistrib?.label - ] = (entitiesMapping[ - finalSubDistributionField === 'internal_id' - ? defaultValue(subDistrib?.entity) - : subDistrib?.label - ] || 0) + (subDistrib?.value ?? 0); + if (distrib && subDistrib) { + entitiesMapping[ + finalSubDistributionField === 'internal_id' + ? getMainRepresentative(subDistrib?.entity) + : subDistrib?.label + ] = (entitiesMapping[ + finalSubDistributionField === 'internal_id' + ? getMainRepresentative(subDistrib?.entity) + : subDistrib?.label + ] || 0) + (subDistrib?.value ?? 0); + } } } const sortedEntityMapping = R.take( @@ -385,7 +172,7 @@ const PublicStixRelationshipsMultiHorizontalBarsComponent = ({ const entityData = R.head( (distrib?.breakdownDistribution ?? []).filter( (n) => (finalSubDistributionField === 'internal_id' - ? defaultValue(n?.entity, t_i18n('Restricted')) + ? getMainRepresentative(n?.entity, t_i18n('Restricted')) : n?.label) === sortedEntity[0], ), ); @@ -393,21 +180,21 @@ const PublicStixRelationshipsMultiHorizontalBarsComponent = ({ if (entityData && entityData.value) { value = entityData.value; } - if (categoriesValues[defaultValue(distrib?.entity)]) { - categoriesValues[defaultValue(distrib?.entity)].push(value); + if (categoriesValues[getMainRepresentative(distrib?.entity)]) { + categoriesValues[getMainRepresentative(distrib?.entity)].push(value); } else { - categoriesValues[defaultValue(distrib?.entity)] = [value]; + categoriesValues[getMainRepresentative(distrib?.entity)] = [value]; } } const sum = ( - categoriesValues[defaultValue(distrib?.entity)] || [] + categoriesValues[getMainRepresentative(distrib?.entity)] || [] ).reduce((partialSum, a) => partialSum + a, 0); - if (categoriesValues[defaultValue(distrib?.entity)]) { - categoriesValues[defaultValue(distrib?.entity)].push( + if (categoriesValues[getMainRepresentative(distrib?.entity)]) { + categoriesValues[getMainRepresentative(distrib?.entity)].push( (distrib?.value ?? 0) - sum, ); } else { - categoriesValues[defaultValue(distrib?.entity)] = [ + categoriesValues[getMainRepresentative(distrib?.entity)] = [ (distrib?.value ?? 0) - sum, ]; } diff --git a/opencti-platform/opencti-front/src/public/components/dashboard/stix_relationships/PublicStixRelationshipsPolarArea.tsx b/opencti-platform/opencti-front/src/public/components/dashboard/stix_relationships/PublicStixRelationshipsPolarArea.tsx index 57ba64aafb65..80e0be1602d9 100644 --- a/opencti-platform/opencti-front/src/public/components/dashboard/stix_relationships/PublicStixRelationshipsPolarArea.tsx +++ b/opencti-platform/opencti-front/src/public/components/dashboard/stix_relationships/PublicStixRelationshipsPolarArea.tsx @@ -9,7 +9,7 @@ import WidgetContainer from '../../../../components/dashboard/WidgetContainer'; import WidgetLoader from '../../../../components/dashboard/WidgetLoader'; import { PublicStixRelationshipsPolarAreaQuery } from './__generated__/PublicStixRelationshipsPolarAreaQuery.graphql'; import WidgetPolarArea from '../../../../components/dashboard/WidgetPolarArea'; -import { defaultValue } from '../../../../utils/defaultRepresentatives'; +import { getMainRepresentative, isFieldForIdentifier } from '../../../../utils/defaultRepresentatives'; const publicStixRelationshipsPolarAreaQuery = graphql` query PublicStixRelationshipsPolarAreaQuery( @@ -28,140 +28,42 @@ const publicStixRelationshipsPolarAreaQuery = graphql` value entity { ... on BasicObject { + id entity_type } ... on BasicRelationship { + id entity_type } - ... on AttackPattern { - name - description - } - ... on Campaign { - name - description - } - ... on CourseOfAction { - name - description - } - ... on Individual { - name - description - } - ... on Organization { - name - description - } - ... on Sector { - name - description - } - ... on System { - name - description - } - ... on Indicator { - name - description - } - ... on Infrastructure { - name - description - } - ... on IntrusionSet { - name - description - } - ... on Position { - name - description - } - ... on City { - name - description - } - ... on Country { - name - description - } - ... on Region { - name - description - } - ... on Malware { - name - description - } - ... on ThreatActor { - name - description - } - ... on Tool { - name - description - } - ... on Vulnerability { - name - description - } - ... on Incident { - name - description - } - ... on Event { - name - description - } - ... on Channel { - name - description - } - ... on Narrative { - name - description - } - ... on Language { - name - } - ... on DataComponent { - name - description - } - ... on DataSource { - name - description - } - ... on Case { - name - description - } - ... on StixCyberObservable { - observable_value - } - ... on MarkingDefinition { - definition_type - definition + ... on StixObject { + representative { + main + } } - ... on KillChainPhase { - kill_chain_name - phase_name + ... on StixRelationship { + representative { + main + } } + # internal objects ... on Creator { name } - ... on Report { + ... on Group { name } - ... on Grouping { - name + # need colors when available + ... on Label { + color } - ... on Note { - attribute_abstract - content + ... on MarkingDefinition { + x_opencti_color } - ... on Opinion { - opinion + ... on Status { + template { + name + color + } } } } @@ -182,14 +84,13 @@ const PublicStixRelationshipsPolarAreaComponent = ({ queryRef, ); - const { t_i18n } = useFormatter(); - if ( publicStixRelationshipsDistribution && publicStixRelationshipsDistribution.length > 0 ) { const attributeField = dataSelection[0].attribute || 'entity_type'; + // TODO: take into account the entity color to send it to the widget (that shall handle it) return ( { @@ -197,8 +98,8 @@ const PublicStixRelationshipsPolarAreaComponent = ({ return []; } return { - label: attributeField.endsWith('_id') - ? defaultValue(item.entity, t_i18n('Restricted')) + label: isFieldForIdentifier(attributeField) + ? getMainRepresentative(item.entity) : item.label, value: item.value ?? 0, }; diff --git a/opencti-platform/opencti-front/src/public/components/dashboard/stix_relationships/PublicStixRelationshipsRadar.tsx b/opencti-platform/opencti-front/src/public/components/dashboard/stix_relationships/PublicStixRelationshipsRadar.tsx index 02fc0c3b879f..eebe0cb310a9 100644 --- a/opencti-platform/opencti-front/src/public/components/dashboard/stix_relationships/PublicStixRelationshipsRadar.tsx +++ b/opencti-platform/opencti-front/src/public/components/dashboard/stix_relationships/PublicStixRelationshipsRadar.tsx @@ -27,142 +27,45 @@ const publicStixRelationshipsRadarsQuery = graphql` value entity { ... on BasicObject { + id entity_type } ... on BasicRelationship { + id entity_type } - ... on AttackPattern { - name - description - x_mitre_id - } - ... on Campaign { - name - description - } - ... on CourseOfAction { - name - description - } - ... on Individual { - name - description - } - ... on Organization { - name - description - } - ... on Sector { - name - description - } - ... on System { - name - description - } - ... on Indicator { - name - description - } - ... on Infrastructure { - name - description - } - ... on IntrusionSet { - name - description - } - ... on Position { - name - description - } - ... on City { - name - description - } - ... on AdministrativeArea { - name - description - } - ... on Country { - name - description - } - ... on Region { - name - description + ... on StixObject { + representative { + main + } } - ... on Malware { - name - description - } - ... on ThreatActor { - name - description - } - ... on Tool { - name - description - } - ... on Vulnerability { - name - description - } - ... on Incident { - name - description - } - ... on Event { - name - description - } - ... on Channel { - name - description - } - ... on Narrative { - name - description - } - ... on Language { - name - } - ... on DataComponent { - name - } - ... on DataSource { - name - } - ... on Case { - name - } - ... on StixCyberObservable { - observable_value - } - ... on MarkingDefinition { - definition_type - definition - } - ... on KillChainPhase { - kill_chain_name - phase_name + ... on StixRelationship { + representative { + main + } } + # internal objects ... on Creator { + id name } - ... on Report { + ... on Group { + id name } - ... on Grouping { - name + # need colors when available + ... on Label { + value + color } - ... on Note { - attribute_abstract - content + ... on MarkingDefinition { + x_opencti_color } - ... on Opinion { - opinion + ... on Status { + template { + name + color + } } } } diff --git a/opencti-platform/opencti-front/src/public/components/dashboard/stix_relationships/PublicStixRelationshipsTimeline.tsx b/opencti-platform/opencti-front/src/public/components/dashboard/stix_relationships/PublicStixRelationshipsTimeline.tsx index effb416aaa52..9250ce32ded6 100644 --- a/opencti-platform/opencti-front/src/public/components/dashboard/stix_relationships/PublicStixRelationshipsTimeline.tsx +++ b/opencti-platform/opencti-front/src/public/components/dashboard/stix_relationships/PublicStixRelationshipsTimeline.tsx @@ -54,6 +54,16 @@ const publicStixRelationshipsTimelineQuery = graphql` last_seen } from { + ... on BasicObject { + id + entity_type + } + ... on StixObject { + representative { + main + secondary + } + } ... on StixDomainObject { id entity_type @@ -66,10 +76,13 @@ const publicStixRelationshipsTimelineQuery = graphql` color } } + # additional info used by the timeline display + ... on Report { + description + published + } ... on AttackPattern { - name description - x_mitre_id killChainPhases { id phase_name @@ -88,112 +101,71 @@ const publicStixRelationshipsTimelineQuery = graphql` } } ... on Campaign { - name description } ... on CourseOfAction { - name description } ... on Individual { - name description } ... on Organization { - name description } ... on Sector { - name description } ... on System { - name description } ... on Indicator { - name description } ... on Infrastructure { - name description } ... on IntrusionSet { - name description } ... on Position { - name description } ... on City { - name description } ... on AdministrativeArea { - name description } ... on Country { - name description } ... on Region { - name description } ... on Malware { - name description } ... on ThreatActor { - name description } ... on Tool { - name description } ... on Vulnerability { - name description } ... on Incident { - name description } ... on Event { - name description } ... on Channel { - name description } ... on Narrative { - name description } - ... on Language { - name - } - ... on DataComponent { - name - } - ... on DataSource { - name - } - ... on Case { - name - } - ... on Note { - attribute_abstract - content - } - ... on Opinion { - opinion - } ... on StixCyberObservable { id entity_type @@ -213,7 +185,6 @@ const publicStixRelationshipsTimelineQuery = graphql` } ... on Indicator { id - name pattern_type pattern_version description @@ -241,6 +212,18 @@ const publicStixRelationshipsTimelineQuery = graphql` created created_at from { + ... on StixObject { + representative { + main + secondary + } + } + ... on StixRelationship { + representative { + main + secondary + } + } ... on StixDomainObject { id entity_type @@ -254,7 +237,6 @@ const publicStixRelationshipsTimelineQuery = graphql` } } ... on AttackPattern { - name description x_mitre_id killChainPhases { @@ -275,75 +257,57 @@ const publicStixRelationshipsTimelineQuery = graphql` } } ... on Campaign { - name description } ... on CourseOfAction { - name description } ... on Individual { - name description } ... on Organization { - name description } ... on Sector { - name description } ... on System { - name description } ... on Indicator { - name description } ... on Infrastructure { - name description } ... on IntrusionSet { - name description } ... on Position { - name description } ... on City { - name description } ... on Country { - name description } ... on Region { - name description } ... on Malware { - name description } ... on ThreatActor { - name description } ... on Tool { - name description } ... on Vulnerability { - name description } ... on Incident { - name description } ... on StixCyberObservable { @@ -365,7 +329,6 @@ const publicStixRelationshipsTimelineQuery = graphql` } ... on Indicator { id - name pattern_type pattern_version description @@ -395,6 +358,18 @@ const publicStixRelationshipsTimelineQuery = graphql` } } to { + ... on StixObject { + representative { + main + secondary + } + } + ... on StixRelationship { + representative { + main + secondary + } + } ... on StixDomainObject { id entity_type @@ -429,75 +404,57 @@ const publicStixRelationshipsTimelineQuery = graphql` } } ... on Campaign { - name description } ... on CourseOfAction { - name description } ... on Individual { - name description } ... on Organization { - name description } ... on Sector { - name description } ... on System { - name description } ... on Indicator { - name description } ... on Infrastructure { - name description } ... on IntrusionSet { - name description } ... on Position { - name description } ... on City { - name description } ... on Country { - name description } ... on Region { - name description } ... on Malware { - name description } ... on ThreatActor { - name description } ... on Tool { - name description } ... on Vulnerability { - name description } ... on Incident { - name description } ... on StixCyberObservable { @@ -519,7 +476,6 @@ const publicStixRelationshipsTimelineQuery = graphql` } ... on Indicator { id - name pattern_type pattern_version description @@ -551,6 +507,18 @@ const publicStixRelationshipsTimelineQuery = graphql` } } to { + ... on StixObject { + representative { + main + secondary + } + } + ... on StixRelationship { + representative { + main + secondary + } + } ... on StixDomainObject { id entity_type @@ -564,7 +532,6 @@ const publicStixRelationshipsTimelineQuery = graphql` } } ... on AttackPattern { - name description x_mitre_id killChainPhases { @@ -585,75 +552,57 @@ const publicStixRelationshipsTimelineQuery = graphql` } } ... on Campaign { - name description } ... on CourseOfAction { - name description } ... on Individual { - name description } ... on Organization { - name description } ... on Sector { - name description } ... on System { - name description } ... on Indicator { - name description } ... on Infrastructure { - name description } ... on IntrusionSet { - name description } ... on Position { - name description } ... on City { - name description } ... on Country { - name description } ... on Region { - name description } ... on Malware { - name description } ... on ThreatActor { - name description } ... on Tool { - name description } ... on Vulnerability { - name description } ... on Incident { - name description } ... on StixCyberObservable { @@ -675,7 +624,6 @@ const publicStixRelationshipsTimelineQuery = graphql` } ... on Indicator { id - name pattern_type pattern_version description @@ -703,6 +651,18 @@ const publicStixRelationshipsTimelineQuery = graphql` created_at parent_types from { + ... on StixObject { + representative { + main + secondary + } + } + ... on StixRelationship { + representative { + main + secondary + } + } ... on StixDomainObject { id entity_type @@ -716,7 +676,6 @@ const publicStixRelationshipsTimelineQuery = graphql` } } ... on AttackPattern { - name description x_mitre_id killChainPhases { @@ -737,75 +696,57 @@ const publicStixRelationshipsTimelineQuery = graphql` } } ... on Campaign { - name description } ... on CourseOfAction { - name description } ... on Individual { - name description } ... on Organization { - name description } ... on Sector { - name description } ... on System { - name description } ... on Indicator { - name description } ... on Infrastructure { - name description } ... on IntrusionSet { - name description } ... on Position { - name description } ... on City { - name description } ... on Country { - name description } ... on Region { - name description } ... on Malware { - name description } ... on ThreatActor { - name description } ... on Tool { - name description } ... on Vulnerability { - name description } ... on Incident { - name description } ... on StixCyberObservable { @@ -827,7 +768,6 @@ const publicStixRelationshipsTimelineQuery = graphql` } ... on Indicator { id - name pattern_type pattern_version description @@ -857,6 +797,18 @@ const publicStixRelationshipsTimelineQuery = graphql` } } to { + ... on StixObject { + representative { + main + secondary + } + } + ... on StixRelationship { + representative { + main + secondary + } + } ... on StixDomainObject { id entity_type @@ -870,7 +822,6 @@ const publicStixRelationshipsTimelineQuery = graphql` } } ... on AttackPattern { - name description x_mitre_id killChainPhases { @@ -891,75 +842,57 @@ const publicStixRelationshipsTimelineQuery = graphql` } } ... on Campaign { - name description } ... on CourseOfAction { - name description } ... on Individual { - name description } ... on Organization { - name description } ... on Sector { - name description } ... on System { - name description } ... on Indicator { - name description } ... on Infrastructure { - name description } ... on IntrusionSet { - name description } ... on Position { - name description } ... on City { - name description } ... on Country { - name description } ... on Region { - name description } ... on Malware { - name description } ... on ThreatActor { - name description } ... on Tool { - name description } ... on Vulnerability { - name description } ... on Incident { - name description } ... on StixCyberObservable { @@ -981,7 +914,6 @@ const publicStixRelationshipsTimelineQuery = graphql` } ... on Indicator { id - name pattern_type pattern_version description diff --git a/opencti-platform/opencti-front/src/public/components/dashboard/stix_relationships/PublicStixRelationshipsTreeMap.tsx b/opencti-platform/opencti-front/src/public/components/dashboard/stix_relationships/PublicStixRelationshipsTreeMap.tsx index 95e653607e11..b9fbcee05c49 100644 --- a/opencti-platform/opencti-front/src/public/components/dashboard/stix_relationships/PublicStixRelationshipsTreeMap.tsx +++ b/opencti-platform/opencti-front/src/public/components/dashboard/stix_relationships/PublicStixRelationshipsTreeMap.tsx @@ -27,141 +27,26 @@ const publicStixRelationshipsTreeMapsQuery = graphql` value entity { ... on BasicObject { + id entity_type } ... on BasicRelationship { + id entity_type } - ... on AttackPattern { - name - description - } - ... on Campaign { - name - description - } - ... on CourseOfAction { - name - description - } - ... on Individual { - name - description - } - ... on Organization { - name - description - } - ... on Sector { - name - description - } - ... on System { - name - description - } - ... on Indicator { - name - description - } - ... on Infrastructure { - name - description - } - ... on IntrusionSet { - name - description - } - ... on Position { - name - description - } - ... on City { - name - description - } - ... on AdministrativeArea { - name - description - } - ... on Country { - name - description - } - ... on Region { - name - description - } - ... on Malware { - name - description - } - ... on ThreatActor { - name - description - } - ... on Tool { - name - description - } - ... on Vulnerability { - name - description - } - ... on Incident { - name - description - } - ... on Event { - name - description - } - ... on Channel { - name - description - } - ... on Narrative { - name - description - } - ... on Language { - name - } - ... on DataComponent { - name - } - ... on DataSource { - name - } - ... on Case { - name - } - ... on StixCyberObservable { - observable_value - } - ... on MarkingDefinition { - definition_type - definition - } - ... on KillChainPhase { - kill_chain_name - phase_name + ... on StixObject { + representative { + main + } } + # objects without representative ... on Creator { name } - ... on Report { - name - } - ... on Grouping { - name - } - ... on Note { - attribute_abstract - content - } - ... on Opinion { - opinion + ... on Status { + template { + name + } } } } diff --git a/opencti-platform/opencti-front/src/utils/Graph.js b/opencti-platform/opencti-front/src/utils/Graph.js index a59a08489e0c..9a934586a239 100644 --- a/opencti-platform/opencti-front/src/utils/Graph.js +++ b/opencti-platform/opencti-front/src/utils/Graph.js @@ -51,6 +51,7 @@ import { dateFormat, dayEndDate, daysAfter, daysAgo, jsDate, minutesBefore, minu import { isDateStringNone, isNone } from '../components/i18n'; import { fileUri } from '../relay/environment'; import { isNotEmptyField } from './utils'; +import { defaultDate, getMainRepresentative } from './defaultRepresentatives'; const genImage = (src) => { const img = new Image(); @@ -547,10 +548,10 @@ export const buildCorrelationData = ( id: n.id, disabled: n.disabled, val: graphLevel[n.entity_type] || graphLevel.Unknown, - name: defaultValue(n), + name: getMainRepresentative(n), defaultDate: jsDate(defaultDate(n)), label: truncate( - defaultValue(n), + getMainRepresentative(n), n.entity_type === 'Attack-Pattern' ? 30 : 20, ), img: graphImages[n.entity_type] || graphImages.Unknown, @@ -774,13 +775,13 @@ export const buildGraphData = (objects, graphData, t) => { ? '-' : dateFormat(n.stop_time || n.last_seen) }` - : defaultValue(n) + : getMainRepresentative(n) }\n${dateFormat(defaultDate(n))}`, defaultDate: jsDate(defaultDate(n)), label: n.parent_types.includes('basic-relationship') ? t(`relationship_${n.relationship_type}`) : truncate( - defaultValue(n), + getMainRepresentative(n), n.entity_type === 'Attack-Pattern' ? 30 : 20, ), img: diff --git a/opencti-platform/opencti-front/src/utils/defaultRepresentatives.ts b/opencti-platform/opencti-front/src/utils/defaultRepresentatives.ts index d95313460e8b..7a27d0e34a7f 100644 --- a/opencti-platform/opencti-front/src/utils/defaultRepresentatives.ts +++ b/opencti-platform/opencti-front/src/utils/defaultRepresentatives.ts @@ -4,7 +4,10 @@ import { isDateStringNone } from '../components/i18n'; import { truncate } from './String'; import { dateFormat } from './Time'; -export const isFieldForIdentifier = (fieldName: string) => { +export const isFieldForIdentifier = (fieldName?: string) => { + if (!fieldName) { + return false; + } return fieldName === 'id' || fieldName.endsWith('.id') || fieldName.endsWith('_id') @@ -86,7 +89,8 @@ export const defaultKey = (n: any) => { return null; }; -export const defaultValue = (n: any, fallback = 'Unknown') => { +// equivalent to querying representative.main +export const getMainRepresentative = (n: any, fallback = 'Unknown') => { if (!n) return ''; if (typeof n.definition === 'object') { return defaultValueMarking(n); @@ -119,21 +123,23 @@ export const defaultValue = (n: any, fallback = 'Unknown') => { n.target_ref_name, 20, )}`) - || defaultValue((R.head(R.pathOr([], ['objects', 'edges'], n)) as any)?.node) + || getMainRepresentative((R.head(R.pathOr([], ['objects', 'edges'], n)) as any)?.node) || (n.from && n.to - && `${truncate(defaultValue(n.from), 20)} ➡️ ${truncate( - defaultValue(n.to), + && `${truncate(getMainRepresentative(n.from), 20)} ➡️ ${truncate( + getMainRepresentative(n.to), 20, )}`) || fallback; return n.x_mitre_id ? `[${n.x_mitre_id}] ${mainValue}` : mainValue; }; -export const defaultSecondaryValue = (n: any) => { +// equivalent to querying representative.secondary +export const getSecondaryRepresentative = (n: any) => { if (!n) return ''; return ( - n.description + n.representative?.secondary + || n.description || n.x_opencti_description || n.content || n.entity_type diff --git a/opencti-platform/opencti-front/src/utils/filters/useSearchEntities.tsx b/opencti-platform/opencti-front/src/utils/filters/useSearchEntities.tsx index a92aca7a451b..e3d28e912474 100644 --- a/opencti-platform/opencti-front/src/utils/filters/useSearchEntities.tsx +++ b/opencti-platform/opencti-front/src/utils/filters/useSearchEntities.tsx @@ -30,7 +30,7 @@ import { NotifierFieldSearchQuery$data } from '@components/common/form/__generat import useAuth, { FilterDefinition } from '../hooks/useAuth'; import { useSearchEntitiesStixCoreObjectsSearchQuery$data } from './__generated__/useSearchEntitiesStixCoreObjectsSearchQuery.graphql'; import { useFormatter } from '../../components/i18n'; -import { defaultValue } from '../defaultRepresentatives'; +import { getMainRepresentative } from '../defaultRepresentatives'; import { fetchQuery } from '../../relay/environment'; import { useSearchEntitiesSchemaSCOSearchQuery$data } from './__generated__/useSearchEntitiesSchemaSCOSearchQuery.graphql'; import type { Theme } from '../../components/Theme'; @@ -438,7 +438,7 @@ const useSearchEntities = ({ const elementIdEntities = ( (data as useSearchEntitiesStixCoreObjectsSearchQuery$data)?.stixCoreObjects?.edges ?? [] ).map((n) => ({ - label: defaultValue(n?.node), + label: getMainRepresentative(n?.node), value: n?.node.id, type: n?.node.entity_type, parentTypes: n?.node.parent_types, diff --git a/opencti-platform/opencti-front/src/utils/graph/EntityDetails.tsx b/opencti-platform/opencti-front/src/utils/graph/EntityDetails.tsx index 44f6545f2be9..7e5084c0b709 100644 --- a/opencti-platform/opencti-front/src/utils/graph/EntityDetails.tsx +++ b/opencti-platform/opencti-front/src/utils/graph/EntityDetails.tsx @@ -21,7 +21,7 @@ import type { SelectedEntity } from './EntitiesDetailsRightBar'; import ErrorNotFound from '../../components/ErrorNotFound'; import ItemIcon from '../../components/ItemIcon'; import type { Theme } from '../../components/Theme'; -import { defaultValue } from '../defaultRepresentatives'; +import { getMainRepresentative } from '../defaultRepresentatives'; import { hexToRGB, itemColor } from '../Colors'; import { truncate } from '../String'; import ItemCreators from '../../components/ItemCreators'; @@ -322,8 +322,8 @@ EntityDetailsComponentProps {t_i18n('Value')} - - {truncate(defaultValue(stixCoreObject), 40)} + + {truncate(getMainRepresentative(stixCoreObject), 40)} {t_i18n('Type')} diff --git a/opencti-platform/opencti-front/src/utils/graph/RelationShipFromAndTo.tsx b/opencti-platform/opencti-front/src/utils/graph/RelationShipFromAndTo.tsx index 6cfd60da0959..2e71eebe0a21 100644 --- a/opencti-platform/opencti-front/src/utils/graph/RelationShipFromAndTo.tsx +++ b/opencti-platform/opencti-front/src/utils/graph/RelationShipFromAndTo.tsx @@ -7,7 +7,7 @@ import { useFormatter } from '../../components/i18n'; import useQueryLoading from '../hooks/useQueryLoading'; import { RelationShipFromAndToQuery } from './__generated__/RelationShipFromAndToQuery.graphql'; import { truncate } from '../String'; -import { defaultValue } from '../defaultRepresentatives'; +import { getMainRepresentative } from '../defaultRepresentatives'; const useStyles = makeStyles(() => ({ label: { @@ -20,6 +20,11 @@ const relationShipFromAndToQuery = graphql` stixCoreObject(id: $id) { id entity_type + ... on StixObject { + representative { + main + } + } ... on StixDomainObject { created } @@ -152,8 +157,8 @@ RelationShipFromAndToComponentProps {t_i18n(direction === 'From' ? 'Source' : 'Target')} - - {truncate(defaultValue(stixCoreObject), 40)} + + {truncate(getMainRepresentative(stixCoreObject), 40)} ); diff --git a/opencti-platform/opencti-front/src/utils/graph/StixMetaObjectDetails.tsx b/opencti-platform/opencti-front/src/utils/graph/StixMetaObjectDetails.tsx index 65472ae50eef..2de36eeee6a0 100644 --- a/opencti-platform/opencti-front/src/utils/graph/StixMetaObjectDetails.tsx +++ b/opencti-platform/opencti-front/src/utils/graph/StixMetaObjectDetails.tsx @@ -9,7 +9,7 @@ import useQueryLoading from '../hooks/useQueryLoading'; import Loader, { LoaderVariant } from '../../components/Loader'; import type { SelectedEntity } from './EntitiesDetailsRightBar'; import ErrorNotFound from '../../components/ErrorNotFound'; -import { defaultValue } from '../defaultRepresentatives'; +import { getMainRepresentative } from '../defaultRepresentatives'; import { hexToRGB, itemColor } from '../Colors'; import { truncate } from '../String'; import ItemCreators from '../../components/ItemCreators'; @@ -97,15 +97,15 @@ StixMetaObjectDetailsComponentProps {t_i18n('Value')} {stixMetaObject.entity_type === 'Marking-Definition' ? ( - + ) : ( - - {truncate(defaultValue(stixMetaObject), 40)} + + {truncate(getMainRepresentative(stixMetaObject), 40)} )} diff --git a/opencti-platform/opencti-front/src/utils/hooks/useDistributionGraphData.ts b/opencti-platform/opencti-front/src/utils/hooks/useDistributionGraphData.ts new file mode 100644 index 000000000000..7b3033952fbd --- /dev/null +++ b/opencti-platform/opencti-front/src/utils/hooks/useDistributionGraphData.ts @@ -0,0 +1,133 @@ +import { useTheme } from '@mui/material/styles'; +import { useFormatter } from '../../components/i18n'; +import { getMainRepresentative, isFieldForIdentifier } from '../defaultRepresentatives'; +import { itemColor } from '../Colors'; + +// common type compatible with all distribution queries +type DistributionNode = { + readonly label: string, + readonly value?: number | null, + + readonly entity?: { + readonly entity_type?: string, + readonly id?: string, + // when colors are requested from Labels, Markings or Status for instance + readonly color?: string | null, + readonly x_opencti_color?: string | null, + readonly template?: { + readonly color?: string | null + } | null + // workspaces + readonly type?: string, + } | null, +}; + +type DistributionQueryData = ReadonlyArray; + +type Selection = { + attribute?: string, + label?: string, +}; + +const useDistributionGraphData = () => { + const { t_i18n } = useFormatter(); + const theme = useTheme(); + + const getColorFromDistributionNode = (n: DistributionNode, selection: Selection) => { + let color = isFieldForIdentifier(selection.attribute) + ? itemColor(n.entity?.entity_type) + : itemColor(n.label); + if (n.entity?.color) { + color = theme.palette.mode === 'light' && n.entity.color === '#ffffff' + ? '#000000' + : n.entity.color; + } + if (n.entity?.x_opencti_color) { + color = theme.palette.mode === 'light' + && n.entity.x_opencti_color === '#ffffff' + ? '#000000' + : n.entity.x_opencti_color; + } + if (n.entity?.template?.color) { + color = theme.palette.mode === 'light' + && n.entity.template.color === '#ffffff' + ? '#000000' + : n.entity.template.color; + } + + return color; + }; + + const buildDistributionGraphData = (distributionData: DistributionQueryData, selection: Selection) => { + return distributionData.map((n) => { + if (!n) return { x: 'Unknown', y: 'Unknown' }; + let { label } = n; + if (isFieldForIdentifier(selection.attribute)) { + label = getMainRepresentative(n.entity) || n.label; + } else if (selection.attribute === 'entity_type' && t_i18n(`entity_${n.label}`) !== `entity_${n.label}`) { + label = t_i18n(`entity_${n.label}`); + } + return { + x: label, + y: n.value, + fillColor: getColorFromDistributionNode(n, selection), + }; + }); + }; + + const buildDistributionRedirectionUtils = (distributionData: DistributionQueryData, selection: Selection) => { + // only build redirections on names distribution + if (selection.attribute === 'name') { + return distributionData.flatMap((n) => { + if (!n || !n.entity) return []; + return { + id: n.entity.id, + entity_type: n.entity?.entity_type === 'Workspace' ? n.entity.type : n.entity.entity_type, + }; + }); + } + return undefined; + }; + + /** + * Conveniently build the series (chart data) and redirectionUtils props for a Widget + * from the distribution query results and the selection config. + * @param distributionData + * @param selection + * @param defaultGraphLabel + */ + const buildWidgetProps = (distributionData: DistributionQueryData, selection: Selection, defaultGraphLabel: string) => { + return { + series: [{ + name: selection.label || t_i18n(defaultGraphLabel), + data: buildDistributionGraphData(distributionData, selection), + }], + redirectionUtils: buildDistributionRedirectionUtils(distributionData, selection), + }; + }; + + /** + * Build from query data the labels to use in the graph. + * @param distributionData + * @param groupBy + */ + const buildWidgetLabelsOption = (distributionData: DistributionQueryData, groupBy: string) => { + return distributionData.map((n) => { + if (!n) return 'Unknown'; + if (isFieldForIdentifier(groupBy)) { + return getMainRepresentative(n.entity); + } + if (groupBy === 'entity_type' && t_i18n(`entity_${n.label}`) !== `entity_${n.label}`) { + return t_i18n(`entity_${n.label}`); + } + return n.label; + }); + }; + + return { + buildWidgetProps, + buildWidgetLabelsOption, + }; +}; + +export default useDistributionGraphData; diff --git a/opencti-platform/opencti-graphql/src/database/engine.js b/opencti-platform/opencti-graphql/src/database/engine.js index 6c4f6e71f2dd..3c2696a9b8b3 100644 --- a/opencti-platform/opencti-graphql/src/database/engine.js +++ b/opencti-platform/opencti-graphql/src/database/engine.js @@ -2698,7 +2698,7 @@ const buildAggregationRelationFilters = async (context, user, aggregationFilters export const elAggregationRelationsCount = async (context, user, indexName, options = {}) => { const { types = [], field = null, searchOptions, aggregationOptions, aggregateOnConnections = true } = options; if (!R.includes(field, ['entity_type', 'internal_id', 'rel_object-marking.internal_id', 'rel_kill-chain-phase.internal_id', 'creator_id', 'rel_created-by.internal_id', null])) { - throw FunctionalError('Aggregation computing use and unsupported field', { field }); + throw FunctionalError('Aggregation computing use an unsupported field', { field }); } const body = await elQueryBodyBuilder(context, user, { ...searchOptions, noSize: true, noSort: true }); const aggregationFilters = await buildAggregationRelationFilters(context, user, aggregationOptions); diff --git a/opencti-platform/opencti-graphql/src/database/middleware.js b/opencti-platform/opencti-graphql/src/database/middleware.js index 77f92c67dee5..0416d4e13a1e 100644 --- a/opencti-platform/opencti-graphql/src/database/middleware.js +++ b/opencti-platform/opencti-graphql/src/database/middleware.js @@ -450,18 +450,22 @@ export const stixLoadByFilters = async (context, user, types, args) => { // region Graphics const convertAggregateDistributions = async (context, user, limit, orderingFunction, distribution) => { const data = R.take(limit, R.sortWith([orderingFunction(R.prop('value'))])(distribution)); - // resolve all of them, limited to ids for comparison in next step + // resolve all of them with system user const allResolveLabels = await elFindByIds(context, SYSTEM_USER, data.map((d) => d.label), { toMap: true }); // entities not granted shall be sent as "restricted" with limited information return data + // filter out unresolved data (like the SYSTEM user for instance) .filter((n) => isNotEmptyField(allResolveLabels[n.label.toLowerCase()])) .map((n) => { const element = allResolveLabels[n.label.toLowerCase()]; if (isUserCanAccessStoreElement(context, user, element)) { return R.assoc('entity', element, n); } - // return R.assoc('entity', { id: n.label, entity_type: n.entity_type, name: 'Restricted' }, n); - return n; // no entity details + return R.assoc('entity', { + id: n.label, + entity_type: n.entity_type, + representative: { main: 'Restricted', secondary: 'Restricted' } + }, n); }); }; export const timeSeriesHistory = async (context, user, types, args) => { From 3b336979f3a7077ac08ea8ba558d52c88f8bb92f Mon Sep 17 00:00:00 2001 From: Laurent Bonnet Date: Wed, 3 Apr 2024 11:54:26 +0200 Subject: [PATCH 09/14] [backend/frontend] fix restricted representative --- .../dashboard/WidgetDistributionList.tsx | 4 +-- .../src/database/entity-representative.js | 5 +++ .../src/database/middleware.js | 31 ++++++++++++++----- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/opencti-platform/opencti-front/src/components/dashboard/WidgetDistributionList.tsx b/opencti-platform/opencti-front/src/components/dashboard/WidgetDistributionList.tsx index 0e5917dee8e5..81a6c6bf3e54 100644 --- a/opencti-platform/opencti-front/src/components/dashboard/WidgetDistributionList.tsx +++ b/opencti-platform/opencti-front/src/components/dashboard/WidgetDistributionList.tsx @@ -52,7 +52,7 @@ const WidgetDistributionList = ({ id: entry.id, entity_type: entry.type, }; - link = entry.id ? computeLink(node) : null; + link = entry.id && entry.label !== 'Restricted' ? computeLink(node) : null; } let linkProps = {}; if (link) { @@ -64,7 +64,7 @@ const WidgetDistributionList = ({ return ( { // -- ENTITY | RELATIONSHIP export const extractRepresentative = (entityData) => { + // the representative can already be given (happens when the internals set it to "Restricted") + if (entityData.representative) { + return entityData.representative; + } + // otherwise we find extract it depending on the entity type if (isStixRelationship(entityData.entity_type)) { return extractRelationshipRepresentative(entityData); } diff --git a/opencti-platform/opencti-graphql/src/database/middleware.js b/opencti-platform/opencti-graphql/src/database/middleware.js index 0416d4e13a1e..6ca10d4d7a47 100644 --- a/opencti-platform/opencti-graphql/src/database/middleware.js +++ b/opencti-platform/opencti-graphql/src/database/middleware.js @@ -453,19 +453,34 @@ const convertAggregateDistributions = async (context, user, limit, orderingFunct // resolve all of them with system user const allResolveLabels = await elFindByIds(context, SYSTEM_USER, data.map((d) => d.label), { toMap: true }); // entities not granted shall be sent as "restricted" with limited information + const grantedIds = []; + for (let i = 0; i < data.length; i += 1) { + const resolved = allResolveLabels[data[i].label.toLowerCase()]; + const canAccess = await isUserCanAccessStoreElement(context, user, resolved); + if (canAccess) { + grantedIds.push(data[i].label.toLowerCase()); + } + } return data // filter out unresolved data (like the SYSTEM user for instance) .filter((n) => isNotEmptyField(allResolveLabels[n.label.toLowerCase()])) .map((n) => { const element = allResolveLabels[n.label.toLowerCase()]; - if (isUserCanAccessStoreElement(context, user, element)) { - return R.assoc('entity', element, n); - } - return R.assoc('entity', { - id: n.label, - entity_type: n.entity_type, - representative: { main: 'Restricted', secondary: 'Restricted' } - }, n); + if (grantedIds.includes(n.label.toLowerCase())) { + return { + ...n, + entity: element + }; + } + return { + ...n, + entity: { + id: element.id, + entity_type: element.entity_type, + parent_types: element.parent_types, + representative: { main: 'Restricted', secondary: 'Restricted' } + } + }; }); }; export const timeSeriesHistory = async (context, user, types, args) => { From 312b0fce7a4ccfc059e20e183ecb32fdbb551b4b Mon Sep 17 00:00:00 2001 From: Laurent Bonnet Date: Wed, 3 Apr 2024 12:14:43 +0200 Subject: [PATCH 10/14] [frontend] use representative --- .../reports/StixCoreObjectReportsHorizontalBars.jsx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/opencti-platform/opencti-front/src/private/components/analyses/reports/StixCoreObjectReportsHorizontalBars.jsx b/opencti-platform/opencti-front/src/private/components/analyses/reports/StixCoreObjectReportsHorizontalBars.jsx index 8c87df94f5ba..16f93bd7ccbf 100644 --- a/opencti-platform/opencti-front/src/private/components/analyses/reports/StixCoreObjectReportsHorizontalBars.jsx +++ b/opencti-platform/opencti-front/src/private/components/analyses/reports/StixCoreObjectReportsHorizontalBars.jsx @@ -12,6 +12,7 @@ import { QueryRenderer } from '../../../../relay/environment'; import inject18n from '../../../../components/i18n'; import { horizontalBarsChartOptions } from '../../../../utils/Charts'; import { simpleNumberFormat } from '../../../../utils/Number'; +import { getMainRepresentative } from '../../../../utils/defaultRepresentatives'; const styles = () => ({ paper: { @@ -40,8 +41,10 @@ const stixCoreObjectReportsHorizontalBarsDistributionQuery = graphql` label value entity { - ... on Identity { - name + ... on StixObject { + representative { + main + } } } } @@ -68,7 +71,7 @@ class StixCoreObjectReportsHorizontalBars extends Component { && props.reportsDistribution.length > 0 ) { const data = props.reportsDistribution.map((n) => ({ - x: n.entity?.name ?? 'Restricted', + x: getMainRepresentative(n.entity) || n.label, y: n.value, })); const chartData = [{ name: t('Number of reports'), data }]; From 2c306f95ab8cea0b35364dbc41a3c01c38646c0a Mon Sep 17 00:00:00 2001 From: Laurent Bonnet Date: Wed, 3 Apr 2024 12:15:03 +0200 Subject: [PATCH 11/14] [frontend] remove dead code --- .../indicators/IndicatorsAreaChart.jsx | 167 ---------------- .../indicators/IndicatorsDonut.jsx | 168 ---------------- .../indicators/IndicatorsHorizontalBars.jsx | 166 ---------------- .../indicators/IndicatorsVerticalBars.jsx | 167 ---------------- .../StixCoreObjectIndicatorsAreaChart.jsx | 182 ------------------ .../StixCoreObjectIndicatorsDonut.jsx | 148 -------------- ...StixCoreObjectIndicatorsHorizontalBars.jsx | 162 ---------------- .../StixCoreObjectIndicatorsVerticalBars.jsx | 182 ------------------ 8 files changed, 1342 deletions(-) delete mode 100644 opencti-platform/opencti-front/src/private/components/observations/indicators/IndicatorsAreaChart.jsx delete mode 100644 opencti-platform/opencti-front/src/private/components/observations/indicators/IndicatorsDonut.jsx delete mode 100644 opencti-platform/opencti-front/src/private/components/observations/indicators/IndicatorsHorizontalBars.jsx delete mode 100644 opencti-platform/opencti-front/src/private/components/observations/indicators/IndicatorsVerticalBars.jsx delete mode 100644 opencti-platform/opencti-front/src/private/components/observations/indicators/StixCoreObjectIndicatorsAreaChart.jsx delete mode 100644 opencti-platform/opencti-front/src/private/components/observations/indicators/StixCoreObjectIndicatorsDonut.jsx delete mode 100644 opencti-platform/opencti-front/src/private/components/observations/indicators/StixCoreObjectIndicatorsHorizontalBars.jsx delete mode 100644 opencti-platform/opencti-front/src/private/components/observations/indicators/StixCoreObjectIndicatorsVerticalBars.jsx diff --git a/opencti-platform/opencti-front/src/private/components/observations/indicators/IndicatorsAreaChart.jsx b/opencti-platform/opencti-front/src/private/components/observations/indicators/IndicatorsAreaChart.jsx deleted file mode 100644 index 61d1d4beef9b..000000000000 --- a/opencti-platform/opencti-front/src/private/components/observations/indicators/IndicatorsAreaChart.jsx +++ /dev/null @@ -1,167 +0,0 @@ -import React, { Component } from 'react'; -import * as PropTypes from 'prop-types'; -import { compose } from 'ramda'; -import { graphql } from 'react-relay'; -import withStyles from '@mui/styles/withStyles'; -import withTheme from '@mui/styles/withTheme'; -import CircularProgress from '@mui/material/CircularProgress'; -import Paper from '@mui/material/Paper'; -import Typography from '@mui/material/Typography'; -import Chart from '../../common/charts/Chart'; -import { QueryRenderer } from '../../../../relay/environment'; -import inject18n from '../../../../components/i18n'; -import { monthsAgo, now } from '../../../../utils/Time'; -import { areaChartOptions } from '../../../../utils/Charts'; -import { simpleNumberFormat } from '../../../../utils/Number'; - -const styles = () => ({ - paper: { - minHeight: 280, - height: '100%', - margin: '4px 0 0 0', - padding: '0 0 10px 0', - borderRadius: 4, - }, - chip: { - fontSize: 10, - height: 20, - marginLeft: 10, - }, -}); - -const indicatorsAreaChartTimeSeriesQuery = graphql` - query IndicatorsAreaChartTimeSeriesQuery( - $field: String! - $operation: StatsOperation! - $startDate: DateTime! - $endDate: DateTime! - $interval: String! - ) { - indicatorsTimeSeries( - field: $field - operation: $operation - startDate: $startDate - endDate: $endDate - interval: $interval - ) { - date - value - } - } -`; - -class IndicatorsAreaChart extends Component { - renderContent() { - const { t, fsd, indicatorType, startDate, endDate, theme } = this.props; - const interval = 'day'; - const finalStartDate = startDate || monthsAgo(12); - const finalEndDate = endDate || now(); - const indicatorsTimeSeriesVariables = { - indicatorType: indicatorType || null, - field: 'created_at', - operation: 'count', - startDate: finalStartDate, - endDate: finalEndDate, - interval, - }; - return ( - { - if (props && props.indicatorsTimeSeries) { - const chartData = props.indicatorsTimeSeries.map((entry) => ({ - x: new Date(entry.date), - y: entry.value, - })); - return ( - - ); - } - if (props) { - return ( -
- - {t('No entities of this type has been found.')} - -
- ); - } - return ( -
- - - -
- ); - }} - /> - ); - } - - render() { - const { t, classes, title, variant, height } = this.props; - return ( -
- - {title || t('Indicators distribution')} - - {variant !== 'inLine' ? ( - - {this.renderContent()} - - ) : ( - this.renderContent() - )} -
- ); - } -} - -IndicatorsAreaChart.propTypes = { - classes: PropTypes.object, - theme: PropTypes.object, - t: PropTypes.func, - md: PropTypes.func, -}; - -export default compose( - inject18n, - withTheme, - withStyles(styles), -)(IndicatorsAreaChart); diff --git a/opencti-platform/opencti-front/src/private/components/observations/indicators/IndicatorsDonut.jsx b/opencti-platform/opencti-front/src/private/components/observations/indicators/IndicatorsDonut.jsx deleted file mode 100644 index e2c10865d517..000000000000 --- a/opencti-platform/opencti-front/src/private/components/observations/indicators/IndicatorsDonut.jsx +++ /dev/null @@ -1,168 +0,0 @@ -import React, { Component } from 'react'; -import * as PropTypes from 'prop-types'; -import { assoc, compose, map } from 'ramda'; -import { graphql } from 'react-relay'; -import withTheme from '@mui/styles/withTheme'; -import withStyles from '@mui/styles/withStyles'; -import CircularProgress from '@mui/material/CircularProgress'; -import Paper from '@mui/material/Paper'; -import Typography from '@mui/material/Typography'; -import Chart from '../../common/charts/Chart'; -import { QueryRenderer } from '../../../../relay/environment'; -import inject18n from '../../../../components/i18n'; -import { donutChartOptions } from '../../../../utils/Charts'; - -const styles = () => ({ - paper: { - height: 300, - minHeight: 300, - maxHeight: 300, - margin: '10px 0 0 0', - padding: 0, - borderRadius: 4, - }, -}); - -const indicatorsDonutDistributionQuery = graphql` - query IndicatorsDonutDistributionQuery( - $field: String! - $operation: StatsOperation! - $limit: Int - $startDate: DateTime - $endDate: DateTime - ) { - indicatorsDistribution( - field: $field - operation: $operation - limit: $limit - startDate: $startDate - endDate: $endDate - ) { - label - value - entity { - ... on Identity { - name - } - } - } - } -`; - -class IndicatorsDonut extends Component { - renderContent() { - const { t, field, startDate, endDate, theme } = this.props; - const indicatorsDistributionVariables = { - field: field || 'pattern_type', - operation: 'count', - limit: 8, - startDate, - endDate, - }; - return ( - { - if ( - props - && props.indicatorsDistribution - && props.indicatorsDistribution.length > 0 - ) { - let data = props.indicatorsDistribution; - if (field && field.includes('internal_id')) { - data = map( - (n) => assoc('label', n.entity?.name ?? 'Restricted', n), - props.indicatorsDistribution, - ); - } - const chartData = data.map((n) => n.value); - const labels = data.map((n) => n.label); - return ( - - ); - } - if (props) { - return ( -
- - {t('No entities of this type has been found.')} - -
- ); - } - return ( -
- - - -
- ); - }} - /> - ); - } - - render() { - const { t, classes, title, variant, height } = this.props; - return ( -
- - {title || t('Indicators distribution')} - - {variant !== 'inLine' ? ( - - {this.renderContent()} - - ) : ( - this.renderContent() - )} -
- ); - } -} - -IndicatorsDonut.propTypes = { - title: PropTypes.string, - field: PropTypes.string, - startDate: PropTypes.string, - endDate: PropTypes.string, - classes: PropTypes.object, - theme: PropTypes.object, - t: PropTypes.func, -}; - -export default compose( - inject18n, - withTheme, - withStyles(styles), -)(IndicatorsDonut); diff --git a/opencti-platform/opencti-front/src/private/components/observations/indicators/IndicatorsHorizontalBars.jsx b/opencti-platform/opencti-front/src/private/components/observations/indicators/IndicatorsHorizontalBars.jsx deleted file mode 100644 index 81bf73ce9330..000000000000 --- a/opencti-platform/opencti-front/src/private/components/observations/indicators/IndicatorsHorizontalBars.jsx +++ /dev/null @@ -1,166 +0,0 @@ -import React, { Component } from 'react'; -import * as PropTypes from 'prop-types'; -import { compose } from 'ramda'; -import { graphql } from 'react-relay'; -import withTheme from '@mui/styles/withTheme'; -import withStyles from '@mui/styles/withStyles'; -import CircularProgress from '@mui/material/CircularProgress'; -import Paper from '@mui/material/Paper'; -import Typography from '@mui/material/Typography'; -import Chart from '../../common/charts/Chart'; -import { QueryRenderer } from '../../../../relay/environment'; -import inject18n from '../../../../components/i18n'; -import { horizontalBarsChartOptions } from '../../../../utils/Charts'; -import { simpleNumberFormat } from '../../../../utils/Number'; - -const styles = () => ({ - paper: { - height: 300, - minHeight: 300, - maxHeight: 300, - margin: '10px 0 0 0', - padding: 0, - borderRadius: 4, - }, -}); - -const indicatorsHorizontalBarsDistributionQuery = graphql` - query IndicatorsHorizontalBarsDistributionQuery( - $field: String! - $operation: StatsOperation! - $limit: Int - $startDate: DateTime - $endDate: DateTime - ) { - indicatorsDistribution( - field: $field - operation: $operation - limit: $limit - startDate: $startDate - endDate: $endDate - ) { - label - value - entity { - ... on Indicator { - name - } - } - } - } -`; - -class IndicatorsHorizontalBars extends Component { - renderContent() { - const { t, field, startDate, endDate, theme } = this.props; - const indicatorsDistributionVariables = { - field: field || 'pattern_type', - operation: 'count', - limit: 8, - startDate, - endDate, - }; - return ( - { - if ( - props - && props.indicatorsDistribution - && props.indicatorsDistribution.length > 0 - ) { - const data = props.indicatorsDistribution.map((n) => ({ - x: n.label, - y: n.value, - })); - const chartData = [{ name: t('Number of indicators'), data }]; - return ( - - ); - } - if (props) { - return ( -
- - {t('No entities of this type has been found.')} - -
- ); - } - return ( -
- - - -
- ); - }} - /> - ); - } - - render() { - const { t, classes, title, variant, height } = this.props; - return ( -
- - {title || t('Indicators distribution')} - - {variant !== 'inLine' ? ( - - {this.renderContent()} - - ) : ( - this.renderContent() - )} -
- ); - } -} - -IndicatorsHorizontalBars.propTypes = { - title: PropTypes.string, - field: PropTypes.string, - startDate: PropTypes.string, - endDate: PropTypes.string, - classes: PropTypes.object, - theme: PropTypes.object, - t: PropTypes.func, -}; - -export default compose( - inject18n, - withTheme, - withStyles(styles), -)(IndicatorsHorizontalBars); diff --git a/opencti-platform/opencti-front/src/private/components/observations/indicators/IndicatorsVerticalBars.jsx b/opencti-platform/opencti-front/src/private/components/observations/indicators/IndicatorsVerticalBars.jsx deleted file mode 100644 index 2ec7666b7363..000000000000 --- a/opencti-platform/opencti-front/src/private/components/observations/indicators/IndicatorsVerticalBars.jsx +++ /dev/null @@ -1,167 +0,0 @@ -import React, { Component } from 'react'; -import * as PropTypes from 'prop-types'; -import { compose } from 'ramda'; -import { graphql } from 'react-relay'; -import withTheme from '@mui/styles/withTheme'; -import withStyles from '@mui/styles/withStyles'; -import CircularProgress from '@mui/material/CircularProgress'; -import Paper from '@mui/material/Paper'; -import Typography from '@mui/material/Typography'; -import Chart from '../../common/charts/Chart'; -import { QueryRenderer } from '../../../../relay/environment'; -import inject18n from '../../../../components/i18n'; -import { monthsAgo, now } from '../../../../utils/Time'; -import { verticalBarsChartOptions } from '../../../../utils/Charts'; -import { simpleNumberFormat } from '../../../../utils/Number'; - -const styles = () => ({ - paper: { - minHeight: 280, - height: '100%', - margin: '4px 0 0 0', - padding: '0 0 10px 0', - borderRadius: 4, - }, - chip: { - fontSize: 10, - height: 20, - marginLeft: 10, - }, -}); - -const reporstVerticalBarsTimeSeriesQuery = graphql` - query IndicatorsVerticalBarsTimeSeriesQuery( - $field: String! - $operation: StatsOperation! - $startDate: DateTime! - $endDate: DateTime! - $interval: String! - ) { - indicatorsTimeSeries( - field: $field - operation: $operation - startDate: $startDate - endDate: $endDate - interval: $interval - ) { - date - value - } - } -`; - -class IndicatorsVerticalBars extends Component { - renderContent() { - const { t, fsd, indicatorType, startDate, endDate, theme } = this.props; - const interval = 'day'; - const finalStartDate = startDate || monthsAgo(12); - const finalEndDate = endDate || now(); - const indicatorsTimeSeriesVariables = { - indicatorType: indicatorType || null, - field: 'created_at', - operation: 'count', - startDate: finalStartDate, - endDate: finalEndDate, - interval, - }; - return ( - { - if (props && props.indicatorsTimeSeries) { - const chartData = props.indicatorsTimeSeries.map((entry) => ({ - x: new Date(entry.date), - y: entry.value, - })); - return ( - - ); - } - if (props) { - return ( -
- - {t('No entities of this type has been found.')} - -
- ); - } - return ( -
- - - -
- ); - }} - /> - ); - } - - render() { - const { t, classes, title, variant, height } = this.props; - return ( -
- - {title || t('Indicators history')} - - {variant !== 'inLine' ? ( - - {this.renderContent()} - - ) : ( - this.renderContent() - )} -
- ); - } -} - -IndicatorsVerticalBars.propTypes = { - classes: PropTypes.object, - theme: PropTypes.object, - t: PropTypes.func, - md: PropTypes.func, -}; - -export default compose( - inject18n, - withTheme, - withStyles(styles), -)(IndicatorsVerticalBars); diff --git a/opencti-platform/opencti-front/src/private/components/observations/indicators/StixCoreObjectIndicatorsAreaChart.jsx b/opencti-platform/opencti-front/src/private/components/observations/indicators/StixCoreObjectIndicatorsAreaChart.jsx deleted file mode 100644 index 6f694f5bb923..000000000000 --- a/opencti-platform/opencti-front/src/private/components/observations/indicators/StixCoreObjectIndicatorsAreaChart.jsx +++ /dev/null @@ -1,182 +0,0 @@ -import React, { Component } from 'react'; -import * as PropTypes from 'prop-types'; -import { compose } from 'ramda'; -import { graphql } from 'react-relay'; -import withTheme from '@mui/styles/withTheme'; -import withStyles from '@mui/styles/withStyles'; -import CircularProgress from '@mui/material/CircularProgress'; -import Paper from '@mui/material/Paper'; -import Typography from '@mui/material/Typography'; -import Chart from '../../common/charts/Chart'; -import { QueryRenderer } from '../../../../relay/environment'; -import inject18n from '../../../../components/i18n'; -import { monthsAgo, now } from '../../../../utils/Time'; -import { areaChartOptions } from '../../../../utils/Charts'; -import { simpleNumberFormat } from '../../../../utils/Number'; - -const styles = () => ({ - paper: { - minHeight: 280, - height: '100%', - margin: '4px 0 0 0', - padding: '0 0 10px 0', - borderRadius: 4, - }, - chip: { - fontSize: 10, - height: 20, - marginLeft: 10, - }, -}); - -const stixCoreObjectIndicatorsAreaChartTimeSeriesQuery = graphql` - query StixCoreObjectIndicatorsAreaChartTimeSeriesQuery( - $objectId: String - $field: String! - $operation: StatsOperation! - $startDate: DateTime! - $endDate: DateTime! - $interval: String! - ) { - indicatorsTimeSeries( - objectId: $objectId - field: $field - operation: $operation - startDate: $startDate - endDate: $endDate - interval: $interval - ) { - date - value - } - } -`; - -class StixCoreObjectIndicatorsAreaChart extends Component { - renderContent() { - const { - t, - fsd, - indicatorType, - startDate, - endDate, - dateAttribute, - stixCoreObjectId, - theme, - } = this.props; - const interval = 'day'; - const finalStartDate = startDate || monthsAgo(12); - const finalEndDate = endDate || now(); - const indicatorsTimeSeriesVariables = { - authorId: null, - objectId: stixCoreObjectId, - indicatorType: indicatorType || null, - field: dateAttribute, - operation: 'count', - startDate: finalStartDate, - endDate: finalEndDate, - interval, - }; - return ( - { - if (props && props.indicatorsTimeSeries) { - const chartData = props.indicatorsTimeSeries.map((entry) => ({ - x: new Date(entry.date), - y: entry.value, - })); - return ( - - ); - } - if (props) { - return ( -
- - {t('No entities of this type has been found.')} - -
- ); - } - return ( -
- - - -
- ); - }} - /> - ); - } - - render() { - const { t, classes, title, variant, height } = this.props; - return ( -
- - {title || t('Indicators history')} - - {variant !== 'inLine' ? ( - - {this.renderContent()} - - ) : ( - this.renderContent() - )} -
- ); - } -} - -StixCoreObjectIndicatorsAreaChart.propTypes = { - classes: PropTypes.object, - theme: PropTypes.object, - stixCoreObjectId: PropTypes.string, - dateAttribute: PropTypes.string, - t: PropTypes.func, - md: PropTypes.func, -}; - -export default compose( - inject18n, - withTheme, - withStyles(styles), -)(StixCoreObjectIndicatorsAreaChart); diff --git a/opencti-platform/opencti-front/src/private/components/observations/indicators/StixCoreObjectIndicatorsDonut.jsx b/opencti-platform/opencti-front/src/private/components/observations/indicators/StixCoreObjectIndicatorsDonut.jsx deleted file mode 100644 index 98865f033979..000000000000 --- a/opencti-platform/opencti-front/src/private/components/observations/indicators/StixCoreObjectIndicatorsDonut.jsx +++ /dev/null @@ -1,148 +0,0 @@ -import React, { Component } from 'react'; -import * as PropTypes from 'prop-types'; -import { compose } from 'ramda'; -import { graphql } from 'react-relay'; -import withTheme from '@mui/styles/withTheme'; -import withStyles from '@mui/styles/withStyles'; -import CircularProgress from '@mui/material/CircularProgress'; -import Paper from '@mui/material/Paper'; -import Typography from '@mui/material/Typography'; -import Chart from '../../common/charts/Chart'; -import { QueryRenderer } from '../../../../relay/environment'; -import inject18n from '../../../../components/i18n'; -import { donutChartOptions } from '../../../../utils/Charts'; - -const styles = () => ({ - paper: { - height: 300, - minHeight: 300, - maxHeight: 300, - margin: '10px 0 0 0', - padding: 0, - borderRadius: 4, - }, -}); - -const stixCoreObjectIndicatorsDonutDistributionQuery = graphql` - query StixCoreObjectIndicatorsDonutDistributionQuery( - $objectId: String - $field: String! - $operation: StatsOperation! - $limit: Int - ) { - indicatorsDistribution( - objectId: $objectId - field: $field - operation: $operation - limit: $limit - ) { - label - value - } - } -`; - -class StixCoreObjectIndicatorsDonut extends Component { - renderContent() { - const { t, stixCoreObjectId, field, theme } = this.props; - const indicatorsDistributionVariables = { - objectId: stixCoreObjectId, - field: field || 'indicator_types', - operation: 'count', - limit: 8, - }; - return ( - { - if ( - props - && props.indicatorsDistribution - && props.indicatorsDistribution.length > 0 - ) { - const data = props.indicatorsDistribution; - const chartData = data.map((n) => n.value); - const labels = data.map((n) => n.label); - return ( - - ); - } - if (props) { - return ( -
- - {t('No entities of this type has been found.')} - -
- ); - } - return ( -
- - - -
- ); - }} - /> - ); - } - - render() { - const { t, classes, title, variant, height } = this.props; - return ( -
- - {title || t('Indicators distribution')} - - {variant !== 'inLine' ? ( - - {this.renderContent()} - - ) : ( - this.renderContent() - )} -
- ); - } -} - -StixCoreObjectIndicatorsDonut.propTypes = { - stixCoreObjectId: PropTypes.string, - title: PropTypes.string, - field: PropTypes.string, - classes: PropTypes.object, - theme: PropTypes.object, - t: PropTypes.func, -}; - -export default compose( - inject18n, - withTheme, - withStyles(styles), -)(StixCoreObjectIndicatorsDonut); diff --git a/opencti-platform/opencti-front/src/private/components/observations/indicators/StixCoreObjectIndicatorsHorizontalBars.jsx b/opencti-platform/opencti-front/src/private/components/observations/indicators/StixCoreObjectIndicatorsHorizontalBars.jsx deleted file mode 100644 index 2fe0b5433bab..000000000000 --- a/opencti-platform/opencti-front/src/private/components/observations/indicators/StixCoreObjectIndicatorsHorizontalBars.jsx +++ /dev/null @@ -1,162 +0,0 @@ -import React, { Component } from 'react'; -import * as PropTypes from 'prop-types'; -import { compose } from 'ramda'; -import { graphql } from 'react-relay'; -import withStyles from '@mui/styles/withStyles'; -import withTheme from '@mui/styles/withTheme'; -import CircularProgress from '@mui/material/CircularProgress'; -import Paper from '@mui/material/Paper'; -import Typography from '@mui/material/Typography'; -import Chart from '../../common/charts/Chart'; -import { QueryRenderer } from '../../../../relay/environment'; -import inject18n from '../../../../components/i18n'; -import { horizontalBarsChartOptions } from '../../../../utils/Charts'; -import { simpleNumberFormat } from '../../../../utils/Number'; - -const styles = () => ({ - paper: { - height: 300, - minHeight: 300, - maxHeight: 300, - margin: '10px 0 0 0', - padding: 0, - borderRadius: 4, - }, -}); - -const stixCoreObjectIndicatorsHorizontalBarsDistributionQuery = graphql` - query StixCoreObjectIndicatorsHorizontalBarsDistributionQuery( - $objectId: String - $field: String! - $operation: StatsOperation! - $limit: Int - ) { - indicatorsDistribution( - objectId: $objectId - field: $field - operation: $operation - limit: $limit - ) { - label - value - entity { - ... on Identity { - name - } - } - } - } -`; - -class StixCoreObjectIndicatorsHorizontalBars extends Component { - renderContent() { - const { t, stixCoreObjectId, field, theme } = this.props; - const indicatorsDistributionVariables = { - objectId: stixCoreObjectId, - field: field || 'indicator_types', - operation: 'count', - limit: 8, - }; - return ( - { - if ( - props - && props.indicatorsDistribution - && props.indicatorsDistribution.length > 0 - ) { - const data = props.indicatorsDistribution.map((n) => ({ - x: n.label, - y: n.value, - })); - const chartData = [{ name: t('Number of indicators'), data }]; - return ( - - ); - } - if (props) { - return ( -
- - {t('No entities of this type has been found.')} - -
- ); - } - return ( -
- - - -
- ); - }} - /> - ); - } - - render() { - const { t, classes, title, variant, height } = this.props; - return ( -
- - {title || t('Indicators distribution')} - - {variant !== 'inLine' ? ( - - {this.renderContent()} - - ) : ( - this.renderContent() - )} -
- ); - } -} - -StixCoreObjectIndicatorsHorizontalBars.propTypes = { - stixCoreObjectId: PropTypes.string, - title: PropTypes.string, - field: PropTypes.string, - classes: PropTypes.object, - theme: PropTypes.object, - t: PropTypes.func, -}; - -export default compose( - inject18n, - withTheme, - withStyles(styles), -)(StixCoreObjectIndicatorsHorizontalBars); diff --git a/opencti-platform/opencti-front/src/private/components/observations/indicators/StixCoreObjectIndicatorsVerticalBars.jsx b/opencti-platform/opencti-front/src/private/components/observations/indicators/StixCoreObjectIndicatorsVerticalBars.jsx deleted file mode 100644 index e8d79268354d..000000000000 --- a/opencti-platform/opencti-front/src/private/components/observations/indicators/StixCoreObjectIndicatorsVerticalBars.jsx +++ /dev/null @@ -1,182 +0,0 @@ -import React, { Component } from 'react'; -import * as PropTypes from 'prop-types'; -import { compose } from 'ramda'; -import { graphql } from 'react-relay'; -import withTheme from '@mui/styles/withTheme'; -import withStyles from '@mui/styles/withStyles'; -import CircularProgress from '@mui/material/CircularProgress'; -import Paper from '@mui/material/Paper'; -import Typography from '@mui/material/Typography'; -import Chart from '../../common/charts/Chart'; -import { QueryRenderer } from '../../../../relay/environment'; -import inject18n from '../../../../components/i18n'; -import { monthsAgo, now } from '../../../../utils/Time'; -import { verticalBarsChartOptions } from '../../../../utils/Charts'; -import { simpleNumberFormat } from '../../../../utils/Number'; - -const styles = () => ({ - paper: { - minHeight: 280, - height: '100%', - margin: '4px 0 0 0', - padding: '0 0 10px 0', - borderRadius: 4, - }, - chip: { - fontSize: 10, - height: 20, - marginLeft: 10, - }, -}); - -const stixCoreObjectReporstVerticalBarsTimeSeriesQuery = graphql` - query StixCoreObjectIndicatorsVerticalBarsTimeSeriesQuery( - $objectId: String - $field: String! - $operation: StatsOperation! - $startDate: DateTime! - $endDate: DateTime! - $interval: String! - ) { - indicatorsTimeSeries( - objectId: $objectId - field: $field - operation: $operation - startDate: $startDate - endDate: $endDate - interval: $interval - ) { - date - value - } - } -`; - -class IndicatorsVerticalBars extends Component { - renderContent() { - const { - t, - fsd, - indicatorType, - startDate, - endDate, - dateAttribute, - stixCoreObjectId, - theme, - } = this.props; - const interval = 'day'; - const finalStartDate = startDate || monthsAgo(12); - const finalEndDate = endDate || now(); - const indicatorsTimeSeriesVariables = { - authorId: null, - objectId: stixCoreObjectId, - indicatorType: indicatorType || null, - field: dateAttribute, - operation: 'count', - startDate: finalStartDate, - endDate: finalEndDate, - interval, - }; - return ( - { - if (props && props.indicatorsTimeSeries) { - const chartData = props.indicatorsTimeSeries.map((entry) => ({ - x: new Date(entry.date), - y: entry.value, - })); - return ( - - ); - } - if (props) { - return ( -
- - {t('No entities of this type has been found.')} - -
- ); - } - return ( -
- - - -
- ); - }} - /> - ); - } - - render() { - const { t, classes, title, variant, height } = this.props; - return ( -
- - {title || t('Indicators history')} - - {variant !== 'inLine' ? ( - - {this.renderContent()} - - ) : ( - this.renderContent() - )} -
- ); - } -} - -IndicatorsVerticalBars.propTypes = { - classes: PropTypes.object, - theme: PropTypes.object, - stixCoreObjectId: PropTypes.string, - dateAttribute: PropTypes.string, - t: PropTypes.func, - md: PropTypes.func, -}; - -export default compose( - inject18n, - withTheme, - withStyles(styles), -)(IndicatorsVerticalBars); From d70e508587cffc421e64a2ee00abdbd2b1813b5f Mon Sep 17 00:00:00 2001 From: Laurent Bonnet Date: Wed, 3 Apr 2024 17:58:00 +0200 Subject: [PATCH 12/14] [backend] add tests for restricted distribution data --- .../01-database/middleware-test.js | 43 ++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/opencti-platform/opencti-graphql/tests/02-integration/01-database/middleware-test.js b/opencti-platform/opencti-graphql/tests/02-integration/01-database/middleware-test.js index 54923915f7ea..dcf6dcad60ec 100644 --- a/opencti-platform/opencti-graphql/tests/02-integration/01-database/middleware-test.js +++ b/opencti-platform/opencti-graphql/tests/02-integration/01-database/middleware-test.js @@ -15,7 +15,7 @@ import { updateAttribute, } from '../../../src/database/middleware'; import { elFindByIds, elLoadById, elRawSearch } from '../../../src/database/engine'; -import { ADMIN_USER, testContext } from '../../utils/testQuery'; +import { ADMIN_USER, buildStandardUser, testContext, USER_PARTICIPATE } from '../../utils/testQuery'; import { ENTITY_TYPE_CAMPAIGN, ENTITY_TYPE_CONTAINER_OBSERVED_DATA, @@ -711,6 +711,47 @@ describe('Relations distribution', () => { const aggregationMap = new Map(distribution.map((i) => [i.label, i.value])); expect(aggregationMap.get('Attack-Pattern')).toEqual(2); }); + it('should relation distribution give entity details', async () => { + // const { limit = 50, order, inferred = false } = options; + // const { startDate, endDate, relationship_type, toTypes, fromId, field, operation } = options; + const malware = await elLoadById(testContext, ADMIN_USER, 'malware--faa5b705-cf44-4e50-8472-29e5fec43c3c'); + const options = { + fromOrToId: [malware.internal_id], + relationship_type: ['uses'], + field: 'internal_id', + operation: 'count', + }; + const distribution = await distributionRelations(testContext, ADMIN_USER, options); + expect(distribution.length).toEqual(3); + expect(distribution[0].entity.representative).toBeUndefined(); + expect(distribution[1].entity.representative).toBeUndefined(); + expect(distribution[2].entity.representative).toBeUndefined(); + expect(distribution[0].entity.x_opencti_stix_ids).toEqual(['attack-pattern--2fc04aa5-48c1-49ec-919a-b88241ef1d17']); + expect(distribution[1].entity.x_opencti_stix_ids).toEqual(['attack-pattern--489a7797-01c3-4706-8cd1-ec56a9db3adc']); + expect(distribution[2].entity.x_opencti_stix_ids).toEqual(['intrusion-set--18854f55-ac7c-4634-bd9a-352dd07613b7']); + }); + it('should relation distribution give restricted entity data', async () => { + // const { limit = 50, order, inferred = false } = options; + // const { startDate, endDate, relationship_type, toTypes, fromId, field, operation } = options; + const malware = await elLoadById(testContext, ADMIN_USER, 'malware--faa5b705-cf44-4e50-8472-29e5fec43c3c'); + const options = { + fromOrToId: [malware.internal_id], + relationship_type: ['uses'], + field: 'internal_id', + operation: 'count', + }; + const WHITE_TLP = { standard_id: 'marking-definition--613f2e26-407d-48c7-9eca-b8e91df99dc9', internal_id: null }; + const WHITE_USER = buildStandardUser([WHITE_TLP]); + const distribution = await distributionRelations(testContext, WHITE_USER, options); + expect(distribution.length).toEqual(3); + + expect(distribution[0].entity.representative).toEqual({ main: 'Restricted', secondary: 'Restricted' }); + expect(distribution[1].entity.representative).toEqual({ main: 'Restricted', secondary: 'Restricted' }); + expect(distribution[2].entity.representative).toEqual({ main: 'Restricted', secondary: 'Restricted' }); + expect(distribution[0].entity.x_opencti_stix_ids).toBeUndefined(); + expect(distribution[1].entity.x_opencti_stix_ids).toBeUndefined(); + expect(distribution[2].entity.x_opencti_stix_ids).toBeUndefined(); + }); }); // Some utils From cfea2e9cb099289b6661196eed0c3857f348c8c9 Mon Sep 17 00:00:00 2001 From: Laurent Bonnet Date: Wed, 3 Apr 2024 18:08:21 +0200 Subject: [PATCH 13/14] [backend] deepscan --- .../tests/02-integration/01-database/middleware-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opencti-platform/opencti-graphql/tests/02-integration/01-database/middleware-test.js b/opencti-platform/opencti-graphql/tests/02-integration/01-database/middleware-test.js index dcf6dcad60ec..1d6e45db3915 100644 --- a/opencti-platform/opencti-graphql/tests/02-integration/01-database/middleware-test.js +++ b/opencti-platform/opencti-graphql/tests/02-integration/01-database/middleware-test.js @@ -15,7 +15,7 @@ import { updateAttribute, } from '../../../src/database/middleware'; import { elFindByIds, elLoadById, elRawSearch } from '../../../src/database/engine'; -import { ADMIN_USER, buildStandardUser, testContext, USER_PARTICIPATE } from '../../utils/testQuery'; +import { ADMIN_USER, buildStandardUser, testContext } from '../../utils/testQuery'; import { ENTITY_TYPE_CAMPAIGN, ENTITY_TYPE_CONTAINER_OBSERVED_DATA, From d383aa4f96f6f72aa103a266fdb1e2e21abc02af Mon Sep 17 00:00:00 2001 From: Laurent Bonnet Date: Wed, 3 Apr 2024 18:37:31 +0200 Subject: [PATCH 14/14] [backend] fix flaky test --- .../02-integration/01-database/middleware-test.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/opencti-platform/opencti-graphql/tests/02-integration/01-database/middleware-test.js b/opencti-platform/opencti-graphql/tests/02-integration/01-database/middleware-test.js index 1d6e45db3915..742fc8026723 100644 --- a/opencti-platform/opencti-graphql/tests/02-integration/01-database/middleware-test.js +++ b/opencti-platform/opencti-graphql/tests/02-integration/01-database/middleware-test.js @@ -726,9 +726,9 @@ describe('Relations distribution', () => { expect(distribution[0].entity.representative).toBeUndefined(); expect(distribution[1].entity.representative).toBeUndefined(); expect(distribution[2].entity.representative).toBeUndefined(); - expect(distribution[0].entity.x_opencti_stix_ids).toEqual(['attack-pattern--2fc04aa5-48c1-49ec-919a-b88241ef1d17']); - expect(distribution[1].entity.x_opencti_stix_ids).toEqual(['attack-pattern--489a7797-01c3-4706-8cd1-ec56a9db3adc']); - expect(distribution[2].entity.x_opencti_stix_ids).toEqual(['intrusion-set--18854f55-ac7c-4634-bd9a-352dd07613b7']); + expect(distribution[0].entity.name).toBeDefined(); + expect(distribution[1].entity.name).toBeDefined(); + expect(distribution[2].entity.name).toBeDefined(); }); it('should relation distribution give restricted entity data', async () => { // const { limit = 50, order, inferred = false } = options; @@ -748,9 +748,9 @@ describe('Relations distribution', () => { expect(distribution[0].entity.representative).toEqual({ main: 'Restricted', secondary: 'Restricted' }); expect(distribution[1].entity.representative).toEqual({ main: 'Restricted', secondary: 'Restricted' }); expect(distribution[2].entity.representative).toEqual({ main: 'Restricted', secondary: 'Restricted' }); - expect(distribution[0].entity.x_opencti_stix_ids).toBeUndefined(); - expect(distribution[1].entity.x_opencti_stix_ids).toBeUndefined(); - expect(distribution[2].entity.x_opencti_stix_ids).toBeUndefined(); + expect(distribution[0].entity.name).toBeUndefined(); + expect(distribution[1].entity.name).toBeUndefined(); + expect(distribution[2].entity.name).toBeUndefined(); }); });