-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement filtering by status in new ui
- Loading branch information
Showing
12 changed files
with
164 additions
and
12 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
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
9 changes: 9 additions & 0 deletions
9
lib/static/new-ui/features/suites/components/TestStatusFilter/index.module.css
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,9 @@ | ||
.test-status-filter-option { | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
} | ||
|
||
.test-status-filter-option__count { | ||
margin-left: var(--g-spacing-1); | ||
} |
46 changes: 46 additions & 0 deletions
46
lib/static/new-ui/features/suites/components/TestStatusFilter/index.tsx
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,46 @@ | ||
import {RadioButton} from '@gravity-ui/uikit'; | ||
import React, {ReactNode} from 'react'; | ||
import {connect} from 'react-redux'; | ||
import {bindActionCreators} from 'redux'; | ||
|
||
import {TestStatus, ViewMode} from '@/constants'; | ||
import * as actions from '@/static/modules/actions'; | ||
import {getStatusCounts, StatusCounts} from '@/static/new-ui/features/suites/components/TestStatusFilter/selectors'; | ||
import {State} from '@/static/new-ui/types/store'; | ||
import {getIconByStatus} from '@/static/new-ui/utils'; | ||
import styles from './index.module.css'; | ||
|
||
interface TestStatusFilterOptionProps { | ||
status: TestStatus | 'total'; | ||
count: number; | ||
} | ||
|
||
function TestStatusFilterOption(props: TestStatusFilterOptionProps): ReactNode { | ||
return <div className={styles['test-status-filter-option']}> | ||
{props.status === 'total' ? <span>All</span> : getIconByStatus(props.status)}<span className={styles['test-status-filter-option__count']}>{props.count}</span> | ||
</div>; | ||
} | ||
|
||
interface TestStatusFilterProps { | ||
statusCounts: StatusCounts; | ||
actions: typeof actions; | ||
viewMode: ViewMode; | ||
} | ||
|
||
function TestStatusFilterInternal({statusCounts, actions, viewMode}: TestStatusFilterProps): ReactNode { | ||
return <RadioButton width={'max'} onChange={(e): void => void actions.changeViewMode(e.target.value)} value={viewMode}> | ||
<RadioButton.Option value={ViewMode.ALL} content={<TestStatusFilterOption status={'total'} count={statusCounts.total}/>} /> | ||
<RadioButton.Option value={ViewMode.PASSED} content={<TestStatusFilterOption status={TestStatus.SUCCESS} count={statusCounts.success}/>} /> | ||
<RadioButton.Option value={ViewMode.FAILED} content={<TestStatusFilterOption status={TestStatus.FAIL} count={statusCounts.fail}/>} /> | ||
<RadioButton.Option value={ViewMode.RETRIED} content={<TestStatusFilterOption status={TestStatus.RETRY} count={statusCounts.retried}/>} /> | ||
<RadioButton.Option value={ViewMode.SKIPPED} content={<TestStatusFilterOption status={TestStatus.SKIPPED} count={statusCounts.skipped}/>} /> | ||
</RadioButton>; | ||
} | ||
|
||
export const TestStatusFilter = connect( | ||
(state: State) => ({ | ||
statusCounts: getStatusCounts(state), | ||
viewMode: state.view.viewMode | ||
}), | ||
(dispatch) => ({actions: bindActionCreators(actions, dispatch)}) | ||
)(TestStatusFilterInternal); |
52 changes: 52 additions & 0 deletions
52
lib/static/new-ui/features/suites/components/TestStatusFilter/selectors.ts
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,52 @@ | ||
import {createSelector} from 'reselect'; | ||
import {getAllBrowserIds, getResults} from '@/static/new-ui/store/selectors'; | ||
|
||
export interface StatusCounts { | ||
success: number; | ||
fail: number; | ||
skipped: number; | ||
total: number; | ||
retried: number; | ||
retries: number; | ||
idle: number; | ||
} | ||
|
||
export const getStatusCounts = createSelector( | ||
[getResults, getAllBrowserIds], | ||
(results, browserIds) => { | ||
const latestAttempts: Record<string, {attempt: number; status: string, timestamp: number}> = {}; | ||
const retriedTests = new Set<string>(); | ||
|
||
let retries = 0; | ||
Object.values(results).forEach(result => { | ||
const {parentId: testId, attempt, status, timestamp} = result; | ||
if (attempt > 0) { | ||
retriedTests.add(testId); | ||
} | ||
if (!latestAttempts[testId] || latestAttempts[testId].timestamp < timestamp) { | ||
retries -= latestAttempts[testId]?.attempt ?? 0; | ||
retries += attempt; | ||
|
||
latestAttempts[testId] = {attempt, status, timestamp}; | ||
} | ||
}); | ||
|
||
const counts: StatusCounts = { | ||
success: 0, | ||
fail: 0, | ||
skipped: 0, | ||
total: browserIds.length, | ||
retried: retriedTests.size, | ||
retries, | ||
idle: 0 | ||
}; | ||
|
||
Object.values(latestAttempts).forEach(({status}) => { | ||
if (Object.prototype.hasOwnProperty.call(counts, status)) { | ||
counts[status as keyof StatusCounts]++; | ||
} | ||
}); | ||
|
||
return counts; | ||
} | ||
); |
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 |
---|---|---|
@@ -1,8 +1,18 @@ | ||
import {State, BrowserEntity, ImageEntity, ResultEntity, SuiteEntity, SuiteState} from '@/static/new-ui/types/store'; | ||
import { | ||
State, | ||
BrowserEntity, | ||
ImageEntity, | ||
ResultEntity, | ||
SuiteEntity, | ||
SuiteState, | ||
BrowserState | ||
} from '@/static/new-ui/types/store'; | ||
|
||
export const getAllRootSuiteIds = (state: State): string[] => state.tree.suites.allRootIds; | ||
export const getSuites = (state: State): Record<string, SuiteEntity> => state.tree.suites.byId; | ||
export const getSuitesState = (state: State): Record<string, SuiteState> => state.tree.suites.stateById; | ||
export const getBrowsers = (state: State): Record<string, BrowserEntity> => state.tree.browsers.byId; | ||
export const getBrowsersState = (state: State): Record<string, BrowserState> => state.tree.browsers.stateById; | ||
export const getAllBrowserIds = (state: State): string[] => state.tree.browsers.allIds; | ||
export const getResults = (state: State): Record<string, ResultEntity> => state.tree.results.byId; | ||
export const getImages = (state: State): Record<string, ImageEntity> => state.tree.images.byId; |
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