Open mfendeksilverstripe opened 1 month ago
Have you tried this on CMS 5.2? There's a chance that https://github.com/silverstripe/silverstripe-admin/pull/1694 will fix this - would require you changing to silverstripe/admin 2.2 to get the fix
Hey @emteknetnz , I've retested this issue on "silverstripe/recipe-cms": "5.2.x-dev",
which pulls in silverstripe/admin 2.2.x-dev 6925ecb
.
The issue is still present.
I've added same ACs to the cards. FYI I suspect this will not be a trivial fix.
And we have to ask ourselves how to handle the recursive scenario where you try to edit a file inside an InserMediaModal and interact with a nested UploadField. It's highly likely this particular scenario will blow up in our face. So it might be that we say "no nested UploadField".
Anyway, I've added this to our Monday refinement session. Maybe we need to do a Spike first before attempting a fix. Not sure.
This is happening because the UploadField
renders InsertMediaModal
which relies on the AssetAdmin
component.
The AssetAdmin
component, as its name suggests, is also the main component used for the asset admin section.
All of the redux state and actions are shared between the AssetAdmin
component (and its children) in the asset admin itself, and the AssetAdmin
component rendered in the upload field's modal. So when you select a file in the modal, it selects it in the main admin, for example.
To resolve this we'd need to split out the state for the upload field from the state for the main asset admin. I can't see an easy non-hacky way to do that.
assetAdmin
namespaced reducers
AssetAdmin
and all its children, telling them which namespace to use for actions and state.mapDispatchToProps()
to map the correct actions (may have to map both sets, not sure if we have the real props at this stage)type
of the action is appropriately namespaced
- Hackily create a new react root for the upload field's modal so it is a fresh instance of react/redux/etc
I'm not sure that would even work? Doesn't the redux store live in window.ss.store and it's not 'namespaced' to the react root? i.e. if you create 2x react roots they'll share the store? I'm only making assumptions here, I haven't tested.
e.g. window.ss.store.getState()['assetAdmin'] returns an object with some things in it but it's not namespaced
Maybe we could add an index "namespace" to 'assetAdmin'? to handle multiple versions of it?
This whole seems very hard and messy
Dunno, haven't investigated it, it was just a possible approach that might maybe possible work. Definitely wouldn't be my go-to. I'd probably prefer just not doing anything over doing that even if it works.
I'd probably prefer just not doing anything
Me too, maybe put a disclaimer somewhere in the docs that using an UploadField in AssetAdmin is known to be buggy?
I don't think there's any way we can fix this without a substantial re-factor of asset-admin. I'm thinking we bump this up to CMS 6.
My instinct would be to:
Most of that stuff should probably be done anyway to have a more solid architecture. Fixing this bug would just be the cherry on top.
I've re-targeted this issue to the CMS 6 milestone. Our ability to address this issue will be contingent on whether we choose to prioritise an asset-admin refactor.
Module version(s) affected
2.1.x-dev
Description
I'm trying to set up a simple
has_one
relation between files. The data setup part works as expected but when I useUploadField
the UI goes through some unexpected interactions (details below) and the selected asset is not saved. This doesn't happen when a different field is used, for example aDropdownField
.Tested this on vanilla install using
"silverstripe/recipe-cms": "5.x-dev",
How to reproduce
Data setup
Model
Form
Config
Test scenario:
Expected behaviour
I can see asset selection modal so I can choose Image A
Clicking insert will put the Image A into the Image B records via the ReplacementAsset relation. I then click save and the record gets updated.
Actual behaviour
The screen transitions into a read only version of the Image B edit form.
I can still interact with the upload field.
Clicking on the upload field will trigger the modal and I can select Image A.
Clicking insert button will navigate back to the edit version of the Image B edit form but the asset selection is lost so no changes are saved to the DDB record of Asset B.
Possible Solution
Managed to create workaround by setting up a separate model admin to allow the use of non-react edit form where the upload field works as expected.
Acceptance criteria
Notes