@bundle-stats/ui 4.17.0 → 4.18.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/lib/components/asset-info/asset-info.i18n.js +11 -0
  2. package/lib/components/asset-info/asset-info.i18n.js.map +1 -0
  3. package/lib/components/asset-info/asset-info.js +16 -16
  4. package/lib/components/asset-info/asset-info.js.map +1 -1
  5. package/lib/components/bundle-assets/bundle-assets.i18n.js +9 -1
  6. package/lib/components/bundle-assets/bundle-assets.i18n.js.map +1 -1
  7. package/lib/components/bundle-assets/bundle-assets.js +9 -112
  8. package/lib/components/bundle-assets/bundle-assets.js.map +1 -1
  9. package/lib/components/bundle-assets/bundle-assets.utils.js +136 -23
  10. package/lib/components/bundle-assets/bundle-assets.utils.js.map +1 -1
  11. package/lib/components/bundle-assets/index.js +8 -26
  12. package/lib/components/bundle-assets/index.js.map +1 -1
  13. package/lib/components/metrics-table/metrics-table.js.map +1 -1
  14. package/lib/components/metrics-table-header/metrics-table-header.js.map +1 -1
  15. package/lib/hooks/rows-sort.js +14 -2
  16. package/lib/hooks/rows-sort.js.map +1 -1
  17. package/lib/hooks/search-params.js.map +1 -1
  18. package/lib-esm/components/asset-info/asset-info.i18n.js +8 -0
  19. package/lib-esm/components/asset-info/asset-info.i18n.js.map +1 -0
  20. package/lib-esm/components/asset-info/asset-info.js +17 -17
  21. package/lib-esm/components/asset-info/asset-info.js.map +1 -1
  22. package/lib-esm/components/bundle-assets/bundle-assets.i18n.js +8 -0
  23. package/lib-esm/components/bundle-assets/bundle-assets.i18n.js.map +1 -1
  24. package/lib-esm/components/bundle-assets/bundle-assets.js +10 -113
  25. package/lib-esm/components/bundle-assets/bundle-assets.js.map +1 -1
  26. package/lib-esm/components/bundle-assets/bundle-assets.utils.js +111 -22
  27. package/lib-esm/components/bundle-assets/bundle-assets.utils.js.map +1 -1
  28. package/lib-esm/components/bundle-assets/index.js +9 -24
  29. package/lib-esm/components/bundle-assets/index.js.map +1 -1
  30. package/lib-esm/components/metrics-table/metrics-table.js.map +1 -1
  31. package/lib-esm/components/metrics-table-header/metrics-table-header.js.map +1 -1
  32. package/lib-esm/hooks/rows-sort.js +14 -2
  33. package/lib-esm/hooks/rows-sort.js.map +1 -1
  34. package/lib-esm/hooks/search-params.js.map +1 -1
  35. package/package.json +3 -3
  36. package/src/components/asset-info/asset-info.i18n.ts +7 -0
  37. package/src/components/asset-info/asset-info.tsx +36 -38
  38. package/src/components/bundle-assets/__tests__/add-metric-report-asset-row-data.ts +2 -2
  39. package/src/components/bundle-assets/bundle-assets.i18n.ts +8 -0
  40. package/src/components/bundle-assets/bundle-assets.stories.tsx +99 -0
  41. package/src/components/bundle-assets/{bundle-assets.jsx → bundle-assets.tsx} +67 -149
  42. package/src/components/bundle-assets/bundle-assets.utils.ts +276 -0
  43. package/src/components/bundle-assets/{index.jsx → index.tsx} +43 -29
  44. package/src/components/metrics-table/metrics-table.tsx +3 -3
  45. package/src/components/metrics-table-header/metrics-table-header.tsx +4 -4
  46. package/src/components/sort-button/sort-button.tsx +1 -1
  47. package/src/hooks/rows-sort.ts +21 -3
  48. package/src/hooks/search-params.js +0 -1
  49. package/src/types.d.ts +5 -1
  50. package/types/components/asset-info/asset-info.d.ts +4 -13
  51. package/types/components/asset-info/asset-info.i18n.d.ts +7 -0
  52. package/types/components/bundle-assets/bundle-assets.d.ts +24 -55
  53. package/types/components/bundle-assets/bundle-assets.i18n.d.ts +8 -0
  54. package/types/components/bundle-assets/bundle-assets.utils.d.ts +17 -5
  55. package/types/components/bundle-assets/index.d.ts +10 -22
  56. package/types/components/metrics-table/metrics-table.d.ts +3 -2
  57. package/types/components/metrics-table-header/metrics-table-header.d.ts +1 -2
  58. package/types/components/sort-button/sort-button.d.ts +1 -2
  59. package/types/hooks/rows-sort.d.ts +1 -1
  60. package/src/components/bundle-assets/bundle-assets.utils.js +0 -149
@@ -1,6 +1,6 @@
1
1
  import React, { useMemo } from 'react';
2
- import PropTypes from 'prop-types';
3
2
  import * as webpack from '@bundle-stats/utils/lib-esm/webpack';
3
+ import type { Job } from '@bundle-stats/utils';
4
4
  import { ASSET_FILTERS } from '@bundle-stats/utils';
5
5
  import {
6
6
  getAssetEntryTypeFilters,
@@ -13,13 +13,37 @@ import { useSearchParams } from '../../hooks/search-params';
13
13
  import { useEntryInfo } from '../../hooks/entry-info';
14
14
  import { getJobsChunksData } from '../../utils/jobs';
15
15
  import { BundleAssets as BundleAssetsComponent } from './bundle-assets';
16
- import { addMetricReportAssetRowData, getRowFilter, getCustomSort } from './bundle-assets.utils';
16
+ import {
17
+ addMetricReportAssetRowData,
18
+ generateGetRowFilter,
19
+ getCustomSort,
20
+ } from './bundle-assets.utils';
21
+ import { ReportMetricAssetRow } from '../../types';
17
22
 
18
- export const BundleAssets = (props) => {
19
- const { jobs, filters, search, setState, sortBy, direction, ...restProps } = props;
23
+ export type BundleAssetsProps = {
24
+ jobs: Array<Job>;
25
+ filters?: Record<string, boolean>;
26
+ search?: string;
27
+ sortBy?: string;
28
+ direction?: string;
29
+ setState: () => void;
30
+ };
20
31
 
21
- const { chunks } = useMemo(() => getJobsChunksData(jobs), [jobs]);
32
+ export const BundleAssets = (props: BundleAssetsProps) => {
33
+ const {
34
+ jobs,
35
+ filters = undefined,
36
+ search = undefined,
37
+ sortBy = undefined,
38
+ direction = undefined,
39
+ setState,
40
+ ...restProps
41
+ } = props;
22
42
 
43
+ // Get chunks data
44
+ const { chunks, chunkIds } = useMemo(() => getJobsChunksData(jobs), [jobs]);
45
+
46
+ // Get filters
23
47
  const { defaultFilters, allEntriesFilters } = useMemo(
24
48
  () => ({
25
49
  defaultFilters: {
@@ -36,7 +60,8 @@ export const BundleAssets = (props) => {
36
60
  [jobs],
37
61
  );
38
62
 
39
- const searchParams = useSearchParams({
63
+ // Get search params data
64
+ const searchProps = useSearchParams({
40
65
  search,
41
66
  filters,
42
67
  defaultFilters,
@@ -44,19 +69,22 @@ export const BundleAssets = (props) => {
44
69
  setState,
45
70
  });
46
71
 
72
+ // Get metric rows
47
73
  const { rows, totalRowCount } = useMemo(() => {
48
74
  const result = webpack.compareBySection.assets(jobs, [addMetricReportAssetRowData]);
49
75
  return { rows: result, totalRowCount: result.length };
50
76
  }, [jobs]);
51
77
 
78
+ // Filter rows
52
79
  const filteredRows = useRowsFilter({
53
80
  rows,
54
- searchPattern: searchParams.searchPattern,
55
- filters: searchParams.filters,
56
- getRowFilter,
81
+ searchPattern: searchProps.searchPattern,
82
+ filters: searchProps.filters,
83
+ getRowFilter: generateGetRowFilter({ chunkIds }),
57
84
  });
58
85
 
59
- const sortParams = useRowsSort({
86
+ // Sort rows
87
+ const sortProps = useRowsSort<ReportMetricAssetRow>({
60
88
  rows: filteredRows,
61
89
  initialField: sortBy,
62
90
  initialDirection: direction,
@@ -68,31 +96,17 @@ export const BundleAssets = (props) => {
68
96
 
69
97
  return (
70
98
  <BundleAssetsComponent
99
+ {...restProps}
100
+ {...searchProps}
71
101
  jobs={jobs}
72
102
  chunks={chunks}
73
- {...restProps}
74
- {...searchParams}
75
- {...sortParams}
103
+ sort={sortProps.sort}
104
+ items={sortProps.items}
76
105
  allItems={rows}
77
106
  totalRowCount={totalRowCount}
107
+ updateSort={sortProps.updateSort}
78
108
  hideEntryInfo={hideEntryInfo}
79
109
  showEntryInfo={showEntryInfo}
80
110
  />
81
111
  );
82
112
  };
83
-
84
- BundleAssets.propTypes = {
85
- jobs: PropTypes.arrayOf(PropTypes.object).isRequired, // eslint-disable-line react/forbid-prop-types
86
- filters: PropTypes.object, // eslint-disable-line react/forbid-prop-types
87
- search: PropTypes.string,
88
- sortBy: PropTypes.string,
89
- direction: PropTypes.string,
90
- setState: PropTypes.func.isRequired,
91
- };
92
-
93
- BundleAssets.defaultProps = {
94
- filters: undefined,
95
- search: undefined,
96
- sortBy: undefined,
97
- direction: undefined,
98
- };
@@ -9,7 +9,7 @@ import { Table } from '../../ui/table';
9
9
  import { Stack } from '../../layout/stack';
10
10
  import { Metric } from '../metric';
11
11
  import { Delta } from '../delta';
12
- import { MetricsTableHeader } from '../metrics-table-header';
12
+ import { MetricsTableHeader, MetricsTableHeaderProps } from '../metrics-table-header';
13
13
  import * as I18N from './metrics-table.i18n';
14
14
  import css from './metrics-table.module.css';
15
15
 
@@ -74,8 +74,8 @@ interface MetricsTableProps extends Omit<React.ComponentProps<typeof Table>, 'ti
74
74
  items: Array<ReportMetricRow>;
75
75
  title?: React.ReactNode;
76
76
  showHeaderSum?: boolean;
77
- sort?: any;
78
- updateSort?: (val: any) => void;
77
+ sort?: MetricsTableHeaderProps['sort'];
78
+ updateSort?: MetricsTableHeaderProps['updateSort'];
79
79
  renderRowHeader?: (item: ReportMetricRow) => React.ReactNode;
80
80
  emptyMessage?: React.ReactNode;
81
81
  showAllItems: boolean;
@@ -12,7 +12,7 @@ import { Table } from '../../ui/table';
12
12
  import { Delta } from '../delta';
13
13
  import { JobName } from '../job-name';
14
14
  import { Metric } from '../metric';
15
- import { SortButton } from '../sort-button';
15
+ import { SortButton, SortButtonProps } from '../sort-button';
16
16
  import * as I18N from './metrics-table-header.i18n';
17
17
  import css from './metrics-table-header.module.css';
18
18
 
@@ -53,8 +53,8 @@ interface ColumnSumProps {
53
53
  rows: Array<ReportMetricRow>;
54
54
  isBaseline: boolean;
55
55
  runIndex: number;
56
- sort?: any;
57
- updateSort?: (val: any) => void;
56
+ sort?: SortButtonProps['sort'];
57
+ updateSort?: SortButtonProps['updateSort'];
58
58
  }
59
59
 
60
60
  const SumColumn = ({ rows, isBaseline, runIndex, updateSort, sort }: ColumnSumProps) => {
@@ -110,7 +110,7 @@ const SumColumn = ({ rows, isBaseline, runIndex, updateSort, sort }: ColumnSumPr
110
110
  );
111
111
  };
112
112
 
113
- interface MetricsTableHeaderProps {
113
+ export interface MetricsTableHeaderProps {
114
114
  /**
115
115
  * Metric column title
116
116
  */
@@ -36,7 +36,7 @@ const getDescAction = (label: string): SortInfo => {
36
36
  return { direction: SORT.DESC, title: `Order ${label} descending` };
37
37
  };
38
38
 
39
- interface SortButtonProps {
39
+ export interface SortButtonProps {
40
40
  fieldPath: string;
41
41
  fieldName: string;
42
42
  label: string;
@@ -5,6 +5,21 @@ import orderBy from 'lodash/orderBy';
5
5
  import type { SortAction } from '../types';
6
6
  import { SORT } from '../constants';
7
7
 
8
+ /**
9
+ * Get sort direction field from a string param
10
+ */
11
+ const getSortDirection = (directionParam: string | undefined): SortAction['direction'] => {
12
+ if (typeof directionParam === 'undefined') {
13
+ return '';
14
+ }
15
+
16
+ if (['asc', 'desc'].includes(directionParam)) {
17
+ return directionParam as SortAction['direction'];
18
+ }
19
+
20
+ return '';
21
+ };
22
+
8
23
  export const getSortFn =
9
24
  <TRow>(fieldPath: string, getCustomSort: UseRowsSortParams<TRow>['getCustomSort']) =>
10
25
  (item: TRow) => {
@@ -18,7 +33,7 @@ export const getSortFn =
18
33
  interface UseRowsSortParams<TRow> {
19
34
  rows: Array<TRow>;
20
35
  initialField?: string;
21
- initialDirection?: SortAction['direction'];
36
+ initialDirection?: string;
22
37
  getCustomSort: (item: any) => Array<string | number | boolean>;
23
38
  setQueryState: (queryParams: {
24
39
  sortBy: SortAction['field'];
@@ -35,11 +50,14 @@ interface UseRowsSort<TRow> {
35
50
  export const useRowsSort = <TRow>({
36
51
  rows,
37
52
  initialField = 'runs[0].delta',
38
- initialDirection = 'desc',
53
+ initialDirection,
39
54
  getCustomSort,
40
55
  setQueryState,
41
56
  }: UseRowsSortParams<TRow>): UseRowsSort<TRow> => {
42
- const [sort, setSort] = useState({ field: initialField, direction: initialDirection });
57
+ const [sort, setSort] = useState({
58
+ field: initialField,
59
+ direction: getSortDirection(initialDirection),
60
+ });
43
61
 
44
62
  const updateSort = useCallback(
45
63
  (newState: SortAction) => {
@@ -102,7 +102,6 @@ export const generateState = (filters, search) => ({
102
102
 
103
103
  export const useSearchParams = ({
104
104
  search: parentSearch = SEARCH_DEFAULT,
105
-
106
105
  filters: parentFilters,
107
106
  defaultFilters,
108
107
  allEntriesFilters,
package/src/types.d.ts CHANGED
@@ -12,9 +12,13 @@ interface FilterFieldData {
12
12
  disabled?: boolean;
13
13
  }
14
14
 
15
+ interface ChildFilterFieldData extends FilterFieldData {
16
+ key: string;
17
+ }
18
+
15
19
  type FilterGroupFieldData = {
16
20
  label: string;
17
- children: Array<{ key: string } & FilterFieldData>;
21
+ children: Array<ChildFilterFieldData>;
18
22
  };
19
23
 
20
24
  type FilterFieldsData = Record<string, FilterFieldData | FilterGroupFieldData>;
@@ -1,19 +1,10 @@
1
1
  import type { ComponentProps, ElementType } from 'react';
2
2
  import React from 'react';
3
- import { MetricRunInfo } from '@bundle-stats/utils';
4
- import type { AssetMetricRun, MetaChunk } from '@bundle-stats/utils/types/webpack';
3
+ import type { WebpackChunk } from '@bundle-stats/utils';
4
+ import type { ReportMetricAssetRow } from '../../types';
5
5
  interface AssetInfoProps {
6
- item: {
7
- label: string;
8
- changed?: boolean;
9
- isChunk?: boolean;
10
- isEntry?: boolean;
11
- isInitial?: boolean;
12
- isNotPredictive?: boolean;
13
- fileType?: string;
14
- runs: Array<AssetMetricRun & MetricRunInfo>;
15
- };
16
- chunks?: Array<MetaChunk>;
6
+ item: ReportMetricAssetRow;
7
+ chunks?: Array<WebpackChunk>;
17
8
  labels: Array<string>;
18
9
  customComponentLink?: ElementType;
19
10
  onClose: () => void;
@@ -0,0 +1,7 @@
1
+ export declare const ENTRY = "Entry";
2
+ export declare const INITIAL = "Initial";
3
+ export declare const CHUNK = "Chunk";
4
+ export declare const CHUNK_TOOLTIP = "The bundler's chunk from which the assets originated";
5
+ export declare const ENTRYPOINT = "Entrypoint";
6
+ export declare const FILE_TYPE = "File type";
7
+ export declare const FILE_TYPE_TOOLTIP = "Asset file type: JS, CSS, image, media, fonts, HTML, or other";
@@ -1,56 +1,25 @@
1
- export function BundleAssets(props: any): React.JSX.Element;
2
- export namespace BundleAssets {
3
- namespace defaultProps {
4
- export let className: string;
5
- export let totalRowCount: number;
6
- export let hasActiveFilters: boolean;
7
- export { ComponentLink as customComponentLink };
8
- export let entryId: string;
9
- }
10
- namespace propTypes {
11
- let className_1: PropTypes.Requireable<string>;
12
- export { className_1 as className };
13
- export let jobs: PropTypes.Validator<(PropTypes.InferProps<{
14
- internalBuildNumber: PropTypes.Requireable<number>;
15
- label: PropTypes.Requireable<string>;
16
- }> | null | undefined)[]>;
17
- export let chunks: PropTypes.Validator<any[]>;
18
- export let items: PropTypes.Validator<(PropTypes.InferProps<{
19
- key: PropTypes.Requireable<string>;
20
- label: PropTypes.Requireable<string>;
21
- runs: PropTypes.Requireable<(PropTypes.InferProps<{
22
- displayValue: PropTypes.Requireable<NonNullable<string | number | null | undefined>>;
23
- displayDelta: PropTypes.Requireable<NonNullable<string | number | null | undefined>>;
24
- }> | null | undefined)[]>;
25
- }> | null | undefined)[]>;
26
- export let updateFilters: PropTypes.Validator<(...args: any[]) => any>;
27
- export let resetFilters: PropTypes.Validator<(...args: any[]) => any>;
28
- export let resetAllFilters: PropTypes.Validator<(...args: any[]) => any>;
29
- let totalRowCount_1: PropTypes.Requireable<number>;
30
- export { totalRowCount_1 as totalRowCount };
31
- export let filters: PropTypes.Validator<NonNullable<PropTypes.InferProps<{
32
- changed: PropTypes.Requireable<boolean>;
33
- id: PropTypes.Requireable<string>;
34
- }>>>;
35
- let entryId_1: PropTypes.Requireable<string>;
36
- export { entryId_1 as entryId };
37
- let hasActiveFilters_1: PropTypes.Requireable<boolean>;
38
- export { hasActiveFilters_1 as hasActiveFilters };
39
- export let search: PropTypes.Validator<string>;
40
- export let updateSearch: PropTypes.Validator<(...args: any[]) => any>;
41
- export let sort: PropTypes.Validator<NonNullable<PropTypes.InferProps<{
42
- field: PropTypes.Requireable<string>;
43
- direction: PropTypes.Requireable<string>;
44
- }>>>;
45
- export let updateSort: PropTypes.Validator<(...args: any[]) => any>;
46
- export let allItems: PropTypes.Validator<(PropTypes.InferProps<{
47
- key: PropTypes.Requireable<string>;
48
- }> | null | undefined)[]>;
49
- export let customComponentLink: PropTypes.Requireable<PropTypes.ReactComponentLike>;
50
- export let hideEntryInfo: PropTypes.Validator<(...args: any[]) => any>;
51
- export let showEntryInfo: PropTypes.Validator<(...args: any[]) => any>;
52
- }
1
+ import type { ElementType } from 'react';
2
+ import React, { ComponentProps } from 'react';
3
+ import type { Job, WebpackChunk } from '@bundle-stats/utils';
4
+ import type { ReportMetricAssetRow, SortAction } from '../../types';
5
+ import { Stack } from '../../layout/stack';
6
+ export interface BundleAssetsProps extends ComponentProps<typeof Stack> {
7
+ jobs: Array<Job>;
8
+ chunks: Array<WebpackChunk>;
9
+ items: Array<ReportMetricAssetRow>;
10
+ allItems: Array<ReportMetricAssetRow>;
11
+ filters: Record<string, boolean>;
12
+ updateFilters: (newFilters: Record<string, boolean>) => void;
13
+ resetFilters: () => void;
14
+ resetAllFilters: () => void;
15
+ totalRowCount?: number;
16
+ entryId?: string;
17
+ sort: SortAction;
18
+ updateSort: (params: SortAction) => void;
19
+ search: string;
20
+ updateSearch: (search: string) => void;
21
+ customComponentLink?: ElementType;
22
+ hideEntryInfo: () => void;
23
+ showEntryInfo: (entryId: string) => void;
53
24
  }
54
- import React from 'react';
55
- import { ComponentLink } from '../component-link';
56
- import PropTypes from 'prop-types';
25
+ export declare const BundleAssets: (props: BundleAssetsProps) => React.JSX.Element;
@@ -1 +1,9 @@
1
1
  export declare const SEARCH_PLACEHOLDER = "Search by asset path";
2
+ export declare const CHANGED = "Changed";
3
+ export declare const FILE_TYPE = "File type";
4
+ export declare const CHUNKS = "Chunks";
5
+ export declare const NO_CHUNK = "No chunk";
6
+ export declare const ENTRY = "Entry";
7
+ export declare const INITIAL = "Initial";
8
+ export declare const CHUNK = "Chunk";
9
+ export declare const OTHER = "Other";
@@ -1,5 +1,17 @@
1
- export function getIsNotPredictive(row: ReportMetricRow): boolean;
2
- export function getAssetMetaStatus(values: any): ReportMetricAssetRowFlagStatus | boolean;
3
- export function addMetricReportAssetRowData(row: ReportMetricRow): ReportMetricAssetRow;
4
- export function getRowFilter(filters: any): (item: any) => boolean;
5
- export function getCustomSort(item: any): any[];
1
+ import type { ReportMetricRow, WebpackChunk } from '@bundle-stats/utils';
2
+ import type { FilterFieldsData, ReportMetricAssetRow, ReportMetricAssetRowMetaStatus } from '../../types';
3
+ export declare const getIsNotPredictive: (row: ReportMetricRow) => boolean;
4
+ export declare const getAssetMetaStatus: (values: Array<boolean | undefined>) => ReportMetricAssetRowMetaStatus | boolean;
5
+ export declare const addMetricReportAssetRowData: (row: ReportMetricRow) => ReportMetricAssetRow;
6
+ type GenerateGetRowFilterOptions = {
7
+ chunkIds: Array<string>;
8
+ };
9
+ export declare const getCustomSort: (item: ReportMetricAssetRow) => Array<boolean | string>;
10
+ type GetFiltersOptions = {
11
+ compareMode: boolean;
12
+ filters: Record<string, boolean>;
13
+ chunks: Array<WebpackChunk>;
14
+ };
15
+ export declare const getFilters: ({ compareMode, filters, chunks, }: GetFiltersOptions) => FilterFieldsData;
16
+ export declare const generateGetRowFilter: ({ chunkIds }: GenerateGetRowFilterOptions) => (filters: Record<string, unknown>) => (item: ReportMetricAssetRow) => boolean;
17
+ export {};
@@ -1,23 +1,11 @@
1
- export function BundleAssets(props: any): React.JSX.Element;
2
- export namespace BundleAssets {
3
- namespace propTypes {
4
- let jobs: PropTypes.Validator<(object | null | undefined)[]>;
5
- let filters: PropTypes.Requireable<object>;
6
- let search: PropTypes.Requireable<string>;
7
- let sortBy: PropTypes.Requireable<string>;
8
- let direction: PropTypes.Requireable<string>;
9
- let setState: PropTypes.Validator<(...args: any[]) => any>;
10
- }
11
- namespace defaultProps {
12
- let filters_1: undefined;
13
- export { filters_1 as filters };
14
- let search_1: undefined;
15
- export { search_1 as search };
16
- let sortBy_1: undefined;
17
- export { sortBy_1 as sortBy };
18
- let direction_1: undefined;
19
- export { direction_1 as direction };
20
- }
21
- }
22
1
  import React from 'react';
23
- import PropTypes from 'prop-types';
2
+ import type { Job } from '@bundle-stats/utils';
3
+ export type BundleAssetsProps = {
4
+ jobs: Array<Job>;
5
+ filters?: Record<string, boolean>;
6
+ search?: string;
7
+ sortBy?: string;
8
+ direction?: string;
9
+ setState: () => void;
10
+ };
11
+ export declare const BundleAssets: (props: BundleAssetsProps) => React.JSX.Element;
@@ -1,6 +1,7 @@
1
1
  import React from 'react';
2
2
  import type { ReportMetricRow } from '@bundle-stats/utils';
3
3
  import { Table } from '../../ui/table';
4
+ import { MetricsTableHeaderProps } from '../metrics-table-header';
4
5
  interface MetricsTableProps extends Omit<React.ComponentProps<typeof Table>, 'title'> {
5
6
  runs: Array<{
6
7
  label: string;
@@ -9,8 +10,8 @@ interface MetricsTableProps extends Omit<React.ComponentProps<typeof Table>, 'ti
9
10
  items: Array<ReportMetricRow>;
10
11
  title?: React.ReactNode;
11
12
  showHeaderSum?: boolean;
12
- sort?: any;
13
- updateSort?: (val: any) => void;
13
+ sort?: MetricsTableHeaderProps['sort'];
14
+ updateSort?: MetricsTableHeaderProps['updateSort'];
14
15
  renderRowHeader?: (item: ReportMetricRow) => React.ReactNode;
15
16
  emptyMessage?: React.ReactNode;
16
17
  showAllItems: boolean;
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import { type ReportMetricRow } from '@bundle-stats/utils';
3
- interface MetricsTableHeaderProps {
3
+ export interface MetricsTableHeaderProps {
4
4
  metricTitle?: React.ReactNode;
5
5
  showSum?: boolean;
6
6
  jobs: Array<{
@@ -12,4 +12,3 @@ interface MetricsTableHeaderProps {
12
12
  updateSort?: (val: any) => void;
13
13
  }
14
14
  export declare const MetricsTableHeader: (props: MetricsTableHeaderProps & React.ComponentProps<"thead">) => React.JSX.Element;
15
- export {};
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import type { SortAction } from '../../types';
3
- interface SortButtonProps {
3
+ export interface SortButtonProps {
4
4
  fieldPath: string;
5
5
  fieldName: string;
6
6
  label: string;
@@ -8,4 +8,3 @@ interface SortButtonProps {
8
8
  updateSort?: (params: SortAction) => void;
9
9
  }
10
10
  export declare const SortButton: (props: SortButtonProps & React.ComponentProps<"div">) => React.JSX.Element;
11
- export {};
@@ -3,7 +3,7 @@ export declare const getSortFn: <TRow>(fieldPath: string, getCustomSort: UseRows
3
3
  interface UseRowsSortParams<TRow> {
4
4
  rows: Array<TRow>;
5
5
  initialField?: string;
6
- initialDirection?: SortAction['direction'];
6
+ initialDirection?: string;
7
7
  getCustomSort: (item: any) => Array<string | number | boolean>;
8
8
  setQueryState: (queryParams: {
9
9
  sortBy: SortAction['field'];
@@ -1,149 +0,0 @@
1
- /**
2
- * @type {import('@bundle-stats/utils').ReportMetricRow} ReportMetricRow
3
- * @type {import('../../types').ReportMetricAssetRow} ReportMetricAssetRow
4
- * @type {import('../../types').ReportMetricAssetRowMetaStatus} ReportMetricAssetRowFlagStatus
5
- */
6
-
7
- import { ASSET_ENTRY_TYPE, ASSET_FILE_TYPE, ASSET_FILTERS, getFileType } from '@bundle-stats/utils';
8
-
9
- /**
10
- * Check if the asset cache is not predictive
11
- *
12
- * @param {ReportMetricRow} row
13
- * @returns {boolean}
14
- */
15
- export const getIsNotPredictive = (row) => {
16
- const { key, runs } = row;
17
-
18
- return runs.reduce((agg, current, index) => {
19
- if (agg) {
20
- return agg;
21
- }
22
-
23
- if (index + 1 === runs.length) {
24
- return agg;
25
- }
26
-
27
- if (
28
- current &&
29
- runs[index + 1] &&
30
- key !== current.name &&
31
- current.name === runs[index + 1].name &&
32
- current.value !== runs[index + 1].value
33
- ) {
34
- return true;
35
- }
36
-
37
- return agg;
38
- }, false);
39
- };
40
-
41
- /**
42
- * @param {Array<boolean>}
43
- * @returns {ReportMetricAssetRowFlagStatus | boolean}
44
- */
45
- export const getAssetMetaStatus = (values) => {
46
- if (!values.includes(true)) {
47
- return false;
48
- }
49
-
50
- // filter empty runs
51
- const metaValues = values.filter((value) => typeof value !== 'undefined');
52
-
53
- const current = metaValues[0];
54
- const metaValuesLength = metaValues.length;
55
-
56
- if (metaValuesLength === 1) {
57
- return Boolean(current);
58
- }
59
-
60
- const baseline = metaValues[metaValuesLength - 1];
61
-
62
- if (current && !baseline) {
63
- return 'added';
64
- }
65
-
66
- if (!current && baseline) {
67
- return 'removed';
68
- }
69
-
70
- return true;
71
- };
72
-
73
- /**
74
- * Add asset row flags
75
- *
76
- * @param {ReportMetricRow} row
77
- * @returns {ReportMetricAssetRow}
78
- */
79
- export const addMetricReportAssetRowData = (row) => {
80
- const { changed, runs } = row;
81
-
82
- // Collect meta for each run
83
- const runsEntry = [];
84
- const runsInitial = [];
85
- const runsChunk = [];
86
-
87
- runs.forEach((run) => {
88
- runsEntry.push(run?.isEntry);
89
- runsInitial.push(run?.isInitial);
90
- runsChunk.push(run?.isChunk);
91
- });
92
-
93
- const isEntry = getAssetMetaStatus(runsEntry);
94
- const isInitial = getAssetMetaStatus(runsInitial);
95
- const isChunk = getAssetMetaStatus(runsChunk);
96
- const isAsset = !(isEntry || isInitial || isChunk);
97
- const isNotPredictive = getIsNotPredictive(row);
98
- const fileType = getFileType(row.key);
99
-
100
- // Flag asset as changed if name and value are identical, if one of the meta tags is changed
101
- const assetChanged =
102
- changed ||
103
- typeof isEntry !== 'boolean' ||
104
- typeof isInitial !== 'boolean' ||
105
- typeof isChunk !== 'boolean';
106
-
107
- return {
108
- ...row,
109
- changed: assetChanged,
110
- isEntry,
111
- isInitial,
112
- isChunk,
113
- isAsset,
114
- isNotPredictive,
115
- fileType,
116
- };
117
- };
118
-
119
- export const getRowFilter = (filters) => (item) => {
120
- if (filters[ASSET_FILTERS.CHANGED] && !item.changed) {
121
- return false;
122
- }
123
-
124
- if (
125
- !(
126
- (filters[`${ASSET_ENTRY_TYPE}.${ASSET_FILTERS.ENTRY}`] && item.isEntry) ||
127
- (filters[`${ASSET_ENTRY_TYPE}.${ASSET_FILTERS.INITIAL}`] && item.isInitial) ||
128
- (filters[`${ASSET_ENTRY_TYPE}.${ASSET_FILTERS.CHUNK}`] && item.isChunk) ||
129
- (filters[`${ASSET_ENTRY_TYPE}.${ASSET_FILTERS.OTHER}`] && item.isAsset)
130
- )
131
- ) {
132
- return false;
133
- }
134
-
135
- if (!filters[`${ASSET_FILE_TYPE}.${item.fileType}`]) {
136
- return false;
137
- }
138
-
139
- return true;
140
- };
141
-
142
- export const getCustomSort = (item) => [
143
- !item.isNotPredictive,
144
- !item.changed,
145
- !item.isInitial,
146
- !item.isEntry,
147
- !item.isChunk,
148
- item.key,
149
- ];