We're planning to migrate Collect's store to redux. First of all, I think we should agree about what the state should look like.
So there is my first proposition, let's discuss :
Entities
As specified in this presentation made by @goldoraf, we should keep a list of our entities.
The entities we need are : Konnectors, Konnector results, Accounts, Jobs.
{
api: {
endpoint: { ... },
entities: {
io.cozy.konnectors: { // installed konnectors },
io.cozy.konnectors.result: {},
io.cozy.accounts: {},
io.cozy.jobs: {}
}
},
},
...
If I undestood well, those entities are already managed by redux-cozy-client, so let's dive into the custom part.
Store
At startup, no konnector is installed and the konnector list comes from the file src/config/konnectors.json
.
...,
store: {
konnectors: {
...
maif: { ... }
trainline: { ... }
...
}
}
...
Connections
We use connections to reflect the status of an account associated with a konnector. To determine this status we need at least the last konnectorResult for the given konnector, and a running job if it exists.
This part of the state will play a major role in Collect, and will be at the center of the realtime logic.
My first idea for this part is something like this. This example is multi-accounts ready !
...,
connections: {
konnectors: {
trainline: {
accounts: {
'3214543345345345453': {
status: 'connecting',
folder: {
status: 'created'
},
konnectorResult: {
id: '8889987657564364',
status: 'errored',
error: {
message: { 'LOGIN_FAILED' }
}
},
job: {
id: '556586856588658909009',
status: 'running'
}
}
}
}
}
}
...
UI
The UI part will consider all the konnectors filtered lists, the use-case and the opened modal. It should look like :
...,
ui: {
categories: {
travel: {
konnectors: [ 'trainline', ... ]
}
},
usecases: [...],
modal: {
konnector: trainline
}
}
...