Skip to content

Commit

Permalink
[front] Align ui filters on runtime mapping capability (#2936)
Browse files Browse the repository at this point in the history
  • Loading branch information
richard-julien authored and SamuelHassine committed Mar 5, 2023
1 parent c34a9fd commit fb1488c
Show file tree
Hide file tree
Showing 15 changed files with 91 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ class Search extends Component {
creator: {
label: 'Creator',
width: '12%',
isSortable: true,
isSortable: isRuntimeSort,
},
objectLabel: {
label: 'Labels',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const ExternalReferences: FunctionComponent<ExternalReferencesProps> = () => {
},
);
const { sortBy, orderAsc, searchTerm, filters, numberOfElements } = viewStorage;
const isRuntimeSort = helper?.isRuntimeFieldEnable();
const isRuntimeSort = helper?.isRuntimeFieldEnable() ?? false;
const dataColumns = {
source_name: {
label: 'Source name',
Expand All @@ -60,7 +60,7 @@ const ExternalReferences: FunctionComponent<ExternalReferencesProps> = () => {
creator: {
label: 'Creator',
width: '12%',
isSortable: isRuntimeSort ?? false,
isSortable: isRuntimeSort,
},
created: {
label: 'Creation date',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { FunctionComponent } from 'react';
import React, { FunctionComponent, useContext } from 'react';
import ListLines from '../../../components/list_lines/ListLines';
import GroupingsLines, {
groupingsLinesQuery,
Expand All @@ -16,7 +16,6 @@ import {
GroupingsLinesPaginationQuery$variables,
} from './groupings/__generated__/GroupingsLinesPaginationQuery.graphql';
import { GroupingLine_node$data } from './groupings/__generated__/GroupingLine_node.graphql';
import { ModuleHelper } from '../../../utils/platformModulesHelper';
import { GroupingLineDummy } from './groupings/GroupingLine';

const LOCAL_STORAGE_KEY = 'view-groupings';
Expand All @@ -33,6 +32,7 @@ const Groupings: FunctionComponent<GroupingsProps> = ({
authorId,
onChangeOpenExports,
}) => {
const { helper } = useContext(UserContext);
const additionnalFilters = [];
if (authorId) {
additionnalFilters.push({
Expand Down Expand Up @@ -87,7 +87,7 @@ const Groupings: FunctionComponent<GroupingsProps> = ({
groupingsLinesQuery,
paginationOptions,
);
const renderLines = (helper: ModuleHelper | undefined) => {
const renderLines = () => {
let exportContext = null;
if (objectId) {
exportContext = `of-entity-${objectId}`;
Expand All @@ -104,7 +104,7 @@ const Groupings: FunctionComponent<GroupingsProps> = ({
...finalFilters,
entity_type: [{ id: 'Grouping', value: 'Grouping' }],
};
const isRuntimeSort = helper?.isRuntimeFieldEnable();
const isRuntimeSort = helper?.isRuntimeFieldEnable() ?? false;
const dataColumns = {
name: {
label: 'Name',
Expand All @@ -119,12 +119,12 @@ const Groupings: FunctionComponent<GroupingsProps> = ({
createdBy: {
label: 'Author',
width: '12%',
isSortable: isRuntimeSort ?? false,
isSortable: isRuntimeSort,
},
creator: {
label: 'Creators',
width: '12%',
isSortable: isRuntimeSort ?? false,
isSortable: isRuntimeSort,
},
objectLabel: {
label: 'Labels',
Expand All @@ -143,7 +143,7 @@ const Groupings: FunctionComponent<GroupingsProps> = ({
},
objectMarking: {
label: 'Marking',
isSortable: isRuntimeSort ?? false,
isSortable: isRuntimeSort,
width: '8%',
},
};
Expand Down Expand Up @@ -221,16 +221,12 @@ const Groupings: FunctionComponent<GroupingsProps> = ({
);
};
return (
<UserContext.Consumer>
{({ helper }) => (
<div>
{renderLines(helper)}
<Security needs={[KNOWLEDGE_KNUPDATE]}>
<GroupingCreation paginationOptions={paginationOptions} />
</Security>
</div>
)}
</UserContext.Consumer>
<div>
{renderLines()}
<Security needs={[KNOWLEDGE_KNUPDATE]}>
<GroupingCreation paginationOptions={paginationOptions} />
</Security>
</div>
);
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { FunctionComponent } from 'react';
import React, { FunctionComponent, useContext } from 'react';
import ListLines from '../../../components/list_lines/ListLines';
import ReportsLines, { reportsLinesQuery } from './reports/ReportsLines';
import ReportCreation from './reports/ReportCreation';
Expand All @@ -12,7 +12,6 @@ import {
ReportsLinesPaginationQuery$variables,
} from './reports/__generated__/ReportsLinesPaginationQuery.graphql';
import { Filters } from '../../../components/list_lines';
import { ModuleHelper } from '../../../utils/platformModulesHelper';
import { ReportLine_node$data } from './reports/__generated__/ReportLine_node.graphql';
import useEntityToggle from '../../../utils/hooks/useEntityToggle';
import useQueryLoading from '../../../utils/hooks/useQueryLoading';
Expand All @@ -32,6 +31,7 @@ const Reports: FunctionComponent<ReportsProps> = ({
authorId,
onChangeOpenExports,
}) => {
const { helper } = useContext(UserContext);
const additionnalFilters = [];
if (authorId) {
additionnalFilters.push({
Expand Down Expand Up @@ -87,7 +87,7 @@ const Reports: FunctionComponent<ReportsProps> = ({
reportsLinesQuery,
paginationOptions,
);
const renderLines = (helper: ModuleHelper | undefined) => {
const renderLines = () => {
let exportContext = null;
if (objectId) {
exportContext = `of-entity-${objectId}`;
Expand All @@ -99,7 +99,7 @@ const Reports: FunctionComponent<ReportsProps> = ({
...renderFilters,
entity_type: [{ id: 'Report', value: 'Report' }],
};
const isRuntimeSort = helper?.isRuntimeFieldEnable();
const isRuntimeSort = helper?.isRuntimeFieldEnable() ?? false;
const dataColumns = {
name: {
label: 'Title',
Expand All @@ -114,12 +114,12 @@ const Reports: FunctionComponent<ReportsProps> = ({
createdBy: {
label: 'Author',
width: '12%',
isSortable: isRuntimeSort ?? false,
isSortable: isRuntimeSort,
},
creator: {
label: 'Creators',
width: '12%',
isSortable: isRuntimeSort ?? false,
isSortable: isRuntimeSort,
},
objectLabel: {
label: 'Labels',
Expand All @@ -138,7 +138,7 @@ const Reports: FunctionComponent<ReportsProps> = ({
},
objectMarking: {
label: 'Marking',
isSortable: isRuntimeSort ?? false,
isSortable: isRuntimeSort,
width: '8%',
},
};
Expand Down Expand Up @@ -220,18 +220,14 @@ const Reports: FunctionComponent<ReportsProps> = ({
);
};
return (
<UserContext.Consumer>
{({ helper }) => (
<ExportContextProvider>
<ExportContextProvider>
<div>
{renderLines(helper)}
{renderLines()}
<Security needs={[KNOWLEDGE_KNUPDATE]}>
<ReportCreation paginationOptions={paginationOptions} />
</Security>
</div>
</ExportContextProvider>
)}
</UserContext.Consumer>
</ExportContextProvider>
);
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useContext } from 'react';
import ListLines from '../../../components/list_lines/ListLines';
import VulnerabilitiesLines, {
vulnerabilitiesLinesQuery,
Expand All @@ -14,8 +14,11 @@ import {
VulnerabilitiesLinesPaginationQuery$variables,
} from './vulnerabilities/__generated__/VulnerabilitiesLinesPaginationQuery.graphql';
import { usePaginationLocalStorage } from '../../../utils/hooks/useLocalStorage';
import { UserContext } from '../../../utils/hooks/useAuth';

const Vulnerabilities = () => {
const { helper } = useContext(UserContext);
const isRuntimeSort = helper?.isRuntimeFieldEnable() ?? false;
const { viewStorage, helpers, paginationOptions } = usePaginationLocalStorage<VulnerabilitiesLinesPaginationQuery$variables>(
'view-vulnerabilities',
{
Expand Down Expand Up @@ -65,7 +68,7 @@ const Vulnerabilities = () => {
creator: {
label: 'Creators',
width: '12%',
isSortable: true,
isSortable: isRuntimeSort,
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const Feedbacks: FunctionComponent<CasesProps> = () => {
openExports,
numberOfElements,
} = viewStorage;
const isRuntimeSort = helper?.isRuntimeFieldEnable();
const isRuntimeSort = helper?.isRuntimeFieldEnable() ?? false;
const dataColumns = {
name: {
label: 'Name',
Expand All @@ -85,12 +85,12 @@ const Feedbacks: FunctionComponent<CasesProps> = () => {
createdBy: {
label: 'Author',
width: '12%',
isSortable: isRuntimeSort ?? false,
isSortable: isRuntimeSort,
},
creator: {
label: 'Creators',
width: '12%',
isSortable: isRuntimeSort ?? false,
isSortable: isRuntimeSort,
},
objectLabel: {
label: 'Labels',
Expand All @@ -110,7 +110,7 @@ const Feedbacks: FunctionComponent<CasesProps> = () => {
objectMarking: {
label: 'Marking',
width: '8%',
isSortable: isRuntimeSort ?? false,
isSortable: isRuntimeSort,
},
};
const queryRef = useQueryLoading<FeedbacksLinesPaginationQuery>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const Incidents: FunctionComponent<CasesProps> = () => {
openExports,
numberOfElements,
} = viewStorage;
const isRuntimeSort = helper?.isRuntimeFieldEnable();
const isRuntimeSort = helper?.isRuntimeFieldEnable() ?? false;
const dataColumns = {
name: {
label: 'Name',
Expand All @@ -93,12 +93,12 @@ const Incidents: FunctionComponent<CasesProps> = () => {
createdBy: {
label: 'Author',
width: '11%',
isSortable: isRuntimeSort ?? false,
isSortable: isRuntimeSort,
},
creator: {
label: 'Creators',
width: '11%',
isSortable: isRuntimeSort ?? false,
isSortable: isRuntimeSort,
},
objectLabel: {
label: 'Labels',
Expand All @@ -118,7 +118,7 @@ const Incidents: FunctionComponent<CasesProps> = () => {
objectMarking: {
label: 'Marking',
width: '8%',
isSortable: isRuntimeSort ?? false,
isSortable: isRuntimeSort,
},
};
const queryRef = useQueryLoading<IncidentsLinesCasesPaginationQuery>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ const ContainerStixCyberObservablesComponent: FunctionComponent<ContainerStixCyb
};

const buildColumns = (helper: ModuleHelper | undefined) => {
const isRuntimeSort = helper?.isRuntimeFieldEnable();
const isRuntimeSort = helper?.isRuntimeFieldEnable() ?? false;
return {
entity_type: {
label: 'Type',
Expand All @@ -242,7 +242,7 @@ const ContainerStixCyberObservablesComponent: FunctionComponent<ContainerStixCyb
observable_value: {
label: 'Value',
width: '30%',
isSortable: isRuntimeSort ?? false,
isSortable: isRuntimeSort,
},
objectLabel: {
label: 'Labels',
Expand All @@ -252,7 +252,7 @@ const ContainerStixCyberObservablesComponent: FunctionComponent<ContainerStixCyb
createdBy: {
label: 'Creator',
width: '15%',
isSortable: isRuntimeSort ?? false,
isSortable: isRuntimeSort,
},
created_at: {
label: 'Creation date',
Expand All @@ -261,7 +261,7 @@ const ContainerStixCyberObservablesComponent: FunctionComponent<ContainerStixCyb
},
objectMarking: {
label: 'Marking',
isSortable: isRuntimeSort ?? false,
isSortable: isRuntimeSort,
},
};
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ ContainerStixObjectsOrStixRelationshipsComponentProps
security.push(KNOWLEDGE_KNPARTICIPATE);
}
const { helper } = useContext(UserContext);
const isRuntimeSort = helper?.isRuntimeFieldEnable();
const isRuntimeSort = helper?.isRuntimeFieldEnable() ?? false;
const dataColumns = {
entity_type: {
label: 'Type',
Expand All @@ -73,12 +73,12 @@ ContainerStixObjectsOrStixRelationshipsComponentProps
createdBy: {
label: 'Author',
width: '12%',
isSortable: isRuntimeSort ?? false,
isSortable: isRuntimeSort,
},
creator: {
label: 'Creator',
width: '12%',
isSortable: isRuntimeSort ?? false,
isSortable: isRuntimeSort,
},
objectLabel: {
label: 'Labels',
Expand All @@ -92,7 +92,7 @@ ContainerStixObjectsOrStixRelationshipsComponentProps
},
objectMarking: {
label: 'Marking',
isSortable: isRuntimeSort ?? false,
isSortable: isRuntimeSort,
width: '8%',
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ class StixCoreObjectOrStixCoreRelationshipContainers extends Component {

// eslint-disable-next-line class-methods-use-this
buildColumns(helper) {
const isRuntimeSort = helper.isRuntimeFieldEnable();
const isRuntimeSort = helper.isRuntimeFieldEnable() ?? false;
return {
entity_type: {
label: 'Type',
Expand All @@ -190,12 +190,12 @@ class StixCoreObjectOrStixCoreRelationshipContainers extends Component {
createdBy: {
label: 'Author',
width: '12%',
isSortable: isRuntimeSort ?? false,
isSortable: isRuntimeSort,
},
creator: {
label: 'Creators',
width: '12%',
isSortable: isRuntimeSort ?? false,
isSortable: isRuntimeSort,
},
objectLabel: {
label: 'Labels',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ class Relationships extends Component {
creator: {
label: 'Creators',
width: '7%',
isSortable: true,
isSortable: isRuntimeSort,
},
created_at: {
label: 'Creation date',
Expand Down
Loading

0 comments on commit fb1488c

Please sign in to comment.