Skip to content

Commit

Permalink
Added skeleton loading state for data consumption and object data red…
Browse files Browse the repository at this point in the history
…uction card

Signed-off-by: Afreen Rahman <afrahman@redhat.com>
  • Loading branch information
Afreen Rahman committed May 18, 2020
1 parent fda6322 commit d004c69
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,14 @@
.nb-data-consumption-card__chart-label {
margin-top: var(--pf-global--spacer--md);
}

.nb-data-consumption-card__chart-skeleton {
margin-top: var(--pf-global--spacer--md);
margin-bottom: var(--pf-global--spacer--md);
width: 50%;
}

.nb-data-consumption-card__chart-legend-skeleton {
margin-top: var(--pf-global--spacer--md);
width: 80%;
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const DataConsumptionCard: React.FC<DashboardItemProps> = ({
let suffixLabel = '';
let maxVal: number;
let maxUnit: string;
let body: React.ReactNode;

const isLoading = _.values(result).includes(undefined);

Expand All @@ -81,6 +82,73 @@ const DataConsumptionCard: React.FC<DashboardItemProps> = ({
if (suffixLabel) suffixLabel = `(in ${suffixLabel})`;
}

if (isLoading) {
body = (
<>
<div className="skeleton-text nb-data-consumption-card__chart-skeleton" />
<GraphEmpty height={200} loading />
<div className="skeleton-text nb-data-consumption-card__chart-legend-skeleton" />
</>
);
} else if (!error && !chartData.some(_.isEmpty)) {
body = (
<>
<div className="nb-data-consumption-card__chart-label text-secondary">
{CHART_LABELS[sortByKpi]} {suffixLabel}
</div>
<Chart
containerComponent={
<ChartVoronoiContainer
labelComponent={<ChartTooltip style={{ fontSize: 8, paddingBottom: 0 }} />}
labels={({ datum }) => `${datum.y} ${maxUnit}`}
voronoiDimension="x"
/>
}
minDomain={{ y: 0 }}
maxDomain={{ y: maxVal + Math.round(maxVal * 0.25) }}
domainPadding={{ x: [padding, padding] }}
legendComponent={
<ChartLegend
themeColor={ChartThemeColor.purple}
data={legendData}
orientation="horizontal"
symbolSpacer={5}
gutter={2}
height={30}
padding={{ top: 50, bottom: 0 }}
style={{ labels: { fontSize: 8 } }}
/>
}
legendPosition="bottom-left"
padding={{
bottom: 50,
left: 30,
right: 20,
top: 30,
}}
themeColor={ChartThemeColor.purple}
>
<ChartAxis style={{ tickLabels: { fontSize: 8, padding: 2 } }} />
<ChartAxis
dependentAxis
showGrid
tickCount={10}
style={{
tickLabels: { fontSize: 8, padding: 0 },
}}
/>
<ChartGroup offset={sortByKpi === BY_EGRESS ? 0 : 11}>
{chartData.map((data, i) => (
<ChartBar key={`chartbar-${i}`} data={data} /> // eslint-disable-line react/no-array-index-key
))}
</ChartGroup>
</Chart>
</>
);
} else {
body = <GraphEmpty />;
}

return (
<DashboardCard>
<DashboardCardHeader>
Expand All @@ -92,64 +160,7 @@ const DataConsumptionCard: React.FC<DashboardItemProps> = ({
setKpi={setsortByKpi}
/>
</DashboardCardHeader>
<DashboardCardBody className="co-dashboard-card__body--top-margin" isLoading={isLoading}>
{!error && !chartData.some(_.isEmpty) ? (
<>
<div className="nb-data-consumption-card__chart-label text-secondary">
{CHART_LABELS[sortByKpi]} {suffixLabel}
</div>
<Chart
containerComponent={
<ChartVoronoiContainer
labelComponent={<ChartTooltip style={{ fontSize: 8, paddingBottom: 0 }} />}
labels={({ datum }) => `${datum.y} ${maxUnit}`}
voronoiDimension="x"
/>
}
minDomain={{ y: 0 }}
maxDomain={{ y: maxVal + 10 }}
domainPadding={{ x: [padding, padding] }}
legendComponent={
<ChartLegend
themeColor={ChartThemeColor.purple}
data={legendData}
orientation="horizontal"
symbolSpacer={5}
gutter={2}
height={30}
padding={{ top: 50, bottom: 0 }}
style={{ labels: { fontSize: 8 } }}
/>
}
legendPosition="bottom-left"
padding={{
bottom: 50,
left: 30,
right: 20,
top: 30,
}}
themeColor={ChartThemeColor.purple}
>
<ChartAxis style={{ tickLabels: { fontSize: 8, padding: 2 } }} />
<ChartAxis
dependentAxis
showGrid
tickCount={10}
style={{
tickLabels: { fontSize: 8, padding: 0 },
}}
/>
<ChartGroup offset={sortByKpi === BY_EGRESS ? 0 : 11}>
{chartData.map((data, i) => (
<ChartBar key={i} data={data} /> // eslint-disable-line react/no-array-index-key
))}
</ChartGroup>
</Chart>
</>
) : (
<GraphEmpty />
)}
</DashboardCardBody>
<DashboardCardBody className="co-dashboard-card__body--top-margin">{body}</DashboardCardBody>
</DashboardCard>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@ import {
FieldLevelHelp,
humanizeBinaryBytes,
humanizePercentage,
LoadingInline,
} from '@console/internal/components/utils';

const ItemBody: React.FC<ItemBodyProps> = React.memo(
({ title, stats, infoText, isLoading, error }) => {
let status: React.ReactElement;
if (error || !stats) {
if (isLoading) {
status = <div className="skeleton-text nb-object-data-reduction__item-body--loading" />;
} else if (error || !stats) {
status = <span className="co-dashboard-text--small text-muted">Not available</span>;
} else if (isLoading) {
status = <LoadingInline />;
} else {
status = <span className="nb-object-data-reduction-card__row-status-item-text">{stats}</span>;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@
.nb-object-data-reduction-card__row-title {
margin-right: 0.5em;
}

.nb-object-data-reduction__item-body--loading {
width: 9rem;
}

0 comments on commit d004c69

Please sign in to comment.