Skip to content

Commit

Permalink
[grid] UI Overview add more sort options
Browse files Browse the repository at this point in the history
Signed-off-by: Viet Nguyen Duc <[email protected]>
  • Loading branch information
VietND96 committed Oct 19, 2024
1 parent 9759c09 commit 4070244
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 11 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci-java.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ jobs:
# https://github.com/bazelbuild/rules_jvm_external/issues/1046
java-version: 17
run: |
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem" /v LongPathsEnabled /t REG_DWORD /d "00000001" /f -RunAsAdmin
git config --global core.longpaths true
bazel test --flaky_test_attempts 3 //java/test/org/openqa/selenium/chrome:ChromeDriverFunctionalTest `
//java/test/org/openqa/selenium/federatedcredentialmanagement:FederatedCredentialManagementTest `
//java/test/org/openqa/selenium/firefox:FirefoxDriverBuilderTest `
Expand Down
50 changes: 39 additions & 11 deletions javascript/grid-ui/src/screens/Overview/Overview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,39 @@ function Overview (): JSX.Element {
fetchPolicy: 'network-only'
})

const [sortOption, setSortOption] = useState('osInfo.name')
function compareSlotStereotypes(a: NodeInfo, b: NodeInfo, attribute: string): number {
const joinA = a.slotStereotypes.length === 1
? a.slotStereotypes[0][attribute]
: a.slotStereotypes.slice().map(st => st[attribute]).reverse().join(',')
const joinB = b.slotStereotypes.length === 1
? b.slotStereotypes[0][attribute]
: b.slotStereotypes.slice().map(st => st[attribute]).reverse().join(',')
return joinA.localeCompare(joinB)
}

const sortProperties = {
'platformName': (a, b) => compareSlotStereotypes(a, b, 'platformName'),
'status': (a, b) => a.status.localeCompare(b.status),
'browserName': (a, b) => compareSlotStereotypes(a, b, 'browserName'),
'browserVersion': (a, b) => compareSlotStereotypes(a, b, 'browserVersion'),
'slotCount': (a, b) => {
const valueA = a.slotStereotypes.reduce((sum, st) => sum + st.slotCount, 0)
const valueB = b.slotStereotypes.reduce((sum, st) => sum + st.slotCount, 0)
return valueA < valueB ? -1 : 1
},
'id': (a, b) => (a.id < b.id ? -1 : 1)
}

const sortPropertiesLabel = {
'platformName': 'Platform Name',
'status': 'Status',
'browserName': 'Browser Name',
'browserVersion': 'Browser Version',
'slotCount': 'Slot Count',
'id': 'ID'
}

const [sortOption, setSortOption] = useState(Object.keys(sortProperties)[0])
const [sortOrder, setSortOrder] = useState(1)
const [sortedNodes, setSortedNodes] = useState<NodeInfo[]>([])
const [isDescending, setIsDescending] = useState(false)
Expand All @@ -62,12 +94,6 @@ function Overview (): JSX.Element {
setSortOrder(event.target.checked ? -1 : 1)
}

const sortProperties = {
'osInfo.name': (a, b) => a.osInfo.name.localeCompare(b.osInfo.name),
'status': (a, b) => a.status.localeCompare(b.status),
'id': (a, b) => (a.id < b.id ? -1 : 1)
}

const sortNodes = useMemo(() => {
return (nodes: NodeInfo[], option: string, order: number) => {
const sortFn = sortProperties[option] || (() => 0)
Expand Down Expand Up @@ -156,10 +182,12 @@ function Overview (): JSX.Element {
<InputLabel>Sort By</InputLabel>
<Box display="flex" alignItems="center">
<Select value={sortOption} onChange={handleSortChange}
label="Sort By" style={{ minWidth: '150px' }}>
<MenuItem value="osInfo.name">Platform</MenuItem>
<MenuItem value="status">Status</MenuItem>
<MenuItem value="id">ID</MenuItem>
label="Sort By" style={{ minWidth: '170px' }}>
{Object.keys(sortProperties).map((key) => (
<MenuItem value={key}>
{sortPropertiesLabel[key]}
</MenuItem>
))}
</Select>
<FormControlLabel
control={<Checkbox checked={isDescending}
Expand Down

0 comments on commit 4070244

Please sign in to comment.