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 3269811
Showing
5 changed files
with
79 additions
and
16 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
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 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; |
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,7 @@ | ||
.nns-list-management-group { | ||
display: flex; | ||
justify-content: space-between; | ||
&__pagination { | ||
flex-grow: 1; | ||
} | ||
} |