Skip to content

Commit

Permalink
Update with lint rules
Browse files Browse the repository at this point in the history
  • Loading branch information
asimonok committed Nov 23, 2023
1 parent c0d04d9 commit ba4fa06
Show file tree
Hide file tree
Showing 37 changed files with 286 additions and 270 deletions.
4 changes: 2 additions & 2 deletions cypress/integration/01-view-panel.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { e2e } from '@grafana/e2e';
import { TestIds } from '../../src/constants';
import { TEST_IDS } from '../../src/constants';

/**
* Dashboard
Expand Down Expand Up @@ -29,7 +29,7 @@ describe('Viewing an Variable panel', () => {
/**
* Root
*/
const chart = currentPanel.find(getTestIdSelector(TestIds.tableView.root));
const chart = currentPanel.find(getTestIdSelector(TEST_IDS.tableView.root));
chart.should('be.visible');

/**
Expand Down
23 changes: 19 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"@grafana/ui": "^10.2.1",
"@tanstack/react-table": "8.9.3",
"@tanstack/react-virtual": "3.0.0-beta.60",
"@volkovlabs/components": "^1.1.0",
"react": "^18.2.0",
"react-beautiful-dnd": "^13.1.1",
"react-dom": "^18.2.0",
Expand All @@ -29,7 +30,7 @@
"@types/node": "^18.18.10",
"@types/react-beautiful-dnd": "^13.1.7",
"@typescript-eslint/eslint-plugin": "^6.11.0",
"@volkovlabs/eslint-config": "^1.1.0",
"@volkovlabs/eslint-config": "^1.2.1",
"@volkovlabs/jest-selectors": "^1.2.0",
"copy-webpack-plugin": "^11.0.0",
"css-loader": "^6.8.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { GrafanaTheme2 } from '@grafana/data';
/**
* Styles
*/
export const Styles = (theme: GrafanaTheme2) => {
export const getStyles = (theme: GrafanaTheme2) => {
return {
root: css`
display: flex;
Expand Down
12 changes: 6 additions & 6 deletions src/components/ButtonView/ButtonView.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { fireEvent, render, screen } from '@testing-library/react';
import { getJestSelectors } from '@volkovlabs/jest-selectors';
import React from 'react';

import { AllValue, AllValueParameter, TestIds } from '../../constants';
import { ALL_VALUE, ALL_VALUE_PARAMETER, TEST_IDS } from '../../constants';
import { useRuntimeVariables } from '../../hooks';
import { VariableType } from '../../types';
import { selectVariableValues } from '../../utils';
Expand Down Expand Up @@ -36,7 +36,7 @@ describe('ButtonView', () => {
/**
* Selectors
*/
const getSelectors = getJestSelectors(TestIds.buttonView);
const getSelectors = getJestSelectors(TEST_IDS.buttonView);
const selectors = getSelectors(screen);

/**
Expand Down Expand Up @@ -77,8 +77,8 @@ describe('ButtonView', () => {
type: VariableType.CUSTOM,
options: [
{
text: AllValue,
value: AllValueParameter,
text: ALL_VALUE,
value: ALL_VALUE_PARAMETER,
selected: false,
},
{
Expand Down Expand Up @@ -164,7 +164,7 @@ describe('ButtonView', () => {
})
);

expect(selectors.item(false, AllValue)).toBeInTheDocument();
expect(selectors.item(false, ALL_VALUE)).toBeInTheDocument();
expect(selectors.item(false, 'device1')).toBeInTheDocument();
expect(selectors.item(false, 'device2')).toBeInTheDocument();
});
Expand Down Expand Up @@ -207,7 +207,7 @@ describe('ButtonView', () => {
/**
* All should be selected
*/
expect(selectVariableValues).toHaveBeenCalledWith([AllValueParameter], variable);
expect(selectVariableValues).toHaveBeenCalledWith([ALL_VALUE_PARAMETER], variable);
});

it('Should work if no status color', () => {
Expand Down
16 changes: 8 additions & 8 deletions src/components/ButtonView/ButtonView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { EventBus, PanelData } from '@grafana/data';
import { Alert, Button, useStyles2, useTheme2 } from '@grafana/ui';
import React, { useMemo } from 'react';

import { AllValue, AllValueParameter, TestIds } from '../../constants';
import { ALL_VALUE, ALL_VALUE_PARAMETER, TEST_IDS } from '../../constants';
import { useRuntimeVariables, useStatus } from '../../hooks';
import { PanelOptions } from '../../types';
import { isVariableWithOptions, updateVariableOptions } from '../../utils';
import { Styles } from './styles';
import { getStyles } from './ButtonView.styles';

/**
* Properties
Expand Down Expand Up @@ -40,7 +40,7 @@ export const ButtonView: React.FC<Props> = ({
/**
* Styles and Theme
*/
const styles = useStyles2(Styles);
const styles = useStyles2(getStyles);
const theme = useTheme2();

/**
Expand Down Expand Up @@ -68,7 +68,7 @@ export const ButtonView: React.FC<Props> = ({
*/
if (!variable) {
return (
<Alert severity="info" title="Variable" data-testid={TestIds.buttonView.noVariableMessage}>
<Alert severity="info" title="Variable" data-testid={TEST_IDS.buttonView.noVariableMessage}>
Variable is not selected.
</Alert>
);
Expand All @@ -80,7 +80,7 @@ export const ButtonView: React.FC<Props> = ({
const options = isVariableWithOptions(variable) && variable.options.length;
if (!options) {
return (
<Alert severity="info" title="Variable" data-testid={TestIds.buttonView.noOptionsMessage}>
<Alert severity="info" title="Variable" data-testid={TEST_IDS.buttonView.noOptionsMessage}>
Options are not available.
</Alert>
);
Expand All @@ -94,10 +94,10 @@ export const ButtonView: React.FC<Props> = ({
padding: ${padding}px;
`
)}
data-testid={TestIds.buttonView.root}
data-testid={TEST_IDS.buttonView.root}
>
{variable.options.map((option) => {
const value = option.value === AllValueParameter ? AllValue : option.value;
const value = option.value === ALL_VALUE_PARAMETER ? ALL_VALUE : option.value;
const status = getStatus(value);
const backgroundColor = option.selected
? status.exist
Expand Down Expand Up @@ -132,7 +132,7 @@ export const ButtonView: React.FC<Props> = ({
value,
});
}}
data-testid={TestIds.buttonView.item(value)}
data-testid={TEST_IDS.buttonView.item(value)}
>
{option.text.toString()}
</Button>
Expand Down
4 changes: 2 additions & 2 deletions src/components/Collapse/Collapse.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { IconButton, useTheme2 } from '@grafana/ui';
import React from 'react';

import { Styles } from './styles';
import { getStyles } from './styles';

/**
* Properties
Expand Down Expand Up @@ -59,7 +59,7 @@ export const Collapse: React.FC<Props> = ({
* Styles and Theme
*/
const theme = useTheme2();
const styles = Styles(theme);
const styles = getStyles(theme);

return (
<div className={styles.root}>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Collapse/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { GrafanaTheme2 } from '@grafana/data';
/**
* Styles
*/
export const Styles = (theme: GrafanaTheme2) => {
export const getStyles = (theme: GrafanaTheme2) => {
return {
root: css`
border: 1px solid ${theme.colors.border.weak};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { GrafanaTheme2 } from '@grafana/data';
/**
* Styles
*/
export const Styles = (theme: GrafanaTheme2) => {
export const getStyles = (theme: GrafanaTheme2) => {
return {
newGroup: css`
margin: ${theme.spacing(2)} 0;
Expand Down
10 changes: 5 additions & 5 deletions src/components/GroupsEditor/GroupsEditor.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { getJestSelectors } from '@volkovlabs/jest-selectors';
import React from 'react';
import { DragDropContext, DropResult } from 'react-beautiful-dnd';

import { TestIds } from '../../constants';
import { TEST_IDS } from '../../constants';
import { LevelsEditor } from '../LevelsEditor';
import { GroupsEditor } from './GroupsEditor';

Expand Down Expand Up @@ -32,7 +32,7 @@ jest.mock('@grafana/ui', () => ({
* Mock LevelsEditor
*/
jest.mock('../LevelsEditor', () => ({
LevelsEditor: jest.fn(() => <div data-testid={TestIds.levelsEditor.root} />),
LevelsEditor: jest.fn(() => <div data-testid={TEST_IDS.levelsEditor.root} />),
}));

/**
Expand Down Expand Up @@ -94,15 +94,15 @@ describe('GroupsEditor', () => {
* Selectors
*/
const getSelectors = getJestSelectors({
...TestIds.groupsEditor,
...TEST_IDS.groupsEditor,
...InTestIds,
});
const selectors = getSelectors(screen);

/**
* Levels Selectors
*/
const getLevelsSelectors = getJestSelectors(TestIds.levelsEditor);
const getLevelsSelectors = getJestSelectors(TEST_IDS.levelsEditor);
const levelsSelectors = getLevelsSelectors(screen);

it('Should render groups', () => {
Expand Down Expand Up @@ -677,7 +677,7 @@ describe('GroupsEditor', () => {
const onChange = jest.fn();

jest.mocked(LevelsEditor).mockImplementation(({ name, onChange }) => (
<div data-testid={TestIds.levelsEditor.root}>
<div data-testid={TEST_IDS.levelsEditor.root}>
<button
data-testid={InTestIds.buttonLevelsUpdate}
onClick={() =>
Expand Down
24 changes: 12 additions & 12 deletions src/components/GroupsEditor/GroupsEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import {
NotDraggingStyle,
} from 'react-beautiful-dnd';

import { TestIds } from '../../constants';
import { TEST_IDS } from '../../constants';
import { LevelsGroup, PanelOptions } from '../../types';
import { reorder } from '../../utils';
import { Collapse } from '../Collapse';
import { LevelsEditor } from '../LevelsEditor';
import { Styles } from './styles';
import { getStyles } from './GroupsEditor.styles';

/**
* Properties
Expand All @@ -42,7 +42,7 @@ export const GroupsEditor: React.FC<Props> = ({ context: { options, data }, onCh
* Styles and Theme
*/
const theme = useTheme2();
const styles = Styles(theme);
const styles = getStyles(theme);

/**
* States
Expand Down Expand Up @@ -199,7 +199,7 @@ export const GroupsEditor: React.FC<Props> = ({ context: { options, data }, onCh
onCancelEdit();
}
}}
data-testid={TestIds.groupsEditor.fieldName}
data-testid={TEST_IDS.groupsEditor.fieldName}
/>
</InlineField>
<Button
Expand All @@ -209,7 +209,7 @@ export const GroupsEditor: React.FC<Props> = ({ context: { options, data }, onCh
icon="times"
size="sm"
onClick={onCancelEdit}
data-testid={TestIds.groupsEditor.buttonCancelRename}
data-testid={TEST_IDS.groupsEditor.buttonCancelRename}
/>
<Button
variant="secondary"
Expand All @@ -222,14 +222,14 @@ export const GroupsEditor: React.FC<Props> = ({ context: { options, data }, onCh
tooltip={
isUpdatedNameValid ? '' : 'Name is empty or group with the same name already exists.'
}
data-testid={TestIds.groupsEditor.buttonSaveRename}
data-testid={TEST_IDS.groupsEditor.buttonSaveRename}
/>
</div>
) : (
<div className={cx(styles.groupHeader, styles.groupHeaderText)}>{name}</div>
)
}
headerTestId={TestIds.groupsEditor.item(name)}
headerTestId={TEST_IDS.groupsEditor.item(name)}
actions={
<>
{editItem !== name && (
Expand All @@ -246,7 +246,7 @@ export const GroupsEditor: React.FC<Props> = ({ context: { options, data }, onCh
setEditName(name);
setEditItem(name);
}}
data-testid={TestIds.groupsEditor.buttonStartRename}
data-testid={TEST_IDS.groupsEditor.buttonStartRename}
/>
)}
<Button
Expand All @@ -261,7 +261,7 @@ export const GroupsEditor: React.FC<Props> = ({ context: { options, data }, onCh
*/
onChangeItems(items.filter((item) => item.name !== name));
}}
data-testid={TestIds.groupsEditor.buttonRemove}
data-testid={TEST_IDS.groupsEditor.buttonRemove}
/>
<Icon name="draggabledots" {...provided.dragHandleProps} className={styles.dragIcon} />
</>
Expand All @@ -281,7 +281,7 @@ export const GroupsEditor: React.FC<Props> = ({ context: { options, data }, onCh
</Droppable>
</DragDropContext>

<InlineFieldRow className={styles.newGroup} data-testid={TestIds.groupsEditor.newItem}>
<InlineFieldRow className={styles.newGroup} data-testid={TEST_IDS.groupsEditor.newItem}>
<InlineField
label="New Group"
grow={true}
Expand All @@ -292,15 +292,15 @@ export const GroupsEditor: React.FC<Props> = ({ context: { options, data }, onCh
placeholder="Unique name"
value={newGroup}
onChange={(event) => setNewGroup(event.currentTarget.value)}
data-testid={TestIds.groupsEditor.newItemName}
data-testid={TEST_IDS.groupsEditor.newItemName}
/>
</InlineField>
<Button
icon="plus"
title="Add Group"
disabled={!newGroup || isNameExistsError}
onClick={onAddNewGroup}
data-testid={TestIds.groupsEditor.buttonAddNew}
data-testid={TEST_IDS.groupsEditor.buttonAddNew}
>
Add
</Button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { GrafanaTheme2 } from '@grafana/data';
/**
* Styles
*/
export const Styles = (theme: GrafanaTheme2) => {
export const getStyles = (theme: GrafanaTheme2) => {
return {
header: css`
padding: ${theme.spacing(0.5, 0.5)};
Expand Down
Loading

0 comments on commit ba4fa06

Please sign in to comment.