Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ui): BundleAssets - add "No chunk" filter #4850

Merged
merged 1 commit into from
Nov 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions packages/ui/src/components/bundle-assets/bundle-assets.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import type {
FilterGroupFieldData,
} from '../../types';

const NO_CHUNK_FILTER = 'NO_CHUNK';

/**
* Check if the asset cache is not predictive
*/
Expand Down Expand Up @@ -166,7 +168,17 @@ export const getFilters = ({
};

if (!isEmpty(chunks)) {
const chunksFilter: FilterGroupFieldData = { label: 'Chunks', children: [] };
const chunksFilter: FilterGroupFieldData = {
label: 'Chunks',
children: [
{
key: NO_CHUNK_FILTER,
label: 'No chunk',
defaultValue: filters[`${ASSET_CHUNK}.${NO_CHUNK_FILTER}`] ?? true,
},
],
};

const chunksOrderedByName = orderBy(chunks, 'name');

chunksOrderedByName.forEach((chunk) => {
Expand Down Expand Up @@ -219,15 +231,17 @@ export const generateGetRowFilter =
({ chunkIds }: GenerateGetRowFilterOptions) => (filters: Record<string, unknown>) => {
// List of chunkIds with filter value set to `true`
const checkedChunkIds: Array<string> = [];
// List of chunks ids, including the NO_CHUNK
const filtersChunkIds = [NO_CHUNK_FILTER, ...chunkIds];

chunkIds.forEach((chunkId) => {
filtersChunkIds.forEach((chunkId) => {
if (filters[`${ASSET_CHUNK}.${chunkId}`]) {
checkedChunkIds.push(chunkId);
}
});

const hasChunkFilters =
checkedChunkIds.length > 0 && checkedChunkIds.length !== chunkIds.length;
checkedChunkIds.length > 0 && checkedChunkIds.length !== filtersChunkIds.length;

return (item: ReportMetricAssetRow) => {
if (filters[ASSET_FILTERS.CHANGED] && !item.changed) {
Expand All @@ -251,7 +265,7 @@ export const generateGetRowFilter =

// Filter if any of the chunkIds are checked
if (hasChunkFilters) {
const rowRunsChunkIds = item?.runs?.map((run) => run?.chunkId) || [];
const rowRunsChunkIds = item?.runs?.map((run) => run?.chunkId || NO_CHUNK_FILTER) || [];
return intersection(rowRunsChunkIds, checkedChunkIds).length > 0;
}

Expand Down