-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(composer): render tags from layer
- Loading branch information
Showing
39 changed files
with
1,493 additions
and
200 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
138 changes: 138 additions & 0 deletions
138
packages/scene-composer/src/components/SceneLayers.spec.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,138 @@ | ||
import * as React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
|
||
import { useStore } from '../store'; | ||
import { processQueries } from '../utils/entityModelUtils/processQueries'; | ||
|
||
import { SceneLayers } from './SceneLayers'; | ||
|
||
jest.mock('../utils/entityModelUtils/processQueries', () => ({ | ||
processQueries: jest.fn(), | ||
})); | ||
|
||
jest.mock('@tanstack/react-query', () => ({ | ||
useQuery: jest.fn(), | ||
})); | ||
|
||
describe('SceneLayers', () => { | ||
const renderSceneNodesFromLayersMock = jest.fn(); | ||
const isViewingMock = jest.fn(); | ||
const getScenePropertyMock = jest.fn(); | ||
const baseState = { | ||
getSceneProperty: getScenePropertyMock, | ||
renderSceneNodesFromLayers: renderSceneNodesFromLayersMock, | ||
isViewing: isViewingMock, | ||
}; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
|
||
isViewingMock.mockReturnValue(true); | ||
getScenePropertyMock.mockReturnValue(['layer1', 'layer2']); | ||
}); | ||
|
||
it('should enable query when have layerId', async () => { | ||
useStore('default').setState(baseState); | ||
let enabledValue = false; | ||
(useQuery as jest.Mock).mockImplementation(({ enabled, ..._ }) => { | ||
enabledValue = enabled; | ||
return {}; | ||
}); | ||
|
||
render(<SceneLayers />); | ||
|
||
expect(enabledValue).toBe(true); | ||
}); | ||
|
||
it('should not enable query when no layerId', async () => { | ||
useStore('default').setState(baseState); | ||
getScenePropertyMock.mockReturnValue([]); | ||
|
||
let enabledValue = true; | ||
(useQuery as jest.Mock).mockImplementation(({ enabled, ..._ }) => { | ||
enabledValue = enabled; | ||
return {}; | ||
}); | ||
|
||
render(<SceneLayers />); | ||
|
||
expect(enabledValue).toBe(false); | ||
}); | ||
|
||
it('should not refetch when not in viewing mode', async () => { | ||
useStore('default').setState(baseState); | ||
isViewingMock.mockReturnValue(false); | ||
let interval; | ||
(useQuery as jest.Mock).mockImplementation(({ refetchInterval, ..._ }) => { | ||
interval = refetchInterval(undefined, { state: {} }); | ||
return {}; | ||
}); | ||
|
||
render(<SceneLayers />); | ||
|
||
expect(interval).toBe(0); | ||
}); | ||
|
||
it('should not refetch when previous query failed', async () => { | ||
useStore('default').setState(baseState); | ||
isViewingMock.mockReturnValue(false); | ||
let interval; | ||
(useQuery as jest.Mock).mockImplementation(({ refetchInterval, ..._ }) => { | ||
interval = refetchInterval(undefined, { state: { error: 'error' } }); | ||
return {}; | ||
}); | ||
|
||
render(<SceneLayers />); | ||
|
||
expect(interval).toBe(0); | ||
}); | ||
|
||
it('should refetch with expected interval', async () => { | ||
useStore('default').setState(baseState); | ||
let interval; | ||
(useQuery as jest.Mock).mockImplementation(({ refetchInterval, ..._ }) => { | ||
interval = refetchInterval(undefined, { state: {} }); | ||
return {}; | ||
}); | ||
|
||
render(<SceneLayers />); | ||
|
||
expect(interval).toBe(10 * 1000); | ||
}); | ||
|
||
it('should call processQueries with expected data', async () => { | ||
useStore('default').setState(baseState); | ||
let queryFunction; | ||
(useQuery as jest.Mock).mockImplementation(({ queryFn, ..._ }) => { | ||
queryFunction = queryFn; | ||
return {}; | ||
}); | ||
|
||
render(<SceneLayers />); | ||
await queryFunction(); | ||
|
||
expect(processQueries as jest.Mock).toBeCalledTimes(1); | ||
expect(processQueries as jest.Mock).toBeCalledWith( | ||
[expect.stringContaining("AND e.entityId = 'layer1'")], | ||
expect.anything(), | ||
); | ||
expect(renderSceneNodesFromLayersMock).not.toBeCalled(); | ||
}); | ||
|
||
it('should call processQueries with expected data', async () => { | ||
useStore('default').setState(baseState); | ||
let queryFunction; | ||
(useQuery as jest.Mock).mockImplementation(({ queryFn, ..._ }) => { | ||
queryFunction = queryFn; | ||
return { data: ['random'] }; | ||
}); | ||
|
||
render(<SceneLayers />); | ||
await queryFunction(); | ||
|
||
expect(processQueries as jest.Mock).toBeCalledTimes(1); | ||
expect(renderSceneNodesFromLayersMock).toBeCalledTimes(1); | ||
expect(renderSceneNodesFromLayersMock).toBeCalledWith(['random'], 'layer1'); | ||
}); | ||
}); |
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,47 @@ | ||
import React, { useContext, useEffect } from 'react'; | ||
import { isEmpty } from 'lodash'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
|
||
import { sceneComposerIdContext } from '../common/sceneComposerIdContext'; | ||
import { useStore } from '../store'; | ||
import { processQueries } from '../utils/entityModelUtils/processQueries'; | ||
import { KnownSceneProperty } from '../interfaces'; | ||
import { DEFAULT_LAYER_RELATIONSHIP_NAME } from '../common/entityModelConstants'; | ||
|
||
export const SceneLayers: React.FC = () => { | ||
const sceneComposerId = useContext(sceneComposerIdContext); | ||
const isViewing = useStore(sceneComposerId)((state) => state.isViewing()); | ||
|
||
const renderSceneNodesFromLayers = useStore(sceneComposerId)((state) => state.renderSceneNodesFromLayers); | ||
const layerIds = useStore(sceneComposerId)((state) => state.getSceneProperty<string[]>(KnownSceneProperty.LayerIds)); | ||
const layerId = layerIds?.[0]; | ||
|
||
const nodes = useQuery({ | ||
enabled: !isEmpty(layerIds), | ||
queryKey: ['scene-layers', layerIds, sceneComposerId], | ||
queryFn: async () => { | ||
const nodes = await processQueries( | ||
[ | ||
`SELECT entity, r, e | ||
FROM EntityGraph | ||
MATCH (entity)-[r]->(e) | ||
WHERE r.relationshipName = '${DEFAULT_LAYER_RELATIONSHIP_NAME}' | ||
AND e.entityId = '${layerId}'`, | ||
], | ||
(node) => (node.properties.layerIds = [...(node.properties.layerIds ?? []), layerId!]), | ||
); | ||
return nodes; | ||
}, | ||
refetchInterval: (_, query) => { | ||
return !query.state.error && isViewing ? 10 * 1000 : 0; | ||
}, | ||
}); | ||
|
||
useEffect(() => { | ||
if (nodes.data) { | ||
renderSceneNodesFromLayers(nodes.data, layerId!); | ||
} | ||
}, [nodes.data, renderSceneNodesFromLayers]); | ||
|
||
return <></>; | ||
}; |
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
65 changes: 0 additions & 65 deletions
65
packages/scene-composer/src/components/panels/AddOrRemoveOverlayButton.tsx
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.