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
256 changes: 175 additions & 81 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,13 @@
},
"devDependencies": {
"@cypress/grep": "6.0.0",
"@types/js-yaml": "4.0.9",
"@types/lodash": "4.17.24",
"@types/murmurhash-js": "1.0.7",
"@types/node": "^22.19.17",
"@types/react": "^17.0.91",
"@types/react-modal": "3.16.3",
"@types/react-redux": "7.1.34",
"@typescript-eslint/eslint-plugin": "^8.58.1",
"@typescript-eslint/parser": "^8.58.1",
"cypress": "15.14.2",
Expand Down
10 changes: 6 additions & 4 deletions src/components/AttachLogModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useDispatch } from 'react-redux';
import {
consoleFetchText,
K8sResourceKind,
Selector,
useK8sWatchResource,
} from '@openshift-console/dynamic-plugin-sdk';
import {
Expand Down Expand Up @@ -257,9 +258,9 @@ const AttachLogModal: React.FC<AttachLogModalProps> = ({ isOpen, onClose, resour
isCronJob ? { isList: true, kind: 'Job', namespace } : null,
);

let selector;
let selector: Selector | undefined;
if (kind === 'Job') {
selector = { 'job-name': name };
selector = { matchLabels: { 'job-name': name } };
} else if (isCronJob) {
const ownedJobNames = (jobs || [])
.filter((job) =>
Expand All @@ -281,7 +282,7 @@ const AttachLogModal: React.FC<AttachLogModalProps> = ({ isOpen, onClose, resour
selector = undefined;
}
} else if (kind === 'VirtualMachine' || kind === 'VirtualMachineInstance') {
selector = { 'vm.kubevirt.io/name': name };
selector = { matchLabels: { 'vm.kubevirt.io/name': name } };
} else if (scaleTarget && scaleTargetLoaded && !scaleTargetError) {
selector = scaleTarget.spec?.selector;
} else {
Expand All @@ -297,7 +298,8 @@ const AttachLogModal: React.FC<AttachLogModalProps> = ({ isOpen, onClose, resour
const changePod = (newPod: K8sResourceKind) => {
if (newPod) {
setPod(newPod);
const newContainers = newPod.spec?.containers?.map((c) => c.name).sort() ?? [];
const newContainers =
newPod.spec?.containers?.map((c: { name: string }) => c.name).sort() ?? [];
setContainers(newContainers);
setContainer(newContainers[0]);
}
Expand Down
6 changes: 3 additions & 3 deletions src/components/AttachmentModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react';
import { useTranslation } from 'react-i18next';
import { useDispatch, useSelector } from 'react-redux';
import { BlueInfoCircleIcon } from '@openshift-console/dynamic-plugin-sdk';
import { CodeEditor, Language } from '@patternfly/react-code-editor';
import { CodeEditor, EditorDidMount, Language } from '@patternfly/react-code-editor';
import {
ActionGroup,
Button,
Expand Down Expand Up @@ -49,10 +49,10 @@ type EditorProps = {
const Editor: React.FC<EditorProps> = ({ onChange }) => {
const attachment: Attachment = useSelector((s: State) => s.plugins?.ols?.get('openAttachment'));

const onEditorDidMount = (_editor, monaco) => {
const onEditorDidMount: EditorDidMount = (_editor, monaco) => {
// Work around crash when CodeEditor attempts to call this nonexistent function
// TODO: Figure out why this is happening
monaco.editor.onDidChangeMarkers = () => {};
(monaco.editor as { onDidChangeMarkers: () => void }).onDidChangeMarkers = () => {};
};

const [isDarkTheme] = useIsDarkTheme();
Expand Down
5 changes: 4 additions & 1 deletion src/components/AttachmentsSizeAlert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useSelector } from 'react-redux';
import { Alert } from '@patternfly/react-core';

import { State } from '../redux-reducers';
import { Attachment } from '../types';

const MAX_CHARS = 1000000;

Expand All @@ -12,7 +13,9 @@ const AttachmentsSizeAlert: React.FC = () => {

const attachments = useSelector((s: State) => s.plugins?.ols?.get('attachments'));

const totalChars = attachments.valueSeq().reduce((sum, a) => sum + a.value.length, 0);
const totalChars = attachments
.valueSeq()
.reduce((sum: number, a: Attachment) => sum + a.value.length, 0);

if (totalChars <= MAX_CHARS) {
return null;
Expand Down
22 changes: 13 additions & 9 deletions src/components/Prompt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import {
consoleFetch,
consoleFetchJSON,
K8sResourceKind,
PrometheusAlert,
PrometheusRule,
PrometheusRulesResponse,
Silence,
useK8sWatchResource,
} from '@openshift-console/dynamic-plugin-sdk';
import { MessageBar } from '@patternfly/chatbot';
Expand Down Expand Up @@ -184,8 +188,8 @@ const Prompt: React.FC<PromptProps> = ({ scrollIntoView }) => {
reader.onload = (event) => {
try {
const yaml = event.target?.result as string;
const content = loadYAML(yaml);
if (typeof content !== 'object') {
const content = loadYAML(yaml) as K8sResourceKind | null;
if (typeof content !== 'object' || content === null) {
setError(t('Uploaded file is not valid YAML'));
return;
}
Expand Down Expand Up @@ -356,8 +360,8 @@ const Prompt: React.FC<PromptProps> = ({ scrollIntoView }) => {
const labels = Object.fromEntries(new URLSearchParams(location.search));
const alertsEndpoint = labels.cluster ? ALERTS_THANOS_ENDPOINT : ALERTS_ENDPOINT;
consoleFetchJSON(alertsEndpoint, 'get', getRequestInitWithAuthHeader())
.then((response) => {
let alert;
.then((response: PrometheusRulesResponse) => {
let alert: PrometheusAlert | undefined;
each(response?.data?.groups, (group) => {
each(group.rules, (rule) => {
alert = rule.alerts?.find((a) => isMatch(labels, a.labels));
Expand Down Expand Up @@ -406,7 +410,7 @@ const Prompt: React.FC<PromptProps> = ({ scrollIntoView }) => {
} else if (kind === 'Silence') {
setLoading();
consoleFetchJSON(`${SILENCE_ENDPOINT}/${name}`, 'get', getRequestInitWithAuthHeader())
.then((silence) => {
.then((silence: Silence) => {
try {
const silenceName =
silence.matchers
Expand All @@ -433,8 +437,8 @@ const Prompt: React.FC<PromptProps> = ({ scrollIntoView }) => {
const ruleLabels = Object.fromEntries(new URLSearchParams(location.search));
const rulesEndpoint = ruleLabels.cluster ? ALERTS_THANOS_ENDPOINT : ALERTS_ENDPOINT;
consoleFetchJSON(rulesEndpoint, 'get', getRequestInitWithAuthHeader())
.then((response) => {
let matchedRule;
.then((response: PrometheusRulesResponse) => {
let matchedRule: PrometheusRule | undefined;
each(response?.data?.groups, (group) => {
const found = group.rules?.find(
(rule) => rule.type === 'alerting' && alertingRuleID(group, rule) === name,
Expand Down Expand Up @@ -575,7 +579,7 @@ const Prompt: React.FC<PromptProps> = ({ scrollIntoView }) => {

dispatch(
chatHistoryPush({
attachments: attachments.map((a) => omit(a, 'originalValue')),
attachments: attachments.map((a: Attachment) => omit(a, 'originalValue')),
hidden: hidePrompt,
text: query,
who: 'user',
Expand Down Expand Up @@ -907,7 +911,7 @@ const Prompt: React.FC<PromptProps> = ({ scrollIntoView }) => {
hasStopButton={isStreaming}
innerRef={textareaRef}
isSendButtonDisabled={!query || query.trim().length === 0}
onChange={(e) => onChange(e, e.target.value)}
onChange={(e: React.ChangeEvent<HTMLTextAreaElement>) => onChange(e, e.target.value)}
onSendMessage={onSubmit}
placeholder={
isTroubleshooting
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/usePopover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Popover from '../components/Popover';

const POPOVER_ID = 'plugin__lightspeed-console-plugin__POPOVER_ID';

const usePopover = () => {
const usePopover = (): null => {
const [isLaunched, , setLaunched] = useBoolean(false);

const launchModal = useModal();
Expand All @@ -18,7 +18,7 @@ const usePopover = () => {
}
}, [isLaunched, launchModal, setLaunched]);

return [];
return null;
};

export default usePopover;
4 changes: 2 additions & 2 deletions src/redux-reducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ const reducer = (state: OLSState, action: OLSAction): OLSState => {
case ActionType.ChatHistoryUpdateByID: {
const index = state
.get('chatHistory')
.findIndex((entry) => entry.get('id') === action.payload.id);
.findIndex((entry: ImmutableMap<string, unknown>) => entry.get('id') === action.payload.id);
return state.mergeIn(['chatHistory', index], action.payload.entry);
}

case ActionType.ChatHistoryUpdateTool: {
const index = state
.get('chatHistory')
.findIndex((entry) => entry.get('id') === action.payload.id);
.findIndex((entry: ImmutableMap<string, unknown>) => entry.get('id') === action.payload.id);
return state.mergeIn(
['chatHistory', index, 'tools', action.payload.toolID],
action.payload.tool,
Expand Down
2 changes: 1 addition & 1 deletion src/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const alertingRuleID = (
rule.query,
..._map(rule.labels, (v, k) => `${v}=${k}`),
].join(',');
return String(murmur3(key, 'monitoring-salt'));
return String(murmur3(key));
};

export const isValidAlertName = (value: string | null | undefined): boolean =>
Expand Down
1 change: 0 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"jsx": "react",
"allowJs": true,
"strict": true,
"noImplicitAny": false,
"strictNullChecks": false,
"noUnusedLocals": true,
"sourceMap": false,
Expand Down