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

EDSC-3719, EDSC-3525: Scroll to granule on map click and table granules bugfix #1813

Merged
merged 36 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
675e752
EDSC-4238: Initial implemenation of the highlighting of text
bnp26 Sep 18, 2024
15876f9
EDSC-4238: finished implementation using Highlighter
bnp26 Sep 18, 2024
f85b035
EDSC-4238: Added the ability to have multiple search filters
bnp26 Sep 18, 2024
35d017a
EDSC-4238: moved props from redux into the GranuleResultsItem instead…
bnp26 Sep 24, 2024
5ce33c3
EDSC-4238: converted tests into RTL from Enzyme. Broke up getSearchWo…
bnp26 Oct 2, 2024
bd75db4
Merge branch 'main' of https://github.com/nasa/earthdata-search into …
bnp26 Oct 2, 2024
35721f0
removed import '@testing-library/jest-dom'
bnp26 Oct 2, 2024
74ea9f3
EDSC-4238: fixed up readableGranuleName in GranuleResultsList.test.js
bnp26 Oct 2, 2024
6de922e
EDSC-4238: Fixed up GranuleResultsDataLinksButton test
bnp26 Oct 2, 2024
1fb9853
EDSC-4238: Addressed most of the comments in the PR
bnp26 Oct 4, 2024
7651751
EDSC-4238: fixed up some more tests
bnp26 Oct 7, 2024
80283bb
Merge branch 'main' into EDSC-4238
bnp26 Oct 7, 2024
41528d6
EDSC-4238: Addressed some more comments
bnp26 Oct 7, 2024
3b117b8
EDSC-4238: a bit more changes to grab the title buttons using the gra…
bnp26 Oct 7, 2024
1979d01
EDSC-4238: added some comments to the getSearchWords test
bnp26 Oct 7, 2024
3d131be
EDSC-4239: added the comments to explain why we do what we do in the …
bnp26 Oct 7, 2024
724b38a
Merge branch 'main' into EDSC-4238
bnp26 Oct 9, 2024
5b342eb
EDSC-4238: updated the tests to match the expected results
bnp26 Oct 9, 2024
29031d5
EDSC-3719: initial implementation of the feature.
bnp26 Oct 15, 2024
69dd789
Merge branch 'main' of https://github.com/nasa/earthdata-search into …
bnp26 Oct 15, 2024
874faf9
Merge branch 'main' of https://github.com/nasa/earthdata-search into …
bnp26 Oct 16, 2024
015ecc5
EDSC-3719: Added scrolling in table and list granule views. Fixed bug…
bnp26 Oct 22, 2024
ea3ec5d
Merge branch 'main' of https://github.com/nasa/earthdata-search into …
bnp26 Oct 22, 2024
2de83fe
EDSC-3719: Fixed console.logs
bnp26 Oct 23, 2024
43351e0
removed 3 more console.log
bnp26 Oct 23, 2024
b337d2d
EDSC-3719: fixed the GranuleResultsTable test
bnp26 Oct 23, 2024
7c27cce
EDSC-3719: fixed GranuleRestultsList
bnp26 Oct 23, 2024
a8f6585
Merge branch 'main' into EDSC-3719
bnp26 Oct 24, 2024
e98e249
Merge branch 'main' into EDSC-3719
bnp26 Oct 28, 2024
8bf1035
EDSC-3719: last couple fixes for PR readyness
bnp26 Oct 29, 2024
b742ef4
Merge branch 'EDSC-3719' of https://github.com/nasa/earthdata-search …
bnp26 Oct 29, 2024
c1adef1
Update collections.body.json
bnp26 Oct 29, 2024
6eb5d04
EDSC-3719: added focusedItem as a required prop
bnp26 Oct 29, 2024
b7ecafb
EDSC-3719: focusedItem is not set on the CollectionResultsTable compo…
bnp26 Oct 29, 2024
78a7854
Merge branch 'main' into EDSC-3719
bnp26 Oct 30, 2024
522ab9c
EDSC-3719: skipping the UI tests for granule views map interactions
bnp26 Oct 31, 2024
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
15 changes: 15 additions & 0 deletions static/src/js/components/EDSCTable/EDSCTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ innerElementType.displayName = 'EDSCTableInnerElement'
* @param {Object} props - The props passed into the component.
* @param {Array} props.columns - The column settings.
* @param {Array} props.data - The collection data.
* @param {Array} props.focusedItem - The item in focus (granule).
* @param {String} props.id - A unique id to pass the table.
* @param {Function} props.isItemLoaded - Callback to see if an item has loaded.
* @param {Object} props.initialTableState - The initial state to be passed to react-table.
Expand All @@ -154,6 +155,7 @@ innerElementType.displayName = 'EDSCTableInnerElement'
const EDSCTable = ({
columns,
data,
focusedItem,
id,
isItemLoaded,
itemCount,
Expand Down Expand Up @@ -199,9 +201,20 @@ const EDSCTable = ({
useEffect(() => {
}, [visibleMiddleIndex])

// When a user clicks on a granule on the map, it will scroll to that granule in the GranuleResultsTable
useEffect(() => {
if (focusedItem) {
const itemIndex = data.findIndex((item) => item.id === focusedItem)
if (itemIndex && listRef && listRef.current) {
listRef.current.scrollToItem(itemIndex, 'center')
}
}
}, [focusedItem])

const options = {}

if (initialRowStateAccessor) options.initialRowStateAccessor = initialRowStateAccessor

if (!isEmpty(initialTableState)) options.initialState = initialTableState

const {
Expand Down Expand Up @@ -492,6 +505,7 @@ const EDSCTable = ({
}

EDSCTable.defaultProps = {
focusedItem: '',
initialRowStateAccessor: null,
initialTableState: {},
isItemLoaded: null,
Expand All @@ -515,6 +529,7 @@ EDSCTable.defaultProps = {
EDSCTable.propTypes = {
columns: PropTypes.arrayOf(PropTypes.shape({})).isRequired,
data: PropTypes.arrayOf(PropTypes.shape({})).isRequired,
focusedItem: PropTypes.string,
bnp26 marked this conversation as resolved.
Show resolved Hide resolved
id: PropTypes.string.isRequired,
initialRowStateAccessor: PropTypes.func,
initialTableState: PropTypes.shape({}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ const GranuleResultsBody = ({
readableGranuleName={readableGranuleName}
directDistributionInformation={directDistributionInformation}
excludedGranuleIds={excludedGranuleIds}
focusedGranuleId={focusedGranuleId}
granules={granulesList}
isCollectionInProject={isCollectionInProject}
isOpenSearch={isOpenSearch}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import './GranuleResultsList.scss'
* @param {String} props.collectionId - The collection ID.
* @param {Object} props.directDistributionInformation - The direct distribution information.
* @param {Array} props.excludedGranuleIds - List of excluded granule IDs.
* @param {String} props.focusedGranuleId - The currently focused granule ID.
* @param {Array} props.granules - List of formatted granule.
* @param {Boolean} props.isOpenSearch - Flag designating CWIC collections.
* @param {Boolean} props.isCollectionInProject - Flag designating if the collection is in the project.
Expand All @@ -35,6 +36,7 @@ export const GranuleResultsList = ({
collectionId,
directDistributionInformation,
excludedGranuleIds,
focusedGranuleId,
granules,
isCollectionInProject,
isOpenSearch,
Expand Down Expand Up @@ -67,6 +69,7 @@ export const GranuleResultsList = ({
collectionId={collectionId}
directDistributionInformation={directDistributionInformation}
excludedGranuleIds={excludedGranuleIds}
focusedGranuleId={focusedGranuleId}
granules={granules}
height={height}
isCollectionInProject={isCollectionInProject}
Expand Down Expand Up @@ -101,6 +104,7 @@ GranuleResultsList.propTypes = {
collectionId: PropTypes.string.isRequired,
directDistributionInformation: PropTypes.shape({}).isRequired,
excludedGranuleIds: PropTypes.arrayOf(PropTypes.string).isRequired,
focusedGranuleId: PropTypes.string.isRequired,
granules: PropTypes.arrayOf(PropTypes.shape({})).isRequired,
isCollectionInProject: PropTypes.bool.isRequired,
isOpenSearch: PropTypes.bool.isRequired,
Expand Down
39 changes: 33 additions & 6 deletions static/src/js/components/GranuleResults/GranuleResultsListBody.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export const GranuleResultsListBody = ({
collectionId,
directDistributionInformation,
excludedGranuleIds,
focusedGranuleId,
granules,
height,
isCollectionInProject,
Expand Down Expand Up @@ -139,10 +140,38 @@ export const GranuleResultsListBody = ({
listRef.current.scrollToItem({
rowIndex,
columnIndex
}, 'center')
}, 'auto')
}
}, [listRef.current])

const scrollToFocusedGranule = (granuleId) => {
const granuleIndex = granules.findIndex((granule) => {
const { id } = granule
if (granuleId === id) return true

return false
})

if (granuleIndex >= 0) {
const {
rowIndex,
columnIndex
} = itemToRowColumnIndicies(granuleIndex, numColumns)

listRef.current.scrollToItem({
rowIndex: rowIndex === 0 ? 0 : rowIndex + 1,
columnIndex,
align: 'center'
})
}
}

useEffect(() => {
if (focusedGranuleId) {
scrollToFocusedGranule(focusedGranuleId)
}
}, [focusedGranuleId])

// `setRowHeight` sets the size in the sizeMap to the height passed from the item.
const setRowHeight = useCallback((rowIndex, columnIndex, size) => {
if (!sizeMap.current[rowIndex]) sizeMap.current[rowIndex] = []
Expand All @@ -167,10 +196,6 @@ export const GranuleResultsListBody = ({

const rowHeight = Math.max(...sizeMap.current[rowIndex])

if (rowIndex === itemCount - 1) {
return rowHeight + (remInPixels * 4)
}

return rowHeight + remInPixels
}, [itemCount])

Expand All @@ -191,6 +216,7 @@ export const GranuleResultsListBody = ({
listRef.current = list
}
}
overscanRowCount={3}
columnCount={numColumns}
columnWidth={() => (width / numColumns) - (remInPixels / numColumns)}
height={height}
Expand Down Expand Up @@ -224,7 +250,7 @@ export const GranuleResultsListBody = ({
}
onItemsRendered={
(gridProps) => {
// OnItemsRendered needs to know which items are visible in the list
// OnItemsRendered needs to know which items are visible in the list
const overscanStartIndex = gridProps.overscanRowStartIndex * numColumns
const overscanStopIndex = gridProps.overscanRowStopIndex * numColumns
const visibleStartIndex = gridProps.visibleRowStartIndex * numColumns
Expand Down Expand Up @@ -260,6 +286,7 @@ GranuleResultsListBody.propTypes = {
collectionId: PropTypes.string.isRequired,
directDistributionInformation: PropTypes.shape({}).isRequired,
excludedGranuleIds: PropTypes.arrayOf(PropTypes.string).isRequired,
focusedGranuleId: PropTypes.string.isRequired,
granules: PropTypes.arrayOf(PropTypes.shape({})).isRequired,
height: PropTypes.number.isRequired,
isCollectionInProject: PropTypes.bool.isRequired,
Expand Down
34 changes: 18 additions & 16 deletions static/src/js/components/GranuleResults/GranuleResultsListItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,22 +97,24 @@ export const GranuleResultsListItem = memo(({
if (!granule) return null

return (
<li className="granule-results-list-item" style={customStyle}>
<GranuleResultsItem
collectionId={collectionId}
directDistributionInformation={directDistributionInformation}
granule={granules[index]}
isCollectionInProject={isCollectionInProject}
isGranuleInProject={isGranuleInProject}
location={location}
onAddGranuleToProjectCollection={onAddGranuleToProjectCollection}
onExcludeGranule={onExcludeGranule}
onFocusedGranuleChange={onFocusedGranuleChange}
onMetricsDataAccess={onMetricsDataAccess}
onRemoveGranuleFromProjectCollection={onRemoveGranuleFromProjectCollection}
readableGranuleName={readableGranuleName}
ref={element}
/>
<li className="granule-results-list-item" style={style}>
<div style={{ padding: '0.825rem' }}>
<GranuleResultsItem
collectionId={collectionId}
directDistributionInformation={directDistributionInformation}
granule={granules[index]}
isCollectionInProject={isCollectionInProject}
isGranuleInProject={isGranuleInProject}
location={location}
onAddGranuleToProjectCollection={onAddGranuleToProjectCollection}
onExcludeGranule={onExcludeGranule}
onFocusedGranuleChange={onFocusedGranuleChange}
onMetricsDataAccess={onMetricsDataAccess}
onRemoveGranuleFromProjectCollection={onRemoveGranuleFromProjectCollection}
readableGranuleName={readableGranuleName}
ref={element}
/>
</div>
</li>
)
})
Expand Down
32 changes: 19 additions & 13 deletions static/src/js/components/GranuleResults/GranuleResultsTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,19 +107,24 @@ export const GranuleResultsTable = ({
}
])

const initialRowStateAccessor = useMemo(() => ({
isFocusedGranule,
isHoveredGranule,
isInProject,
isCollectionInProject
}) => ({
isFocusedGranule,
isHoveredGranule,
isInProject,
isCollectionInProject
}), [focusedGranuleId])
const initialRowStateAccessor = useCallback((row) => {
const { original = {} } = row
const {
isFocusedGranule,
isHoveredGranule,
isInProject,
isCollectionInProject
} = original

return {
isFocusedGranule,
isHoveredGranule,
isInProject,
isCollectionInProject
}
}, [focusedGranuleId])

const rowClassNamesFromRowState = useMemo(() => ({
const rowClassNamesFromRowState = useCallback(({
isFocusedGranule,
isHoveredGranule,
isCollectionInProject,
Expand All @@ -133,7 +138,7 @@ export const GranuleResultsTable = ({
return classNames
})

const rowTitleFromRowState = useMemo(() => ({ isFocusedGranule }) => {
const rowTitleFromRowState = useCallback(({ isFocusedGranule }) => {
let rowTitle = 'Focus granule on map'

if (isFocusedGranule) rowTitle = 'Unfocus granule on map'
Expand Down Expand Up @@ -182,6 +187,7 @@ export const GranuleResultsTable = ({
columns={columns}
initialTableState={initialTableState}
data={granules}
focusedItem={focusedGranuleId}
itemCount={itemCount}
loadMoreItems={loadMoreItems}
isItemLoaded={isItemLoaded}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function setup(type) {
collectionId: 'collectionId',
directDistributionInformation: {},
excludedGranuleIds: [],
focusedGranule: '',
focusedGranuleId: '',
granules: [
{
title: '123'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,11 @@ describe('GranuleResultsTable component', () => {
const table = enzymeWrapper.find(EDSCTable)

const result = table.props().initialRowStateAccessor({
isFocusedGranule: true,
isCollectionInProject: true,
isInProject: false
original: {
isFocusedGranule: true,
isCollectionInProject: true,
isInProject: false
}
})

expect(result).toEqual({
Expand Down
4 changes: 0 additions & 4 deletions tests/e2e/map/map.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1465,10 +1465,6 @@ test.describe('Map interactions', () => {
await expect(page.locator('.granule-spatial-label-temporal')).toHaveText('2021-05-31 15:30:522021-05-31 15:31:22')
})

test('focuses the selected granule', async ({ page }) => {
await expect(page.getByRole('button', { name: /S1A_IW_SLC__1SDV_20210531T153052_20210531T153122_038133_04802B_C09D/ })).toHaveClass(/granule-results-item--active/)
})

test('updates the URL', async ({ page }) => {
await expect(page).toHaveURL(/\/search\/granules.*g=G2061166811-ASF/)
})
Expand Down
Loading
Loading