Skip to content
Open
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
8 changes: 8 additions & 0 deletions .changeset/beige-ravens-find.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@cloudoperators/juno-ui-components": patch
"@cloudoperators/juno-app-greenhouse": patch
"@cloudoperators/juno-app-supernova": patch
"@cloudoperators/juno-app-doop": patch
---

Resolves all CodeQL static analysis warnings to improve code quality, reliability, and maintainability. These fixes address potential bugs, redundant code, and anti-patterns detected by automated code scanning.
3 changes: 1 addition & 2 deletions apps/doop/src/components/Highlighter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ const Highlighter = () => {
React.useEffect(() => {
const observers = createObservers((mutations: any) => {
for (const mutation of mutations) {
// @ts-expect-error TS(2367) FIXME: This condition will always return 'false' since th... Remove this comment to see the full error message
if (!mutation.type === "childList") continue
if (mutation.type !== "childList") continue

// ignore changes to search nodes
const addedOrRemovedNodes = Array.from(mutation.addedNodes).concat(Array.from(mutation.removedNodes))
Expand Down
2 changes: 1 addition & 1 deletion apps/doop/src/lib/filterViolations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const filterByActiveFilters = (violationGroups: any[], clusterIdentities: any[],
true
)
)
found = found && constraint.violation_groups?.length > 0
found = (constraint.violation_groups?.length ?? 0) > 0
}

// ############ CLUSTER FILTERS ############
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import { useClusterApi } from "../hooks/useClusterApi"

const ClusterEdit: React.FC<any> = () => {
const clusterInEdit = useStore((state: any) => state.clusterInEdit)
clusterInEdit?.spec
const setClusterInEdit = useStore((state: any) => state.setClusterInEdit)

const [submitMessage, setSubmitResultMessage] = React.useState<ResultMessage>({ message: "", ok: false })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ export const OptionInput: React.FC<OptionInputProps> = (props: OptionInputProps)
const [errortext, setErrorText] = useState<string>("")

const handleJsonValidation = (value: string) => {
let object
try {
object = JSON.parse(value)
JSON.parse(value)
} catch (e) {
setValid(false)
setErrorText("Invalid JSON")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ export default () =>
currentTeam: "",
defaultTeam: "",
teamMemberships: [],
// @ts-expect-error TS(1117): An object literal cannot have multiple properties ... Remove this comment to see the full error message
namespace: "",

actions: {
initialize: (endpoint: any, token: any, namespace: any, userGroup: any) =>
Expand Down
5 changes: 1 addition & 4 deletions apps/greenhouse/src/lib/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,15 @@
*/

export const parseError = (error: any) => {
let errMsg: string
if (error?.message) {
// @ts-expect-error TS(2304): Cannot find name 'errMsg'.
errMsg = error?.message
try {
// @ts-expect-error TS(2304): Cannot find name 'errMsg'.
errMsg = JSON.parse(error?.message).msg
} catch (error) {
console.debug(error)
}
// @ts-expect-error TS(2304): Cannot find name 'errMsg'.
} else errMsg = error.toString()
// @ts-expect-error TS(2304): Cannot find name 'errMsg'.
return errMsg
}

Expand Down
2 changes: 1 addition & 1 deletion apps/supernova/src/components/alerts/AlertStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const AlertStatus = ({ alert }: any) => {

return (
<div className="cursor-default">
{alert && <span>{alert?.status?.state}</span>}
{alert?.status?.state && <span>{alert.status.state}</span>}
{inhibitor && (
<div className="text-xs mt-2">
<Stack direction="vertical">
Expand Down
29 changes: 17 additions & 12 deletions apps/supernova/src/lib/createFiltersSlice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,20 @@ const parsePredefinedFilters = (predefinedFilters: any[]): FilterState["predefin
}

const parseInitialFilters = (
initialFilters: Record<string, string[]>,
initialFilters: Record<string, string[]> | null | undefined,
filterLabels: string[]
): Record<string, string[]> => {
if (!initialFilters) return {}

if (typeof initialFilters !== "object" || initialFilters === null) {
if (typeof initialFilters !== "object" || Array.isArray(initialFilters)) {
console.warn("[supernova]::parseInitialFilters: initialFilters object is not an object")
return {}
}

const validatedFilters: Record<string, string[]> = initialFilters

// Check if all values are arrays
initialFilters = Object.entries(initialFilters).reduce((acc: any, [key, value]) => {
const filteredByType = Object.entries(validatedFilters).reduce((acc: Record<string, string[]>, [key, value]) => {
if (Array.isArray(value)) {
acc[key] = value // valid key-value pair
} else {
Expand All @@ -87,25 +89,28 @@ const parseInitialFilters = (
}, {})

// Check if all keys are in filterLabelValues
if (!Object.keys(initialFilters).every((key) => filterLabels.includes(key))) {
if (!Object.keys(filteredByType).every((key) => filterLabels.includes(key))) {
console.warn(
"[supernova]::parseInitialFilters: Some keys of the initialFilters object are not valid filter labels. They must be configured as filterLabels first. Using only valid keys."
)

// filter out the keys that are not in filterLabels, return the rest
// this will ensure that at least the valid keys are used as initial filters
const filtered = Object.keys(initialFilters)
const filtered = Object.keys(filteredByType)
.filter((key) => filterLabels.includes(key))
.reduce((obj, key) => {
return {
...obj,
[key]: initialFilters[key],
}
}, {})
.reduce(
(obj, key) => {
return {
...obj,
[key]: filteredByType[key],
}
},
{} as Record<string, string[]>
)
return filtered
}

return initialFilters
return filteredByType
}

const parseActivePredefinedFilter = (predefinedFilters: any): string | null => {
Expand Down
18 changes: 10 additions & 8 deletions apps/supernova/src/lib/createSilencesSlice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,16 @@ const createSilencesSlice: (options?: Record<string, any>) => StateCreator<AppSt

setSilences: ({ items }) => {
if (!items) return
;(set((state: any) => ({
silences: {
...state.silences,
items: items,
updatedAt: Date.now(),
},
})),
false)
set(
(state: any) => ({
silences: {
...state.silences,
items: items,
updatedAt: Date.now(),
},
}),
false
)
},

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,12 @@ describe("ComboBox", () => {
await waitFor(() =>
render(
<AppShellProvider shadowRoot={false}>
<ComboBox id="My Id" />
<ComboBox id="my-id" />
</AppShellProvider>
)
)
expect(screen.getByRole("combobox")).toBeInTheDocument()
expect(screen.getByRole("combobox")).toHaveAttribute("id", "My Id")
expect(screen.getByRole("combobox")).toHaveAttribute("id", "my-id")
})

test("renders the id of the ComboBox input as the for attribute of the label", async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ describe("Message component", () => {
})

test("renders the component with all provided props", () => {
render(<Message data-testid="my-message" id="My shiny little Message" />)
expect(screen.getByTestId("my-message")).toHaveAttribute("id", "My shiny little Message")
render(<Message data-testid="my-message" id="my-shiny-little-message" />)
expect(screen.getByTestId("my-message")).toHaveAttribute("id", "my-shiny-little-message")
})
})

Expand Down
4 changes: 2 additions & 2 deletions packages/ui-components/src/components/Toast/Toast.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ describe("Toast", () => {
})

test("renders all props as passed", () => {
render(<Toast data-testid="my-toast" id="My shiny little Message" />)
expect(screen.getByTestId("my-toast")).toHaveAttribute("id", "My shiny little Message")
render(<Toast data-testid="my-toast" id="my-shiny-little-message" />)
expect(screen.getByTestId("my-toast")).toHaveAttribute("id", "my-shiny-little-message")
})
})
Loading