Skip to content

Commit

Permalink
enhance(ui): MetricsTreemap - improve group title click
Browse files Browse the repository at this point in the history
- add hover state
- toggle search
  • Loading branch information
vio committed May 18, 2024
1 parent 68aefe4 commit da248ef
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 31 deletions.
44 changes: 32 additions & 12 deletions packages/ui/src/components/bundle-assets/bundle-assets.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ const DISPLAY_TYPE_GROUPS = {

const getFileTypeFilters = (filters) =>
Object.entries(FILE_TYPE_LABELS).map(([key, label]) => ({
key,
label,
defaultValue: get(filters, `${ASSET_FILE_TYPE}.${key}`, true),
}));
key,
label,
defaultValue: get(filters, `${ASSET_FILE_TYPE}.${key}`, true),
}));

const getFilters = ({ compareMode, filters }) => ({
[ASSET_FILTERS.CHANGED]: {
Expand Down Expand Up @@ -163,9 +163,18 @@ RowHeader.defaultProps = {
};

const ViewMetricsTreemap = (props) => {
const { metricsTableTitle, jobs, items, displayType, emptyMessage, showEntryInfo, updateSearch } =
props;
const {
metricsTableTitle,
jobs,
items,
displayType,
emptyMessage,
showEntryInfo,
updateSearch,
search,
} = props;

// Get treenodes based on group
const treeNodes = useMemo(() => {
if (displayType.groupBy === 'folder') {
return getTreemapNodesGroupedByPath(items);
Expand All @@ -174,19 +183,28 @@ const ViewMetricsTreemap = (props) => {
return getTreemapNodes(items);
}, [items, displayType.groupBy]);

// Search based on the group path on group title click
const onGroupClick = useCallback(
(groupPath) => {
// Clear seach when groupPath is emty (root)
if (groupPath === '') {
updateSearch('');
return;
}
// Search by group path
// 1. use `^` to match only the string beggining
// 2. add `/` suffix to match only exact directories
// 3. if the group path is empty(root), clear search
if (groupPath) {
updateSearch(`^${groupPath}/`);
} else {
// 2. add `/` suffix to exactly match the directory
const newSearch = `^${groupPath}/`;

// Reset search when toggling the same groupPath
if (newSearch === search) {
updateSearch('');
return;
}

updateSearch(`^${groupPath}/`);
},
[updateSearch],
[updateSearch, search],
);

return (
Expand Down Expand Up @@ -215,6 +233,7 @@ ViewMetricsTreemap.propTypes = {
emptyMessage: PropTypes.node.isRequired,
showEntryInfo: PropTypes.func.isRequired,
updateSearch: PropTypes.func.isRequired,
search: PropTypes.string.isRequired,
};

export const BundleAssets = (props) => {
Expand Down Expand Up @@ -348,6 +367,7 @@ export const BundleAssets = (props) => {
emptyMessage={emptyMessage}
showEntryInfo={showEntryInfo}
updateSearch={updateSearch}
search={search}
/>
)}
</Box>
Expand Down
36 changes: 28 additions & 8 deletions packages/ui/src/components/bundle-modules/bundle-modules.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,22 @@ interface ViewMetricsTreemapProps {
emptyMessage: React.ReactNode;
showEntryInfo: React.ComponentProps<typeof MetricsTreemap>['onItemClick'];
updateSearch: (newSerarch: string) => void;
search: string;
}

const ViewMetricsTreemap = (props: ViewMetricsTreemapProps) => {
const { metricsTableTitle, jobs, items, displayType, emptyMessage, showEntryInfo, updateSearch } =
props;
const {
metricsTableTitle,
jobs,
items,
displayType,
emptyMessage,
showEntryInfo,
updateSearch,
search,
} = props;

// Get treenodes based on group
const treeNodes = useMemo(() => {
if (displayType.groupBy === 'folder') {
return getTreemapNodesGroupedByPath(items);
Expand All @@ -88,19 +98,28 @@ const ViewMetricsTreemap = (props: ViewMetricsTreemapProps) => {
return getTreemapNodes(items);
}, [items, displayType]);

// Search based on the group path on group title click
const onGroupClick = useCallback(
(groupPath: string) => {
// Clear seach when groupPath is emty (root)
if (groupPath === '') {
updateSearch('');
return;
}
// Search by group path
// 1. use `^` to match only the string beggining
// 2. add `/` suffix to match only exact directories
// 3. if the group path is empty(root), clear search
if (groupPath) {
updateSearch(`^${groupPath}/`);
} else {
// 2. add `/` suffix to exactly match the directory
const newSearch = `^${groupPath}/`;

// Reset search when toggling the same groupPath
if (newSearch === search) {
updateSearch('');
return;
}

updateSearch(newSearch);
},
[updateSearch],
[updateSearch, search],
);

return (
Expand Down Expand Up @@ -306,6 +325,7 @@ export const BundleModules = (props: BundleModulesProps) => {
emptyMessage={emptyMessage}
showEntryInfo={showEntryInfo}
updateSearch={updateSearch}
search={search}
/>
)}
</Box>
Expand Down
26 changes: 19 additions & 7 deletions packages/ui/src/components/bundle-packages/bundle-packages.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,9 @@ RowHeader.propTypes = {
};

const ViewMetricsTreemap = (props) => {
const { metricsTableTitle, jobs, items, displayType, emptyMessage, showEntryInfo, updateSearch } = props;
const { metricsTableTitle, jobs, items, displayType, emptyMessage, showEntryInfo, updateSearch, search } = props;

// Get treenodes based on group
const treeNodes = useMemo(() => {
if (displayType.groupBy === 'folder') {
return getTreemapNodesGroupedByPath(items);
Expand All @@ -130,19 +131,28 @@ const ViewMetricsTreemap = (props) => {
return getTreemapNodes(items);
}, [items, displayType.groupBy]);

// Search based on the group path on group title click
const onGroupClick = useCallback(
(groupPath) => {
// Clear seach when groupPath is emty (root)
if (groupPath === '') {
updateSearch('');
return;
}
// Search by group path
// 1. use `^` to match only the string beggining
// 2. add `/` suffix to match only exact directories
// 3. if the group path is empty(root), clear search
if (groupPath) {
updateSearch(`^${groupPath}/`);
} else {
// 2. add `/` suffix to exactly match the directory
const newSearch = `^${groupPath}/`;

// Reset search when toggling the same groupPath
if (newSearch === search) {
updateSearch('');
return;
}

updateSearch(newSearch);
},
[updateSearch],
[updateSearch, search],
);

return (
Expand Down Expand Up @@ -171,6 +181,7 @@ ViewMetricsTreemap.propTypes = {
emptyMessage: PropTypes.node.isRequired,
showEntryInfo: PropTypes.func.isRequired,
updateSearch: PropTypes.func.isRequired,
search: PropTypes.string.isRequired,
};

export const BundlePackages = (props) => {
Expand Down Expand Up @@ -300,6 +311,7 @@ export const BundlePackages = (props) => {
emptyMessage={emptyMessage}
showEntryInfo={showEntryInfo}
updateSearch={updateSearch}
search={search}
/>
)}
</Box>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@
}

.tileGroupTitle {
position: relative;
width: 100%;
padding: 4px 2px 4px var(--space-xxsmall);
padding: var(--space-xxxsmall) 1px var(--space-xxxsmall) var(--space-xxsmall);
color: var(--color-text);
font-family: var(--font-family-fixed);
font-size: 10px;
Expand All @@ -36,7 +37,17 @@
}

.tileGroupTitleTotal {
margin-left: var(--space-xxxsmall);
margin-left: var(--space-xxsmall);
color: var(--color-text-light);
}

.tileGroupTitle {
transition: var(--ui-transition-out);
}

.tileGroupTitle:hover .tileGroupTitleText {
text-decoration: underline;
transition: var(--ui-transition-in);
}

/** Tile group size variation */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,9 @@ const TileGroup = (props: TileGroupProps) => {
style={{ left, top, width, height }}
className={rootClassName}
>
<div className={css.tileGroupTitle}>{title}</div>
<div className={css.tileGroupTitle}>
<span className={css.tileGroupTitleText}>{title}</span>
</div>
</div>
);
}
Expand All @@ -365,7 +367,7 @@ const TileGroup = (props: TileGroupProps) => {
>
{title && (
<div className={css.tileGroupTitle}>
{title}
<span className={css.tileGroupTitleText}>{title}</span>
{metricRunInfo && (
<span className={css.tileGroupTitleTotal}>
{`${metricRunInfo.displayValue}`}
Expand Down

0 comments on commit da248ef

Please sign in to comment.