Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { useGraphContext } from '../GraphContext';
import { ObjectToParse } from '../utils/useGraphParser';
import GraphToolbarRemoveConfirm, { GraphToolbarDeleteConfirmProps } from './GraphToolbarRemoveConfirm';
import ContainerAddStixCoreObjectsInLine from '../../../private/components/common/containers/ContainerAddStixCoreObjectsInLine';
import { getRelationshipMainRepresentative } from '../../../utils/defaultRepresentatives';

export interface GraphToolbarContentToolsProps {
stixCoreObjectRefetchQuery?: GraphQLTaggedNode;
Expand Down Expand Up @@ -57,8 +58,8 @@ const GraphToolbarContentTools = ({
context,
rawObjects,
graphState: {
selectedNodes,
selectedLinks,
selectedNodes: rawSelectedNodes,
selectedLinks: rawSelectedLinks,
isAddRelationOpen,
},
} = useGraphContext();
Expand All @@ -70,6 +71,23 @@ const GraphToolbarContentTools = ({
addLink,
} = useGraphInteractions();

// if a link or node is a relationship, display correctly its representative
const selectedLinks = rawSelectedLinks.map((o) => o.relationship_type
? {
...o,
name: getRelationshipMainRepresentative(
{ label: (o.source as GraphNode).label },
{ label: (o.target as GraphNode).label },
10),
}
: o);
const selectedNodes = rawSelectedNodes.map((o) => o.relationship_type
? {
...o,
name: o.label, // no source and target if the relationship is displayed as a node
}
: o);

const head = selectedNodes.slice(0, 1);
const tail = selectedNodes.slice(-1);
const mid = selectedNodes.slice(1, -1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ export const defaultKey = (n: any) => {
return null;
};

export const getRelationshipMainRepresentative = (from: any, to: any, truncateLimit = 20) => {
return `${truncate(getMainRepresentative(from), truncateLimit)} ➡️ ${truncate(getMainRepresentative(to), truncateLimit)}`;
};

// equivalent to querying representative.main
export const getMainRepresentative = (n: any, fallback = 'Unknown') => {
if (!n) return '';
Expand Down Expand Up @@ -129,12 +133,9 @@ export const getMainRepresentative = (n: any, fallback = 'Unknown') => {
|| getMainRepresentative((R.head(n.objects?.edges ?? []) as any)?.node)
|| (n.from
&& n.to
&& `${truncate(getMainRepresentative(n.from), 20)} ➡️ ${truncate(
getMainRepresentative(n.to),
20,
)}`)
|| n.main_entity_name
|| fallback;
&& getRelationshipMainRepresentative(n.from, n.to))
|| n.main_entity_name
|| fallback;
return n.x_mitre_id ? `[${n.x_mitre_id}] ${mainValue}` : mainValue;
};

Expand Down
Loading