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

HOSTSD-295 Fix dashboard and filter #122

Merged
merged 1 commit into from
Mar 22, 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
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(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cleans things up and makes it easier to maintain.

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 ? (
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't show dropdown unless there is more than one option

<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 ? (
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't show dropdown unless there is more than one option

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