Skip to content

Commit

Permalink
[frontend] Add default startTime and stopTime for all relationships c…
Browse files Browse the repository at this point in the history
  • Loading branch information
marieflorescontact authored and ParamConstructor committed Oct 30, 2024
1 parent 3795d28 commit 4ecdba3
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import CommitMessage from '../../common/form/CommitMessage';
import StixNestedRefRelationshipCreationFromKnowledgeGraph from '../../common/stix_nested_ref_relationships/StixNestedRefRelationshipCreationFromKnowledgeGraph';
import inject18n from '../../../../components/i18n';
import StixCoreRelationshipCreation from '../../common/stix_core_relationships/StixCoreRelationshipCreation';
import { dateFormat } from '../../../../utils/Time';
import { dateFormat, minutesBefore, now } from '../../../../utils/Time';
import { truncate } from '../../../../utils/String';
import StixCoreRelationshipEdition from '../../common/stix_core_relationships/StixCoreRelationshipEdition';
import StixDomainObjectEdition from '../../common/stix_domain_objects/StixDomainObjectEdition';
Expand Down Expand Up @@ -456,6 +456,9 @@ class GroupingKnowledgeGraphBar extends Component {
: [selectedNodes[0]];
}
const stixCoreObjectOrRelationshipId = (selectedNodes[0]?.id ?? null) || (selectedLinks[0]?.id ?? null);

const defaultTime = now();

return (
<UserContext.Consumer>
{({ bannerSettings }) => (
Expand Down Expand Up @@ -986,10 +989,10 @@ class GroupingKnowledgeGraphBar extends Component {
fromObjects={relationFromObjects}
toObjects={relationToObjects}
startTime={
lastLinkFirstSeen || dateFormat(grouping.published)
lastLinkFirstSeen || minutesBefore(1, defaultTime)
}
stopTime={
lastLinkLastSeen || dateFormat(grouping.published)
lastLinkLastSeen || defaultTime
}
confidence={grouping.confidence}
handleClose={this.handleCloseCreateRelationship.bind(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import StixNestedRefRelationshipCreationFromKnowledgeGraph from '../../common/st
import CommitMessage from '../../common/form/CommitMessage';
import inject18n from '../../../../components/i18n';
import StixCoreRelationshipCreation from '../../common/stix_core_relationships/StixCoreRelationshipCreation';
import { dateFormat } from '../../../../utils/Time';
import { dateFormat, minutesBefore, now } from '../../../../utils/Time';
import { truncate } from '../../../../utils/String';
import StixCoreRelationshipEdition from '../../common/stix_core_relationships/StixCoreRelationshipEdition';
import StixDomainObjectEdition from '../../common/stix_domain_objects/StixDomainObjectEdition';
Expand Down Expand Up @@ -487,6 +487,7 @@ class ReportKnowledgeGraphBar extends Component {
: [selectedNodes[0]];
}
const stixCoreObjectOrRelationshipId = (selectedNodes[0]?.id ?? null) || (selectedLinks[0]?.id ?? null);
const defaultTime = now();
return (
<UserContext.Consumer>
{({ bannerSettings }) => (
Expand Down Expand Up @@ -1055,10 +1056,10 @@ class ReportKnowledgeGraphBar extends Component {
fromObjects={relationFromObjects}
toObjects={relationToObjects}
startTime={
lastLinkFirstSeen || dateFormat(report.published)
lastLinkFirstSeen || minutesBefore(1, defaultTime)
}
stopTime={
lastLinkLastSeen || dateFormat(report.published)
lastLinkLastSeen || defaultTime
}
confidence={report.confidence}
handleClose={this.handleCloseCreateRelationship.bind(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import StixNestedRefRelationshipCreationFromKnowledgeGraph from '../../common/st
import CommitMessage from '../../common/form/CommitMessage';
import inject18n from '../../../../components/i18n';
import StixCoreRelationshipCreation from '../../common/stix_core_relationships/StixCoreRelationshipCreation';
import { dateFormat } from '../../../../utils/Time';
import { dateFormat, minutesBefore, now } from '../../../../utils/Time';
import { truncate } from '../../../../utils/String';
import StixCoreRelationshipEdition from '../../common/stix_core_relationships/StixCoreRelationshipEdition';
import StixDomainObjectEdition from '../../common/stix_domain_objects/StixDomainObjectEdition';
Expand Down Expand Up @@ -459,6 +459,9 @@ class IncidentKnowledgeGraphBar extends Component {
: [selectedNodes[0]];
}
const stixCoreObjectOrRelationshipId = (selectedNodes[0]?.id ?? null) || (selectedLinks[0]?.id ?? null);

const defaultTime = now();

return (
<UserContext.Consumer>
{({ bannerSettings }) => (
Expand Down Expand Up @@ -992,10 +995,10 @@ class IncidentKnowledgeGraphBar extends Component {
fromObjects={relationFromObjects}
toObjects={relationToObjects}
startTime={
lastLinkFirstSeen || dateFormat(caseData.published)
lastLinkFirstSeen || minutesBefore(1, defaultTime)
}
stopTime={
lastLinkLastSeen || dateFormat(caseData.published)
lastLinkLastSeen || defaultTime
}
confidence={caseData.confidence}
handleClose={this.handleCloseCreateRelationship.bind(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import StixNestedRefRelationshipCreationFromKnowledgeGraph from '../../common/st
import CommitMessage from '../../common/form/CommitMessage';
import inject18n from '../../../../components/i18n';
import StixCoreRelationshipCreation from '../../common/stix_core_relationships/StixCoreRelationshipCreation';
import { dateFormat } from '../../../../utils/Time';
import { dateFormat, minutesBefore, now } from '../../../../utils/Time';
import { truncate } from '../../../../utils/String';
import StixCoreRelationshipEdition from '../../common/stix_core_relationships/StixCoreRelationshipEdition';
import StixDomainObjectEdition from '../../common/stix_domain_objects/StixDomainObjectEdition';
Expand Down Expand Up @@ -459,6 +459,9 @@ class CaseRfiKnowledgeGraphBar extends Component {
: [selectedNodes[0]];
}
const stixCoreObjectOrRelationshipId = (selectedNodes[0]?.id ?? null) || (selectedLinks[0]?.id ?? null);

const defaultTime = now();

return (
<UserContext.Consumer>
{({ bannerSettings }) => (
Expand Down Expand Up @@ -989,10 +992,10 @@ class CaseRfiKnowledgeGraphBar extends Component {
fromObjects={relationFromObjects}
toObjects={relationToObjects}
startTime={
lastLinkFirstSeen || dateFormat(caseData.published)
lastLinkFirstSeen || minutesBefore(1, defaultTime)
}
stopTime={
lastLinkLastSeen || dateFormat(caseData.published)
lastLinkLastSeen || defaultTime
}
confidence={caseData.confidence}
handleClose={this.handleCloseCreateRelationship.bind(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import StixNestedRefRelationshipCreationFromKnowledgeGraph from '../../common/st
import CommitMessage from '../../common/form/CommitMessage';
import inject18n from '../../../../components/i18n';
import StixCoreRelationshipCreation from '../../common/stix_core_relationships/StixCoreRelationshipCreation';
import { dateFormat } from '../../../../utils/Time';
import { dateFormat, minutesBefore, now } from '../../../../utils/Time';
import { truncate } from '../../../../utils/String';
import StixCoreRelationshipEdition from '../../common/stix_core_relationships/StixCoreRelationshipEdition';
import StixDomainObjectEdition from '../../common/stix_domain_objects/StixDomainObjectEdition';
Expand Down Expand Up @@ -459,6 +459,9 @@ class CaseRftKnowledgeGraphBar extends Component {
: [selectedNodes[0]];
}
const stixCoreObjectOrRelationshipId = (selectedNodes[0]?.id ?? null) || (selectedLinks[0]?.id ?? null);

const defaultTime = now();

return (
<UserContext.Consumer>
{({ bannerSettings }) => (
Expand Down Expand Up @@ -989,10 +992,10 @@ class CaseRftKnowledgeGraphBar extends Component {
fromObjects={relationFromObjects}
toObjects={relationToObjects}
startTime={
lastLinkFirstSeen || dateFormat(caseData.published)
lastLinkFirstSeen || minutesBefore(1, defaultTime)
}
stopTime={
lastLinkLastSeen || dateFormat(caseData.published)
lastLinkLastSeen || defaultTime
}
confidence={caseData.confidence}
handleClose={this.handleCloseCreateRelationship.bind(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import ItemIcon from '../../../../components/ItemIcon';
import { useSchemaCreationValidation } from '../../../../utils/hooks/useEntitySettings';
import useDefaultValues from '../../../../utils/hooks/useDefaultValues';
import { getMainRepresentative } from '../../../../utils/defaultRepresentatives';
import { minutesBefore, now } from '../../../../utils/Time';

// Deprecated - https://mui.com/system/styles/basics/
// Do not use it for new code.
Expand Down Expand Up @@ -138,13 +139,15 @@ const StixCoreRelationshipCreationForm = ({
? 'related-to'
: '';

const defaultTime = now();

const initialValues = useDefaultValues(
STIX_CORE_RELATIONSHIP_TYPE,
{
relationship_type: defaultRelationshipType,
confidence: defaultConfidence,
start_time: !isNone(defaultStartTime) ? defaultStartTime : null,
stop_time: !isNone(defaultStopTime) ? defaultStopTime : null,
start_time: !isNone(defaultStartTime) ? defaultStartTime : minutesBefore(1, defaultTime),
stop_time: !isNone(defaultStopTime) ? defaultStopTime : defaultTime,
description: '',
killChainPhases: [],
externalReferences: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import makeStyles from '@mui/styles/makeStyles';
import { commitMutation, QueryRenderer } from '../../../../relay/environment';
import { useFormatter } from '../../../../components/i18n';
import { itemColor } from '../../../../utils/Colors';
import { dayStartDate, parse } from '../../../../utils/Time';
import { minutesBefore, now, parse } from '../../../../utils/Time';
import ItemIcon from '../../../../components/ItemIcon';
import SelectField from '../../../../components/fields/SelectField';
import StixNestedRefRelationCreationFromEntityLines, { stixNestedRefRelationshipCreationFromEntityLinesQuery } from './StixNestedRefRelationshipCreationFromEntityLines';
Expand Down Expand Up @@ -701,10 +701,12 @@ const StixNestedRefRelationshipCreationFromEntity = ({
// nested objects with different entity type will soon be implemented
if (!isSameEntityType) relationshipTypes = [];
const defaultRelationshipType = R.head(relationshipTypes);

const defaultTime = now();
const initialValues = {
relationship_type: defaultRelationshipType,
start_time: dayStartDate(),
stop_time: dayStartDate(),
start_time: minutesBefore(1, defaultTime),
stop_time: defaultTime,
};

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import { parseDomain } from '../../../../utils/Graph';
import { INVESTIGATION_INUPDATE } from '../../../../utils/hooks/useGranted';
import Security from '../../../../utils/Security';
import { truncate } from '../../../../utils/String';
import { dateFormat } from '../../../../utils/Time';
import { dateFormat, minutesBefore, now } from '../../../../utils/Time';
import StixCoreRelationshipCreation from '../../common/stix_core_relationships/StixCoreRelationshipCreation';
import StixCoreRelationshipEdition from '../../common/stix_core_relationships/StixCoreRelationshipEdition';
import StixDomainObjectEdition from '../../common/stix_domain_objects/StixDomainObjectEdition';
Expand Down Expand Up @@ -358,6 +358,8 @@ class InvestigationGraphBar extends Component {

const isRollBackToLastPreExpansionStateDisabled = !getPreExpansionStateList();

const defaultTime = now();

return (
<UserContext.Consumer>
{({ bannerSettings }) => (
Expand Down Expand Up @@ -918,8 +920,8 @@ class InvestigationGraphBar extends Component {
open={openCreatedRelation}
fromObjects={relationFromObjects}
toObjects={relationToObjects}
startTime={lastLinkFirstSeen || null}
stopTime={lastLinkLastSeen || null}
startTime={lastLinkFirstSeen || minutesBefore(1, defaultTime)}
stopTime={lastLinkLastSeen || defaultTime}
confidence={50}
handleClose={this.handleCloseCreateRelationship.bind(
this,
Expand Down

0 comments on commit 4ecdba3

Please sign in to comment.