Projects STRLCPY opencti Commits 18f2a9f5
🤬
Revision indexing in progress... (symbol navigation in revisions will be accurate after indexed)
  • ■ ■ ■ ■ ■ ■
    opencti-platform/opencti-front/src/components/list_lines/index.d.ts
     1 +import { FunctionComponent } from 'react';
     2 + 
     3 +export interface DataColumn { isSortable: boolean, label: string, width?: string | number }
     4 + 
     5 +export type Filters<F = Record<string, unknown>[]> = Record<string, F>;
     6 + 
     7 +export enum OrderMode {
     8 + 'asc',
     9 + 'desc',
     10 +}
     11 + 
     12 +export interface PaginationOptions {
     13 + fromRole?: unknown,
     14 + toId?: unknown,
     15 + search?: string,
     16 + orderBy?: string,
     17 + orderMode: OrderMode,
     18 + filters?: Filters,
     19 +}
     20 + 
     21 +export type ListLines = FunctionComponent<unknown>;
     22 + 
  • ■ ■ ■ ■ ■
    opencti-platform/opencti-front/src/private/components/events/StixSightingRelationships.tsx
    skipped 5 lines
    6 6   stixSightingRelationshipsLinesQuery,
    7 7  } from './stix_sighting_relationships/StixSightingRelationshipsLines';
    8 8  import { convertFilters } from '../../../utils/ListParameters';
    9  -import useLocalStorage from '../../../utils/hooks/useLocalStorage';
     9 +import useLocalStorage, { localStorageToPaginationOptions } from '../../../utils/hooks/useLocalStorage';
    10 10  import { isUniqFilter } from '../common/lists/Filters';
     11 +import { Filters, PaginationOptions } from '../../../components/list_lines';
    11 12   
    12 13  const dataColumns = {
    13 14   x_opencti_negative: {
    skipped 44 lines
    58 59   
    59 60  const LOCAL_STORAGE_KEY = 'view-stix-sighting-relationships';
    60 61   
    61  -interface LocalStorageProps {
    62  - numberOfElements: { number: number, symbol: string },
    63  - filters: Record<string, Record<string, unknown>[]>,
    64  - searchTerm: string,
    65  - sortBy: string,
    66  - orderAsc: boolean,
    67  - openExports: boolean,
    68  -}
    69  - 
    70 62  const StixSightingRelationships = () => {
    71  - const [viewStorage, setViewStorage] = useLocalStorage<LocalStorageProps>(LOCAL_STORAGE_KEY, {
     63 + const [viewStorage, setViewStorage] = useLocalStorage(LOCAL_STORAGE_KEY, {
    72 64   numberOfElements: { number: 0, symbol: '' },
    73  - filters: {},
     65 + filters: {} as Filters,
    74 66   searchTerm: '',
    75 67   sortBy: 'created',
    76 68   orderAsc: false,
    skipped 24 lines
    101 93   event.stopPropagation();
    102 94   event.preventDefault();
    103 95   }
    104  - if ((filters?.[key]?.length ?? 0) > 0) {
     96 + if ((filters[key]?.length ?? 0) > 0) {
    105 97   setViewStorage((c) => ({
    106 98   ...c,
    107 99   filters: {
    skipped 14 lines
    122 114   }
    123 115   };
    124 116   
    125  - const renderLines = (paginationOptions: {
    126  - toId?: unknown,
    127  - search?: unknown,
    128  - orderBy?: unknown,
    129  - orderMode?: unknown,
    130  - filters?: unknown,
    131  - }) => (
     117 + const renderLines = (paginationOptions: PaginationOptions) => (
    132 118   <ListLines
    133 119   sortBy={sortBy}
    134 120   orderAsc={orderAsc}
    skipped 49 lines
    184 170   toSightingId = R.head(filters.toSightingId)?.id;
    185 171   processedFilters = R.dissoc('toSightingId', processedFilters);
    186 172   }
    187  - const finalFilters = convertFilters(processedFilters);
    188  - const paginationOptions = {
    189  - toId: toSightingId,
    190  - search: searchTerm,
    191  - orderBy: sortBy,
    192  - orderMode: orderAsc ? 'asc' : 'desc',
    193  - filters: finalFilters,
    194  - };
     173 + const finalFilters = convertFilters(processedFilters) as unknown as Filters;
     174 + const paginationOptions = localStorageToPaginationOptions({ ...viewStorage, toId: toSightingId, filters: finalFilters });
    195 175   return (
    196 176   <div>{renderLines(paginationOptions)}</div>
    197 177   );
    skipped 4 lines
  • ■ ■ ■ ■ ■ ■
    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  - 
  • ■ ■ ■ ■ ■ ■
    opencti-platform/opencti-front/src/private/components/settings/Attributes.tsx
     1 +import React from 'react';
     2 +import { useParams } from 'react-router-dom';
     3 +import makeStyles from '@mui/styles/makeStyles';
     4 +import { QueryRenderer } from '../../../relay/environment';
     5 +import ListLines from '../../../components/list_lines/ListLines';
     6 +import LabelsAttributesMenu from './LabelsAttributesMenu';
     7 +import AttributesLines, { AttributesLinesProps, attributesLinesQuery } from './attributes/AttributesLines';
     8 +import LabelCreation from './labels/LabelCreation';
     9 +import useLocalStorage, { LocalStorage, localStorageToPaginationOptions } from '../../../utils/hooks/useLocalStorage';
     10 + 
     11 +const useStyles = makeStyles(() => ({
     12 + container: {
     13 + margin: 0,
     14 + padding: '0 200px 50px 0',
     15 + },
     16 +}));
     17 + 
     18 +const Attributes = () => {
     19 + const classes = useStyles();
     20 + const { attributeKey: attributeName } = useParams();
     21 + const [viewStorage, setViewStorage] = useLocalStorage('view-attributes', {
     22 + sortBy: 'value',
     23 + orderAsc: true,
     24 + searchTerm: '',
     25 + });
     26 + 
     27 + const handleSearch = (value: string) => setViewStorage((c) => ({ ...c, searchTerm: value }));
     28 + 
     29 + const handleSort = (field: string, order: boolean) => setViewStorage((c) => ({
     30 + ...c,
     31 + sortBy: field,
     32 + orderAsc: order,
     33 + }));
     34 + 
     35 + const renderLines = (paginationOptions: LocalStorage) => {
     36 + const { sortBy, orderAsc, searchTerm } = paginationOptions;
     37 + 
     38 + const dataColumns = {
     39 + value: {
     40 + label: 'Value',
     41 + width: '80%',
     42 + isSortable: true,
     43 + },
     44 + };
     45 + return (
     46 + <ListLines
     47 + sortBy={sortBy}
     48 + orderAsc={orderAsc}
     49 + dataColumns={dataColumns}
     50 + handleSort={handleSort}
     51 + handleSearch={handleSearch}
     52 + displayImport={false}
     53 + secondaryAction={true}
     54 + keyword={searchTerm}
     55 + >
     56 + <QueryRenderer
     57 + query={attributesLinesQuery}
     58 + variables={localStorageToPaginationOptions(paginationOptions)}
     59 + render={({ props }: { props: AttributesLinesProps['data'] }) => (
     60 + <AttributesLines
     61 + data={props}
     62 + paginationOptions={paginationOptions}
     63 + dataColumns={dataColumns}
     64 + initialLoading={!props}
     65 + />
     66 + )}
     67 + />
     68 + </ListLines>
     69 + );
     70 + };
     71 + 
     72 + const queryProps = { ...viewStorage, attributeName };
     73 + 
     74 + return (
     75 + <div className={classes.container}>
     76 + <LabelsAttributesMenu />
     77 + {renderLines(queryProps)}
     78 + <LabelCreation paginationOptions={viewStorage} />
     79 + </div>
     80 + );
     81 +};
     82 + 
     83 +export default Attributes;
     84 + 
  • ■ ■ ■ ■ ■ ■
    opencti-platform/opencti-front/src/private/components/settings/attributes/AttributesLines.js opencti-platform/opencti-front/src/private/components/settings/attributes/AttributesLines.tsx
    1  -import React from 'react';
    2  -import * as PropTypes from 'prop-types';
    3  -import { graphql, createPaginationContainer } from 'react-relay';
     1 +import React, { FunctionComponent } from 'react';
     2 +import { createPaginationContainer, graphql } from 'react-relay';
     3 +import { RelayPaginationProp } from 'react-relay/ReactRelayTypes';
    4 4  import ListLinesContent from '../../../../components/list_lines/ListLinesContent';
    5 5  import { AttributeLine, AttributeLineDummy } from './AttributeLine';
     6 +import { AttributesLinesAttributesQuery$data } from './__generated__/AttributesLinesAttributesQuery.graphql';
     7 +import { DataColumn } from '../../../../components/list_lines';
     8 +import { LocalStorage } from '../../../../utils/hooks/useLocalStorage';
     9 + 
     10 +export interface AttributesLinesProps {
     11 + paginationOptions: LocalStorage,
     12 + dataColumns: Record<string, DataColumn>,
     13 + data?: AttributesLinesAttributesQuery$data,
     14 + relay: RelayPaginationProp,
     15 + initialLoading?: boolean,
     16 +}
    6 17   
    7 18  const nbOfRowsToLoad = 200;
    8 19   
    9  -const AttributesLines = (props) => {
    10  - const { data, initialLoading, dataColumns, relay, paginationOptions } = props;
     20 +const AttributesLines: FunctionComponent<AttributesLinesProps> = ({ data, initialLoading, dataColumns, relay, paginationOptions }) => {
    11 21   const attributes = data?.runtimeAttributes?.edges ?? [];
    12 22   const globalCount = data?.runtimeAttributes?.pageInfo?.globalCount ?? nbOfRowsToLoad;
    13 23   const refetch = () => relay.refetchConnection(nbOfRowsToLoad);
    skipped 15 lines
    29 39   );
    30 40  };
    31 41   
    32  -AttributesLines.propTypes = {
    33  - classes: PropTypes.object,
    34  - paginationOptions: PropTypes.object,
    35  - dataColumns: PropTypes.object.isRequired,
    36  - data: PropTypes.object,
    37  - relay: PropTypes.object,
    38  - attributes: PropTypes.object,
    39  - initialLoading: PropTypes.bool,
    40  -};
    41  - 
    42 42  export const attributesQuery = graphql`
    43 43   query AttributesLinesAttributesQuery($key: String!) {
    44 44   runtimeAttributes(attributeName: $key) {
    skipped 3 lines
    48 48   key
    49 49   value
    50 50   }
     51 + }
     52 + pageInfo {
     53 + endCursor
     54 + hasNextPage
     55 + globalCount
    51 56   }
    52 57   }
    53 58   }
    skipped 73 lines
  • ■ ■ ■ ■ ■
    opencti-platform/opencti-front/src/utils/hooks/useLocalStorage.ts
    1  -import { useState } from 'react';
     1 +import { Dispatch, SetStateAction, useState } from 'react';
    2 2  import { isEmptyField } from '../utils';
     3 +import { Filters, OrderMode, PaginationOptions } from '../../components/list_lines';
    3 4   
    4  -const useLocalStorage = <T>(key: string, initialValue: T) => {
     5 +export interface LocalStorage {
     6 + numberOfElements?: { number: number, symbol: string },
     7 + filters?: Filters,
     8 + searchTerm?: string,
     9 + sortBy?: string,
     10 + orderAsc?: boolean,
     11 + openExports?: boolean,
     12 +}
     13 + 
     14 +export const localStorageToPaginationOptions = <T extends LocalStorage>({ searchTerm, filters, sortBy, orderAsc, ...props }: T): PaginationOptions => ({
     15 + ...props,
     16 + search: searchTerm,
     17 + orderMode: orderAsc ? OrderMode.asc : OrderMode.desc,
     18 + orderBy: sortBy,
     19 + filters,
     20 +});
     21 + 
     22 +const useLocalStorage = <T = LocalStorage>(key: string, initialValue: T): [value: T, setValue: Dispatch<SetStateAction<T>>] => {
    5 23   // State to store our value
    6 24   // Pass initial state function to useState so logic is only executed once
    7 25   const [storedValue, setStoredValue] = useState<T>(() => {
    skipped 28 lines
    36 54   throw Error('Error while setting values in local storage');
    37 55   }
    38 56   };
    39  - return [storedValue, setValue] as const;
     57 + return [storedValue, setValue];
    40 58  };
    41 59   
    42 60  export default useLocalStorage;
    skipped 1 lines
  • ■ ■ ■ ■
    opencti-platform/opencti-graphql/src/database/engine.js
    skipped 1786 lines
    1787 1787   };
    1788 1788   const data = await elRawSearch(context, user, field, query);
    1789 1789   const { buckets } = data.aggregations.values;
    1790  - const values = (buckets ?? []).map((n) => n.key);
     1790 + const values = (buckets ?? []).map((n) => n.key).filter((val) => (search ? val.includes(search.toLowerCase()) : true));
    1791 1791   const nodeElements = values.map((val) => ({ node: { id: val, key: field, value: val } }));
    1792 1792   return buildPagination(0, null, nodeElements, nodeElements.length);
    1793 1793  };
    skipped 502 lines
Please wait...
Page is in error, reload to recover