Skip to content

Commit

Permalink
[fix] when get an error from benchmarks API assume no benchmarks are …
Browse files Browse the repository at this point in the history
…available (#275)
  • Loading branch information
sijav authored Jul 18, 2024
1 parent 25fbf0d commit 3f12571
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 12 deletions.
6 changes: 5 additions & 1 deletion src/locales/de-DE/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ msgstr "Kritisch"
msgid "Current Product Tier"
msgstr ""

#: src/pages/panel/workspace-settings/workspace-alerting-settings/WorkspaceAlertingSettings.tsx:305
#: src/pages/panel/workspace-settings/workspace-alerting-settings/WorkspaceAlertingSettings.tsx:306
msgid "Currently, there are no connected services available for configuration. Please be informed that connecting at least one service is necessary to configure alerting settings."
msgstr "Derzeit stehen keine verbundenen Dienste zur Konfiguration zur Verfügung. Bitte beachten Sie, dass zum Konfigurieren der Alarmeinstellungen die Verbindung mindestens eines Dienstes erforderlich ist."

Expand Down Expand Up @@ -2449,6 +2449,10 @@ msgstr ""
msgid "Warning"
msgstr "Warnung"

#: src/pages/panel/workspace-settings/workspace-alerting-settings/WorkspaceAlertingSettings.tsx:311
msgid "We are currently trying to list your projects. Please stay tuned - we will send you an Email when cloud accounts have been collected"
msgstr ""

#: src/pages/auth/login/LoginPage.tsx:191
msgid "We have sent an email with a confirmation link to your email address. Please follow the link to activate your account."
msgstr "Wir haben eine E-Mail mit einem Bestätigungslink an Ihre E-Mail-Adresse gesendet. Bitte folgen Sie dem Link, um Ihr Konto zu aktivieren."
Expand Down
6 changes: 5 additions & 1 deletion src/locales/en-US/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ msgstr "Critical"
msgid "Current Product Tier"
msgstr "Current Product Tier"

#: src/pages/panel/workspace-settings/workspace-alerting-settings/WorkspaceAlertingSettings.tsx:305
#: src/pages/panel/workspace-settings/workspace-alerting-settings/WorkspaceAlertingSettings.tsx:306
msgid "Currently, there are no connected services available for configuration. Please be informed that connecting at least one service is necessary to configure alerting settings."
msgstr "Currently, there are no connected services available for configuration. Please be informed that connecting at least one service is necessary to configure alerting settings."

Expand Down Expand Up @@ -2449,6 +2449,10 @@ msgstr "Version"
msgid "Warning"
msgstr "Warning"

#: src/pages/panel/workspace-settings/workspace-alerting-settings/WorkspaceAlertingSettings.tsx:311
msgid "We are currently trying to list your projects. Please stay tuned - we will send you an Email when cloud accounts have been collected"
msgstr "We are currently trying to list your projects. Please stay tuned - we will send you an Email when cloud accounts have been collected"

#: src/pages/auth/login/LoginPage.tsx:191
msgid "We have sent an email with a confirmation link to your email address. Please follow the link to activate your account."
msgstr "We have sent an email with a confirmation link to your email address. Please follow the link to activate your account."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { axiosWithAuth } from 'src/shared/utils/axios'

export const getWorkspaceInventoryReportBenchmarksQuery = ({
signal,
queryKey: [, workspaceId, benchmark_ids, short, with_checks, ids_only],
queryKey: [, workspaceId, benchmark_ids, short, with_checks, ids_only, withError0Result],
}: QueryFunctionContext<
[
'workspace-inventory-report-benchmarks',
Expand All @@ -15,6 +15,7 @@ export const getWorkspaceInventoryReportBenchmarksQuery = ({
boolean | undefined,
boolean | undefined,
boolean | undefined,
boolean | undefined,
]
>) => {
const params: Record<string, string> = {}
Expand All @@ -37,5 +38,11 @@ export const getWorkspaceInventoryReportBenchmarksQuery = ({
params: Object.keys(params).length ? params : undefined,
})
.then((res) => res.data)
.catch((e) => {
if (withError0Result) {
return [] as Benchmark[]
}
throw e
})
: ([] as Benchmark[])
}
19 changes: 16 additions & 3 deletions src/pages/panel/shared/utils/useGetBenchmarks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,28 @@ import { useUserProfile } from 'src/core/auth'
import { getWorkspaceInventoryReportBenchmarksQuery } from 'src/pages/panel/shared/queries'
import { Benchmark } from 'src/shared/types/server-shared'

export function useGetBenchmarks(select: true, ids?: string[] | undefined): { data: Benchmark[] | undefined; isLoading: boolean }
export function useGetBenchmarks(
select: true,
ids?: string[] | undefined,
withError0Result?: boolean,
): { data: Benchmark[] | undefined; isLoading: boolean }
export function useGetBenchmarks(
select?: false,
ids?: string[],
withError0Result?: boolean,
): { data: Record<string, Benchmark | undefined> | undefined; isLoading: boolean }
export function useGetBenchmarks(select: boolean = false, ids: string[] = []) {
export function useGetBenchmarks(select: boolean = false, ids: string[] = [], withError0Result?: boolean) {
const { selectedWorkspace } = useUserProfile()
const { data, isLoading } = useQuery({
queryKey: ['workspace-inventory-report-benchmarks', selectedWorkspace?.id, select ? ids.join(',') : undefined, true, false, false],
queryKey: [
'workspace-inventory-report-benchmarks',
selectedWorkspace?.id,
select ? ids.join(',') : undefined,
true,
false,
false,
withError0Result,
],
queryFn: getWorkspaceInventoryReportBenchmarksQuery,
gcTime: Number.POSITIVE_INFINITY,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const WorkspaceAlertingSettingsCheckbox = ({
export const WorkspaceAlertingSettings = () => {
const { selectedWorkspace, checkPermission } = useUserProfile()
const hasPermission = checkPermission('updateSettings')
const { data: benchmarks, isLoading: isBenchmarksLoading } = useGetBenchmarks(true)
const { data: benchmarks, isLoading: isBenchmarksLoading } = useGetBenchmarks(true, undefined, true)
const [{ data: alertingSettings, isLoading: isAlertingSettingsLoading }, { data: notifications, isLoading: isNotificationsLoading }] =
useQueries({
queries: [
Expand Down Expand Up @@ -301,11 +301,18 @@ export const WorkspaceAlertingSettings = () => {
</TableContainer>
) : (
<Stack>
<Alert severity="warning">
<Trans>
Currently, there are no connected services available for configuration. Please be informed that connecting at least one service is
necessary to configure alerting settings.
</Trans>
<Alert severity={benchmarks?.length ? 'warning' : 'info'}>
{benchmarks?.length ? (
<Trans>
Currently, there are no connected services available for configuration. Please be informed that connecting at least one service
is necessary to configure alerting settings.
</Trans>
) : (
<Trans>
We are currently trying to list your projects. Please stay tuned - we will send you an Email when cloud accounts have been
collected
</Trans>
)}
</Alert>
</Stack>
)
Expand Down

0 comments on commit 3f12571

Please sign in to comment.