forked from OpenCTI-Platform/opencti
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[frontend] add useOverviewLayoutCustomization hook (OpenCTI-Platform#…
- Loading branch information
Showing
17 changed files
with
263 additions
and
52 deletions.
There are no files selected for viewing
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
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
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
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
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
9 changes: 9 additions & 0 deletions
9
opencti-platform/opencti-front/src/utils/hooks/useOverviewLayoutCustomization.ts
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,9 @@ | ||
import useAuth from './useAuth'; | ||
|
||
const useOverviewLayoutCustomization: (entityType: string) => Array<{ key: string, width: number }> = (entityType) => { | ||
const { overviewLayoutCustomization } = useAuth(); | ||
return Array.from(overviewLayoutCustomization?.get(entityType)?.entries() ?? []) | ||
.flatMap(([key, width]) => ({ key, width })); | ||
}; | ||
|
||
export default useOverviewLayoutCustomization; |
50 changes: 50 additions & 0 deletions
50
opencti-platform/opencti-front/src/utils/tests/overviewLayoutCustomization.test.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,50 @@ | ||
import { describe, it, expect } from 'vitest'; | ||
import { renderHook } from '@testing-library/react'; | ||
import React from 'react'; | ||
import useAuth from '../hooks/useAuth'; | ||
import { createMockUserContext, ProvidersWrapper, ProvidersWrapperProps } from './test-render'; | ||
|
||
describe('overviewLayoutCustomization', () => { | ||
const threatActorIndividualEntityType = 'Threat-Actor-Individual'; | ||
const wrapper = ({ children }: ProvidersWrapperProps) => { | ||
return ( | ||
<ProvidersWrapper | ||
userContext={ | ||
createMockUserContext() | ||
} | ||
> | ||
{children} | ||
</ProvidersWrapper> | ||
); | ||
}; | ||
const { result } = renderHook(() => useAuth(), { wrapper }); | ||
|
||
it('should provide overview layout customization settings by block for a given entity type', () => { | ||
const expectedWidgetsKeys = [ | ||
'details', | ||
'basicInformation', | ||
'demographics-biographics', | ||
'latestCreatedRelationships', | ||
'latestContainers', | ||
'externalReferences', | ||
'mostRecentHistory', | ||
'notes', | ||
]; | ||
const threatActorIndividualOverviewLayoutCustomization = result.current?.overviewLayoutCustomization?.get(threatActorIndividualEntityType); | ||
expect( | ||
Array.from(threatActorIndividualOverviewLayoutCustomization?.keys() ?? []), | ||
).toEqual( | ||
expectedWidgetsKeys, | ||
); | ||
}); | ||
|
||
it('should provide width for every widget', () => { | ||
const threatActorIndividualOverviewLayoutCustomization = result.current?.overviewLayoutCustomization?.get(threatActorIndividualEntityType); | ||
expect( | ||
Array.from(threatActorIndividualOverviewLayoutCustomization?.values() ?? []) | ||
.every((width) => !!width), | ||
).toEqual( | ||
true, | ||
); | ||
}); | ||
}); |
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
Oops, something went wrong.