-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(platform): the interaction of bundle report
- Loading branch information
Showing
8 changed files
with
256 additions
and
194 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
68 changes: 68 additions & 0 deletions
68
packages/bundle-report/src/bundle-detail/resource-tabs/assets-table-row.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,68 @@ | ||
import { IDetailsRowProps, IDetailsRowStyles, DetailsRow, PivotItem } from '@fluentui/react' | ||
import { NeutralColors } from '@fluentui/theme' | ||
import { useState, useMemo, useCallback } from 'react' | ||
|
||
import { TooltipWithEllipsis } from '@perfsee/components' | ||
import { AssetInfo } from '@perfsee/shared' | ||
|
||
import { ColoredSize } from '../components' | ||
import { TableExtraWrap, StyledPivot, StyledInfoItem } from '../style' | ||
|
||
type Props = { item: AssetInfo } | ||
|
||
const TableExtraInfo = (props: Props) => { | ||
const { item } = props | ||
|
||
return ( | ||
<TableExtraWrap> | ||
<StyledPivot styles={{ itemContainer: { width: '100%', padding: '8px' } }}> | ||
<PivotItem headerText="included packages"> | ||
{item.packages.map((pkg) => { | ||
if (typeof pkg === 'string') { | ||
return <StyledInfoItem key={pkg}>{pkg}</StyledInfoItem> | ||
} | ||
|
||
return ( | ||
<StyledInfoItem key={pkg.path}> | ||
<TooltipWithEllipsis content={pkg.name + (pkg.version ? `@${pkg.version}` : '')} /> | ||
<ColoredSize size={pkg.size} hoverable={false} /> | ||
</StyledInfoItem> | ||
) | ||
})} | ||
</PivotItem> | ||
</StyledPivot> | ||
</TableExtraWrap> | ||
) | ||
} | ||
|
||
const DetailRowItem = (props: IDetailsRowProps) => { | ||
const [opened, setOpened] = useState<boolean>() | ||
|
||
const customStyles: Partial<IDetailsRowStyles> = useMemo( | ||
() => ({ | ||
cell: { | ||
cursor: 'pointer', | ||
backgroundColor: opened ? NeutralColors.gray20 : undefined, | ||
}, | ||
}), | ||
[opened], | ||
) | ||
|
||
const onClick = useCallback(() => { | ||
setOpened((opened) => !opened) | ||
}, []) | ||
|
||
return ( | ||
<> | ||
<DetailsRow {...props} styles={customStyles} onClick={onClick} /> | ||
{opened && <TableExtraInfo item={props.item} />} | ||
</> | ||
) | ||
} | ||
|
||
export const onAssetTableRenderRow = (props?: IDetailsRowProps) => { | ||
if (props) { | ||
return <DetailRowItem {...props} /> | ||
} | ||
return null | ||
} |
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
110 changes: 110 additions & 0 deletions
110
packages/bundle-report/src/bundle-detail/resource-tabs/package-table-row.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,110 @@ | ||
import { IDetailsRowProps, IDetailsRowStyles, DetailsRow, PivotItem } from '@fluentui/react' | ||
import { NeutralColors } from '@fluentui/theme' | ||
import { useState, useMemo, useCallback } from 'react' | ||
|
||
import { TooltipWithEllipsis } from '@perfsee/components' | ||
import { OLD_SOURCE_CODE_PATH, Size, SOURCE_CODE_PATH } from '@perfsee/shared' | ||
|
||
import { ColoredSize } from '../components' | ||
import { TableExtraWrap, StyledInfoItem, StyledPivot } from '../style' | ||
|
||
import { Package } from './package-filter' | ||
|
||
type LoadInner = { | ||
size: Size | ||
list: Record<string, Size> | ||
} | ||
|
||
export type LoadType = { | ||
intermidiate?: LoadInner | ||
initial?: LoadInner | ||
async?: LoadInner | ||
} | ||
|
||
type Props = { item: Package; packagesLoadTypeMap: Map<number, LoadType> } | ||
|
||
const TableExtraInfo = (props: Props) => { | ||
const { item, packagesLoadTypeMap } = props | ||
|
||
const loadType = packagesLoadTypeMap.get(item.ref) ?? {} | ||
|
||
return ( | ||
<TableExtraWrap> | ||
<StyledPivot styles={{ itemContainer: { width: '100%', padding: '8px' } }}> | ||
{Object.entries(loadType).map(([type, { list }]) => { | ||
const title = `${type} assets` | ||
return ( | ||
<PivotItem headerText={title} key={type}> | ||
{Object.entries(list) | ||
.sort(([, sizeA], [, sizeB]) => sizeB.raw - sizeA.raw) | ||
.map(([key, innerSize]) => { | ||
return ( | ||
<StyledInfoItem key={key}> | ||
<TooltipWithEllipsis content={key} /> | ||
<ColoredSize size={innerSize} hoverable={false} /> | ||
</StyledInfoItem> | ||
) | ||
})} | ||
</PivotItem> | ||
) | ||
})} | ||
{!!item.issuers.length && ( | ||
<PivotItem headerText="issuers"> | ||
{item.issuers.map((issuer) => ( | ||
<StyledInfoItem key={issuer}> | ||
<b>{issuer === OLD_SOURCE_CODE_PATH ? SOURCE_CODE_PATH : issuer}</b> | ||
</StyledInfoItem> | ||
))} | ||
</PivotItem> | ||
)} | ||
{!!item.notes?.length && ( | ||
<PivotItem headerText="notes"> | ||
{item.notes.map((note) => ( | ||
<StyledInfoItem key={note}> | ||
<b>{note}</b> | ||
</StyledInfoItem> | ||
))} | ||
</PivotItem> | ||
)} | ||
</StyledPivot> | ||
</TableExtraWrap> | ||
) | ||
} | ||
|
||
interface DetailRowItemProps extends IDetailsRowProps { | ||
map: Map<number, LoadType> | ||
} | ||
|
||
const DetailRowItem = (props: DetailRowItemProps) => { | ||
const [opened, setOpened] = useState<boolean>() | ||
|
||
const customStyles: Partial<IDetailsRowStyles> = useMemo( | ||
() => ({ | ||
cell: { | ||
cursor: 'pointer', | ||
backgroundColor: opened ? NeutralColors.gray20 : undefined, | ||
}, | ||
}), | ||
[opened], | ||
) | ||
|
||
const onClick = useCallback(() => { | ||
setOpened((opened) => !opened) | ||
}, []) | ||
|
||
return ( | ||
<> | ||
<DetailsRow {...props} styles={customStyles} onClick={onClick} /> | ||
{opened && <TableExtraInfo packagesLoadTypeMap={props.map} item={props.item} />} | ||
</> | ||
) | ||
} | ||
|
||
export const onPackageTableRenderRow = (map: Map<number, LoadType>) => { | ||
return (props?: IDetailsRowProps) => { | ||
if (props) { | ||
return <DetailRowItem map={map} {...props} /> | ||
} | ||
return null | ||
} | ||
} |
Oops, something went wrong.