Skip to content

Commit

Permalink
fix(platform): the interaction of bundle report
Browse files Browse the repository at this point in the history
  • Loading branch information
lizimeow committed Feb 27, 2023
1 parent fd1a4b8 commit a76ee6e
Show file tree
Hide file tree
Showing 8 changed files with 256 additions and 194 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ interface Props {
hoverable?: boolean
}

const Wrapper = styled('div')<{ color: string }>(({ color }) => ({
const Wrapper = styled('div')<{ color: string; underline?: boolean }>(({ color, underline }) => ({
display: 'inline-block',
color,
textDecoration: underline ? 'underline' : 'none',
}))

const SizeLabel = styled('label')(({ theme }) => ({
Expand Down Expand Up @@ -80,8 +81,12 @@ export const ColoredSize = ({ size, hoverable = true }: Props) => {
}, [size, theme])

const content = useMemo(
() => <Wrapper color={sizeColor}>{PrettyBytes.create(size.raw).toString()}</Wrapper>,
[size.raw, sizeColor],
() => (
<Wrapper underline={hoverable} color={sizeColor}>
{PrettyBytes.create(size.raw).toString()}
</Wrapper>
),
[size.raw, sizeColor, hoverable],
)

return hoverable ? (
Expand Down
46 changes: 26 additions & 20 deletions packages/bundle-report/src/bundle-detail/components/diff.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,15 @@ export type ByteSizeWithDiffProps = Diff<Size> & {
className?: string
showDiffBellow?: boolean
hideIfNonComparable?: boolean
underline?: boolean
}

export function ByteSizeWithDiff({
current,
baseline,
className,
showDiffBellow = true,
underline = false,
hideIfNonComparable = false,
}: ByteSizeWithDiffProps) {
const plainCardProps = useMemo<IPlainCardProps>(
Expand All @@ -151,7 +153,7 @@ export function ByteSizeWithDiff({
return (
<HoverCard plainCardProps={plainCardProps} type={HoverCardType.plain}>
<Stack>
<ByteSize size={current.raw} className={className} />
<ByteSize underline={underline} size={current.raw} className={className} />
<NumberDiff
current={current.raw}
baseline={baseline?.raw}
Expand All @@ -165,7 +167,7 @@ export function ByteSizeWithDiff({

return (
<HoverCard plainCardProps={plainCardProps} type={HoverCardType.plain}>
<ByteSize size={current.raw} className={className} />
<ByteSize underline={underline} size={current.raw} className={className} />
</HoverCard>
)
}
Expand All @@ -176,6 +178,7 @@ export interface ByteSizeProps {
hightlight?: boolean
signed?: boolean
className?: string
underline?: boolean
}

const ByteSizeLabel = styled('label')({})
Expand All @@ -184,27 +187,30 @@ const ByteSizeNumber = styled('span')({})

const ByteSizeUnit = styled('span')({})

const ByteSizeWrapper = styled.div<{ hightlight?: boolean }>(({ hightlight, theme }) => ({
display: 'inline-block',
cursor: 'pointer',
...(hightlight
? {
[`${ByteSizeLabel}, ${ByteSizeUnit}`]: {
color: theme!.text.colorSecondary,
fontSize: '12px',
},
[`${ByteSizeNumber}`]: {
fontSize: '16px',
},
}
: {}),
}))

export function ByteSize({ label, size, hightlight, signed, className }: ByteSizeProps) {
const ByteSizeWrapper = styled.div<{ hightlight?: boolean; underline?: boolean }>(
({ hightlight, underline, theme }) => ({
display: 'inline-block',
cursor: 'pointer',
...(hightlight
? {
[`${ByteSizeLabel}, ${ByteSizeUnit}`]: {
color: theme!.text.colorSecondary,
fontSize: '12px',
},
[`${ByteSizeNumber}`]: {
fontSize: '16px',
},
}
: {}),
textDecoration: underline ? 'underline' : 'none',
}),
)

export function ByteSize({ label, size, hightlight, signed, className, underline }: ByteSizeProps) {
const bytes = PrettyBytes.create(size, { signed })

return (
<ByteSizeWrapper hightlight={hightlight}>
<ByteSizeWrapper hightlight={hightlight} underline={underline}>
{label && <ByteSizeLabel>{label}: </ByteSizeLabel>}
<ByteSizeNumber className={className}>
{bytes.prefix}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const DisplayTime = styled.span<{ time: number }>(({ theme, time }) => {

return {
color,
textDecoration: 'underline',
}
})

Expand Down
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
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ limitations under the License.
*/

import { FileAddOutlined, QuestionCircleOutlined } from '@ant-design/icons'
import { Stack, SelectionMode, IGroup, HoverCard, HoverCardType, DirectionalHint, TooltipHost } from '@fluentui/react'
import { Stack, SelectionMode, IGroup, TooltipHost } from '@fluentui/react'
import { groupBy } from 'lodash'
import { FC, useMemo, useState } from 'react'

Expand All @@ -27,28 +27,12 @@ import { ColoredSize, TransferTime } from '../components'
import { TableHeaderFilterWrap } from '../style'

import { AssetFilter } from './asset-filter'
import { onAssetTableRenderRow } from './assets-table-row'

type AssetRow = AssetInfo & {
isNew: boolean
}

function renderPackagesCard(packages: NonNullable<AssetInfo['packages']>) {
return (
<ul style={{ paddingRight: '20px' }}>
{packages.map((pkg) =>
typeof pkg === 'string' ? (
<li key={pkg}>{pkg}</li>
) : (
<li key={pkg.path}>
{pkg.name}
{pkg.version && `@${pkg.version}`}: <ColoredSize size={pkg.size} hoverable={false} />
</li>
),
)}
</ul>
)
}

interface Props {
diff: EntryDiff
}
Expand Down Expand Up @@ -178,20 +162,7 @@ export const AssetsTable: FC<Props> = ({ diff }) => {
return null
}

return (
<HoverCard
type={HoverCardType.plain}
plainCardProps={{
onRenderPlainCard: renderPackagesCard,
renderData: asset.packages,
directionalHint: DirectionalHint.bottomRightEdge,
gapSpace: 10,
}}
instantOpenOnClick={true}
>
<a>(count: {asset.packages.length})</a>
</HoverCard>
)
return <span>count: {asset.packages.length}</span>
},
sorter: (a, b) => (a.packages?.length ?? 0) - (b.packages?.length ?? 0),
},
Expand All @@ -207,6 +178,7 @@ export const AssetsTable: FC<Props> = ({ diff }) => {
selectionMode={SelectionMode.none}
columns={columns}
disableVirtualization={items.length < 100}
onRenderRow={onAssetTableRenderRow}
/>
</Stack>
)
Expand Down
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
}
}

0 comments on commit a76ee6e

Please sign in to comment.