Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FW-6190 clear media selection after adding #632

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/common/hooks/useArrayStateManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ function useArrayStateManager({ maxItems }) {
const removeItemFromArray = (array, item) =>
[...array].filter((elem) => elem !== item && elem?.id !== item?.id)

const checkForItem = (array, item) =>
array.some((elem) => elem === item || elem?.id === item?.id)
const checkForItem = (array, item) => {
if (typeof item === 'object') {
return array.some((elem) => elem?.id === item?.id)
}
return array.some((elem) => elem === item)
}

const handleSelectAdditionalItems = (selectedItem) => {
if (maxItems === 1) {
Expand Down
1 change: 1 addition & 0 deletions src/components/AddAudioModal/AddAudioModalContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ function AddAudioModalContainer({
return (
<AddMediaModalWrapper
selectedMedia={selectedItems}
setSelectedMedia={setSelectedItems}
updateSavedMedia={updateSavedMedia}
type={TYPE_AUDIO}
modalOpen={modalOpen}
Expand Down
1 change: 1 addition & 0 deletions src/components/AddImageModal/AddImageModalContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ function AddImageModalContainer({
return (
<AddMediaModalWrapper
selectedMedia={selectedItems}
setSelectedMedia={setSelectedItems}
updateSavedMedia={updateSavedMedia}
type={TYPE_IMAGE}
modalOpen={modalOpen}
Expand Down
3 changes: 3 additions & 0 deletions src/components/AddMediaModalWrapper/AddMediaModalWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import getIcon from 'common/utils/getIcon'

function AddMediaModalWrapper({
selectedMedia,
setSelectedMedia,
updateSavedMedia,
type,
modalOpen,
Expand All @@ -26,6 +27,7 @@ function AddMediaModalWrapper({
// allowing user to attach the selected/uploaded files to the document.
const handleOnClick = () => {
if (tabHasSelectedItems) updateSavedMedia(selectedMedia)
setSelectedMedia([])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is a bigger problem here than how we handle switching tabs. It appears that the selector is not distinguishing between the full list of selected items (the value of the form control) and the list of items that are currently selected in the modal. Looks like this affects the EntryArrayField as well.

I'm going to need to think about this a bit to figure out the best place to adjust this.

setSelectedTab(tab)
}
return (
Expand Down Expand Up @@ -82,6 +84,7 @@ const { array, bool, func, node, object, oneOf } = PropTypes

AddMediaModalWrapper.propTypes = {
selectedMedia: array,
setSelectedMedia: func,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should expose both selectedMedia and setSelectedMedia as parameters, because it introduces a confusing duplication about how to set the selected media.

updateSavedMedia: func,
type: oneOf([TYPE_AUDIO, TYPE_IMAGE, TYPE_VIDEO]),
tabOptions: array,
Expand Down
1 change: 1 addition & 0 deletions src/components/AddVideoModal/AddVideoModalContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ function AddVideoModalContainer({
return (
<AddMediaModalWrapper
selectedMedia={selectedItems}
setSelectedMedia={setSelectedItems}
updateSavedMedia={updateSavedMedia}
type={TYPE_VIDEO}
modalOpen={modalOpen}
Expand Down