Skip to content

Commit

Permalink
LookoutV2: Move back to first page when set of rows changes (armadapr…
Browse files Browse the repository at this point in the history
  • Loading branch information
robertdavidsmith authored Dec 13, 2023
1 parent 4d19adf commit 787eec4
Showing 1 changed file with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -290,11 +290,18 @@ export const JobsTableContainer = ({
}
}

const setToFirstPage = () => {
setPagination({
pageIndex: 0,
pageSize: pageSize,
})
}

const loadPrefs = (prefs: JobsTablePreferences) => {
setGrouping(prefs.groupedColumns)
setExpanded(prefs.expandedState)
setPagination({
pageIndex: prefs.pageIndex,
pageIndex: 0,
pageSize: prefs.pageSize,
})
setLookoutOrder(prefs.order)
Expand All @@ -320,9 +327,7 @@ export const JobsTableContainer = ({
setTextFields(prefs.filters)

// Load data
setRowsToFetch(
pendingDataForAllVisibleData(prefs.expandedState, data, prefs.pageSize, prefs.pageIndex * prefs.pageSize),
)
setRowsToFetch(pendingDataForAllVisibleData(prefs.expandedState, data, prefs.pageSize))
}

// Update query params with table state
Expand Down Expand Up @@ -360,6 +365,7 @@ export const JobsTableContainer = ({
const loadCustomView = (name: string) => {
try {
const prefs = customViewsService.getView(name)
setToFirstPage()
loadPrefs(prefs)
} catch (e) {
console.error(getErrorMessage(e))
Expand Down Expand Up @@ -449,6 +455,7 @@ export const JobsTableContainer = ({

const onGroupingChange = useCallback(
(newGroups: ColumnId[]) => {
setToFirstPage()
// Reset currently expanded/selected when grouping changes
setSelectedRows({})
setSidebarJobId(undefined)
Expand Down Expand Up @@ -565,6 +572,7 @@ export const JobsTableContainer = ({
}

const onFilterChange = (updater: Updater<ColumnFiltersState>) => {
setToFirstPage()
const newFilterState = updaterToValue(updater, columnFilterState)
setLookoutFilters(parseLookoutFilters(newFilterState))
setColumnFilterState(newFilterState)
Expand All @@ -583,11 +591,12 @@ export const JobsTableContainer = ({
}

const onSortingChange = (updater: Updater<SortingState>) => {
setToFirstPage()
const newSortingState = updaterToValue(updater, sorting)
setLookoutOrder(toLookoutOrder(newSortingState))
setSorting(newSortingState)
// Refetch any expanded subgroups, and root data with updated sorting params
setRowsToFetch(pendingDataForAllVisibleData(expanded, data, pageSize, pageIndex * pageSize))
setRowsToFetch(pendingDataForAllVisibleData(expanded, data, pageSize))
}

const onColumnSizingChange = useCallback(
Expand Down Expand Up @@ -729,7 +738,9 @@ export const JobsTableContainer = ({
activeJobSets={activeJobSets}
onActiveJobSetsChanged={(newVal) => {
setActiveJobSets(newVal)
onRefresh()
setToFirstPage()
setSelectedRows({})
setRowsToFetch(pendingDataForAllVisibleData(expanded, data, pageSize))
}}
onRefresh={onRefresh}
autoRefresh={autoRefresh}
Expand Down

0 comments on commit 787eec4

Please sign in to comment.