Commit d8717503 authored by Alexandre Delanoë's avatar Alexandre Delanoë

Merge remote-tracking branch 'origin/594-dev-ngrams-patch-fixes' into dev

parents f824c0e3 058fa2fe
Pipeline #4608 failed with stage
in 0 seconds
...@@ -35,7 +35,6 @@ initialState ...@@ -35,7 +35,6 @@ initialState
initialState {loaded: {ngramsTable: Versioned {version}}} = initialState {loaded: {ngramsTable: Versioned {version}}} =
{ ngramsLocalPatch: mempty { ngramsLocalPatch: mempty
, ngramsStagePatch: mempty , ngramsStagePatch: mempty
, ngramsValidPatch: mempty
, ngramsSelection : mempty , ngramsSelection : mempty
, ngramsVersion: version , ngramsVersion: version
} }
......
...@@ -93,7 +93,6 @@ initialState = ...@@ -93,7 +93,6 @@ initialState =
{ ngramsLocalPatch: mempty { ngramsLocalPatch: mempty
, ngramsSelection: mempty , ngramsSelection: mempty
, ngramsStagePatch: mempty , ngramsStagePatch: mempty
, ngramsValidPatch: mempty
, ngramsVersion: 0 , ngramsVersion: 0
} }
...@@ -824,6 +823,12 @@ mainNgramsTableCpt = here.component "mainNgramsTable" cpt ...@@ -824,6 +823,12 @@ mainNgramsTableCpt = here.component "mainNgramsTable" cpt
-- onNgramsClickRef <- R.useRef Nothing -- onNgramsClickRef <- R.useRef Nothing
-- onSaveRef <- R.useRef Nothing -- onSaveRef <- R.useRef Nothing
state <- T.useBox initialState state <- T.useBox initialState
-- https://gitlab.iscpif.fr/gargantext/purescript-gargantext/issues/594
-- Refreshing view when state.ngramsVersion changes.
ngramsVersion <- T.useFocused (_.ngramsVersion) (\a b -> b { ngramsVersion = a}) state
ngramsVersion' <- T.useLive T.unequal ngramsVersion
-- ngramsLocalPatch <- T.useFocused (_.ngramsLocalPatch) (\a b -> b { ngramsLocalPatch = a }) state -- ngramsLocalPatch <- T.useFocused (_.ngramsLocalPatch) (\a b -> b { ngramsLocalPatch = a }) state
-- nodeId <- T.useFocused (_.nodeId) (\a b -> b { nodeId = a }) path -- nodeId <- T.useFocused (_.nodeId) (\a b -> b { nodeId = a }) path
...@@ -841,11 +846,11 @@ mainNgramsTableCpt = here.component "mainNgramsTable" cpt ...@@ -841,11 +846,11 @@ mainNgramsTableCpt = here.component "mainNgramsTable" cpt
case cacheState' of case cacheState' of
NT.CacheOn -> pure $ R.fragment NT.CacheOn -> pure $ R.fragment
[ loadedNgramsTableHeader { searchQuery, params } [ loadedNgramsTableHeader { searchQuery, params }
, mainNgramsTableCacheOn (Record.merge props { state }) , mainNgramsTableCacheOn (Record.merge props { key: show ngramsVersion', state })
] ]
NT.CacheOff -> pure $ R.fragment NT.CacheOff -> pure $ R.fragment
[loadedNgramsTableHeader { searchQuery, params} [ loadedNgramsTableHeader { searchQuery, params }
, mainNgramsTableCacheOff (Record.merge props { state }) , mainNgramsTableCacheOff (Record.merge props { key: show ngramsVersion', state })
] ]
...@@ -1015,6 +1020,7 @@ ngramsTreeEditRealCpt = here.component "ngramsTreeEditReal" cpt where ...@@ -1015,6 +1020,7 @@ ngramsTreeEditRealCpt = here.component "ngramsTreeEditReal" cpt where
type MainNgramsTableCacheProps = type MainNgramsTableCacheProps =
( state :: T.Box State ( state :: T.Box State
, key :: String
| MainNgramsTableProps ) | MainNgramsTableProps )
mainNgramsTableCacheOn :: R2.Leaf MainNgramsTableCacheProps mainNgramsTableCacheOn :: R2.Leaf MainNgramsTableCacheProps
......
...@@ -50,11 +50,12 @@ syncResetButtonsCpt = here.component "syncResetButtons" cpt ...@@ -50,11 +50,12 @@ syncResetButtonsCpt = here.component "syncResetButtons" cpt
synchronizeClick _ = delay unit $ \_ -> do synchronizeClick _ = delay unit $ \_ -> do
T.write_ true synchronizing T.write_ true synchronizing
performAction $ Synchronize { afterSync: newAfterSync } performAction $ Synchronize { afterSync: newAfterSync }
performAction ResetPatches
newAfterSync x = do newAfterSync x = do
afterSync x afterSync x
liftEffect $ T.write_ false synchronizing liftEffect $ do
T.write_ false synchronizing
performAction ResetPatches
pure $ pure $
......
...@@ -340,7 +340,6 @@ renderNgramsItemCpt = here.component "renderNgramsItem" cpt ...@@ -340,7 +340,6 @@ renderNgramsItemCpt = here.component "renderNgramsItem" cpt
tbl :: NgramsTable tbl :: NgramsTable
tbl = applyNgramsPatches { ngramsLocalPatch tbl = applyNgramsPatches { ngramsLocalPatch
, ngramsStagePatch: mempty , ngramsStagePatch: mempty
, ngramsValidPatch: mempty
, ngramsVersion: 0 } ngramsTable , ngramsVersion: 0 } ngramsTable
getNgramsChildren' :: NgramsTerm -> Array NgramsTerm getNgramsChildren' :: NgramsTerm -> Array NgramsTerm
getNgramsChildren' n = A.fromFoldable $ ngramsChildren n getNgramsChildren' n = A.fromFoldable $ ngramsChildren n
......
...@@ -362,8 +362,8 @@ applyNgramsTablePatch (NgramsTablePatch ngramsPatches) (NgramsTable m) = ...@@ -362,8 +362,8 @@ applyNgramsTablePatch (NgramsTablePatch ngramsPatches) (NgramsTable m) =
applyPatchMap applyNgramsPatch ngramsPatches m.ngrams_repo_elements } applyPatchMap applyNgramsPatch ngramsPatches m.ngrams_repo_elements }
applyNgramsPatches :: forall s. CoreState s -> NgramsTable -> NgramsTable applyNgramsPatches :: forall s. CoreState s -> NgramsTable -> NgramsTable
applyNgramsPatches {ngramsLocalPatch, ngramsStagePatch, ngramsValidPatch} = applyNgramsPatches { ngramsLocalPatch, ngramsStagePatch } =
applyNgramsTablePatch (ngramsLocalPatch <> ngramsStagePatch <> ngramsValidPatch) applyNgramsTablePatch ( ngramsLocalPatch <> ngramsStagePatch )
-- First the valid patch, then the stage patch, and finally the local patch. -- First the valid patch, then the stage patch, and finally the local patch.
{- {-
...@@ -436,8 +436,7 @@ syncPatches props state callback = do ...@@ -436,8 +436,7 @@ syncPatches props state callback = do
s { s {
ngramsLocalPatch = fromNgramsPatches mempty ngramsLocalPatch = fromNgramsPatches mempty
, ngramsStagePatch = fromNgramsPatches mempty , ngramsStagePatch = fromNgramsPatches mempty
, ngramsValidPatch = fromNgramsPatches newPatch <> ngramsLocalPatch <> s.ngramsValidPatch -- First the local patch, then the newly received newPatch.
-- First the already valid patch, then the local patch, then the newly received newPatch.
, ngramsVersion = newVersion , ngramsVersion = newVersion
}) state }) state
here.log2 "[syncPatches] ngramsVersion" newVersion here.log2 "[syncPatches] ngramsVersion" newVersion
...@@ -448,7 +447,6 @@ syncPatchesAsync :: forall p s. CoreParams p -> R.State (CoreState s) -> (Unit - ...@@ -448,7 +447,6 @@ syncPatchesAsync :: forall p s. CoreParams p -> R.State (CoreState s) -> (Unit -
syncPatchesAsync props@{ listIds, tabType } syncPatchesAsync props@{ listIds, tabType }
({ ngramsLocalPatch: ngramsLocalPatch@{ ngramsPatches } ({ ngramsLocalPatch: ngramsLocalPatch@{ ngramsPatches }
, ngramsStagePatch , ngramsStagePatch
, ngramsValidPatch
, ngramsVersion , ngramsVersion
} /\ setState) callback = do } /\ setState) callback = do
when (isEmptyNgramsTablePatch ngramsStagePatch) $ do when (isEmptyNgramsTablePatch ngramsStagePatch) $ do
...@@ -462,8 +460,7 @@ syncPatchesAsync props@{ listIds, tabType } ...@@ -462,8 +460,7 @@ syncPatchesAsync props@{ listIds, tabType }
s { s {
ngramsLocalPatch = fromNgramsPatches mempty ngramsLocalPatch = fromNgramsPatches mempty
, ngramsStagePatch = fromNgramsPatches mempty , ngramsStagePatch = fromNgramsPatches mempty
, ngramsValidPatch = fromNgramsPatches newPatch <> ngramsLocalPatch <> s.ngramsValidPatch -- First the local patch, then the newly received newPatch.
-- First the already valid patch, then the local patch, then the newly received newPatch.
, ngramsVersion = newVersion , ngramsVersion = newVersion
} }
here.log2 "[syncPatches] ngramsVersion" newVersion here.log2 "[syncPatches] ngramsVersion" newVersion
......
...@@ -507,8 +507,6 @@ type CoreState s = ...@@ -507,8 +507,6 @@ type CoreState s =
, ngramsStagePatch :: NgramsTablePatch , ngramsStagePatch :: NgramsTablePatch
-- ^ These patches are staged (scheduled for synchronization). -- ^ These patches are staged (scheduled for synchronization).
-- Requests are being performed at the moment. -- Requests are being performed at the moment.
, ngramsValidPatch :: NgramsTablePatch
-- ^ These patches have been synchronized with the server.
, ngramsVersion :: Version , ngramsVersion :: Version
| s | s
} }
......
//import crypto from 'crypto'; import { subtle } from '../../src/external-deps/crypto.js';
async function getSHA256Hash(input) { async function getSHA256Hash(input) {
const textAsBuffer = new TextEncoder().encode(input); const textAsBuffer = new TextEncoder().encode(input);
const hashBuffer = await globalThis.crypto.subtle.digest("SHA-256", textAsBuffer); const hashBuffer = await subtle.digest("SHA-256", textAsBuffer);
const hashArray = Array.from(new Uint8Array(hashBuffer)); const hashArray = Array.from(new Uint8Array(hashBuffer));
const hash = hashArray const hash = hashArray
.map((item) => item.toString(16).padStart(2, "0")) .map((item) => item.toString(16).padStart(2, "0"))
......
module Gargantext.Utils.Crypto where module Gargantext.Utils.Crypto where
import Control.Promise (Promise, toAffE) import Control.Promise (Promise, toAffE)
import Data.Array as Array
import Data.Set (Set) import Data.Set (Set)
import Data.Set as Set import Data.Set as Set
import Data.Array as Array import Data.String (joinWith)
import Effect (Effect) import Effect (Effect)
import Effect.Aff (Aff) import Effect.Aff (Aff)
...@@ -39,7 +40,7 @@ instance IsHashable (Array String) where ...@@ -39,7 +40,7 @@ instance IsHashable (Array String) where
hash = hash <<< concat hash = hash <<< concat
where where
concat :: Array Hash -> String concat :: Array Hash -> String
concat = Array.foldl (<>) "" concat = joinWith "" <<< Array.sort
instance IsHashable (Set String) where instance IsHashable (Set String) where
......
// https://siteultra.com/blog/using-subtle-in-a-javascript-module-from-both-the-browser-and-nodejs
let subtle = undefined;
if (typeof window !== 'undefined' && window.crypto && window.crypto.subtle) {
subtle = window.crypto.subtle;
} else {
// Import 'crypto' module in Node.js environment
subtle = require('crypto').subtle;
}
exports.subtle = subtle;
...@@ -124,7 +124,7 @@ spec = ...@@ -124,7 +124,7 @@ spec =
it "Hash List with backend works" do it "Hash List with backend works" do
let list = ["a","b"] let list = ["a","b"]
let hashed = "ab19ec537f09499b26f0f62eed7aefad46ab9f498e06a7328ce8e8ef90da6d86" let hashed = "fb8e20fc2e4c3f248c60c39bd652f3c1347298bb977b8b4d5903b85055620603"
-- ^ hash from backend with text above -- ^ hash from backend with text above
h <- Crypto.hash list h <- Crypto.hash list
h`shouldEqual` hashed h`shouldEqual` hashed
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment