-
Notifications
You must be signed in to change notification settings - Fork 946
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[frontend] public widget : entities heatmap
- Loading branch information
Showing
2 changed files
with
126 additions
and
1 deletion.
There are no files selected for viewing
117 changes: 117 additions & 0 deletions
117
...tform/opencti-front/src/public/components/dashboard/PublicStixCoreObjectsMultiHeatMap.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
import { graphql, PreloadedQuery, usePreloadedQuery } from 'react-relay'; | ||
import React from 'react'; | ||
import WidgetNoData from '../../../components/dashboard/WidgetNoData'; | ||
import type { PublicWidgetContainerProps } from './publicWidgetContainerProps'; | ||
import { useFormatter } from '../../../components/i18n'; | ||
import useQueryLoading from '../../../utils/hooks/useQueryLoading'; | ||
import WidgetContainer from '../../../components/dashboard/WidgetContainer'; | ||
import WidgetLoader from '../../../components/dashboard/WidgetLoader'; | ||
import { PublicStixCoreObjectsMultiHeatMapQuery } from './__generated__/PublicStixCoreObjectsMultiHeatMapQuery.graphql'; | ||
import WidgetMultiHeatMap from '../../../components/dashboard/WidgetMultiHeatMap'; | ||
import type { PublicManifestWidget } from './PublicManifest'; | ||
|
||
const publicStixCoreObjectsMultiHeatMapQuery = graphql` | ||
query PublicStixCoreObjectsMultiHeatMapQuery( | ||
$startDate: DateTime | ||
$endDate: DateTime | ||
$uriKey: String! | ||
$widgetId : String! | ||
) { | ||
publicStixCoreObjectsMultiTimeSeries( | ||
startDate: $startDate | ||
endDate: $endDate | ||
uriKey: $uriKey | ||
widgetId : $widgetId | ||
) { | ||
data { | ||
date | ||
value | ||
} | ||
} | ||
} | ||
`; | ||
|
||
interface PublicStixCoreObjectsMultiHeatMapComponentProps { | ||
parameters: PublicManifestWidget['parameters'] | ||
dataSelection: PublicManifestWidget['dataSelection'] | ||
queryRef: PreloadedQuery<PublicStixCoreObjectsMultiHeatMapQuery> | ||
} | ||
|
||
const PublicStixCoreObjectsMultiHeatMapComponent = ({ | ||
parameters, | ||
dataSelection, | ||
queryRef, | ||
}: PublicStixCoreObjectsMultiHeatMapComponentProps) => { | ||
const { t_i18n } = useFormatter(); | ||
const { publicStixCoreObjectsMultiTimeSeries } = usePreloadedQuery( | ||
publicStixCoreObjectsMultiHeatMapQuery, | ||
queryRef, | ||
); | ||
|
||
if (publicStixCoreObjectsMultiTimeSeries) { | ||
const allValues = publicStixCoreObjectsMultiTimeSeries | ||
.map((serie) => (serie?.data ?? []).flatMap((o) => o?.value ?? [])) | ||
.flat(); | ||
const maxValue = Math.max(...allValues); | ||
const minValue = Math.min(...allValues); | ||
|
||
return ( | ||
<WidgetMultiHeatMap | ||
data={publicStixCoreObjectsMultiTimeSeries.map((serie, i) => ({ | ||
name: dataSelection[i].label ?? t_i18n('Number of entities'), | ||
data: (serie?.data ?? []).map((entry) => ({ | ||
x: new Date(entry?.date), | ||
y: entry?.value, | ||
})), | ||
})).sort((a, b) => b.name.localeCompare(a.name))} | ||
minValue={minValue} | ||
maxValue={maxValue} | ||
isStacked={parameters.stacked} | ||
withExport={false} | ||
readonly={true} | ||
/> | ||
); | ||
} | ||
return <WidgetNoData />; | ||
}; | ||
|
||
const PublicStixCoreObjectsMultiHeatMap = ({ | ||
uriKey, | ||
widget, | ||
startDate, | ||
endDate, | ||
title, | ||
}: PublicWidgetContainerProps) => { | ||
const { t_i18n } = useFormatter(); | ||
const { id, parameters, dataSelection } = widget; | ||
const queryRef = useQueryLoading<PublicStixCoreObjectsMultiHeatMapQuery>( | ||
publicStixCoreObjectsMultiHeatMapQuery, | ||
{ | ||
uriKey, | ||
widgetId: id, | ||
startDate, | ||
endDate, | ||
}, | ||
); | ||
|
||
return ( | ||
<WidgetContainer | ||
title={parameters.title ?? title ?? t_i18n('Entities number')} | ||
variant="inLine" | ||
> | ||
{queryRef ? ( | ||
<React.Suspense fallback={<WidgetLoader />}> | ||
<PublicStixCoreObjectsMultiHeatMapComponent | ||
queryRef={queryRef} | ||
parameters={parameters} | ||
dataSelection={dataSelection} | ||
/> | ||
</React.Suspense> | ||
) : ( | ||
<WidgetLoader /> | ||
)} | ||
</WidgetContainer> | ||
); | ||
}; | ||
|
||
export default PublicStixCoreObjectsMultiHeatMap; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters