-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(datagrid): Rewrite QualityIndicator in typescript (#4003)
* chore(datagrid): Boot rtl config & continue ts migration * review
- Loading branch information
Showing
25 changed files
with
117 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@talend/react-datagrid': minor | ||
--- | ||
|
||
- Boot rtl config | ||
- Rewrite QualityIndicator in typescript |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,5 @@ node_modules | |
|
||
**/*.stories.js | ||
packages/design-tokens/supernova-exporter | ||
**/jest.setup.js | ||
**/jest.config.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
const defaults = require('@talend/scripts-config-jest/jest.config.js'); | ||
|
||
module.exports = { | ||
...defaults, | ||
setupFilesAfterEnv: [...defaults.setupFilesAfterEnv, './jest.setup.js'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// DS is mocked by ui-scripts, preventing us to use testing-library getByLabelText & others selectors | ||
jest.unmock('@talend/design-system'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 0 additions & 35 deletions
35
packages/datagrid/src/components/DefaultCellRenderer/QualityIndicator.component.js
This file was deleted.
Oops, something went wrong.
34 changes: 34 additions & 0 deletions
34
packages/datagrid/src/components/DefaultCellRenderer/QualityIndicator.component.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import React from 'react'; | ||
import classNames from 'classnames'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
import { QUALITY_INVALID_KEY } from '../../constants'; | ||
|
||
import theme from './QualityIndicator.scss'; | ||
import { Quality } from '../../types'; | ||
|
||
export interface QualityIndicatorProps { | ||
qualityIndex: keyof Quality; | ||
} | ||
|
||
function QualityIndicator({ qualityIndex }: QualityIndicatorProps): JSX.Element | null { | ||
const { t } = useTranslation(); | ||
|
||
if (qualityIndex !== QUALITY_INVALID_KEY) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<div | ||
className={classNames( | ||
theme['td-cell-quality-indicator'], | ||
// required for hover styling by parent | ||
'td-cell-quality-indicator', | ||
theme['td-cell-quality-indicator--invalid'], | ||
)} | ||
title={t('QUALITY_INDICATOR_INVALID_VALUE', 'Invalid value')} | ||
/> | ||
); | ||
} | ||
|
||
export default QualityIndicator; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 5 additions & 5 deletions
10
...aultCellRenderer/QualityIndicator.test.js → ...ultCellRenderer/QualityIndicator.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import { render, screen } from '@testing-library/react'; | ||
|
||
import QualityIndicator from './QualityIndicator.component'; | ||
import { QUALITY_INVALID_KEY, QUALITY_VALID_KEY } from '../../constants'; | ||
|
||
describe('#QualityIndicator', () => { | ||
it('should render when quality index is QUALITY_INVALID_KEY', () => { | ||
const wrapper = shallow(<QualityIndicator qualityIndex={QUALITY_INVALID_KEY} />); | ||
render(<QualityIndicator qualityIndex={QUALITY_INVALID_KEY} />); | ||
|
||
expect(wrapper.getElement()).toMatchSnapshot(); | ||
expect(screen.getByTitle('Invalid value')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should not render when quality index is different of QUALITY_INVALID_KEY', () => { | ||
const wrapper = shallow(<QualityIndicator qualityIndex={QUALITY_VALID_KEY} />); | ||
render(<QualityIndicator qualityIndex={QUALITY_VALID_KEY} />); | ||
|
||
expect(wrapper.getElement()).toMatchSnapshot(); | ||
expect(screen.queryByTitle('Invalid value')).not.toBeInTheDocument(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 0 additions & 10 deletions
10
...s/datagrid/src/components/DefaultCellRenderer/__snapshots__/QualityIndicator.test.js.snap
This file was deleted.
Oops, something went wrong.
18 changes: 0 additions & 18 deletions
18
packages/datagrid/src/components/DefaultPinHeaderRenderer/PinHeaderRenderer.component.tsx
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
packages/datagrid/src/components/DefaultPinHeaderRenderer/PinHeaderRenderer.test.js
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
...grid/src/components/DefaultPinHeaderRenderer/__snapshots__/PinHeaderRenderer.test.js.snap
This file was deleted.
Oops, something went wrong.
6 changes: 0 additions & 6 deletions
6
packages/datagrid/src/components/DefaultPinHeaderRenderer/index.ts
This file was deleted.
Oops, something went wrong.
15 changes: 15 additions & 0 deletions
15
packages/datagrid/src/components/PinHeaderRenderer/PinHeaderRenderer.component.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import React from 'react'; | ||
import { ButtonIcon } from '@talend/design-system'; | ||
import theme from './PinHeaderRenderer.scss'; | ||
|
||
export const PIN_HEADER_RENDERER_COMPONENT = 'pinHeaderRenderer'; | ||
|
||
export type PinHeaderRendererProps = Omit<Parameters<typeof ButtonIcon>[0], 'size' | 'icon'>; | ||
|
||
export default function PinHeaderRenderer(props: PinHeaderRendererProps): JSX.Element { | ||
return ( | ||
<div className={theme['td-pin-header']}> | ||
<ButtonIcon icon="talend-ellipsis" size="S" {...props} /> | ||
</div> | ||
); | ||
} |
File renamed without changes.
17 changes: 17 additions & 0 deletions
17
packages/datagrid/src/components/PinHeaderRenderer/PinHeaderRenderer.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import React from 'react'; | ||
import { fireEvent, render, screen } from '@testing-library/react'; | ||
|
||
import DefaultPinHeaderRenderer from './PinHeaderRenderer.component'; | ||
|
||
describe('PinHeader', () => { | ||
it('should render', () => { | ||
const onClick = jest.fn(); | ||
render(<DefaultPinHeaderRenderer onClick={onClick}>My menu</DefaultPinHeaderRenderer>); | ||
|
||
fireEvent.mouseEnter(screen.getByRole('button')); | ||
expect(screen.getByRole('tooltip')).toBeInTheDocument(); | ||
|
||
fireEvent.click(screen.getByRole('button')); | ||
expect(onClick).toHaveBeenCalled(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default, PIN_HEADER_RENDERER_COMPONENT } from './PinHeaderRenderer.component'; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,7 @@ | ||
const NAMESPACE_INDEX = 'index.'; | ||
const NAMESPACE_DATA = 'data.'; | ||
const COLUMN_INDEX = 'index'; | ||
const QUALITY_KEY = '@talend-quality@'; | ||
const QUALITY_INVALID_KEY = -1; | ||
const QUALITY_EMPTY_KEY = 0; | ||
const QUALITY_VALID_KEY = 1; | ||
|
||
export { | ||
NAMESPACE_INDEX, | ||
NAMESPACE_DATA, | ||
COLUMN_INDEX, | ||
QUALITY_KEY, | ||
QUALITY_INVALID_KEY, | ||
QUALITY_EMPTY_KEY, | ||
QUALITY_VALID_KEY, | ||
}; | ||
export const NAMESPACE_INDEX = 'index.'; | ||
export const NAMESPACE_DATA = 'data.'; | ||
export const COLUMN_INDEX = 'index'; | ||
export const QUALITY_KEY = '@talend-quality@'; | ||
export const QUALITY_INVALID_KEY = -1; | ||
export const QUALITY_EMPTY_KEY = 0; | ||
export const QUALITY_VALID_KEY = 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,2 @@ | ||
import { | ||
NAMESPACE_INDEX, | ||
NAMESPACE_DATA, | ||
COLUMN_INDEX, | ||
QUALITY_KEY, | ||
QUALITY_INVALID_KEY, | ||
QUALITY_EMPTY_KEY, | ||
QUALITY_VALID_KEY, | ||
} from './datagrid.constants'; | ||
import { AVRO_TYPES, LOGICAL_TYPES } from './avro-type.constant'; | ||
|
||
export { | ||
NAMESPACE_INDEX, | ||
NAMESPACE_DATA, | ||
COLUMN_INDEX, | ||
QUALITY_KEY, | ||
QUALITY_INVALID_KEY, | ||
QUALITY_EMPTY_KEY, | ||
QUALITY_VALID_KEY, | ||
AVRO_TYPES, | ||
LOGICAL_TYPES, | ||
}; | ||
export * from './datagrid.constants'; | ||
export { AVRO_TYPES, LOGICAL_TYPES } from './avro-type.constant'; |
8 changes: 4 additions & 4 deletions
8
packages/datagrid/src/index.js → packages/datagrid/src/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import * as constants from './constants'; | ||
import DataGrid, * as components from './components'; | ||
|
||
DataGrid.constants = constants; | ||
DataGrid.components = components; | ||
|
||
export default DataGrid; | ||
export default Object.assign(DataGrid, { | ||
constants, | ||
components, | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { QUALITY_EMPTY_KEY, QUALITY_INVALID_KEY, QUALITY_VALID_KEY } from '../constants'; | ||
|
||
export interface QualityEntry { | ||
percentage: number; | ||
total: number; | ||
} | ||
|
||
export interface Quality { | ||
[QUALITY_INVALID_KEY]: QualityEntry; | ||
[QUALITY_EMPTY_KEY]: QualityEntry; | ||
[QUALITY_VALID_KEY]: QualityEntry; | ||
} |