Skip to content

Commit

Permalink
HOSTSD-295 Fix dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
Fosol committed Mar 22, 2024
1 parent c889d85 commit 571c83e
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 96 deletions.
154 changes: 64 additions & 90 deletions src/dashboard/src/components/dashboard/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,42 @@ export const Dashboard = () => {
values.tenant,
]);

const handleExport = React.useCallback(
async (filter: {
search?: string;
tenantId?: number;
organizationId?: number;
organizationName?: string;
operatingSystemItemId?: number;
serviceNowKey?: string;
startDate?: string;
endDate?: string;
}) => {
const toastLoading = toast.loading('Generating Excel document...');
try {
await download({
search: filter.search,
tenantId: filter.tenantId,
organizationId: filter.organizationId,
organizationName: filter.organizationName,
operatingSystemItemId: filter.operatingSystemItemId,
serviceNowKey: filter.serviceNowKey,
startDate: filter.startDate,
endDate: filter.endDate,
});
toast.dismiss(toastLoading);
toast.success('Excel document has been downloaded successfully.');
} catch (ex) {
toast.dismiss(toastLoading);

const error = ex as Error;
toast.error('Failed to download data. ' + error.message);
console.error(error);
}
},
[download],
);

return (
<>
<Breadcrumbs multipleOrganizations={organizations.length > 1} />
Expand Down Expand Up @@ -204,23 +240,11 @@ export const Dashboard = () => {
}
}}
showExport
onExport={async () => {
const toastLoading = toast.loading('Generating Excel document...');

try {
await download({
tenantId: dashboardTenant?.id,
organizationId: dashboardOrganization?.id,
});
toast.dismiss(toastLoading);
toast.success('Excel document has been downloaded successfully.');
} catch (ex) {
toast.dismiss(toastLoading);

const error = ex as Error;
toast.error('Failed to download data. ' + error.message);
console.error(error);
}
onExport={() => {
handleExport({
tenantId: dashboardTenant?.id,
organizationId: dashboardOrganization?.id,
});
}}
/>
)}
Expand All @@ -235,50 +259,24 @@ export const Dashboard = () => {
serverItems={dashboardServerItems}
loading={!isReadyOrganizations || !isReadyServerItems}
showExport
onExport={async () => {
const toastLoading = toast.loading('Generating Excel document...');

try {
await download({
tenantId: dashboardTenant?.id,
});
toast.dismiss(toastLoading);
toast.success('Excel document has been downloaded successfully.');
} catch (ex) {
toast.dismiss(toastLoading);

const error = ex as Error;
toast.error('Failed to download data. ' + error.message);
console.error(error);
}
onExport={() => {
handleExport({ tenantId: dashboardTenant?.id });
}}
/>
)}
<StorageTrendsChart
large={!!dashboardOrganization || !!dashboardOperatingSystemItem || !!dashboardServerItem}
serverItems={dashboardServerItem ? [dashboardServerItem] : dashboardServerItems}
showExport
onExport={async (startDate, endDate) => {
const toastLoading = toast.loading('Generating Excel document...');

try {
await downloadHistory({
tenantId: dashboardTenant?.id,
organizationId: dashboardOrganization?.id,
operatingSystemItemId: dashboardOperatingSystemItem?.id,
serviceNowKey: dashboardServerItem?.serviceNowKey,
startDate: startDate,
endDate: endDate,
});
toast.dismiss(toastLoading);
toast.success('Excel document has been downloaded successfully.');
} catch (ex) {
toast.dismiss(toastLoading);

const error = ex as Error;
toast.error('Failed to download data. ' + error.message);
console.error(error);
}
onExport={(startDate, endDate) => {
handleExport({
tenantId: dashboardTenant?.id,
organizationId: dashboardOrganization?.id,
operatingSystemItemId: dashboardOperatingSystemItem?.id,
serviceNowKey: dashboardServerItem?.serviceNowKey,
startDate: startDate,
endDate: endDate,
});
}}
/>
{showAllocationByStorageVolume && (
Expand Down Expand Up @@ -362,23 +360,11 @@ export const Dashboard = () => {
await updateDashboard({});
}
}}
onExport={async (search) => {
const toastLoading = toast.loading('Generating Excel document...');

try {
await download({
tenantId: dashboardTenant?.id,
organizationName: search ? search : undefined,
});
toast.dismiss(toastLoading);
toast.success('Excel document has been downloaded successfully.');
} catch (ex) {
toast.dismiss(toastLoading);

const error = ex as Error;
toast.error('Failed to download data. ' + error.message);
console.error(error);
}
onExport={(search) => {
handleExport({
tenantId: dashboardTenant?.id,
organizationName: search ? search : undefined,
});
}}
/>
)}
Expand All @@ -399,25 +385,13 @@ export const Dashboard = () => {
await updateDashboard({ tenant, organization, operatingSystemItem, serverItem });
}}
showExport
onExport={async (search) => {
const toastLoading = toast.loading('Generating Excel document...');

try {
await download({
tenantId: dashboardTenant?.id,
organizationId: dashboardOrganization?.id,
operatingSystemItemId: dashboardOperatingSystemItem?.id,
search: search ? search : undefined,
});
toast.dismiss(toastLoading);
toast.success('Excel document has been downloaded successfully.');
} catch (ex) {
toast.dismiss(toastLoading);

const error = ex as Error;
toast.error('Failed to download data. ' + error.message);
console.error(error);
}
onExport={(search) => {
handleExport({
tenantId: dashboardTenant?.id,
organizationId: dashboardOrganization?.id,
operatingSystemItemId: dashboardOperatingSystemItem?.id,
search: search ? search : undefined,
});
}}
/>
)}
Expand Down
4 changes: 2 additions & 2 deletions src/dashboard/src/components/filter/FilteredOrganizations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const FilteredOrganizations = ({}: IFilteredOrganizationsProps) => {
setValues((values) => ({ ...values, organization: organizations[0] }));
}, [setFilteredOrganizations, organizations, setValues, filteredOrganizations.length]);

return (
return filteredOrganizationOptions.length > 1 ? (
<Select
label="Organization"
variant="filter"
Expand Down Expand Up @@ -123,5 +123,5 @@ export const FilteredOrganizations = ({}: IFilteredOrganizationsProps) => {
setLoading(false);
}}
/>
);
) : null;
};
6 changes: 2 additions & 4 deletions src/dashboard/src/components/filter/FilteredTenants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const FilteredTenants = ({}: IFilteredTenantsProps) => {
if (tenants.length === 1) setValues((values) => ({ ...values, tenant: tenants[0] }));
}, [filteredTenants.length, setFilteredTenants, setValues, tenants]);

return filteredTenantOptions.length > 0 ? (
return filteredTenantOptions.length > 1 ? (
<Select
label="Tenant"
variant="filter"
Expand Down Expand Up @@ -128,7 +128,5 @@ export const FilteredTenants = ({}: IFilteredTenantsProps) => {
setLoading(false);
}}
/>
) : (
<></>
);
) : null;
};

0 comments on commit 571c83e

Please sign in to comment.