Skip to content

Commit

Permalink
Merge branch 'main' into select-id
Browse files Browse the repository at this point in the history
  • Loading branch information
GermanVor authored May 24, 2024
2 parents 186ac34 + e35ce8b commit f2b0ae3
Show file tree
Hide file tree
Showing 14 changed files with 225 additions and 128 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"jsx-a11y/no-autofocus": "off",
"import/no-extraneous-dependencies": "off",
"import/consistent-type-specifier-style": ["error", "prefer-top-level"],
"@typescript-eslint/prefer-ts-expect-error": "error",
"@typescript-eslint/consistent-type-imports": ["error", {"prefer": "type-imports", "fixStyle": "separate-type-imports"}]
},
"overrides": [
Expand Down
2 changes: 1 addition & 1 deletion CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
/src/components/Hotkey @d3m1d0v
/src/components/Icon @amje
/src/components/Label @goshander
/src/components/Link @LakeVostok
/src/components/Link @Estasie
/src/components/List @korvin89
/src/components/Loader @SeqviriouM
/src/components/Menu @NikitaCG
Expand Down
2 changes: 1 addition & 1 deletion src/components/Disclosure/Disclosure.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export interface DisclosureProps extends QAProps {

const isDisclosureSummaryComponent = isOfType(DisclosureSummary);

// @ts-ignore this ts-error is appears when forwarding ref. It complains that DisclosureComposition props is not provided initially
// @ts-expect-error this ts-error is appears when forwarding ref. It complains that DisclosureComposition props is not provided initially
export const Disclosure: React.FunctionComponent<DisclosureProps> & DisclosureComposition =
React.forwardRef<HTMLDivElement, DisclosureProps>(function Disclosure(props, ref) {
const {
Expand Down
85 changes: 85 additions & 0 deletions src/components/Pagination/__tests__/Pagination.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import React from 'react';

import {noop} from 'lodash';

import {render, screen} from '../../../../test-utils/utils';
import {Pagination} from '../Pagination';
import {PaginationQa, getPaginationPageQa} from '../constants';

describe('Pagination component', () => {
test('Single page', () => {
render(<Pagination pageSize={20} total={20} onUpdate={noop} page={0} />);

const firstButton = screen.getByTestId(PaginationQa.PaginationButtonFirst);
expect(firstButton).toBeDisabled();

const prevButton = screen.getByTestId(PaginationQa.PaginationButtonPrevious);
expect(prevButton).toBeDisabled();

const nextButton = screen.getByTestId(PaginationQa.PaginationButtonNext);
expect(nextButton).toBeDisabled();
});

describe('Two pages', () => {
const PAGE_SIZE = 20;
const TOTAL = PAGE_SIZE + 1;

const FIRST_PAGE = 1;
const SECOND_PAGE = 2;

test('First page is current', () => {
render(
<Pagination pageSize={PAGE_SIZE} total={TOTAL} onUpdate={noop} page={FIRST_PAGE} />,
);

const firstPageButton = screen.getByTestId(getPaginationPageQa(FIRST_PAGE));
expect(firstPageButton).toHaveAttribute('aria-pressed', 'true');

const secondPageButton = screen.getByTestId(getPaginationPageQa(SECOND_PAGE));
expect(secondPageButton).toHaveAttribute('aria-pressed', 'false');

const firstButton = screen.getByTestId(PaginationQa.PaginationButtonFirst);
expect(firstButton).toBeDisabled();

const prevButton = screen.getByTestId(PaginationQa.PaginationButtonPrevious);
expect(prevButton).toBeDisabled();

const nextButton = screen.getByTestId(PaginationQa.PaginationButtonNext);
expect(nextButton).not.toBeDisabled();
});

test('Second page is current', () => {
render(
<Pagination
pageSize={PAGE_SIZE}
total={TOTAL}
onUpdate={noop}
page={SECOND_PAGE}
/>,
);

const firstPageButton = screen.getByTestId(getPaginationPageQa(FIRST_PAGE));
expect(firstPageButton).toHaveAttribute('aria-pressed', 'false');

const secondPageButton = screen.getByTestId(getPaginationPageQa(SECOND_PAGE));
expect(secondPageButton).toHaveAttribute('aria-pressed', 'true');

const firstButton = screen.getByTestId(PaginationQa.PaginationButtonFirst);
expect(firstButton).not.toBeDisabled();

const prevButton = screen.getByTestId(PaginationQa.PaginationButtonPrevious);
expect(prevButton).not.toBeDisabled();

const nextButton = screen.getByTestId(PaginationQa.PaginationButtonNext);
expect(nextButton).toBeDisabled();
});
});

test('Total property undefined', () => {
render(<Pagination pageSize={20} onUpdate={noop} page={0} total={undefined} />);

const nextButton = screen.getByTestId(PaginationQa.PaginationButtonNext);

expect(nextButton).not.toBeDisabled();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';

import {Button} from '../../../Button';
import {block} from '../../../utils/cn';
import {PaginationQa} from '../../constants';
import {getPaginationPageQa} from '../../constants';
import type {PageItem, PaginationProps, PaginationSize} from '../../types';

import './PaginationPage.scss';
Expand All @@ -18,7 +18,7 @@ type Props = {
};

export const PaginationPage = ({item, size, pageSize, className, onUpdate}: Props) => {
const qa = `${PaginationQa.PaginationPage}-${item.page}`;
const qa = getPaginationPageQa(item.page);
if (item.simple) {
return (
<div data-qa={qa} className={b('simple', {size}, className)}>
Expand Down
4 changes: 4 additions & 0 deletions src/components/Pagination/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ export const PaginationQa = {
PaginationButtonPrevious: 'pagination-button-previous',
PaginationButtonNext: 'pagination-button-next',
};

export const getPaginationPageQa = (pageNumber: number) => {
return `${PaginationQa.PaginationPage}-${pageNumber}`;
};
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,8 @@ describe('withTableSettings', () => {
);
expect(osSettings).toBeDefined();
expect(osxSettings).toBeDefined();
// @ts-ignore
expect(osSettings.isSelected).toBe(true);
// @ts-ignore
expect(osxSettings.isSelected).toBe(false);
expect(osSettings?.isSelected).toBe(true);
expect(osxSettings?.isSelected).toBe(false);
});

it('should return columns when no settings provided', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ export function withTableActions<I extends TableDataItem, E extends {} = {}>(

return (item: I, index: number, event: React.MouseEvent<HTMLTableRowElement>) => {
if (
// @ts-ignore
// @ts-expect-error
event.nativeEvent.target.matches(
`.${actionsButtonCn}, .${actionsButtonCn} *`,
)
Expand Down
2 changes: 1 addition & 1 deletion src/components/Table/hoc/withTableCopy/withTableCopy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export function withTableCopy<I extends TableDataItem, E extends {} = {}>(
return (item: I, index: number, event: React.MouseEvent<HTMLTableRowElement>) => {
const buttonClassName = b('copy-button');
if (
// @ts-ignore
// @ts-expect-error
event.nativeEvent.target.matches(
`.${buttonClassName}, .${buttonClassName} *`,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export function withTableSelection<I extends TableDataItem, E extends {} = {}>(
event: React.ChangeEvent<HTMLInputElement>,
) => {
const {checked} = event.target;
// @ts-ignore shiftKey is defined for click events
// @ts-expect-error shiftKey is defined for click events
const isShiftPressed = event.nativeEvent.shiftKey;
const {data, selectedIds, onSelectionChange} = this.props;

Expand Down Expand Up @@ -191,7 +191,7 @@ export function withTableSelection<I extends TableDataItem, E extends {} = {}>(
return (item: I, index: number, event: React.MouseEvent<HTMLTableRowElement>) => {
const checkboxClassName = b('selection-checkbox');
if (
// @ts-ignore
// @ts-expect-error
event.nativeEvent.target.matches(
`.${checkboxClassName}, .${checkboxClassName} *`,
)
Expand Down
8 changes: 6 additions & 2 deletions src/components/layout/Flex/Flex.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,10 @@ type FlexPropsWithTypedAttrs<T extends React.ElementType> = FlexProps<T> &
* ---
* Storybook - https://preview.gravity-ui.com/uikit/?path=/docs/layout--playground#flex
*/
export const Flex = function Flex<T extends React.ElementType = 'div'>(props: FlexProps<T>) {
export const Flex = React.forwardRef(function Flex<T extends React.ElementType = 'div'>(
props: FlexProps<T>,
ref: FlexRef<T>,
) {
const {
as: propsAs,
direction,
Expand Down Expand Up @@ -187,6 +190,7 @@ export const Flex = function Flex<T extends React.ElementType = 'div'>(props: Fl
},
className,
)}
ref={ref}
style={{
flexDirection: applyMediaProps(direction),
flexGrow: grow === true ? 1 : grow,
Expand All @@ -213,6 +217,6 @@ export const Flex = function Flex<T extends React.ElementType = 'div'>(props: Fl
: children}
</Box>
);
} as (<C extends React.ElementType = 'div'>(
}) as (<C extends React.ElementType = 'div'>(
props: FlexPropsWithTypedAttrs<C> & {ref?: FlexRef<C>},
) => React.ReactElement) & {displayName: string};
2 changes: 1 addition & 1 deletion src/components/layout/demo/ColPresenter/ColPresenter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {Col} from '../../Col/Col';
import type {ColProps} from '../../Col/Col';
import {Box} from '../Box/Box';

// @ts-ignore-error
// @ts-expect-error
const pickSizeProps = <T extends {}>({l, xl, s, m, xxl, xxxl, size}: T = {}): string => {
// skip empty values
return Object.entries({...{l, xl, s, m, xxl, xxxl, size}})
Expand Down
Loading

0 comments on commit f2b0ae3

Please sign in to comment.