@openneuro/app 4.12.0-alpha.0 → 4.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openneuro/app",
|
|
3
|
-
"version": "4.12.0
|
|
3
|
+
"version": "4.12.0",
|
|
4
4
|
"description": "React JS web frontend for the OpenNeuro platform.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "public/client.js",
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
"@emotion/react": "11.6.0",
|
|
21
21
|
"@emotion/styled": "11.6.0",
|
|
22
22
|
"@niivue/niivue": "0.23.1",
|
|
23
|
-
"@openneuro/client": "^4.12.0
|
|
24
|
-
"@openneuro/components": "^4.12.0
|
|
23
|
+
"@openneuro/client": "^4.12.0",
|
|
24
|
+
"@openneuro/components": "^4.12.0",
|
|
25
25
|
"bids-validator": "1.9.9",
|
|
26
26
|
"bytes": "^3.0.0",
|
|
27
27
|
"comlink": "^4.0.5",
|
|
@@ -104,5 +104,5 @@
|
|
|
104
104
|
"publishConfig": {
|
|
105
105
|
"access": "public"
|
|
106
106
|
},
|
|
107
|
-
"gitHead": "
|
|
107
|
+
"gitHead": "611c84329ef63f730878f701aafaa1bc4c703ea4"
|
|
108
108
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
|
-
import { render } from '@testing-library/react'
|
|
3
|
-
import { SearchParamsCtx } from '../search-params-ctx'
|
|
2
|
+
import { render, screen, fireEvent } from '@testing-library/react'
|
|
3
|
+
import { SearchParamsProvider, SearchParamsCtx } from '../search-params-ctx'
|
|
4
|
+
import AuthorInput from '../inputs/author-input'
|
|
5
|
+
import { MemoryRouter } from 'react-router-dom'
|
|
4
6
|
import '@testing-library/jest-dom'
|
|
5
7
|
|
|
6
8
|
/**
|
|
@@ -15,6 +17,48 @@ export const searchRender = (ui, { providerProps, ...renderOptions }) => {
|
|
|
15
17
|
)
|
|
16
18
|
}
|
|
17
19
|
|
|
18
|
-
describe('
|
|
19
|
-
it('
|
|
20
|
+
describe('SearchParamsProvider', () => {
|
|
21
|
+
it('restores URL searchParams state', () => {
|
|
22
|
+
const route = '/search?query={"authors"%3A["Test+Author"]}'
|
|
23
|
+
const wrapper = ({ children }) => (
|
|
24
|
+
<MemoryRouter initialEntries={[route]}>
|
|
25
|
+
<SearchParamsProvider>{children}</SearchParamsProvider>
|
|
26
|
+
</MemoryRouter>
|
|
27
|
+
)
|
|
28
|
+
render(
|
|
29
|
+
<SearchParamsCtx.Consumer>
|
|
30
|
+
{value => <span>Received: {value.searchParams.authors.pop()}</span>}
|
|
31
|
+
</SearchParamsCtx.Consumer>,
|
|
32
|
+
{ wrapper },
|
|
33
|
+
)
|
|
34
|
+
expect(screen.getByText(/^Received:/).textContent).toBe(
|
|
35
|
+
'Received: Test Author',
|
|
36
|
+
)
|
|
37
|
+
})
|
|
38
|
+
it('edits array fields correctly', () => {
|
|
39
|
+
const route = '/search?query={"authors"%3A["Test+Author"]}'
|
|
40
|
+
const wrapper = ({ children }) => (
|
|
41
|
+
<MemoryRouter initialEntries={[route]}>
|
|
42
|
+
<SearchParamsProvider>{children}</SearchParamsProvider>
|
|
43
|
+
</MemoryRouter>
|
|
44
|
+
)
|
|
45
|
+
render(
|
|
46
|
+
<SearchParamsCtx.Consumer>
|
|
47
|
+
{value => (
|
|
48
|
+
<>
|
|
49
|
+
<AuthorInput />
|
|
50
|
+
<span>Received: {value.searchParams.authors.join(', ')}</span>
|
|
51
|
+
</>
|
|
52
|
+
)}
|
|
53
|
+
</SearchParamsCtx.Consumer>,
|
|
54
|
+
{ wrapper },
|
|
55
|
+
)
|
|
56
|
+
const textInput = screen.getByRole('textbox')
|
|
57
|
+
const button = screen.getByRole('button')
|
|
58
|
+
fireEvent.change(textInput, { target: { value: 'New Author' } })
|
|
59
|
+
fireEvent.click(button)
|
|
60
|
+
expect(screen.getByText(/^Received:/).textContent).toBe(
|
|
61
|
+
'Received: Test Author, New Author',
|
|
62
|
+
)
|
|
63
|
+
})
|
|
20
64
|
})
|
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
|
|
3
|
-
useState,
|
|
4
|
-
useContext,
|
|
5
|
-
FC,
|
|
6
|
-
ReactNode,
|
|
7
|
-
} from 'react'
|
|
1
|
+
import React, { createContext, useContext, FC, ReactNode } from 'react'
|
|
2
|
+
import { useSearchParams } from 'react-router-dom'
|
|
8
3
|
import initialSearchParams from './initial-search-params'
|
|
9
4
|
|
|
10
5
|
export const SearchParamsCtx = createContext(null)
|
|
@@ -16,9 +11,34 @@ interface SearchParamsProviderProps {
|
|
|
16
11
|
export const SearchParamsProvider: FC<SearchParamsProviderProps> = ({
|
|
17
12
|
children,
|
|
18
13
|
}) => {
|
|
19
|
-
const [
|
|
14
|
+
const [searchQuery, setSearch] = useSearchParams()
|
|
15
|
+
|
|
16
|
+
let searchParams
|
|
17
|
+
try {
|
|
18
|
+
const query = searchQuery.get('query')
|
|
19
|
+
if (query) {
|
|
20
|
+
searchParams = JSON.parse(query)
|
|
21
|
+
}
|
|
22
|
+
} catch (err) {
|
|
23
|
+
console.error(err)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const setSearchParams = newParamsCall => {
|
|
27
|
+
const merged = { ...searchParams, ...newParamsCall(searchParams) }
|
|
28
|
+
setSearch(
|
|
29
|
+
{
|
|
30
|
+
query: JSON.stringify(merged),
|
|
31
|
+
},
|
|
32
|
+
{ replace: true },
|
|
33
|
+
)
|
|
34
|
+
}
|
|
35
|
+
|
|
20
36
|
return (
|
|
21
|
-
<SearchParamsCtx.Provider
|
|
37
|
+
<SearchParamsCtx.Provider
|
|
38
|
+
value={{
|
|
39
|
+
searchParams: { ...initialSearchParams, ...searchParams },
|
|
40
|
+
setSearchParams,
|
|
41
|
+
}}>
|
|
22
42
|
{children}
|
|
23
43
|
</SearchParamsCtx.Provider>
|
|
24
44
|
)
|