Skip to content

Commit 00e8bb1

Browse files
authored
Fix Options types generation (#861)
1 parent a0415ad commit 00e8bb1

File tree

3 files changed

+59
-62
lines changed

3 files changed

+59
-62
lines changed

packages/devextreme-react-generator/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"author": "Developer Express Inc.",
33
"name": "devextreme-react-generator",
4-
"version": "4.1.3",
4+
"version": "4.1.4",
55
"description": "DevExtreme React UI and Visualization Components",
66
"repository": {
77
"type": "git",

packages/devextreme-react-generator/src/component-generator.test.ts

Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ import dxCLASS_NAME, {
99
1010
import { Component as BaseComponent, IHtmlOptions } from "BASE_COMPONENT_PATH";
1111
12-
type ICLASS_NAMEOptions = React.PropsWithChildren<Properties & IHtmlOptions & {
13-
}>
12+
type ICLASS_NAMEOptions = React.PropsWithChildren<Properties & IHtmlOptions>
1413
1514
class CLASS_NAME extends BaseComponent<React.PropsWithChildren<ICLASS_NAMEOptions>> {
1615
@@ -42,10 +41,13 @@ it('generates extension component', () => {
4241
// #region EXPECTED
4342
const EXPECTED = `
4443
import dxCLASS_NAME, {
45-
Properties as ICLASS_NAMEOptions
44+
Properties
4645
} from "DX/WIDGET/PATH";
4746
4847
import { ExtensionComponent as BaseComponent } from "EXTENSION_COMPONENT_PATH";
48+
import { IHtmlOptions } from "BASE_COMPONENT_PATH";
49+
50+
type ICLASS_NAMEOptions = React.PropsWithChildren<Properties & IHtmlOptions>
4951
5052
class CLASS_NAME extends BaseComponent<React.PropsWithChildren<ICLASS_NAMEOptions>> {
5153
@@ -457,8 +459,7 @@ import dxCLASS_NAME, {
457459
import { Component as BaseComponent, IHtmlOptions } from "BASE_COMPONENT_PATH";
458460
import NestedOption from "CONFIG_COMPONENT_PATH";
459461
460-
type ICLASS_NAMEOptions = React.PropsWithChildren<Properties & IHtmlOptions & {
461-
}>
462+
type ICLASS_NAMEOptions = React.PropsWithChildren<Properties & IHtmlOptions>
462463
463464
class CLASS_NAME extends BaseComponent<React.PropsWithChildren<ICLASS_NAMEOptions>> {
464465
@@ -571,8 +572,7 @@ import dxCLASS_NAME, {
571572
import { Component as BaseComponent, IHtmlOptions } from "BASE_COMPONENT_PATH";
572573
import NestedOption from "CONFIG_COMPONENT_PATH";
573574
574-
type ICLASS_NAMEOptions = React.PropsWithChildren<Properties & IHtmlOptions & {
575-
}>
575+
type ICLASS_NAMEOptions = React.PropsWithChildren<Properties & IHtmlOptions>
576576
577577
class CLASS_NAME extends BaseComponent<React.PropsWithChildren<ICLASS_NAMEOptions>> {
578578
@@ -639,8 +639,7 @@ import dxCLASS_NAME, {
639639
import { Component as BaseComponent, IHtmlOptions } from "BASE_COMPONENT_PATH";
640640
import NestedOption from "CONFIG_COMPONENT_PATH";
641641
642-
type ICLASS_NAMEOptions = React.PropsWithChildren<Properties & IHtmlOptions & {
643-
}>
642+
type ICLASS_NAMEOptions = React.PropsWithChildren<Properties & IHtmlOptions>
644643
645644
class CLASS_NAME extends BaseComponent<React.PropsWithChildren<ICLASS_NAMEOptions>> {
646645
@@ -724,8 +723,7 @@ import dxCLASS_NAME, {
724723
import { Component as BaseComponent, IHtmlOptions } from "BASE_COMPONENT_PATH";
725724
import NestedOption from "CONFIG_COMPONENT_PATH";
726725
727-
type ICLASS_NAMEOptions = React.PropsWithChildren<Properties & IHtmlOptions & {
728-
}>
726+
type ICLASS_NAMEOptions = React.PropsWithChildren<Properties & IHtmlOptions>
729727
730728
class CLASS_NAME extends BaseComponent<React.PropsWithChildren<ICLASS_NAMEOptions>> {
731729
@@ -800,8 +798,7 @@ import dxCLASS_NAME, {
800798
import { Component as BaseComponent, IHtmlOptions } from "BASE_COMPONENT_PATH";
801799
import NestedOption from "CONFIG_COMPONENT_PATH";
802800
803-
type ICLASS_NAMEOptions = React.PropsWithChildren<Properties & IHtmlOptions & {
804-
}>
801+
type ICLASS_NAMEOptions = React.PropsWithChildren<Properties & IHtmlOptions>
805802
806803
class CLASS_NAME extends BaseComponent<React.PropsWithChildren<ICLASS_NAMEOptions>> {
807804
@@ -873,8 +870,7 @@ import dxCLASS_NAME, {
873870
import { Component as BaseComponent, IHtmlOptions } from "BASE_COMPONENT_PATH";
874871
import NestedOption from "CONFIG_COMPONENT_PATH";
875872
876-
type ICLASS_NAMEOptions = React.PropsWithChildren<Properties & IHtmlOptions & {
877-
}>
873+
type ICLASS_NAMEOptions = React.PropsWithChildren<Properties & IHtmlOptions>
878874
879875
class CLASS_NAME extends BaseComponent<React.PropsWithChildren<ICLASS_NAMEOptions>> {
880876
@@ -966,8 +962,7 @@ import dxCLASS_NAME, {
966962
import * as PropTypes from "prop-types";
967963
import { Component as BaseComponent, IHtmlOptions } from "BASE_COMPONENT_PATH";
968964
969-
type ICLASS_NAMEOptions = React.PropsWithChildren<Properties & IHtmlOptions & {
970-
}>
965+
type ICLASS_NAMEOptions = React.PropsWithChildren<Properties & IHtmlOptions>
971966
972967
class CLASS_NAME extends BaseComponent<React.PropsWithChildren<ICLASS_NAMEOptions>> {
973968
@@ -1014,8 +1009,7 @@ import dxCLASS_NAME, {
10141009
import * as PropTypes from "prop-types";
10151010
import { Component as BaseComponent, IHtmlOptions } from "BASE_COMPONENT_PATH";
10161011
1017-
type ICLASS_NAMEOptions = React.PropsWithChildren<Properties & IHtmlOptions & {
1018-
}>
1012+
type ICLASS_NAMEOptions = React.PropsWithChildren<Properties & IHtmlOptions>
10191013
10201014
class CLASS_NAME extends BaseComponent<React.PropsWithChildren<ICLASS_NAMEOptions>> {
10211015
@@ -1069,8 +1063,7 @@ import dxCLASS_NAME, {
10691063
import * as PropTypes from "prop-types";
10701064
import { Component as BaseComponent, IHtmlOptions } from "BASE_COMPONENT_PATH";
10711065
1072-
type ICLASS_NAMEOptions = React.PropsWithChildren<Properties & IHtmlOptions & {
1073-
}>
1066+
type ICLASS_NAMEOptions = React.PropsWithChildren<Properties & IHtmlOptions>
10741067
10751068
class CLASS_NAME extends BaseComponent<React.PropsWithChildren<ICLASS_NAMEOptions>> {
10761069
@@ -1120,8 +1113,7 @@ import dxCLASS_NAME, {
11201113
import * as PropTypes from "prop-types";
11211114
import { Component as BaseComponent, IHtmlOptions } from "BASE_COMPONENT_PATH";
11221115
1123-
type ICLASS_NAMEOptions = React.PropsWithChildren<Properties & IHtmlOptions & {
1124-
}>
1116+
type ICLASS_NAMEOptions = React.PropsWithChildren<Properties & IHtmlOptions>
11251117
11261118
class CLASS_NAME extends BaseComponent<React.PropsWithChildren<ICLASS_NAMEOptions>> {
11271119
@@ -1171,8 +1163,7 @@ import dxCLASS_NAME, {
11711163
import * as PropTypes from "prop-types";
11721164
import { Component as BaseComponent, IHtmlOptions } from "BASE_COMPONENT_PATH";
11731165
1174-
type ICLASS_NAMEOptions = React.PropsWithChildren<Properties & IHtmlOptions & {
1175-
}>
1166+
type ICLASS_NAMEOptions = React.PropsWithChildren<Properties & IHtmlOptions>
11761167
11771168
class CLASS_NAME extends BaseComponent<React.PropsWithChildren<ICLASS_NAMEOptions>> {
11781169
@@ -1238,8 +1229,7 @@ import dxCLASS_NAME, {
12381229
12391230
import { Component as BaseComponent, IHtmlOptions } from "BASE_COMPONENT_PATH";
12401231
1241-
type ICLASS_NAMEOptions = React.PropsWithChildren<Properties & IHtmlOptions & {
1242-
}>
1232+
type ICLASS_NAMEOptions = React.PropsWithChildren<Properties & IHtmlOptions>
12431233
12441234
class CLASS_NAME extends BaseComponent<React.PropsWithChildren<ICLASS_NAMEOptions>> {
12451235
@@ -1286,8 +1276,7 @@ import dxCLASS_NAME, {
12861276
import { Component as BaseComponent, IHtmlOptions } from "BASE_COMPONENT_PATH";
12871277
import NestedOption from "CONFIG_COMPONENT_PATH";
12881278
1289-
type ICLASS_NAMEOptions = React.PropsWithChildren<Properties & IHtmlOptions & {
1290-
}>
1279+
type ICLASS_NAMEOptions = React.PropsWithChildren<Properties & IHtmlOptions>
12911280
12921281
class CLASS_NAME extends BaseComponent<React.PropsWithChildren<ICLASS_NAMEOptions>> {
12931282
@@ -1370,8 +1359,7 @@ type ICLASS_NAMEOptionsNarrowedEvents = {
13701359
onSomethingHappened?: ((e: SomethingHappenedEvent) => void);
13711360
}
13721361
1373-
type ICLASS_NAMEOptions = React.PropsWithChildren<ReplaceFieldTypes<Properties, ICLASS_NAMEOptionsNarrowedEvents> & IHtmlOptions & {
1374-
}>
1362+
type ICLASS_NAMEOptions = React.PropsWithChildren<ReplaceFieldTypes<Properties, ICLASS_NAMEOptionsNarrowedEvents> & IHtmlOptions>
13751363
13761364
class CLASS_NAME extends BaseComponent<React.PropsWithChildren<ICLASS_NAMEOptions>> {
13771365
@@ -1408,8 +1396,7 @@ import dxCLASS_NAME, {
14081396
14091397
import { Component as BaseComponent, IHtmlOptions } from "BASE_COMPONENT_PATH";
14101398
1411-
type ICLASS_NAMEOptions = React.PropsWithChildren<Properties & IHtmlOptions & {
1412-
}>
1399+
type ICLASS_NAMEOptions = React.PropsWithChildren<Properties & IHtmlOptions>
14131400
14141401
class CLASS_NAME extends BaseComponent<React.PropsWithChildren<ICLASS_NAMEOptions>> {
14151402

packages/devextreme-react-generator/src/component-generator.ts

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -215,11 +215,10 @@ const renderModule: (model: {
215215

216216
const renderImports: (model: {
217217
dxExportPath: string;
218+
htmlOptionsPath: string;
218219
baseComponentPath: string;
219220
baseComponentName: string;
220221
widgetName: string;
221-
optionsAliasName?: string;
222-
hasExtraOptions: boolean;
223222
hasPropTypings: boolean;
224223
hasExplicitTypes: boolean;
225224
configComponentPath?: string;
@@ -232,18 +231,23 @@ const renderImports: (model: {
232231
+ '<#?#>'
233232

234233
+ 'import <#= it.widgetName #>, {\n'
235-
+ ' Properties<#? it.optionsAliasName #> as <#= it.optionsAliasName #><#?#>\n'
234+
+ ' Properties\n'
236235
+ '} from "<#= it.dxExportPath #>";\n\n'
237236

238237
+ '<#? it.hasPropTypings #>'
239238
+ 'import * as PropTypes from "prop-types";\n'
240239
+ '<#?#>'
241240

242-
+ 'import { <#= it.baseComponentName #> as BaseComponent'
243-
+ '<#? it.hasExtraOptions #>'
244-
+ ', IHtmlOptions'
245-
+ '<#?#>'
246-
+ ' } from "<#= it.baseComponentPath #>";\n'
241+
+ '<#? it.htmlOptionsPath === it.baseComponentPath #>'
242+
243+
+ 'import { <#= it.baseComponentName #> as BaseComponent, IHtmlOptions } from "<#= it.baseComponentPath #>";\n'
244+
245+
+ '<#??#>'
246+
247+
+ 'import { <#= it.baseComponentName #> as BaseComponent } from "<#= it.baseComponentPath #>";\n'
248+
+ 'import { IHtmlOptions } from "<#= it.htmlOptionsPath #>";\n'
249+
250+
+ '<#?#>'
247251

248252
+ '<#? it.configComponentPath #>'
249253
+ 'import NestedOption from "<#= it.configComponentPath #>";\n'
@@ -364,27 +368,35 @@ const renderOptionsInterface: (model: {
364368
+ `type <#= it.optionsName #>NarrowedEvents${TYPE_PARAMS_WITH_DEFAULTS} = <#= it.renderedNarrowedEvents #>\n\n`
365369
+ '<#?#>'
366370

367-
+ `type <#= it.optionsName #>${TYPE_PARAMS_WITH_DEFAULTS} = React.PropsWithChildren<<#? it.renderedNarrowedEvents #>ReplaceFieldTypes<<#?#>Properties${TYPE_PARAMS}<#? it.renderedNarrowedEvents #>, <#= it.optionsName #>NarrowedEvents${TYPE_PARAMS}><#?#> & IHtmlOptions & {\n`
371+
+ `type <#= it.optionsName #>${TYPE_PARAMS_WITH_DEFAULTS} = React.PropsWithChildren<<#? it.renderedNarrowedEvents #>ReplaceFieldTypes<<#?#>Properties${TYPE_PARAMS}<#? it.renderedNarrowedEvents #>, <#= it.optionsName #>NarrowedEvents${TYPE_PARAMS}><#?#> & IHtmlOptions`
368372

369-
+ '<#? it.typeParams #>'
370-
+ ` dataSource?: Properties${TYPE_PARAMS}["dataSource"];\n`
371-
+ '<#?#>'
373+
+ '<#? it.typeParams || it.templates?.length || it.defaultProps?.length || it.onChangeEvents?.length #>'
372374

373-
+ '<#~ it.templates :template #>'
374-
+ ` <#= template.render #>?: ${TYPE_RENDER};\n`
375-
+ ` <#= template.component #>?: ${TYPE_COMPONENT};\n`
376-
+ ` <#= template.keyFn #>?: ${TYPE_KEY_FN};\n`
377-
+ '<#~#>'
375+
+ ' & {\n'
378376

379-
+ '<#~ it.defaultProps :prop #>'
380-
+ ' <#= prop.name #>?: <#= prop.type #>;\n'
381-
+ '<#~#>'
377+
+ '<#? it.typeParams #>'
378+
+ ` dataSource?: Properties${TYPE_PARAMS}["dataSource"];\n`
379+
+ '<#?#>'
382380

383-
+ '<#~ it.onChangeEvents :prop #>'
384-
+ ' <#= prop.name #>?: <#= prop.type #>;\n'
385-
+ '<#~#>'
381+
+ '<#~ it.templates :template #>'
382+
+ ` <#= template.render #>?: ${TYPE_RENDER};\n`
383+
+ ` <#= template.component #>?: ${TYPE_COMPONENT};\n`
384+
+ ` <#= template.keyFn #>?: ${TYPE_KEY_FN};\n`
385+
+ '<#~#>'
386+
387+
+ '<#~ it.defaultProps :prop #>'
388+
+ ' <#= prop.name #>?: <#= prop.type #>;\n'
389+
+ '<#~#>'
390+
391+
+ '<#~ it.onChangeEvents :prop #>'
392+
+ ' <#= prop.name #>?: <#= prop.type #>;\n'
393+
+ '<#~#>'
394+
395+
+ '}'
396+
397+
+ '<#?#>'
386398

387-
+ '}>',
399+
+ '>',
388400
);
389401

390402
const renderComponent: (model: {
@@ -607,7 +619,6 @@ function generate(
607619
}))
608620
: undefined;
609621

610-
const hasExtraOptions = !component.isExtension;
611622
const widgetName = `dx${uppercaseFirst(component.name)}`;
612623

613624
const renderedPropTypings = component.propTypings
@@ -623,13 +634,12 @@ function generate(
623634

624635
renderedImports: renderImports({
625636
dxExportPath: component.dxExportPath,
637+
htmlOptionsPath: component.baseComponentPath,
626638
baseComponentPath: component.isExtension
627639
? component.extensionComponentPath
628640
: component.baseComponentPath,
629641
baseComponentName: component.isExtension ? 'ExtensionComponent' : 'Component',
630642
widgetName,
631-
optionsAliasName: hasExtraOptions ? undefined : optionsName,
632-
hasExtraOptions,
633643
hasPropTypings: isNotEmptyArray(renderedPropTypings),
634644
hasExplicitTypes,
635645
configComponentPath: isNotEmptyArray(nestedComponents)
@@ -640,7 +650,7 @@ function generate(
640650
wildcardTypeImports,
641651
}),
642652

643-
renderedOptionsInterface: !hasExtraOptions ? undefined : renderOptionsInterface({
653+
renderedOptionsInterface: renderOptionsInterface({
644654
optionsName,
645655
defaultProps: defaultProps || [],
646656
onChangeEvents: onChangeEvents || [],

0 commit comments

Comments
 (0)