Skip to content

Commit

Permalink
[fix] Error on table and pie card api update (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
sijav authored Nov 30, 2023
1 parent 3e0675b commit a9a6e2a
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 39 deletions.
5 changes: 5 additions & 0 deletions src/locales/de-DE/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ msgid "© 2023 Some Engineering Inc. All rights reserved."
msgstr "© 2023 Some Engineering Services GMBH. Alle Rechte vorbehalten."

#: src/pages/panel/accounts/AccountsTable.tsx:31
#: src/pages/panel/inventory/InventoryTable.error.tsx:74
#: src/pages/panel/inventory/InventoryTable.tsx:84
#: src/pages/panel/inventory/utils/getAutoCompleteFromKey.tsx:67
#: src/shared/layouts/panel-layout/UserProfileButton.tsx:103
Expand Down Expand Up @@ -104,6 +105,10 @@ msgstr "Automatisches Cloud Setup"
msgid "AWS Marketplace has been successfully subscribed"
msgstr "AWS Marketplace wurde erfolgreich abonniert"

#: src/pages/panel/inventory/InventoryAdvanceSearch.tsx:124
msgid "Bad query"
msgstr "Schlechte Abfrage"

#: src/pages/panel/inventory/ResourceDetail.tsx:170
msgid "Basic Information"
msgstr "Grundinformation"
Expand Down
5 changes: 5 additions & 0 deletions src/locales/en-US/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ msgid "© 2023 Some Engineering Inc. All rights reserved."
msgstr "© 2023 Some Engineering Inc. All rights reserved."

#: src/pages/panel/accounts/AccountsTable.tsx:31
#: src/pages/panel/inventory/InventoryTable.error.tsx:74
#: src/pages/panel/inventory/InventoryTable.tsx:84
#: src/pages/panel/inventory/utils/getAutoCompleteFromKey.tsx:67
#: src/shared/layouts/panel-layout/UserProfileButton.tsx:103
Expand Down Expand Up @@ -104,6 +105,10 @@ msgstr "Automatic Cloud Setup"
msgid "AWS Marketplace has been successfully subscribed"
msgstr "AWS Marketplace has been successfully subscribed"

#: src/pages/panel/inventory/InventoryAdvanceSearch.tsx:124
msgid "Bad query"
msgstr "Bad query"

#: src/pages/panel/inventory/ResourceDetail.tsx:170
msgid "Basic Information"
msgstr "Basic Information"
Expand Down
6 changes: 5 additions & 1 deletion src/pages/panel/inventory/InventoryAdvanceSearch.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Trans } from '@lingui/macro'
import ArrowDropDownIcon from '@mui/icons-material/ArrowDropDownCircleOutlined'
import SearchIcon from '@mui/icons-material/Search'
import { Box, Collapse, Divider, IconButton, TextField, styled } from '@mui/material'
Expand All @@ -23,6 +24,7 @@ export interface InventoryAdvanceSearchConfig {
interface InventoryAdvanceSearchProps {
value: string
onChange: (value: string) => void
hasError: boolean
}

const StyledArrowDropDownIcon = styled(ArrowDropDownIcon, { shouldForwardProp: shouldForwardProp })<{ showAdvanceSearch: boolean }>(
Expand All @@ -33,7 +35,7 @@ const StyledArrowDropDownIcon = styled(ArrowDropDownIcon, { shouldForwardProp: s
}),
)

export const InventoryAdvanceSearch = ({ value: searchCrit, onChange }: InventoryAdvanceSearchProps) => {
export const InventoryAdvanceSearch = ({ value: searchCrit, onChange, hasError }: InventoryAdvanceSearchProps) => {
const initializedRef = useRef(false)
const [searchParams] = useSearchParams()
const [hideFilters, setHideFilters] = useState(() => searchParams.get('hide') === 'true')
Expand Down Expand Up @@ -118,6 +120,8 @@ export const InventoryAdvanceSearch = ({ value: searchCrit, onChange }: Inventor
value={searchCritValue}
onChange={handleChange}
InputProps={{ startAdornment: <SearchIcon /> }}
error={hasError}
helperText={hasError ? <Trans>Bad query</Trans> : null}
/>
</Collapse>
<Box my={2}>
Expand Down
27 changes: 4 additions & 23 deletions src/pages/panel/inventory/InventoryPage.tsx
Original file line number Diff line number Diff line change
@@ -1,36 +1,17 @@
import { Stack, Typography } from '@mui/material'
import { Suspense, useEffect, useRef, useState } from 'react'
import { useSearchParams } from 'react-router-dom'
import { useAbsoluteNavigate } from 'src/shared/absolute-navigate'
import { ErrorBoundaryFallback, NetworkErrorBoundary } from 'src/shared/error-boundary-fallback'
import { TableViewPage } from 'src/shared/layouts/panel-layout'
import { LoadingSuspenseFallback } from 'src/shared/loading'
import { InventoryAdvanceSearch } from './InventoryAdvanceSearch'
import { InventoryTable } from './InventoryTable'

const TableNetworkErrorBoundary = ({ resetErrorBoundary, searchCrit }: { resetErrorBoundary: () => void; searchCrit: string }) => {
const initialized = useRef(false)
useEffect(() => {
if (initialized.current) {
resetErrorBoundary()
}
initialized.current = true
}, [searchCrit, resetErrorBoundary])
return (
<TableViewPage>
<Stack flex={1} height="100%" alignItems="center" justifyContent="center">
<Typography variant="h3" color="error.main">
Wrong query
</Typography>
</Stack>
</TableViewPage>
)
}
import { InventoryTableError } from './InventoryTable.error'

export default function InventoryPage() {
const [searchParams] = useSearchParams()
const initialized = useRef(false)
const navigate = useAbsoluteNavigate()
const [hasError, setHasError] = useState(false)
const [searchCrit, setSearchCrit] = useState(() => searchParams.get('q') || 'all')
const history = {
change: searchParams.get('change'),
Expand All @@ -52,11 +33,11 @@ export default function InventoryPage() {
<NetworkErrorBoundary FallbackComponent={ErrorBoundaryFallback}>
<Suspense fallback={<LoadingSuspenseFallback />}>
<NetworkErrorBoundary FallbackComponent={ErrorBoundaryFallback}>
<InventoryAdvanceSearch value={searchCrit} onChange={setSearchCrit} />
<InventoryAdvanceSearch value={searchCrit} onChange={setSearchCrit} hasError={hasError} />
</NetworkErrorBoundary>
<NetworkErrorBoundary
fallbackRender={({ resetErrorBoundary }) => (
<TableNetworkErrorBoundary resetErrorBoundary={resetErrorBoundary} searchCrit={searchCrit} />
<InventoryTableError resetErrorBoundary={resetErrorBoundary} searchCrit={searchCrit} setHasError={setHasError} />
)}
>
<InventoryTable
Expand Down
86 changes: 86 additions & 0 deletions src/pages/panel/inventory/InventoryTable.error.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { t } from '@lingui/macro'
import { Table, TableBody, TableCell, TableHead, TableRow } from '@mui/material'
import { useEffect, useRef } from 'react'
import { TablePagination, TableViewPage } from 'src/shared/layouts/panel-layout'

interface InventoryTableProps {
searchCrit: string
resetErrorBoundary: () => void
setHasError: (hasError: boolean) => void
}

const defaultColumns = [
{
name: 'kind',
kind: 'string',
display: 'Kind',
},
{
name: 'id',
kind: 'string',
display: 'Id',
},
{
name: 'name',
kind: 'string',
display: 'Name',
},
{
name: 'age',
kind: 'duration',
display: 'Age',
},
{
name: 'last_update',
kind: 'duration',
display: 'Last Update',
},
{
name: 'cloud',
kind: 'string',
display: 'Cloud',
},
{
name: 'account',
kind: 'string',
display: 'Account',
},
{
name: 'region',
kind: 'string',
display: 'Region',
},
{
name: 'zone',
kind: 'string',
display: 'Zone',
},
]

export const InventoryTableError = ({ searchCrit, resetErrorBoundary, setHasError }: InventoryTableProps) => {
const initialized = useRef(false)
useEffect(() => {
if (initialized.current) {
setHasError(false)
resetErrorBoundary()
} else {
setHasError(true)
initialized.current = true
}
}, [searchCrit, resetErrorBoundary, setHasError])

return (
<TableViewPage pagination={<TablePagination dataCount={0} page={0} rowsPerPage={10} setPage={() => {}} setRowsPerPage={() => {}} />}>
<Table stickyHeader aria-label={t`Accounts`}>
<TableHead>
<TableRow>
{defaultColumns.map((column, i) => (
<TableCell key={`${column.name}-${i}`}>{column.display}</TableCell>
))}
</TableRow>
</TableHead>
<TableBody />
</Table>
</TableViewPage>
)
}
24 changes: 12 additions & 12 deletions src/pages/panel/shared/utils/PieCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,13 @@ export const PieCard = ({ data }: { data?: GetWorkspaceInventoryReportSummaryRes
value: account_summary.failed_checks?.critical || 0,
name: 'Critical',
label: account_summary.failed_checks?.critical
? typeof account_summary.failed_resources?.critical === 'number'
? numberToShortHRT(account_summary.failed_resources.critical)
? typeof account.failed_resources_by_severity?.critical === 'number'
? numberToShortHRT(account.failed_resources_by_severity.critical)
: numberToShortHRT(account_summary.failed_checks.critical)
: undefined,
description: account_summary.failed_checks?.critical
? t`We've identified ${
account_summary.failed_resources?.critical?.toLocaleString() ?? ''
account.failed_resources_by_severity?.critical?.toLocaleString() ?? '0'
} non-compliant resources out of ${account.resource_count.toLocaleString()} through ${
account_summary.failed_checks?.critical.toLocaleString() ?? '0'
} ${'Critical'.toString()}-severity security checks.`
Expand All @@ -148,13 +148,13 @@ export const PieCard = ({ data }: { data?: GetWorkspaceInventoryReportSummaryRes
value: account_summary.failed_checks?.high || 0,
name: 'High',
label: account_summary.failed_checks?.high
? typeof account_summary.failed_resources?.high === 'number'
? numberToShortHRT(account_summary.failed_resources.high)
? typeof account.failed_resources_by_severity?.high === 'number'
? numberToShortHRT(account.failed_resources_by_severity.high)
: numberToShortHRT(account_summary.failed_checks.high)
: undefined,
description: account_summary.failed_checks?.high
? t`We've identified ${
account_summary.failed_resources?.high?.toLocaleString() ?? ''
account.failed_resources_by_severity?.high?.toLocaleString() ?? '0'
} non-compliant resources out of ${account.resource_count.toLocaleString()} through ${
account_summary.failed_checks?.high.toLocaleString() ?? '0'
} ${'High'.toString()}-severity security checks.`
Expand All @@ -171,13 +171,13 @@ export const PieCard = ({ data }: { data?: GetWorkspaceInventoryReportSummaryRes
value: account_summary.failed_checks?.medium || 0,
name: 'Medium',
label: account_summary.failed_checks?.medium
? typeof account_summary.failed_resources?.medium === 'number'
? numberToShortHRT(account_summary.failed_resources.medium)
? typeof account.failed_resources_by_severity?.medium === 'number'
? numberToShortHRT(account.failed_resources_by_severity.medium)
: numberToShortHRT(account_summary.failed_checks.medium)
: undefined,
description: account_summary.failed_checks?.medium
? t`We've identified ${
account_summary.failed_resources?.medium?.toLocaleString() ?? ''
account.failed_resources_by_severity?.medium?.toLocaleString() ?? '0'
} non-compliant resources out of ${account.resource_count.toLocaleString()} through ${
account_summary.failed_checks?.medium.toLocaleString() ?? '0'
} ${'Medium'.toString()}-severity security checks.`
Expand All @@ -194,13 +194,13 @@ export const PieCard = ({ data }: { data?: GetWorkspaceInventoryReportSummaryRes
value: account_summary.failed_checks?.low || 0,
name: 'Low',
label: account_summary.failed_checks?.low
? typeof account_summary.failed_resources?.low === 'number'
? numberToShortHRT(account_summary.failed_resources.low)
? typeof account.failed_resources_by_severity?.low === 'number'
? numberToShortHRT(account.failed_resources_by_severity.low)
: numberToShortHRT(account_summary.failed_checks.low)
: undefined,
description: account_summary.failed_checks?.low
? t`We've identified ${
account_summary.failed_resources?.low?.toLocaleString() ?? ''
account.failed_resources_by_severity?.low?.toLocaleString() ?? '0'
} non-compliant resources out of ${account.resource_count.toLocaleString()} through ${
account_summary.failed_checks?.low.toLocaleString() ?? '0'
} ${'Low'.toString()}-severity security checks.`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export interface Benchmark {
string,
{
score: number
failed_checks: FailedChecksType | null
failed_resources: FailedChecksType | null
failed_checks: Partial<FailedChecksType> | null
failed_resources: Partial<FailedChecksType> | null
}
>
}
Expand All @@ -33,6 +33,7 @@ export type WorkspaceAccountReportSummary = {
cloud: string
score: number
resource_count: number
failed_resources_by_severity: Partial<FailedChecksType> | null
}

export interface WorkspaceCheckSummary {
Expand All @@ -47,7 +48,6 @@ export interface WorkspaceCheckSummary {
export interface GetWorkspaceInventoryReportSummaryResponse {
overall_score: number
check_summary: WorkspaceCheckSummary
account_check_summary: WorkspaceCheckSummary
accounts: WorkspaceAccountReportSummary[]
benchmarks: Benchmark[]
changed_vulnerable: ChangedSitatuation
Expand Down

0 comments on commit a9a6e2a

Please sign in to comment.