Skip to content

Commit 8a23603

Browse files
committed
OU-1264: address linting issues
1 parent 1e55c70 commit 8a23603

6 files changed

Lines changed: 29 additions & 23 deletions

File tree

web/cypress/component/mocks/OlsToolUIPersesWrapper.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
import React from 'react';
2-
3-
export const OlsToolUIPersesWrapper = ({ children, initialTimeRange, initialTimeZone = 'local' }) => (
1+
export const OlsToolUIPersesWrapper = ({
2+
children,
3+
initialTimeRange,
4+
initialTimeZone = 'local',
5+
}) => (
46
<div
57
data-testid="perses-wrapper"
68
data-time-range={JSON.stringify(initialTimeRange)}

web/cypress/component/mocks/perses-dashboards.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import React from 'react';
2-
31
export const Panel = ({ definition, panelOptions }) => (
42
<div data-testid="mock-panel">
53
<div data-testid="panel-definition" data-definition={JSON.stringify(definition)} />

web/cypress/component/ols-tool-ui/ShowTimeseries.cy.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,20 +98,25 @@ describe('ShowTimeseries', () => {
9898
if (expected.startISO) {
9999
expect(timeRange.start).to.eq(expected.startISO);
100100
} else {
101-
expect(new Date(timeRange.start).getTime()).to.be.closeTo(now - expected.startOffsetMs, 5000);
101+
expect(new Date(timeRange.start).getTime()).to.be.closeTo(
102+
now - expected.startOffsetMs,
103+
5000,
104+
);
102105
}
103106
if (expected.endISO) {
104107
expect(timeRange.end).to.eq(expected.endISO);
105108
} else {
106-
expect(new Date(timeRange.end).getTime()).to.be.closeTo(now - expected.endOffsetMs, 5000);
109+
expect(new Date(timeRange.end).getTime()).to.be.closeTo(
110+
now - expected.endOffsetMs,
111+
5000,
112+
);
107113
}
108114
});
109115
});
110116
});
111117

112118
it('timezone support: defaults to UTC when not specified', () => {
113119
cy.mount(<ShowTimeseries tool={tool} />);
114-
cy.get('[data-testid="perses-wrapper"]')
115-
.should('have.attr', 'data-timezone', 'UTC');
120+
cy.get('[data-testid="perses-wrapper"]').should('have.attr', 'data-timezone', 'UTC');
116121
});
117122
});

web/cypress/support/component.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22
import ReactDOM from 'react-dom';
33
import '@patternfly/react-core/dist/styles/base.css';
4+
import * as ReactI18next from 'react-i18next';
45

56
function mount(jsx: React.ReactElement) {
67
const root = document.querySelector('[data-cy-root]');
@@ -10,6 +11,7 @@ function mount(jsx: React.ReactElement) {
1011
}
1112

1213
declare global {
14+
// eslint-disable-next-line @typescript-eslint/no-namespace
1315
namespace Cypress {
1416
interface Chainable {
1517
mount: typeof mount;
@@ -22,14 +24,11 @@ Cypress.Commands.add('mount', mount);
2224
// Mock react-i18next for all component tests: returns the key with {{interpolations}} replaced
2325
const mockT = (key: string, opts?: Record<string, string>) => {
2426
if (opts) {
25-
return Object.entries(opts).reduce(
26-
(result, [k, v]) => result.replace(`{{${k}}}`, v),
27-
key,
28-
);
27+
return Object.entries(opts).reduce((result, [k, v]) => result.replace(`{{${k}}}`, v), key);
2928
}
3029
return key;
3130
};
3231

3332
beforeEach(() => {
34-
cy.stub(require('react-i18next'), 'useTranslation').returns({ t: mockT });
33+
cy.stub(ReactI18next, 'useTranslation').returns({ t: mockT });
3534
});

web/src/components/dashboards/perses/setupExternalPanelAddition.ts renamed to web/src/components/dashboards/perses/ExternalPanelAddition.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1-
import { useEffect, useState, useCallback } from 'react';
1+
import { ReactElement, useEffect, useState, useCallback } from 'react';
22
import { useDispatch, useSelector } from 'react-redux';
33
import { useDashboardActions, useDashboardStore } from '@perses-dev/dashboards';
44
import { dashboardsOpened, dashboardsPersesPanelExternallyAdded } from '../../../store/actions';
55

6-
interface SetupExternalPanelAdditionOptions {
6+
interface ExternalPanelAdditionProps {
77
isEditMode: boolean;
88
onEditButtonClick: () => void;
99
}
1010

11-
export function setupExternalPanelAddition({
11+
// Effect-only component that registers hooks related to exposing adding panels
12+
// from external intergrations.
13+
// See components/ols-tool-ui/helpers/AddToDashboardButton.tsx for example use.
14+
export function ExternalPanelAddition({
1215
isEditMode,
1316
onEditButtonClick,
14-
}: SetupExternalPanelAdditionOptions) {
17+
}: ExternalPanelAdditionProps): ReactElement | null {
1518
const dispatch = useDispatch();
1619
const addPersesPanelExternally: any = useSelector(
1720
(s: any) => s.plugins?.mcp?.dashboards?.addPersesPanelExternally,
@@ -74,4 +77,6 @@ export function setupExternalPanelAddition({
7477
dispatch(dashboardsOpened(false));
7578
};
7679
}, [dispatch]);
80+
81+
return null;
7782
}

web/src/components/dashboards/perses/dashboard-app.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { useUpdateDashboardMutation } from './dashboard-api';
2929
import { useTranslation } from 'react-i18next';
3030
import { useToast } from './ToastProvider';
3131
import { useSearchParams } from 'react-router';
32-
import { setupExternalPanelAddition } from './setupExternalPanelAddition';
32+
import { ExternalPanelAddition } from './ExternalPanelAddition';
3333

3434
export interface DashboardAppProps {
3535
dashboardResource: DashboardResource | EphemeralDashboardResource;
@@ -125,10 +125,6 @@ export const OCPDashboardApp = (props: DashboardAppProps): ReactElement => {
125125
}
126126
};
127127

128-
// Register hooks related to exposing adding panels from external intergrations.
129-
// See components/ols-tool-ui/helpers/AddToDashboardButton.tsx for example use.
130-
setupExternalPanelAddition({ isEditMode, onEditButtonClick });
131-
132128
const updateDashboardMutation = useUpdateDashboardMutation();
133129

134130
const onSave = useCallback(
@@ -173,6 +169,7 @@ export const OCPDashboardApp = (props: DashboardAppProps): ReactElement => {
173169
flexDirection: 'column',
174170
}}
175171
>
172+
<ExternalPanelAddition isEditMode={isEditMode} onEditButtonClick={onEditButtonClick} />
176173
<OCPDashboardToolbar
177174
dashboardName={dashboardResource.metadata.name}
178175
initialVariableIsSticky={isInitialVariableSticky}

0 commit comments

Comments
 (0)