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: show empty chart when we're loading flag metrics #8419

Merged
merged 3 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
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
3 changes: 1 addition & 2 deletions frontend/src/component/personalDashboard/ConnectSDK.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ export const ExistingFlag: FC<{ project: string }> = ({ project }) => {
export const ConnectSDK: FC<{ project: string }> = ({ project }) => {
return (
<ActionBox data-loading>
{' '}
<TitleContainer>
<NeutralCircleContainer>2</NeutralCircleContainer>
Connect an SDK
Expand All @@ -104,7 +103,7 @@ export const ConnectSDK: FC<{ project: string }> = ({ project }) => {
</p>
</div>
<div>
<Button href={`projects/${project}`} variant='contained'>
<Button href={`/projects/${project}`} variant='contained'>
Go to project
</Button>
</div>
Expand Down
39 changes: 35 additions & 4 deletions frontend/src/component/personalDashboard/FlagMetricsChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,31 @@ export const PlaceholderFlagMetricsChart: React.FC<{ label?: string }> = ({
);
};

export const EmptyFlagMetricsChart = () => {
const theme = useTheme();

const options = useMemo(() => {
return createPlaceholderBarChartOptions(theme);
}, [theme]);

const data = useMemo(() => {
return {
labels: [],
datasets: [],
};
}, [theme]);

return (
<ChartWrapper>
<Bar
data={data}
options={options}
aria-label='A placeholder bar chart with a single feature flag exposure metrics'
/>
</ChartWrapper>
);
};

const useMetricsEnvironments = (project: string, flagName: string) => {
const [environment, setEnvironment] = useState<string | null>(null);
const { feature } = useFeature(project, flagName);
Expand Down Expand Up @@ -96,7 +121,7 @@ const useFlagMetrics = (
environment: string | null,
hoursBack: number,
) => {
const { featureMetrics: metrics = [] } = useFeatureMetricsRaw(
const { featureMetrics: metrics = [], loading } = useFeatureMetricsRaw(
flagName,
hoursBack,
);
Expand Down Expand Up @@ -126,7 +151,7 @@ const useFlagMetrics = (
return createBarChartOptions(theme, hoursBack, locationSettings);
}, [theme, hoursBack, locationSettings]);

return { data, options };
return { data, options, loading };
};

const EnvironmentSelect: FC<{
Expand Down Expand Up @@ -183,7 +208,11 @@ export const FlagMetricsChart: FC<{
const { environment, setEnvironment, activeEnvironments } =
useMetricsEnvironments(flag.project, flag.name);

const { data, options } = useFlagMetrics(flag.name, environment, hoursBack);
const { data, options, loading } = useFlagMetrics(
flag.name,
environment,
hoursBack,
);

const noData = data.datasets[0].data.length === 0;

Expand All @@ -210,7 +239,9 @@ export const FlagMetricsChart: FC<{
</MetricsSelectors>
</ExposureAndMetricsRow>

{noData ? (
{loading ? (
<EmptyFlagMetricsChart />
) : noData ? (
<PlaceholderFlagMetricsChart />
) : (
<ChartWrapper>
Expand Down