■ ■ ■ ■ ■ ■
opencti-platform/opencti-front/src/private/components/settings/Attributes.js
1 | | - | import React, { Component } from 'react'; |
2 | | - | import * as PropTypes from 'prop-types'; |
3 | | - | import { compose, propOr } from 'ramda'; |
4 | | - | import { withRouter } from 'react-router-dom'; |
5 | | - | import withStyles from '@mui/styles/withStyles'; |
6 | | - | import { QueryRenderer } from '../../../relay/environment'; |
7 | | - | import { |
8 | | - | buildViewParamsFromUrlAndStorage, |
9 | | - | saveViewParameters, |
10 | | - | } from '../../../utils/ListParameters'; |
11 | | - | import inject18n from '../../../components/i18n'; |
12 | | - | import ListLines from '../../../components/list_lines/ListLines'; |
13 | | - | import LabelsAttributesMenu from './LabelsAttributesMenu'; |
14 | | - | import AttributesLines, { |
15 | | - | attributesLinesQuery, |
16 | | - | } from './attributes/AttributesLines'; |
17 | | - | |
18 | | - | const styles = () => ({ |
19 | | - | container: { |
20 | | - | margin: 0, |
21 | | - | padding: '0 200px 50px 0', |
22 | | - | }, |
23 | | - | }); |
24 | | - | |
25 | | - | class Attributes extends Component { |
26 | | - | constructor(props) { |
27 | | - | super(props); |
28 | | - | const params = buildViewParamsFromUrlAndStorage( |
29 | | - | props.history, |
30 | | - | props.location, |
31 | | - | 'view-attributes', |
32 | | - | ); |
33 | | - | this.state = { |
34 | | - | sortBy: propOr('definition', 'sortBy', params), |
35 | | - | orderAsc: propOr(true, 'orderAsc', params), |
36 | | - | searchTerm: propOr('', 'searchTerm', params), |
37 | | - | view: propOr('lines', 'view', params), |
38 | | - | }; |
39 | | - | } |
40 | | - | |
41 | | - | saveView() { |
42 | | - | saveViewParameters( |
43 | | - | this.props.history, |
44 | | - | this.props.location, |
45 | | - | 'view-attributes', |
46 | | - | this.state, |
47 | | - | ); |
48 | | - | } |
49 | | - | |
50 | | - | handleSearch(value) { |
51 | | - | this.setState({ searchTerm: value }, () => this.saveView()); |
52 | | - | } |
53 | | - | |
54 | | - | handleSort(field, orderAsc) { |
55 | | - | this.setState({ sortBy: field, orderAsc }, () => this.saveView()); |
56 | | - | } |
57 | | - | |
58 | | - | renderLines(paginationOptions) { |
59 | | - | const { sortBy, orderAsc, searchTerm } = this.state; |
60 | | - | const dataColumns = { |
61 | | - | value: { |
62 | | - | label: 'Value', |
63 | | - | width: '80%', |
64 | | - | isSortable: false, |
65 | | - | }, |
66 | | - | }; |
67 | | - | return ( |
68 | | - | <ListLines |
69 | | - | sortBy={sortBy} |
70 | | - | orderAsc={orderAsc} |
71 | | - | dataColumns={dataColumns} |
72 | | - | handleSort={this.handleSort.bind(this)} |
73 | | - | handleSearch={this.handleSearch.bind(this)} |
74 | | - | displayImport={false} |
75 | | - | secondaryAction={true} |
76 | | - | keyword={searchTerm} |
77 | | - | > |
78 | | - | <QueryRenderer |
79 | | - | query={attributesLinesQuery} |
80 | | - | variables={{ count: 200, orderMode: 'asc', ...paginationOptions }} |
81 | | - | render={({ props }) => ( |
82 | | - | <AttributesLines |
83 | | - | data={props} |
84 | | - | paginationOptions={paginationOptions} |
85 | | - | dataColumns={dataColumns} |
86 | | - | initialLoading={props === null} |
87 | | - | /> |
88 | | - | )} |
89 | | - | /> |
90 | | - | </ListLines> |
91 | | - | ); |
92 | | - | } |
93 | | - | |
94 | | - | render() { |
95 | | - | const { |
96 | | - | classes, |
97 | | - | match: { |
98 | | - | params: { attributeKey }, |
99 | | - | }, |
100 | | - | } = this.props; |
101 | | - | const { view, searchTerm } = this.state; |
102 | | - | const paginationOptions = { |
103 | | - | attributeName: attributeKey, |
104 | | - | search: searchTerm, |
105 | | - | orderMode: 'asc', |
106 | | - | }; |
107 | | - | return ( |
108 | | - | <div className={classes.container}> |
109 | | - | <LabelsAttributesMenu /> |
110 | | - | {view === 'lines' ? this.renderLines(paginationOptions) : ''} |
111 | | - | </div> |
112 | | - | ); |
113 | | - | } |
114 | | - | } |
115 | | - | |
116 | | - | Attributes.propTypes = { |
117 | | - | classes: PropTypes.object, |
118 | | - | t: PropTypes.func, |
119 | | - | history: PropTypes.object, |
120 | | - | match: PropTypes.object, |
121 | | - | location: PropTypes.object, |
122 | | - | }; |
123 | | - | |
124 | | - | export default compose(inject18n, withRouter, withStyles(styles))(Attributes); |
125 | | - | |