mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-25 00:07:47 +01:00
Fix row selection on paginated pages (#5706)
This commit is contained in:
parent
4e56d1d8d5
commit
9b7981047d
@ -50,6 +50,7 @@ import { TableEmptyState } from './TableEmptyState/TableEmptyState';
|
||||
import { useRowActions } from './hooks/useRowActions';
|
||||
import { useUiFlag } from 'hooks/useUiFlag';
|
||||
import { FeatureTagCell } from 'component/common/Table/cells/FeatureTagCell/FeatureTagCell';
|
||||
import { useSelectedData } from './hooks/useSelectedData';
|
||||
|
||||
interface IPaginatedProjectFeatureTogglesProps {
|
||||
environments: IProject['environments'];
|
||||
@ -372,6 +373,8 @@ export const PaginatedProjectFeatureToggles = ({
|
||||
[columnVisibility, setTableState],
|
||||
);
|
||||
|
||||
const selectedData = useSelectedData(features, rowSelection);
|
||||
|
||||
return (
|
||||
<>
|
||||
<PageContent
|
||||
@ -482,10 +485,10 @@ export const PaginatedProjectFeatureToggles = ({
|
||||
{featureToggleModals}
|
||||
</div>
|
||||
</PageContent>
|
||||
<BatchSelectionActionsBar count={Object.keys(rowSelection).length}>
|
||||
<BatchSelectionActionsBar count={selectedData.length}>
|
||||
<ProjectFeaturesBatchActions
|
||||
selectedIds={Object.keys(rowSelection)}
|
||||
data={features}
|
||||
data={selectedData}
|
||||
projectId={projectId}
|
||||
onResetSelection={table.resetRowSelection}
|
||||
onChange={refetch}
|
||||
|
@ -0,0 +1,27 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
|
||||
export const useSelectedData = <T extends { name: string }>(
|
||||
data: T[],
|
||||
selection: Record<string, boolean>,
|
||||
): T[] => {
|
||||
const [selectedData, setSelectedData] = useState<T[]>([]);
|
||||
|
||||
useEffect(() => {
|
||||
setSelectedData((prevSelectedData) => {
|
||||
const combinedData = [...data];
|
||||
prevSelectedData.forEach((item) => {
|
||||
if (
|
||||
!combinedData.find(
|
||||
(dataItem) => dataItem.name === item.name,
|
||||
)
|
||||
) {
|
||||
combinedData.push(item);
|
||||
}
|
||||
});
|
||||
|
||||
return combinedData.filter((item) => selection[item.name]);
|
||||
});
|
||||
}, [data, selection]);
|
||||
|
||||
return selectedData;
|
||||
};
|
Loading…
Reference in New Issue
Block a user