Skip to content

Commit dc5240a

Browse files
committed
disable in mds use case
Signed-off-by: Jackie Han <[email protected]>
1 parent 83b344f commit dc5240a

File tree

2 files changed

+52
-14
lines changed

2 files changed

+52
-14
lines changed

public/pages/DetectorResults/__tests__/AnomalyResultsTable.test.tsx

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import React from 'react';
1313
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
1414
import '@testing-library/jest-dom';
1515
import { AnomalyResultsTable } from '../containers/AnomalyResultsTable';
16-
import { getSavedObjectsClient, getNotifications } from '../../../services';
16+
import { getSavedObjectsClient, getNotifications, getDataSourceEnabled } from '../../../services';
1717
import { CoreServicesContext } from '../../../components/CoreServices/CoreServices';
1818

1919
const mockWindowOpen = jest.fn();
@@ -25,6 +25,7 @@ Object.defineProperty(window, 'open', {
2525
jest.mock('../../../services', () => ({
2626
getSavedObjectsClient: jest.fn(),
2727
getNotifications: jest.fn(),
28+
getDataSourceEnabled: jest.fn(),
2829
}));
2930

3031
const mockCoreServices = {
@@ -75,6 +76,8 @@ describe('AnomalyResultsTable', () => {
7576
addDanger: jest.fn(),
7677
},
7778
});
79+
80+
(getDataSourceEnabled as jest.Mock).mockReturnValue({ enabled: false });
7881
});
7982

8083
it('shows no anomalies message when there are no anomalies', () => {
@@ -168,4 +171,30 @@ describe('AnomalyResultsTable', () => {
168171
});
169172
}
170173
});
174+
175+
describe('mds feature flag', () => {
176+
it('shows Actions column when mds is disabled', () => {
177+
(getDataSourceEnabled as jest.Mock).mockReturnValue({ enabled: false });
178+
179+
renderWithContext(<AnomalyResultsTable {...defaultProps} />);
180+
181+
const actionsColumn = screen.getByText('Actions');
182+
expect(actionsColumn).toBeInTheDocument();
183+
184+
const discoverButton = screen.getByTestId('discoverIcon');
185+
expect(discoverButton).toBeInTheDocument();
186+
});
187+
188+
it('hides Actions column when mds is enabled', () => {
189+
(getDataSourceEnabled as jest.Mock).mockReturnValue({ enabled: true });
190+
191+
renderWithContext(<AnomalyResultsTable {...defaultProps} />);
192+
193+
const actionsColumn = screen.queryByText('Actions');
194+
expect(actionsColumn).not.toBeInTheDocument();
195+
196+
const discoverButton = screen.queryByTestId('discoverIcon');
197+
expect(discoverButton).not.toBeInTheDocument();
198+
});
199+
});
171200
});

public/pages/DetectorResults/containers/AnomalyResultsTable.tsx

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import { AnomalyData } from '../../../models/interfaces';
2828
import { getTitleWithCount } from '../../../utils/utils';
2929
import { convertToCategoryFieldAndEntityString } from '../../utils/anomalyResultUtils';
3030
import { HeatmapCell } from '../../AnomalyCharts/containers/AnomalyHeatmapChart';
31-
import { getSavedObjectsClient, getNotifications } from '../../../services';
31+
import { getSavedObjectsClient, getNotifications, getDataSourceEnabled } from '../../../services';
3232

3333
//@ts-ignore
3434
const EuiBasicTable = EuiBasicTableComponent as any;
@@ -130,22 +130,31 @@ export function AnomalyResultsTable(props: AnomalyResultsTableProps) {
130130
};
131131

132132
const getCustomColumns = () => {
133+
const dataSourceEnabled = getDataSourceEnabled().enabled;
133134
const columns = [...staticColumn] as any[];
134-
const actionsColumnIndex = columns.findIndex((column: any) => column.field === 'actions');
135135

136-
if (actionsColumnIndex !== -1) {
137-
const actionsColumn = { ...columns[actionsColumnIndex] } as any;
136+
if (!dataSourceEnabled) {
137+
const actionsColumnIndex = columns.findIndex((column: any) => column.field === 'actions');
138138

139-
if (actionsColumn.actions && Array.isArray(actionsColumn.actions)) {
140-
actionsColumn.actions = [
141-
{
142-
...actionsColumn.actions[0],
143-
onClick: (item: any) => handleOpenDiscover(item.startTime, item.endTime, item),
144-
},
145-
];
139+
if (actionsColumnIndex !== -1) {
140+
const actionsColumn = { ...columns[actionsColumnIndex] } as any;
141+
142+
if (actionsColumn.actions && Array.isArray(actionsColumn.actions)) {
143+
actionsColumn.actions = [
144+
{
145+
...actionsColumn.actions[0],
146+
onClick: (item: any) => handleOpenDiscover(item.startTime, item.endTime, item),
147+
},
148+
];
149+
}
150+
151+
columns[actionsColumnIndex] = actionsColumn;
152+
}
153+
} else {
154+
const actionsColumnIndex = columns.findIndex((column: any) => column.field === 'actions');
155+
if (actionsColumnIndex !== -1) {
156+
columns.splice(actionsColumnIndex, 1);
146157
}
147-
148-
columns[actionsColumnIndex] = actionsColumn;
149158
}
150159

151160
return columns;

0 commit comments

Comments
 (0)