This repository has been archived by the owner on Nov 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
916e5c5
commit a828fe6
Showing
3 changed files
with
74 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<number | null>(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; | ||
const bValue = b.metadata.name; | ||
|
||
if (activeSortDirection === 'asc') { | ||
return (aValue as string).localeCompare(bValue as string); | ||
} | ||
return (bValue as string).localeCompare(aValue as string); | ||
}); | ||
} | ||
|
||
const nameSortParams: ThSortType = { | ||
sortBy: { | ||
index: activeSortIndex, | ||
direction: activeSortDirection, | ||
}, | ||
onSort: (_event, index, direction) => { | ||
setActiveSortIndex(index); | ||
setActiveSortDirection(direction); | ||
}, | ||
columnIndex: 1, | ||
}; | ||
|
||
return { sortedStates, nameSortParams }; | ||
}; | ||
|
||
export default useSortStates; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.nns-list-management-group { | ||
display: flex; | ||
justify-content: space-between; | ||
&__pagination { | ||
flex-grow: 1; | ||
} | ||
} |