Skip to content
Merged
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
5 changes: 5 additions & 0 deletions packages/manager/.changeset/pr-13346-fixed-1770026687465.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Fixed
---

IAM: Assigned Roles table pagination fixes ([#13346](https://github.com/linode/manager/pull/13346))
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@ export const AccountDelegations = () => {
users: true,
});

const pagination = usePaginationV2({
currentRoute: '/iam/delegations',
initialPage: 1,
preferenceKey: 'iam-delegations-pagination',
});

const { handleOrderChange, order, orderBy } = useOrderV2({
initialRoute: {
defaultOrder: {
Expand Down Expand Up @@ -84,8 +78,14 @@ export const AccountDelegations = () => {
});
}, [filteredDelegations, order]);

const pagination = usePaginationV2({
currentRoute: '/iam/delegations',
initialPage: 1,
preferenceKey: 'iam-delegations-pagination',
clientSidePaginationData: sortedDelegations,
});

const handleSearch = (value: string) => {
pagination.handlePageChange(1);
navigate({
to: DELEGATIONS_ROUTE,
search: { query: value || undefined },
Expand Down Expand Up @@ -123,7 +123,7 @@ export const AccountDelegations = () => {
</Stack>

<Paginate
data={sortedDelegations}
data={pagination.paginatedData}
page={pagination.page}
pageSize={pagination.pageSize}
pageSizeSetter={pagination.handlePageSizeChange}
Expand Down
35 changes: 14 additions & 21 deletions packages/manager/src/features/IAM/Roles/RolesTable/RolesTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,6 @@ export const RolesTable = ({ roles = [] }: Props) => {
const { data: permissions } = usePermissions('account', ['is_account_admin']);
const isAccountAdmin = permissions?.is_account_admin;

const pagination = usePaginationV2({
currentRoute: '/iam/roles',
defaultPageSize: DEFAULT_PAGE_SIZE,
initialPage: 1,
preferenceKey: ROLES_TABLE_PREFERENCE_KEY,
});

// Filtering
const getFilteredRows = (
text: string,
Expand Down Expand Up @@ -113,26 +106,29 @@ export const RolesTable = ({ roles = [] }: Props) => {
return sortRows(filteredRows, sort.order, sort.column);
}, [filteredRows, sort]);

const paginatedRows = React.useMemo(() => {
const start = (pagination.page - 1) * pagination.pageSize;
return sortedRows.slice(start, start + pagination.pageSize);
}, [sortedRows, pagination.page, pagination.pageSize]);
const pagination = usePaginationV2({
currentRoute: '/iam/roles',
defaultPageSize: DEFAULT_PAGE_SIZE,
initialPage: 1,
preferenceKey: ROLES_TABLE_PREFERENCE_KEY,
clientSidePaginationData: sortedRows,
});

const areAllSelected = React.useMemo(() => {
return (
!!paginatedRows?.length &&
!!pagination.paginatedData?.length &&
!!selectedRows?.length &&
paginatedRows?.length === selectedRows?.length
pagination.paginatedData?.length === selectedRows?.length
);
}, [paginatedRows, selectedRows]);
}, [pagination.paginatedData, selectedRows]);

const handleSort = (event: CustomEvent, column: string) => {
setSort({ column, order: event.detail as Order });
};

const handleSelect = (event: CustomEvent, row: 'all' | RoleView) => {
if (row === 'all') {
setSelectedRows(areAllSelected ? [] : paginatedRows);
setSelectedRows(areAllSelected ? [] : pagination.paginatedData);
} else if (selectedRows.includes(row)) {
setSelectedRows(selectedRows.filter((r) => r !== row));
} else {
Expand All @@ -145,12 +141,10 @@ export const RolesTable = ({ roles = [] }: Props) => {
to: location.pathname,
search: { query: fs !== '' ? fs : undefined },
});
pagination.handlePageChange(1);
};

const handleChangeEntityTypeFilter = (_: never, entityType: SelectOption) => {
setFilterableEntityType(entityType ?? ALL_ROLES_OPTION);
pagination.handlePageChange(1);
};

const assignRoleRow = (row: RoleView) => {
Expand All @@ -170,7 +164,6 @@ export const RolesTable = ({ roles = [] }: Props) => {
const handlePageSizeChange = (event: CustomEvent<{ pageSize: number }>) => {
const newSize = event.detail.pageSize;
pagination.handlePageSizeChange(newSize);
pagination.handlePageChange(1);
};

return (
Expand Down Expand Up @@ -287,14 +280,14 @@ export const RolesTable = ({ roles = [] }: Props) => {
</TableRow>
</TableHead>
<TableBody>
{!paginatedRows?.length ? (
{!pagination.paginatedData?.length ? (
<TableRow>
<TableCell style={{ justifyContent: 'center' }}>
No items to display.
</TableCell>
</TableRow>
) : (
paginatedRows.map((roleRow) => (
pagination.paginatedData.map((roleRow) => (
<TableRow
expandable
hoverable
Expand Down Expand Up @@ -373,7 +366,7 @@ export const RolesTable = ({ roles = [] }: Props) => {
</Table>
{sortedRows.length !== 0 && sortedRows.length > DEFAULT_PAGE_SIZE && (
<Pagination
count={filteredRows.length}
count={sortedRows.length}
onPageChange={handlePageChange}
onPageSizeChange={handlePageSizeChange}
page={pagination.page}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,6 @@
const [order, setOrder] = React.useState<'asc' | 'desc'>('asc');
const [orderBy, setOrderBy] = React.useState<OrderByKeys>('entity_name');

const pagination = usePaginationV2({
currentRoute: isDefaultDelegationRolesForChildAccount
? '/iam/roles/defaults/entity-access'
: `/iam/users/$username/entities`,
initialPage: 1,
preferenceKey: ENTITIES_TABLE_PREFERENCE_KEY,
});

const handleOrderChange = (newOrderBy: OrderByKeys) => {
if (orderBy === newOrderBy) {
setOrder(order === 'asc' ? 'desc' : 'asc');
Expand Down Expand Up @@ -181,12 +173,6 @@
} else {
setIsRemoveAssignmentDialogOpen(false);
}
// If we just deleted the last one on a page, reset to the previous page.
const removedLastOnPage =
filteredAndSortedRoles.length % pagination.pageSize === 1;
if (removedLastOnPage) {
pagination.handlePageChange(pagination.page - 1);
}
};

const filteredRoles = getFilteredRoles({
Expand All @@ -209,6 +195,15 @@
return 0;
});

const pagination = usePaginationV2({
currentRoute: isDefaultDelegationRolesForChildAccount
? '/iam/roles/defaults/entity-access'
: `/iam/users/$username/entities`,
initialPage: 1,
preferenceKey: ENTITIES_TABLE_PREFERENCE_KEY,
clientSidePaginationData: filteredAndSortedRoles,
});

const renderTableBody = () => {
if (entitiesLoading || loading) {
return <TableRowLoading columns={3} rows={1} />;
Expand All @@ -230,59 +225,54 @@
if (assignedRoles && entities) {
return (
<>
{filteredAndSortedRoles
.slice(
(pagination.page - 1) * pagination.pageSize,
pagination.page * pagination.pageSize
)
.map((el: EntitiesRole) => {
const actions: Action[] = [
{
disabled: !permissionToCheck,
onClick: () => {
handleChangeRole(el, 'change-role-for-entity');
},
title: 'Change Role',
tooltip: !permissionToCheck
? 'You do not have permission to change this role.'
: undefined,
{pagination.paginatedData.map((el: EntitiesRole) => {
const actions: Action[] = [
{
disabled: !permissionToCheck,
onClick: () => {
handleChangeRole(el, 'change-role-for-entity');
},
{
disabled: !permissionToCheck,
onClick: () => {
handleRemoveAssignment(el);
},
title: isDefaultDelegationRolesForChildAccount
? 'Remove'
: 'Remove Assignment',
tooltip: !permissionToCheck
? 'You do not have permission to remove this assignment.'
: undefined,
title: 'Change Role',
tooltip: !permissionToCheck
? 'You do not have permission to change this role.'
: undefined,
},
{
disabled: !permissionToCheck,
onClick: () => {
handleRemoveAssignment(el);
},
];

return (
<TableRow key={el.id}>
<TableCell>
<Typography>{el.entity_name}</Typography>
</TableCell>
<TableCell sx={{ display: { sm: 'table-cell', xs: 'none' } }}>
<Typography>
{getFormattedEntityType(el.entity_type)}
</Typography>
</TableCell>
<TableCell sx={{ display: { sm: 'table-cell', xs: 'none' } }}>
<Typography>{el.role_name}</Typography>
</TableCell>
<TableCell actionCell>
<ActionMenu
actionsList={actions}
ariaLabel={`Action menu for entity ${el.entity_name}`}
/>
</TableCell>
</TableRow>
);
})}
title: isDefaultDelegationRolesForChildAccount
? 'Remove'
: 'Remove Assignment',
tooltip: !permissionToCheck
? 'You do not have permission to remove this assignment.'
: undefined,
},
];

return (
<TableRow key={el.id}>
<TableCell>
<Typography>{el.entity_name}</Typography>
</TableCell>
<TableCell sx={{ display: { sm: 'table-cell', xs: 'none' } }}>

Check warning on line 259 in packages/manager/src/features/IAM/Shared/AssignedEntitiesTable/AssignedEntitiesTable.tsx

View workflow job for this annotation

GitHub Actions / ESLint Review (manager)

[eslint] reported by reviewdog 🐢 Define a constant instead of duplicating this literal 4 times. Raw Output: {"ruleId":"sonarjs/no-duplicate-string","severity":1,"message":"Define a constant instead of duplicating this literal 4 times.","line":259,"column":49,"nodeType":"Literal","endLine":259,"endColumn":61}
<Typography>
{getFormattedEntityType(el.entity_type)}
</Typography>
</TableCell>
<TableCell sx={{ display: { sm: 'table-cell', xs: 'none' } }}>
<Typography>{el.role_name}</Typography>
</TableCell>
<TableCell actionCell>
<ActionMenu
actionsList={actions}
ariaLabel={`Action menu for entity ${el.entity_name}`}
/>
</TableCell>
</TableRow>
);
})}
</>
);
}
Expand Down Expand Up @@ -384,7 +374,7 @@
role={selectedRole}
username={username}
/>
{filteredRoles.length > PAGE_SIZES[0] && (
{pagination.paginatedData.length > PAGE_SIZES[0] && (
<PaginationFooter
count={filteredRoles.length}
handlePageChange={pagination.handlePageChange}
Expand Down
Loading