Skip to content

Commit

Permalink
[api/frontend] Implement tagging for tools/vulnerabilities/reports/in…
Browse files Browse the repository at this point in the history
…dicators (#345)
  • Loading branch information
Samuel Hassine authored Jan 23, 2020
1 parent 0792900 commit 002137d
Show file tree
Hide file tree
Showing 43 changed files with 636 additions and 135 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import CityObservables from './CityObservables';
import StixDomainEntityHeader from '../../common/stix_domain_entities/StixDomainEntityHeader';
import FileManager from '../../common/files/FileManager';
import CityPopover from './CityPopover';
import Loader from "../../../../components/Loader";
import Loader from '../../../../components/Loader';

const subscription = graphql`
subscription RootCitiesSubscription($id: ID!) {
Expand All @@ -36,7 +36,6 @@ const cityQuery = graphql`
name
alias
...City_city
...CityOverview_city
...CityReports_city
...CityKnowledge_city
...CityObservables_city
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ const countryQuery = graphql`
name
alias
...Country_country
...CountryOverview_country
...CountryReports_country
...CountryKnowledge_country
...CountryObservables_country
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ const organizationQuery = graphql`
name
alias
...Organization_organization
...OrganizationOverview_organization
...OrganizationDetails_organization
...OrganizationReports_organization
...OrganizationKnowledge_organization
...OrganizationObservables_organization
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ const personQuery = graphql`
name
alias
...Person_person
...PersonOverview_person
...PersonDetails_person
...PersonReports_person
...PersonKnowledge_person
...FileImportViewer_entity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ const regionQuery = graphql`
name
alias
...Region_region
...RegionOverview_region
...RegionReports_region
...RegionKnowledge_region
...RegionObservables_region
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ const sectorQuery = graphql`
query RootSectorQuery($id: String!) {
sector(id: $id) {
...Sector_sector
...SectorOverview_sector
...SectorSubsectors_sector
...SectorReports_sector
...SectorKnowledge_sector
...FileImportViewer_entity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ class ReportComponent extends Component {
spacing={3}
classes={{ container: classes.gridContainer }}
>
<Grid item={true} xs={4}>
<Grid item={true} xs={3}>
<ReportOverview report={report} />
</Grid>
<Grid item={true} xs={2}>
<Grid item={true} xs={3}>
<ReportIdentity report={report} />
</Grid>
<Grid item={true} xs={6}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@ import MenuItem from '@material-ui/core/MenuItem';
import Fab from '@material-ui/core/Fab';
import { Add, Close } from '@material-ui/icons';
import {
compose, pathOr, pipe, map, pluck, union, assoc,
compose,
pathOr,
pipe,
map,
pluck,
union,
evolve,
path,
} from 'ramda';
import * as Yup from 'yup';
import graphql from 'babel-plugin-relay/macro';
Expand All @@ -33,6 +40,7 @@ import IdentityCreation, {
} from '../common/identities/IdentityCreation';
import { attributesQuery } from '../settings/attributes/AttributesLines';
import Loader from '../../../components/Loader';
import TagAutocompleteField from '../common/form/TagAutocompleteField';

const styles = (theme) => ({
drawerPaper: {
Expand Down Expand Up @@ -158,15 +166,19 @@ class ReportCreation extends Component {
}

onSubmit(values, { setSubmitting, resetForm }) {
const finalValues = pipe(
assoc('published', parse(values.published).format()),
assoc('markingDefinitions', pluck('value', values.markingDefinitions)),
assoc('createdByRef', values.createdByRef.value),
)(values);
const adaptedValues = evolve(
{
published: parse(values.published).format(),
createdByRef: path(['value']),
markingDefinitions: pluck('value'),
tags: pluck('value'),
},
values,
);
commitMutation({
mutation: reportMutation,
variables: {
input: finalValues,
input: adaptedValues,
},
updater: (store) => {
const payload = store.getRootField('reportAdd');
Expand Down Expand Up @@ -236,6 +248,7 @@ class ReportCreation extends Component {
report_class: '',
createdByRef: '',
markingDefinitions: [],
tags: [],
}}
validationSchema={reportValidation(t)}
onSubmit={this.onSubmit.bind(this)}
Expand Down Expand Up @@ -311,6 +324,7 @@ class ReportCreation extends Component {
this,
)}
/>
<TagAutocompleteField />
<div className={classes.buttons}>
<Button
variant="contained"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import React, { Component } from 'react';
import * as PropTypes from 'prop-types';
import { compose, pathOr } from 'ramda';
import { compose } from 'ramda';
import { createFragmentContainer } from 'react-relay';
import graphql from 'babel-plugin-relay/macro';
import { withStyles } from '@material-ui/core/styles';
import Paper from '@material-ui/core/Paper';
import Typography from '@material-ui/core/Typography';
import inject18n from '../../../components/i18n';
import ItemStatus from '../../../components/ItemStatus';
import ItemCreator from '../../../components/ItemCreator';
import ItemConfidenceLevel from '../../../components/ItemConfidenceLevel';
import StixDomainEntityTags from '../common/stix_domain_entities/StixDomainEntityTags';

const styles = () => ({
paper: {
Expand All @@ -23,29 +23,14 @@ const styles = () => ({

class ReportDetailsComponent extends Component {
render() {
const {
t, fld, classes, report,
} = this.props;
const { t, classes, report } = this.props;
return (
<div style={{ height: '100%' }}>
<Typography variant="h4" gutterBottom={true}>
{t('Details')}
</Typography>
<Paper classes={{ root: classes.paper }} elevation={2}>
<Typography variant="h3" gutterBottom={true}>
{t('Author')}
</Typography>
<ItemCreator
createdByRef={pathOr(null, ['createdByRef', 'node'], report)}
/>
<Typography
variant="h3"
gutterBottom={true}
style={{ marginTop: 20 }}
>
{t('Publication date')}
</Typography>
{fld(report.published)}
<StixDomainEntityTags tags={report.tags} id={report.id} />
<Typography
variant="h3"
gutterBottom={true}
Expand Down Expand Up @@ -88,21 +73,23 @@ const ReportDetails = createFragmentContainer(ReportDetailsComponent, {
report: graphql`
fragment ReportDetails_report on Report {
id
published
object_status
source_confidence_level
createdByRef {
node {
id
name
entity_type
tags {
edges {
node {
id
tag_type
value
color
}
relation {
id
}
}
}
}
`,
});

export default compose(
inject18n,
withStyles(styles),
)(ReportDetails);
export default compose(inject18n, withStyles(styles))(ReportDetails);
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { compose, pathOr, take } from 'ramda';
import inject18n from '../../../components/i18n';
import ItemMarking from '../../../components/ItemMarking';
import ItemStatus from '../../../components/ItemStatus';
import StixObjectTags from '../common/stix_object/StixObjectTags';

const styles = (theme) => ({
item: {
Expand Down Expand Up @@ -47,9 +48,8 @@ const styles = (theme) => ({
class ReportLineComponent extends Component {
render() {
const {
t, fd, classes, node, dataColumns,
t, fd, classes, node, dataColumns, onTagClick,
} = this.props;

return (
<ListItem
classes={{ root: classes.item }}
Expand All @@ -72,10 +72,20 @@ class ReportLineComponent extends Component {
</div>
<div
className={classes.bodyItem}
style={{ width: dataColumns.createdByRef.width }}
style={{ width: dataColumns.createdBy.width }}
>
{pathOr('', ['createdByRef', 'node', 'name'], node)}
</div>
<div
className={classes.bodyItem}
style={{ width: dataColumns.tags.width }}
>
<StixObjectTags
variant="inList"
tags={node.tags}
onClick={onTagClick.bind(this)}
/>
</div>
<div
className={classes.bodyItem}
style={{ width: dataColumns.published.width }}
Expand Down Expand Up @@ -128,6 +138,7 @@ ReportLineComponent.propTypes = {
classes: PropTypes.object,
fd: PropTypes.func,
t: PropTypes.func,
onTagClick: PropTypes.func,
};

const ReportLineFragment = createFragmentContainer(ReportLineComponent, {
Expand All @@ -151,6 +162,19 @@ const ReportLineFragment = createFragmentContainer(ReportLineComponent, {
}
}
}
tags {
edges {
node {
id
tag_type
value
color
}
relation {
id
}
}
}
}
`,
});
Expand Down Expand Up @@ -179,10 +203,16 @@ class ReportLineDummyComponent extends Component {
</div>
<div
className={classes.bodyItem}
style={{ width: dataColumns.createdByRef.width }}
style={{ width: dataColumns.createdBy.width }}
>
<div className="fakeItem" style={{ width: '70%' }} />
</div>
<div
className={classes.bodyItem}
style={{ width: dataColumns.tags.width }}
>
<div className="fakeItem" style={{ width: '80%' }} />
</div>
<div
className={classes.bodyItem}
style={{ width: dataColumns.published.width }}
Expand Down
Loading

0 comments on commit 002137d

Please sign in to comment.