@openneuro/app 4.20.6-alpha.8 → 4.21.0-alpha.1

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.
Files changed (42) hide show
  1. package/package.json +4 -4
  2. package/src/scripts/app.tsx +16 -10
  3. package/src/scripts/components/__tests__/agreement.spec.tsx +24 -0
  4. package/src/scripts/components/agreement.tsx +76 -0
  5. package/src/scripts/dataset/__tests__/__snapshots__/snapshot-container.spec.tsx.snap +10 -330
  6. package/src/scripts/dataset/components/BrainLifeButton.tsx +38 -0
  7. package/src/scripts/dataset/components/CloneDropdown.tsx +31 -0
  8. package/src/scripts/dataset/components/DatasetAlert.tsx +25 -0
  9. package/src/scripts/dataset/components/DatasetGitAccess.tsx +82 -0
  10. package/src/scripts/dataset/components/DatasetHeader.tsx +43 -0
  11. package/src/scripts/dataset/components/DatasetHeaderMeta.tsx +22 -0
  12. package/src/scripts/dataset/components/DatasetToolButton.tsx +52 -0
  13. package/src/scripts/dataset/components/DatasetTools.tsx +149 -0
  14. package/src/scripts/dataset/components/MetaDataBlock.tsx +24 -0
  15. package/src/scripts/dataset/components/MetaDataListBlock.tsx +23 -0
  16. package/src/scripts/dataset/components/ModalitiesMetaDataBlock.tsx +32 -0
  17. package/src/scripts/dataset/components/NemarButton.tsx +34 -0
  18. package/src/scripts/dataset/components/ValidationBlock.tsx +11 -0
  19. package/src/scripts/dataset/components/VersionList.tsx +115 -0
  20. package/src/scripts/dataset/components/__tests__/DatasetAlert.spec.tsx +25 -0
  21. package/src/scripts/dataset/components/__tests__/DatasetHeaders.spec.tsx +18 -0
  22. package/src/scripts/dataset/components/__tests__/DatasetTools.spec.tsx +133 -0
  23. package/src/scripts/dataset/draft-container.tsx +9 -11
  24. package/src/scripts/dataset/files/__tests__/file.spec.jsx +13 -4
  25. package/src/scripts/dataset/files/file.tsx +27 -21
  26. package/src/scripts/dataset/fragments/dataset-alert-draft.tsx +1 -1
  27. package/src/scripts/dataset/fragments/dataset-alert-version.tsx +1 -1
  28. package/src/scripts/dataset/routes/dataset-default.tsx +1 -1
  29. package/src/scripts/dataset/routes/download-dataset.tsx +7 -1
  30. package/src/scripts/dataset/routes/snapshot-default.tsx +1 -1
  31. package/src/scripts/dataset/snapshot-container.tsx +10 -12
  32. package/src/scripts/scss/README.md +3 -0
  33. package/src/scripts/scss/dataset/comments.scss +152 -0
  34. package/src/scripts/scss/dataset/dataset-page.scss +397 -0
  35. package/src/scripts/scss/dataset/dataset-tool.scss +281 -0
  36. package/src/scripts/scss/dataset/dropdown.scss +29 -0
  37. package/src/scripts/scss/dataset/validation.scss +392 -0
  38. package/src/scripts/scss/dataset/version-dropdown.scss +121 -0
  39. package/src/scripts/scss/index.scss +6 -0
  40. package/src/scripts/scss/variables.scss +205 -0
  41. package/src/scripts/utils/__tests__/local-storage.spec.tsx +32 -0
  42. package/src/scripts/utils/local-storage.tsx +53 -0
@@ -0,0 +1,32 @@
1
+ import React, { useEffect } from "react"
2
+ import { render } from "@testing-library/react"
3
+ import { LocalStorageProvider, useLocalStorage } from "../local-storage"
4
+
5
+ const STORAGE_KEY = "tests"
6
+
7
+ const TestComponent = () => {
8
+ const [value, setValue] = useLocalStorage(STORAGE_KEY)
9
+ useEffect(() => {
10
+ setValue("testing")
11
+ }, [value])
12
+ return null
13
+ }
14
+
15
+ describe("localStorage hooks", () => {
16
+ beforeEach(() => {
17
+ localStorage.clear()
18
+ })
19
+ afterEach(() => {
20
+ localStorage.clear()
21
+ })
22
+ it("sets and retrieves a value", () => {
23
+ render(
24
+ <LocalStorageProvider defaultValue={{}}>
25
+ <TestComponent />
26
+ </LocalStorageProvider>,
27
+ )
28
+ expect(JSON.parse(localStorage.getItem("openneuro")).tests).toEqual(
29
+ "testing",
30
+ )
31
+ })
32
+ })
@@ -0,0 +1,53 @@
1
+ import React from "react"
2
+ import { createContext, useContext, useEffect, useState } from "react"
3
+
4
+ /** Shared context for all local storage updates */
5
+ const LocalStorageContext = createContext({
6
+ localStorageValue: { agreement: false },
7
+ setLocalStorageValue: undefined,
8
+ })
9
+
10
+ const LOCAL_STORAGE_KEY = "openneuro"
11
+
12
+ function getStorageValue<T>(key: string, defaultValue: T): T {
13
+ const saved = localStorage.getItem(key)
14
+ if (saved) return JSON.parse(saved)
15
+ else return defaultValue
16
+ }
17
+
18
+ /**
19
+ * Local storage hook that updates across components
20
+ * @param key Field name for localstorage object
21
+ */
22
+ export function useLocalStorage<T>(
23
+ key: string,
24
+ ): [T, (value: T) => void] {
25
+ const context = useContext(LocalStorageContext)
26
+ const setValue = (value: T) => {
27
+ const update = {}
28
+ update[key] = value
29
+ context?.setLocalStorageValue(update)
30
+ }
31
+ return [context?.localStorageValue[key], setValue]
32
+ }
33
+
34
+ export function LocalStorageProvider({ children, defaultValue }) {
35
+ const [localStorageValue, setLocalStorageValue] = useState(() => {
36
+ return getStorageValue(LOCAL_STORAGE_KEY, defaultValue)
37
+ })
38
+
39
+ useEffect(() => {
40
+ const val = localStorage.getItem(LOCAL_STORAGE_KEY)
41
+ const prev = val ? JSON.parse(val) : {}
42
+ const updateValue = { ...prev, ...defaultValue, ...localStorageValue }
43
+ localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(updateValue))
44
+ }, [localStorageValue])
45
+
46
+ return (
47
+ <LocalStorageContext.Provider
48
+ value={{ localStorageValue, setLocalStorageValue }}
49
+ >
50
+ {children}
51
+ </LocalStorageContext.Provider>
52
+ )
53
+ }