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

SWC-6910 - Entity Finder 'Selected' tab #1442

Merged
merged 5 commits into from
Dec 9, 2024

Conversation

nickgros
Copy link
Collaborator

@nickgros nickgros commented Dec 5, 2024

  • Update EntityFinder to show selected items in a tab instead of a lower pane
  • Updated EntityFinder selection to use a Map of entity ID -> Reference instead of entity ID -> version number. With this change, we can remove hacky behavior to store a fake 'null' version number in all places except one case where it is used as an value
  • Update styles to more closely match design
  • Update EntityFinder tests to be type-checked

See the EntityFinderModal story for a demo

@@ -66,7 +66,7 @@ export const EntityFileBrowser: React.FunctionComponent<
},
}
return (
<div className="EntityFinderReflexContainer">
<div className="EntityFileBrowser EntityFinderReflexContainer">
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added class name to apply cascaded styles

Comment on lines -36 to -38
selectedCopy: count => {
return `${count} Item${count > 1 ? 's' : ''} Selected`
},
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removed now-unused selectedCopy prop.

@@ -10,7 +10,6 @@ import {
} from '../../../src/components/EntityFinder/details/EntityDetailsList'
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Moved this file so it is now type-checked

@@ -355,61 +361,24 @@ describe('EntityFinder tests', () => {
})

describe('Search', () => {
it('Updates the search button text when only one type is selectable', async () => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The search input field is no longer hidden behind a button press, so many of these search tests are no longer relevant.

Comment on lines -45 to -47
// In the map used to track selections, we use -1 to denote 'selected without version'
// This is necessary because undefined is returned by map.get when the item is not in the map
export const NO_VERSION_NUMBER = -1
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated the selected type from a map of (entityID, versionNumber) to a map of (entityID, Reference), so we can remove this hacky convention

Comment on lines -82 to -83
/** The text to show before the list of selected entities */
selectedCopy?: string | ((count: number) => string)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

prop is no longer used after these changes

Comment on lines -226 to -254
{searchActive ? (
<Button
variant="outlined"
color="primary"
onClick={() => {
setSearchActive(false)
setSearchInput('')
setSearchTerms(undefined)
}}
startIcon={<ArrowBackOutlinedIcon />}
sx={{ flexShrink: 0, mr: 1 }}
>
Back to Browse
</Button>
) : (
<Button
variant="contained"
color="primary"
className="EntityFinder__Search__SearchButton"
onClick={() => {
setSearchActive(true)
searchInputRef.current!.focus()
}}
startIcon={<SearchIcon />}
sx={{ flexShrink: 0 }}
>
{searchButtonText}
</Button>
)}
Copy link
Collaborator Author

@nickgros nickgros Dec 5, 2024

Choose a reason for hiding this comment

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

Removed these buttons to show/hide search. The new design has the search input always visible.

Comment on lines +269 to +284
endAdornment: searchTerms ? (
<InputAdornment position="end">
<IconButton
size={'small'}
onClick={() => {
setSearchInput('')
setSearchTerms(undefined)
setSearchActive(false)
}}
aria-label="Clear Search"
disabled={!searchInput && !searchActive}
>
<ClearIcon />
</IconButton>
</InputAdornment>
) : undefined,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Still show a clear button to return to the file browser from the search state

Comment on lines 387 to 400
<div
role={'tabpanel'}
style={{
display: currentTab === EntityFinderTab.SELECTED ? 'block' : 'none',
}}
>
<EntityDetailsList
{...entityDetailsListProps}
configuration={{
type: EntityDetailsListDataConfigurationType.REFERENCE_LIST,
referenceList: Array.from(selectedEntitiesSnapshot.values()),
}}
/>
)}
</div>
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Show the selected items in an EntityDetailsList

references: Reference[]
}

export const ReferenceDetails: React.FunctionComponent<SearchDetailsProps> = ({
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The selected items will be provided as References. This component translates the reference list to entity headers, which can be passed into DetailsView to render the table.

@@ -1,40 +1,36 @@
import '@testing-library/jest-dom'
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

File is now type-checked

Comment on lines +543 to +545
<option value={NO_VERSION_NUMBER_OPTION_VALUE}>
{latestVersionText}
</option>
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The only place we have to maintain the "NO_VERSION_NUMBER" = -1 convention, because an <option value cannot be null

Comment on lines +217 to +232
useEffect(() => {
if (
FinderScope.CURRENT_PROJECT === scope &&
projectId &&
!isLoadingProjectHeader &&
!projectHeader
) {
// The header wasn't returned, so the user doesn't have access to the current project
// Let's change the scope to something else
displayToast(
`You don't have access to the current project (${projectId}).`,
'warning',
)
setScope(FinderScope.CREATED_BY_ME)
}
}, [isLoadingProjectHeader, projectHeader, projectId, scope])
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Put this in an effect to prevent firing every render

Comment on lines -424 to -425
<div className="Browse">Browse:</div>
<div onClick={e => e.stopPropagation()}>
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removed "Browse" copy

Comment on lines +375 to +379
<Tooltip title={tooltipContent} placement="right">
<div className="EntityName" ref={ref}>
{nodeText}
</Tooltip>
</div>
</div>
</Tooltip>
Copy link
Collaborator Author

@nickgros nickgros Dec 5, 2024

Choose a reason for hiding this comment

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

Wrap tooltip around the div so that it is positioned to the right of the visible text, not to the right of the overflowing & not visible text.

Comment on lines +351 to +365
<>
{isLoading ? (
<SynapseSpinner size={10} />
) : (
<button
aria-label={isOpen ? 'Collapse' : 'Expand'}
onClick={event => {
event.stopPropagation()
toggleExpand()
}}
>
<ExpandIcon className="ExpandButton" />
</button>
)}
</>
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Update icon

- Update EntityFinder to show selected items in a tab instead of a lower pane
- Updated EntityFinder selection to use a Map of entity ID -> Reference instead of entity ID -> version number. With this change, we can remove hacky behavior to store a fake 'null' version number in all places except one case where it is used as an <option> value
- Update styles to more closely match design
- Update EntityFinder tests to be type-checked
Comment on lines 34 to 44
.MuiDialog-root {
.EntityFinder {
&__MainPanel.MainPanelDualPane,
&__MainPanel.MainPanelSearch {
// Hack to make the dialog responsive to the width of the entity finder
// We may be able to remove this if we remove/replace the EntityFinder's `AutoSizer` component with something other
// than the 'react-base-table' implementation
width: 85vw;
}
}
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Extract this style to only apply it in a dialog. Otherwise, we can make the width of the entity finder 100%

Comment on lines +47 to +48
--entity-finder-height: #{$-finder-height};
--entity-tree-header-height: 65px;
Copy link
Collaborator Author

@nickgros nickgros Dec 5, 2024

Choose a reason for hiding this comment

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

Fix a calculation issue in the experimental EntityFileBrowser (where --entity-tree-header-height should be 0px) by creating CSS variables with these values.

Without this change, the EntityFileBrowser appears to have empty space in the tree that overflowing content should be using

Comment on lines -39 to -50
&__Search__Input {
transition: flex-grow 250ms ease-in-out, width 250ms ease-in-out;
&[data-active='true'] {
flex-grow: 1;
width: 100%;
}
&[data-active='false'] {
flex-grow: 0.00001;
overflow: hidden;
width: 0;
}
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Interaction that used these styles was removed

Comment on lines +84 to +86
.TreeView.BrowseTree {
padding-left: 20px;
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Do not apply this padding to the EntityFileBrowser

.Node.BrowseNode {
grid-template-columns: [toggle] 20px [name] auto;
grid-template-columns: [toggle] 20px [name] minmax(0, max-content);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixes entity name overflow

Comment on lines +18 to +21
grid-template-columns: [toggle] 15px [icon] 27px [name] minmax(
0,
max-content
) [badge] auto;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixes entity name overflow

@nickgros nickgros added the chromatic Deploys the latest commit on this PR to Chromatic and runs snapshot tests label Dec 5, 2024
@nickgros nickgros added chromatic Deploys the latest commit on this PR to Chromatic and runs snapshot tests and removed chromatic Deploys the latest commit on this PR to Chromatic and runs snapshot tests labels Dec 6, 2024
@nickgros nickgros added chromatic Deploys the latest commit on this PR to Chromatic and runs snapshot tests and removed chromatic Deploys the latest commit on this PR to Chromatic and runs snapshot tests labels Dec 6, 2024
selectColumnType: selectMultiple ? 'checkbox' : 'none',
toggleSelection: toggleSelection,
enableSelectAll: selectMultiple,
setCurrentContainer: setCurrentContainer,
}

return (
<SynapseErrorBoundary>
<div className="EntityFinder">
<Box
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated this flex container to include the tabs & the search input. This section is only styled using MUI, SCSS does not touch these

Comment on lines +221 to +223
sx={{
flexWrap: { xs: 'wrap', md: 'nowrap' },
}}
Copy link
Collaborator Author

@nickgros nickgros Dec 6, 2024

Choose a reason for hiding this comment

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

Just kinda tweaked this responsive layout with the search bar until it felt good

2024-12-06.11-57-42.mp4

Copy link
Member

Choose a reason for hiding this comment

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

I think this is fine, but there may be some confusion on the scope of this search box (users may think this is searching the selected entities table, for example).
The real mobile responsive issue is the browse UX, which I think is out of scope for this ticket

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Great point

onKeyDown={(event: any) => {
if (event.key === 'Enter') {
const trimmedInput = event.target.value.trim()
setSearchActive(!!trimmedInput)
Copy link
Member

Choose a reason for hiding this comment

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

@nickgros : On search, I think we should change to the Browse tab. When I'm on the Selected tab and do a search, the search results are not shown (I need to know to switch tabs to see the results)

Copy link
Collaborator Author

@nickgros nickgros Dec 6, 2024

Choose a reason for hiding this comment

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

Good catch, and that's a good idea--in general this is weird so I will probably follow-up with design about this.

@nickgros nickgros added chromatic Deploys the latest commit on this PR to Chromatic and runs snapshot tests and removed chromatic Deploys the latest commit on this PR to Chromatic and runs snapshot tests labels Dec 9, 2024
@nickgros nickgros merged commit 9cb7ad9 into Sage-Bionetworks:main Dec 9, 2024
7 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chromatic Deploys the latest commit on this PR to Chromatic and runs snapshot tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants