Skip to content

Commit

Permalink
chore(new-ui): fix missing suites when suite both has nested browsers…
Browse files Browse the repository at this point in the history
… and suites
  • Loading branch information
shadowusr committed Sep 27, 2024
1 parent 0c05428 commit 849d140
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import {get, last} from 'lodash';
import {
isImageEntityFail,
isResultEntityError,
isSuiteEntityLeaf,
hasBrowsers,
hasSuites,
BrowserEntity,
SuiteEntity
} from '@/static/new-ui/types/store';
Expand Down Expand Up @@ -90,21 +91,19 @@ export const getTreeViewItems = createSelector(
return null;
}

if (isSuiteEntityLeaf(suiteData)) {
return {
data,
children: suiteData.browserIds
.map((browserId) => formatBrowser(browsers[browserId], data))
.filter(Boolean) as TreeViewItem<TreeViewBrowserData>[]
};
} else {
return {
data,
children: suiteData.suiteIds
.map((suiteId) => formatSuite(suites[suiteId], data))
.filter(Boolean) as TreeViewItem<TreeViewSuiteData | TreeViewBrowserData>[]
};
const children: TreeViewItem<TreeViewSuiteData | TreeViewBrowserData>[] = [];
if (hasBrowsers(suiteData)) {
children.push(...suiteData.browserIds
.map((browserId) => formatBrowser(browsers[browserId], data))
.filter(Boolean) as TreeViewItem<TreeViewBrowserData>[]);
}
if (hasSuites(suiteData)) {
children.push(...suiteData.suiteIds
.map((suiteId) => formatSuite(suites[suiteId], data))
.filter(Boolean) as TreeViewItem<TreeViewSuiteData | TreeViewBrowserData>[]);
}

return {data, children};
};

const tree = rootSuiteIds
Expand Down
3 changes: 2 additions & 1 deletion lib/static/new-ui/types/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ export interface SuiteEntityLeaf {

export type SuiteEntity = SuiteEntityNode | SuiteEntityLeaf;

export const isSuiteEntityLeaf = (suite: SuiteEntity): suite is SuiteEntityLeaf => Boolean((suite as SuiteEntityLeaf).browserIds);
export const hasBrowsers = (suite: SuiteEntity): suite is SuiteEntityLeaf => Boolean((suite as SuiteEntityLeaf).browserIds);
export const hasSuites = (suite: SuiteEntity): suite is SuiteEntityNode => Boolean((suite as SuiteEntityNode).suiteIds);

export interface BrowserEntity {
id: string;
Expand Down

0 comments on commit 849d140

Please sign in to comment.