Skip to content

Commit

Permalink
Generalize SKU specific verbiage
Browse files Browse the repository at this point in the history
  • Loading branch information
brendasukh committed Dec 2, 2020
1 parent 21f7d80 commit ff83308
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function createRenderer(col: keyof RowData, classes: Record<string, string>) {
const row = rowData as RowData;
const rowStyles = classnames(classes.row, {
[classes.rowTotal]: row.id === 'total',
[classes.colFirst]: col === 'sku',
[classes.colFirst]: col === 'label',
[classes.colLast]: col === 'ratio',
});

Expand All @@ -50,7 +50,7 @@ function createRenderer(col: keyof RowData, classes: Record<string, string>) {
/>
);
default:
return <Typography className={rowStyles}>{row.sku}</Typography>;
return <Typography className={rowStyles}>{row.label}</Typography>;
}
};
}
Expand All @@ -63,7 +63,7 @@ function createSorter(field?: keyof Omit<RowData, 'id'>) {
const b = data2 as RowData;
if (a.id === 'total') return 1;
if (b.id === 'total') return 1;
if (field === 'sku') return a.sku.localeCompare(b.sku);
if (field === 'label') return a.label.localeCompare(b.label);

return field
? a[field] - b[field]
Expand All @@ -80,7 +80,7 @@ const defaultEntity: Entity = {

type RowData = {
id: string;
sku: string;
label: string;
previous: number;
current: number;
ratio: number;
Expand Down Expand Up @@ -118,10 +118,12 @@ export const ProductEntityDialog = ({

const columns: TableColumn[] = [
{
field: 'sku',
title: <Typography className={firstColClasses}>SKU</Typography>,
render: createRenderer('sku', classes),
customSort: createSorter('sku'),
field: 'label',
title: (
<Typography className={firstColClasses}>{entitiesLabel}</Typography>
),
render: createRenderer('label', classes),
customSort: createSorter('label'),
width: '33.33%',
},
{
Expand Down Expand Up @@ -154,14 +156,14 @@ export const ProductEntityDialog = ({
const rowData: RowData[] = entity.entities
.map(e => ({
id: e.id || 'Unknown',
sku: e.id || 'Unknown',
label: e.id || 'Unknown',
previous: e.aggregation[0],
current: e.aggregation[1],
ratio: e.change.ratio,
}))
.concat({
id: 'total',
sku: 'Total',
label: 'Total',
previous: entity.aggregation[0],
current: entity.aggregation[1],
ratio: entity.change.ratio,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ export const ProductInsightsChart = ({
const [selectLabel, setSelected] = useState<Maybe<string>>();
const isSelected = useMemo(() => !isUndefined(selectLabel), [selectLabel]);
const isClickable = useMemo(() => {
const skus =
const breakdownEntities =
entity.entities.find(e => e.id === activeLabel)?.entities ?? [];
return skus.length > 0;
return breakdownEntities.length > 0;
}, [entity, activeLabel]);

const legendTitle = `Cost ${entity.change.ratio <= 0 ? 'Savings' : 'Growth'}`;
Expand Down Expand Up @@ -122,10 +122,13 @@ export const ProductInsightsChart = ({

const activeEntity = findAlways(entity.entities, e => e.id === id);
const ratio = activeEntity.change.ratio;
const skus = activeEntity.entities;
const subtitle = `${skus.length} ${pluralOf(skus.length, 'SKU')}`;
const breakdownEntities = activeEntity.entities;
const subtitle = `${breakdownEntities.length} ${pluralOf(
breakdownEntities.length,
entity.entitiesLabel || 'SKU',
)}`;

if (skus.length) {
if (breakdownEntities.length) {
return (
<BarChartTooltip
title={title}
Expand All @@ -151,7 +154,7 @@ export const ProductInsightsChart = ({
);
}

// If an entity doesn't have any skus, there aren't any costs to break down.
// If an entity doesn't have any sub-entities, there aren't any costs to break down.
return (
<BarChartTooltip
title={title}
Expand Down

0 comments on commit ff83308

Please sign in to comment.