address comments from coderabbit.

This commit is contained in:
Darshan
2025-10-06 19:59:29 +05:30
parent df7f405397
commit 7cb4a5a836
4 changed files with 35 additions and 14 deletions
+4 -4
View File
@@ -256,24 +256,24 @@ function seededRandom(seed: number) {
return x - Math.floor(x);
}
const BASE_TIME_MS = Date.now();
export function generateFakeBarChartData(seed = 1) {
const fakeData: [number, number][] = [];
const now = Date.now();
for (let i = 23; i >= 0; i--) {
const val = seededRandom(seed + i) * 1_000_000;
fakeData.push([now - i * 60 * 60 * 1000, Math.round(val)]);
fakeData.push([BASE_TIME_MS - i * 60 * 60 * 1000, Math.round(val)]);
}
return fakeData;
}
export function generateFakeLineChartData(seed = 2) {
const fakeData: [number, number][] = [];
const now = Date.now();
let value = seededRandom(seed) * 5000 + 5000;
for (let i = 23; i >= 0; i--) {
value += (seededRandom(seed + i) - 0.5) * 1000;
value = Math.max(0, value);
fakeData.push([now - i * 60 * 60 * 1000, Math.round(value)]);
fakeData.push([BASE_TIME_MS - i * 60 * 60 * 1000, Math.round(value)]);
}
return fakeData;
}
@@ -83,15 +83,24 @@
<ActionMenu.Root width="fit-content" slot="tooltip" let:toggle>
<ActionMenu.Item.Button
on:click={(event) => toggle(event) && dispatch('change', '24h')}>
on:click={(event) => {
toggle(event);
dispatch('change', '24h');
}}>
24h
</ActionMenu.Item.Button>
<ActionMenu.Item.Button
on:click={(event) => toggle(event) && dispatch('change', '30d')}>
on:click={(event) => {
toggle(event);
dispatch('change', '30d');
}}>
30d
</ActionMenu.Item.Button>
<ActionMenu.Item.Button
on:click={(event) => toggle(event) && dispatch('change', '90d')}>
on:click={(event) => {
toggle(event);
dispatch('change', '90d');
}}>
90d
</ActionMenu.Item.Button>
</ActionMenu.Root>
@@ -84,14 +84,20 @@
<ActionMenu.Root width="fit-content" slot="tooltip" let:toggle>
<ActionMenu.Item.Button
on:click={(event) => toggle(event) && dispatch('change', '24h')}
>24h</ActionMenu.Item.Button>
on:click={(event) => {
toggle(event);
dispatch('change', '24h');
}}>24h</ActionMenu.Item.Button>
<ActionMenu.Item.Button
on:click={(event) => toggle(event) && dispatch('change', '30d')}
>30d</ActionMenu.Item.Button>
on:click={(event) => {
toggle(event);
dispatch('change', '30d');
}}>30d</ActionMenu.Item.Button>
<ActionMenu.Item.Button
on:click={(event) => toggle(event) && dispatch('change', '90d')}
>90d</ActionMenu.Item.Button>
on:click={(event) => {
toggle(event);
dispatch('change', '90d');
}}>90d</ActionMenu.Item.Button>
</ActionMenu.Root>
</Popover>
</Layout.Stack>
@@ -22,7 +22,13 @@ export const usage = cachedStore<
return {
load: async (start, end, period) => {
const currentData = get(usage);
const currentParamsHash = hash([page.params.project, start, end, period.toString()]);
const currentParamsHash = hash([
page.params.project,
page.params.region,
start,
end,
period.toString()
]);
// don't hit the API call if we have the data!
if (lastParamsHash === currentParamsHash && currentData && !isDev) {