Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeScriptified basic_table. #2428

Merged
merged 82 commits into from
Dec 9, 2019
Merged
Show file tree
Hide file tree
Changes from 81 commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
ee2b251
TypeScriptify custom_item_action.
sainthkh Oct 11, 2019
250bd2b
TypeScriptify default_item_action.
sainthkh Oct 11, 2019
ea8d657
Created action_types.ts.
sainthkh Oct 11, 2019
df8a094
Added missing props in DefaultItemAction.
sainthkh Oct 11, 2019
766404b
TypeScriptify expanded_item_actions.
sainthkh Oct 11, 2019
a73bce9
TypeScriptify CollapsedItemActions.
sainthkh Oct 13, 2019
b1cbb97
TypeScriptify LoadingTableBody.
sainthkh Oct 13, 2019
6e62a2c
TypeScriptify PaginationBar.
sainthkh Oct 13, 2019
c5b0e76
TypeScriptify BasicTable.
sainthkh Oct 14, 2019
781ed0e
Removed anys.
sainthkh Oct 14, 2019
dcf83da
Removed more anys.
sainthkh Oct 14, 2019
95450c2
Removed any in item and itemId.
sainthkh Oct 14, 2019
f5565ed
TypeScriptify EuiInMemoryTable.
sainthkh Oct 15, 2019
ec27dd7
Fixed bug in PropType generation.
sainthkh Oct 15, 2019
306c70e
Clean up.
sainthkh Oct 15, 2019
06afcbf
Used Omit.
sainthkh Oct 15, 2019
9ca68f6
Thread generics throughout EuiBasicTable
pugnascotia Oct 16, 2019
d999c21
Tweaks
pugnascotia Oct 16, 2019
30fb9d2
More tweaks
pugnascotia Oct 16, 2019
049c959
Even more tweaks
pugnascotia Oct 16, 2019
3fb8714
Merge pull request #1 from pugnascotia/ts-basic-table
sainthkh Oct 16, 2019
dd1d652
Added responsive prop to EuiInMemoryTable.
sainthkh Oct 16, 2019
e7f8b89
any -> Event.
sainthkh Oct 16, 2019
d767d71
Fixed selectable test failure.
sainthkh Oct 16, 2019
e209494
Renamed prop interfaces.
sainthkh Oct 16, 2019
467bd7f
Merge upstream.
sainthkh Oct 22, 2019
cf5c203
Some typescript updates
chandlerprall Oct 23, 2019
8c29e77
ts->proptypes test for direct-usage literal values
chandlerprall Oct 24, 2019
2022116
Update: State -> CollapsedItemActionsState
sainthkh Oct 24, 2019
8533bba
Update: State -> CollapsedItemActionsState
sainthkh Oct 24, 2019
7ca9ef3
Update State -> CustomItemActionState
sainthkh Oct 24, 2019
9e6a007
Update State -> CustomItemActionState
sainthkh Oct 24, 2019
db56653
Merge remote-tracking branch 'upstream/master' into ts-basic-table
sainthkh Oct 24, 2019
fce5c12
clean up types in in_memory_table
chandlerprall Oct 28, 2019
17e967d
Merge pull request #2 from chandlerprall/ts-basic-table
sainthkh Oct 28, 2019
bc413a4
Fixed ExpandedItemActions snapshot. Because it has some props that do…
sainthkh Oct 29, 2019
45f27a1
Remove more anys.
sainthkh Oct 29, 2019
07730c4
Updated i18ntokens.json.
sainthkh Oct 29, 2019
a7dbdb6
Merge remote-tracking branch 'upstream/master' into ts-basic-table
sainthkh Nov 12, 2019
96f0e3b
TypeScriptify custom_item_action.
sainthkh Oct 11, 2019
d870291
TypeScriptify default_item_action.
sainthkh Oct 11, 2019
c0edfe3
Created action_types.ts.
sainthkh Oct 11, 2019
890a01e
Added missing props in DefaultItemAction.
sainthkh Oct 11, 2019
7b94c7c
TypeScriptify expanded_item_actions.
sainthkh Oct 11, 2019
11cac1f
TypeScriptify CollapsedItemActions.
sainthkh Oct 13, 2019
41a23b6
TypeScriptify LoadingTableBody.
sainthkh Oct 13, 2019
ae3c8a1
TypeScriptify PaginationBar.
sainthkh Oct 13, 2019
3259a1c
TypeScriptify BasicTable.
sainthkh Oct 14, 2019
1b785c7
Removed anys.
sainthkh Oct 14, 2019
ab91fa7
Removed more anys.
sainthkh Oct 14, 2019
262f1f3
Removed any in item and itemId.
sainthkh Oct 14, 2019
5bfc737
TypeScriptify EuiInMemoryTable.
sainthkh Oct 15, 2019
b6eb031
Fixed bug in PropType generation.
sainthkh Oct 15, 2019
18dc72d
Clean up.
sainthkh Oct 15, 2019
9aa27ec
Used Omit.
sainthkh Oct 15, 2019
e944eee
Thread generics throughout EuiBasicTable
pugnascotia Oct 16, 2019
7ec868f
Tweaks
pugnascotia Oct 16, 2019
b221494
More tweaks
pugnascotia Oct 16, 2019
bac79f8
Even more tweaks
pugnascotia Oct 16, 2019
927e9c0
Added responsive prop to EuiInMemoryTable.
sainthkh Oct 16, 2019
48c8a92
any -> Event.
sainthkh Oct 16, 2019
528838b
Fixed selectable test failure.
sainthkh Oct 16, 2019
8ff3883
Renamed prop interfaces.
sainthkh Oct 16, 2019
cbd291e
Some typescript updates
chandlerprall Oct 23, 2019
548a89f
ts->proptypes test for direct-usage literal values
chandlerprall Oct 24, 2019
93ec991
Update: State -> CollapsedItemActionsState
sainthkh Oct 24, 2019
572716e
Update: State -> CollapsedItemActionsState
sainthkh Oct 24, 2019
b3820d6
Update State -> CustomItemActionState
sainthkh Oct 24, 2019
65dc1b1
Update State -> CustomItemActionState
sainthkh Oct 24, 2019
82e5e54
clean up types in in_memory_table
chandlerprall Oct 28, 2019
2de08e0
Fixed ExpandedItemActions snapshot. Because it has some props that do…
sainthkh Oct 29, 2019
32c1e16
Remove more anys.
sainthkh Oct 29, 2019
75d9e32
more types
chandlerprall Nov 1, 2019
18a39b4
guarantee the page argument in table callbacks if pagination is provided
chandlerprall Nov 1, 2019
10de16e
rebased against master
chandlerprall Nov 13, 2019
2b07266
export EuiBasicTableColumn type
chandlerprall Nov 18, 2019
dda88bd
Added TD attributes to field and computed column types
chandlerprall Nov 18, 2019
21d3836
Accept string | number for EuiTableSortMobile's key
chandlerprall Nov 18, 2019
d25f49c
Merge chandlerprall/ts-basic-table into ts-basic-table.
sainthkh Nov 23, 2019
d11b1c1
Merge remote-tracking branch 'upstream/master' into ts-basic-table
sainthkh Nov 23, 2019
e3620a8
Merge branch 'master' into saintkh-ts-basic-table
chandlerprall Dec 9, 2019
8e513a3
changelog
chandlerprall Dec 9, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions scripts/babel/proptypes-from-ts-props/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,15 @@ function getPropTypesForNode(node, optional, state) {
// ^^^ Foo
case 'TSTypeAnnotation':
propType = getPropTypesForNode(node.typeAnnotation, true, state);

if (
types.isLiteral(propType) ||
(types.isIdentifier(propType) &&
propType.name === 'undefined')
) {
// can't use a literal straight, wrap it with PropTypes.oneOf([ the_literal ])
propType = convertLiteralToOneOf(types, propType);
}
break;

// Foo['bar']
Expand Down Expand Up @@ -538,7 +547,11 @@ function getPropTypesForNode(node, optional, state) {
];

let propTypeValue = typeProperty.value;
if (types.isLiteral(propTypeValue)) {
if (
types.isLiteral(propTypeValue) ||
(types.isIdentifier(propTypeValue) &&
propTypeValue.name === 'undefined')
) {
// can't use a literal straight, wrap it with PropTypes.oneOf([ the_literal ])
propTypeValue = convertLiteralToOneOf(types, propTypeValue);
}
Expand Down Expand Up @@ -628,7 +641,7 @@ function getPropTypesForNode(node, optional, state) {
// which don't translate to prop types.
.filter(property => property.key != null)
.map(property => {
const propertyPropType =
let propertyPropType =
property.type === 'TSMethodSignature'
? getPropTypesForNode(
{ type: 'TSFunctionType' },
Expand All @@ -641,6 +654,17 @@ function getPropTypesForNode(node, optional, state) {
state
);

if (
types.isLiteral(propertyPropType) ||
(types.isIdentifier(propertyPropType) &&
propertyPropType.name === 'undefined')
) {
propertyPropType = convertLiteralToOneOf(types, propertyPropType);
if (!property.optional) {
propertyPropType = makePropTypeRequired(types, propertyPropType);
}
}

const objectProperty = types.objectProperty(
types.identifier(
property.key.name || `"${property.key.value}"`
Expand Down
92 changes: 91 additions & 1 deletion scripts/babel/proptypes-from-ts-props/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,35 @@ FooComponent.propTypes = {
};`);
});

it('understands undefined & null props', () => {
const result = transform(
`
import React from 'react';
interface IFooProps {
foo: undefined;
bar: null;
bazz: undefined | null;
}
const FooComponent: React.SFC<IFooProps> = () => {
return (<div>Hello World</div>);
}`,
babelOptions
);

expect(result.code).toBe(`import React from 'react';
import PropTypes from "prop-types";

const FooComponent = () => {
return <div>Hello World</div>;
};

FooComponent.propTypes = {
foo: PropTypes.oneOf([undefined]).isRequired,
bar: PropTypes.oneOf([null]).isRequired,
bazz: PropTypes.oneOf([undefined, null]).isRequired
};`);
});

it('understands function props', () => {
const result = transform(
`
Expand Down Expand Up @@ -224,6 +253,33 @@ FooComponent.propTypes = {
};`);
});

it('understands literal values as a type', () => {
const result = transform(
`
import React from 'react';
interface IFooProps {
foo: 'bar';
bazz?: 5;
}
const FooComponent: React.SFC<IFooProps> = () => {
return (<div>Hello World</div>);
}`,
babelOptions
);

expect(result.code).toBe(`import React from 'react';
import PropTypes from "prop-types";

const FooComponent = () => {
return <div>Hello World</div>;
};

FooComponent.propTypes = {
foo: PropTypes.oneOf(["bar"]).isRequired,
bazz: PropTypes.oneOf([5])
};`);
});

});

describe('function propTypes', () => {
Expand Down Expand Up @@ -1117,7 +1173,7 @@ const FooComponent = () => {
};

FooComponent.propTypes = {
type: PropTypes.oneOfType([PropTypes.oneOf(["foo"]), PropTypes.oneOf(["bar"])]),
type: PropTypes.oneOfType([PropTypes.oneOf(["foo"]).isRequired, PropTypes.oneOf(["bar"]).isRequired]).isRequired,
value: PropTypes.oneOfType([PropTypes.string.isRequired, PropTypes.number.isRequired]).isRequired
};`);
});
Expand Down Expand Up @@ -1479,6 +1535,40 @@ FooComponent.propTypes = {
};`);
});

it('understands discriminated unions', () => {
const result = transform(
`
import React from 'react'
interface OptA { type: 'a'; value: string; }
interface OptB { type: 'b'; valid: boolean; }
type Option = OptA | OptB;
interface Props { option: Option }
const Foo: React.SFC<Props> = ({ option }: Props) => {
return (<div>{option.type == 'a' ? option.value : option.valid}</div>);
}`,
babelOptions
);

expect(result.code).toBe(`import React from 'react';
import PropTypes from "prop-types";

const Foo = ({
option
}) => {
return <div>{option.type == 'a' ? option.value : option.valid}</div>;
};

Foo.propTypes = {
option: PropTypes.oneOfType([PropTypes.shape({
type: PropTypes.oneOf(["a"]).isRequired,
value: PropTypes.string.isRequired
}).isRequired, PropTypes.shape({
type: PropTypes.oneOf(["b"]).isRequired,
valid: PropTypes.bool.isRequired
}).isRequired]).isRequired
};`);
});

it('understands an optional Array of strings and numbers', () => {
const result = transform(
`
Expand Down
22 changes: 11 additions & 11 deletions src-docs/src/i18ntokens.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"column": 14
}
},
"filepath": "src/components/basic_table/basic_table.js"
"filepath": "src/components/basic_table/basic_table.tsx"
},
{
"token": "euiBasicTable.selectAllRows",
Expand All @@ -29,7 +29,7 @@
"column": 77
}
},
"filepath": "src/components/basic_table/basic_table.js"
"filepath": "src/components/basic_table/basic_table.tsx"
},
{
"token": "euiBasicTable.selectThisRow",
Expand All @@ -45,39 +45,39 @@
"column": 79
}
},
"filepath": "src/components/basic_table/basic_table.js"
"filepath": "src/components/basic_table/basic_table.tsx"
},
{
"token": "euiCollapsedItemActions.allActions",
"defString": "All actions",
"highlighting": "string",
"loc": {
"start": {
"line": 107,
"line": 148,
"column": 6
},
"end": {
"line": 107,
"line": 148,
"column": 80
}
},
"filepath": "src/components/basic_table/collapsed_item_actions.js"
"filepath": "src/components/basic_table/collapsed_item_actions.tsx"
},
{
"token": "euiCollapsedItemActions.allActions",
"defString": "All actions",
"highlighting": "string",
"loc": {
"start": {
"line": 124,
"line": 165,
"column": 6
},
"end": {
"line": 124,
"line": 165,
"column": 80
}
},
"filepath": "src/components/basic_table/collapsed_item_actions.js"
"filepath": "src/components/basic_table/collapsed_item_actions.tsx"
},
{
"token": "euiBottomBar.screenReaderAnnouncement",
Expand Down Expand Up @@ -1685,11 +1685,11 @@
"highlighting": "string",
"loc": {
"start": {
"line": 49,
"line": 60,
"column": 8
},
"end": {
"line": 49,
"line": 60,
"column": 72
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ exports[`EuiBasicTable empty renders a node as a custom message 1`] = `
<p>
no items, click
<a
href={true}
href=""
>
here
</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

exports[`CustomItemAction render 1`] = `
<div
style={null}
className="test"
>
<Component
<span
onBlur={[Function]}
onFocus={[Function]}
/>
>
test
</span>
</div>
`;
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`DefaultItemAction render - default button 1`] = `
<EuiToolTip
content="action 1"
delay="long"
position="top"
>
<EuiButtonEmpty
color="primary"
flush="right"
isDisabled={false}
onClick={[Function]}
size="s"
>
action1
</EuiButtonEmpty>
</EuiToolTip>
`;

exports[`DefaultItemAction render - button 1`] = `
<EuiToolTip
content="action 1"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`ExpandedItemActions render 1`] = `
Array [
<Fragment>
<DefaultItemAction
action={
Object {
Expand All @@ -12,15 +12,13 @@ Array [
}
className=""
enabled={true}
index={0}
item={
Object {
"id": "xyz",
}
}
itemId="xyz"
key="item_action_xyz_0"
/>,
/>
<CustomItemAction
action={
Object {
Expand All @@ -37,8 +35,7 @@ Array [
"id": "xyz",
}
}
itemId="xyz"
key="item_action_xyz_1"
/>,
]
/>
</Fragment>
`;
Loading