Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[backend] use representatives in distrib graphs, including 'restricted' case (#6319) #6323

Merged
merged 14 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -38,6 +39,8 @@ const WidgetDistributionList = ({
>
<List style={{ marginTop: -10 }}>
{data.map((entry, key) => {
const label = getMainRepresentative(entry.entity) || entry.label;

let link: string | null = null;
if (entry.type !== 'User' || hasSettingAccess) {
const node: {
Expand All @@ -49,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) {
Expand All @@ -61,7 +64,7 @@ const WidgetDistributionList = ({

return (
<ListItemButton
key={entry.label}
key={entry.id ?? entry.label}
dense={true}
divider={true}
{...linkProps}
Expand Down Expand Up @@ -94,7 +97,7 @@ const WidgetDistributionList = ({
paddingRight: 10,
}}
>
{entry.label}
{label}
</div>
}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 } from '../../utils/Graph';
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
Expand All @@ -22,32 +21,25 @@ const WidgetDonut = ({
readonly = false,
}: WidgetDonutProps) => {
const theme = useTheme<Theme>();
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)
: 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'
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 (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 { getMainRepresentative } from '../../utils/defaultRepresentatives';
import ItemStatus from '../ItemStatus';
import ItemMarkings from '../ItemMarkings';
import { useFormatter } from '../i18n';
Expand Down Expand Up @@ -72,7 +72,7 @@ const WidgetListCoreObjects = ({
primary={
<>
<div style={bodyItemStyle('30%')}>
{defaultValue(stixCoreObject)}
{getMainRepresentative(stixCoreObject)}
</div>
<div style={bodyItemStyle('10%')}>
{fsd(date)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 { getMainRepresentative } from '../../utils/defaultRepresentatives';
import ItemMarkings from '../ItemMarkings';
import { computeLink } from '../../utils/Entity';
import type { Theme } from '../Theme';
Expand Down Expand Up @@ -116,7 +116,7 @@ const WidgetListRelationships = ({
<div style={bodyItemStyle('18%')}>
<code>
{stixRelationship.from
? defaultValue(stixRelationship.from)
? getMainRepresentative(stixRelationship.from)
: t_i18n('Restricted')}
</code>
</div>
Expand Down Expand Up @@ -149,7 +149,7 @@ const WidgetListRelationships = ({
<div style={bodyItemStyle('18%')}>
<code>
{stixRelationship.to
? defaultValue(stixRelationship.to)
? getMainRepresentative(stixRelationship.to)
: t_i18n('Restricted')}
</code>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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/Graph';
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
Expand All @@ -25,19 +25,14 @@ const WidgetRadar = ({
}: WidgetRadarProps) => {
const theme = useTheme<Theme>();
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)
: groupBy === 'entity_type' && t_i18n(`entity_${n.label}`) !== `entity_${n.label}`
? t_i18n(`entity_${n.label}`)
: n.label));

const labels = buildWidgetLabelsOption(data, groupBy);
return (
<Chart
options={radarChartOptions(theme, labels, [], true, false) as ApexOptions}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 { getSecondaryRepresentative, getMainRepresentative } from '../../utils/defaultRepresentatives';
import MarkdownDisplay from '../MarkdownDisplay';
import ItemIcon from '../ItemIcon';
import { itemColor } from '../../utils/Colors';
Expand All @@ -33,9 +33,9 @@ const WidgetTimeline = ({ data }: WidgetTimelineProps) => {
}}
>
<Timeline position="alternate">
{data.map(({ value, link }) => {
{data.map(({ value, link }, index) => {
return (
<TimelineItem key={value.id}>
<TimelineItem key={`${value.id}-${index}`}>
<TimelineOppositeContent
sx={{ paddingTop: '18px' }}
color="text.secondary"
Expand Down Expand Up @@ -67,11 +67,11 @@ const WidgetTimeline = ({ data }: WidgetTimelineProps) => {
<TimelineContent>
<Paper variant="outlined" sx={{ padding: '15px' }} className="noDrag">
<Typography variant="h2">
{defaultValue(value)}
{getMainRepresentative(value)}
</Typography>
<div style={{ marginTop: -5, color: '#a8a8a8' }}>
<MarkdownDisplay
content={value.description}
content={getSecondaryRepresentative(value)}
limit={150}
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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/Graph';
import { getMainRepresentative, isFieldForIdentifier } from '../../utils/defaultRepresentatives';

interface WidgetTreeProps {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand All @@ -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)
: 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 (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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/Graph';
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';
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@ import {
computeTimeRangeInterval,
computeTimeRangeValues,
decodeGraphData,
defaultSecondaryValue,
defaultValue,
encodeGraphData,
linkPaint,
nodeAreaPaint,
nodePaint,
nodeThreePaint,
} from '../../../../utils/Graph';
import { getSecondaryRepresentative, getMainRepresentative } from '../../../../utils/defaultRepresentatives';
import { buildViewParamsFromUrlAndStorage, saveViewParameters } from '../../../../utils/ListParameters';
import GroupingKnowledgeGraphBar from './GroupingKnowledgeGraphBar';
import { groupingMutationFieldPatch } from './GroupingEditionOverview';
Expand Down Expand Up @@ -955,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())
Expand Down