+
{
}
className="list-managment-group__pagination"
defaultToFullPage
- itemCount={filteredData?.length}
+ itemCount={sortedStates?.length}
page={pagination?.page}
perPage={pagination?.perPage}
perPageOptions={paginationDefaultValues}
/>
- {filteredData.length > 0 ? (
-
-
+ {sortedStates?.length ? (
+
+
+
+ {activeColumns.map((column) => (
+
+ {column.title}
+ |
+ ))}
+
+
+
{paginatedData.map((nnstate, index) => (
{
rowData={{ rowIndex: index, selectedFilters }}
/>
))}
-
+
) : (
)}
diff --git a/src/views/states/list/hooks/useSortStates.ts b/src/views/states/list/hooks/useSortStates.ts
new file mode 100644
index 00000000..c79928ed
--- /dev/null
+++ b/src/views/states/list/hooks/useSortStates.ts
@@ -0,0 +1,40 @@
+import { useState } from 'react';
+
+import { ThSortType } from '@patternfly/react-table/dist/esm/components/Table/base';
+import { V1beta1NodeNetworkState } from '@types';
+
+const useSortStates = (
+ nodeNetworkStates: V1beta1NodeNetworkState[],
+): { sortedStates: V1beta1NodeNetworkState[]; nameSortParams: ThSortType } => {
+ const [activeSortIndex, setActiveSortIndex] = useState
(null);
+ const [activeSortDirection, setActiveSortDirection] = useState<'asc' | 'desc' | null>(null);
+
+ let sortedStates = nodeNetworkStates;
+ if (activeSortIndex === 1) {
+ sortedStates = nodeNetworkStates.sort((a, b) => {
+ const aValue = a.metadata.name as string;
+ const bValue = b.metadata.name as string;
+
+ if (activeSortDirection === 'asc') {
+ return (aValue as string).localeCompare(bValue);
+ }
+ return (bValue as string).localeCompare(aValue);
+ });
+ }
+
+ const nameSortParams: ThSortType = {
+ sortBy: {
+ index: activeSortIndex,
+ direction: activeSortDirection,
+ },
+ onSort: (_event, index, direction) => {
+ setActiveSortIndex(index);
+ setActiveSortDirection(direction);
+ },
+ columnIndex: 1,
+ };
+
+ return { sortedStates, nameSortParams };
+};
+
+export default useSortStates;
diff --git a/src/views/states/list/hooks/useStateColumns.ts b/src/views/states/list/hooks/useStateColumns.ts
index c68cde81..c17ab530 100644
--- a/src/views/states/list/hooks/useStateColumns.ts
+++ b/src/views/states/list/hooks/useStateColumns.ts
@@ -7,6 +7,8 @@ import {
useActiveColumns,
} from '@openshift-console/dynamic-plugin-sdk';
+export const COLUMN_NAME_ID = 'name';
+
const useStateColumns = (): [
TableColumn[],
TableColumn[],
@@ -21,7 +23,7 @@ const useStateColumns = (): [
},
{
title: t('Name'),
- id: 'name',
+ id: COLUMN_NAME_ID,
},
{
title: t('Network interface'),
diff --git a/src/views/states/list/states-list.scss b/src/views/states/list/states-list.scss
new file mode 100644
index 00000000..2bfa3440
--- /dev/null
+++ b/src/views/states/list/states-list.scss
@@ -0,0 +1,7 @@
+.nns-list-management-group {
+ display: flex;
+ justify-content: space-between;
+ &__pagination {
+ flex-grow: 1;
+ }
+}