Skip to content

Commit 71ba6d3

Browse files
authored
Add flow lib defs to repository (#5)
1 parent 879e27f commit 71ba6d3

File tree

5 files changed

+150
-2
lines changed

5 files changed

+150
-2
lines changed

.flowconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Default flow options are good for most use cases, so this is left blank.
22
[ignore]
33
.*/example/.*
4+
.*/flow-libdef/.*
45

56
[include]
67

@@ -19,7 +20,6 @@ module.file_ext=.js
1920
.*/node_modules/react-select/.*
2021
.*/node_modules/react-jss/.*
2122
.*/node_modules/react-beautiful-dnd/.*
22-
.*/node_modules/@ginkgo-bioworks/react-json-schema-form-builder/.*
2323

2424
[version]
2525
0.92.1

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ coverage
1111
dist
1212
example/build
1313

14-
.DS-store
14+
.DS_Store
1515

1616
npm-debug.log*

CONTRIBUTING.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ In this repository, the source code for the component library is in the `src` di
1414

1515
The example app being run on the [GitHub Pages site](https://ginkgobioworks.github.io/react-json-schema-form-builder/), meanwhile, has its code stored in the `example` directory. It relies on an additional set of dependencies, which are stored in the `devDependencies` within the `package.json` file.
1616

17+
Library definitions for [Flow type annotations](https://flow.org/en/docs/types/) are stored in `src/flowlibdefs`, where the file structure under the `flow-typed` [best practices](https://github.com/flow-typed/flow-typed/blob/master/CONTRIBUTING.md) are followed. If any of the types in `src/formBuilder/types.js` are changed, or if the properties of the `FormBuilder` or `PredefinedGallery` are altered, then these flow typed library definitions should also be changed. This library definition is altered manually, and is currently set for major version 1 of the Form Builder. To update to library definition a PR must be made on the [flow-typed repository](https://github.com/flow-typed/flow-typed).
18+
1719
## Testing
1820

1921
The `src` directory also contains testing files written for the [jest](https://jestjs.io/en/) test harness. The tests use [Enzyme](https://github.com/enzymejs/enzyme) for component and DOM manipulation and traversal. These tests are run in the CI/CD pipeline, and must pass before a branch can be merged into the 'main' branch. Changes may be needed to the test harness to accommodate new features or fixes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
declare module '@ginkgo-bioworks/react-json-schema-form-builder' {
2+
declare type CardProps = {
3+
name: string,
4+
required: boolean,
5+
dataOptions: { [string]: any },
6+
uiOptions: { [string]: any },
7+
$ref?: string,
8+
dependents?: Array<{
9+
children: Array<string>,
10+
value?: any,
11+
}>,
12+
dependent?: boolean,
13+
parent?: string,
14+
propType: string,
15+
neighborNames: Array<string>,
16+
};
17+
18+
declare type SectionProps = {
19+
name: string,
20+
required: boolean,
21+
schema: { [string]: any },
22+
uischema: { [string]: any },
23+
$ref?: string,
24+
dependents?: Array<{
25+
children: Array<string>,
26+
value?: any,
27+
}>,
28+
dependent?: boolean,
29+
propType: string,
30+
neighborNames: Array<string>,
31+
};
32+
33+
declare type ElementProps = CardProps & SectionProps;
34+
35+
declare type Parameters = {
36+
[string]: string | number | boolean | Array<string | number>,
37+
name: string,
38+
path: string,
39+
definitionData: { [string]: any },
40+
definitionUi: { [string]: any },
41+
category: string,
42+
'ui:option': { [string]: any },
43+
};
44+
45+
declare type DataType =
46+
| 'string'
47+
| 'number'
48+
| 'boolean'
49+
| 'integer'
50+
| 'array'
51+
| '*'
52+
| null;
53+
54+
declare type MatchType = {
55+
types: Array<DataType>,
56+
widget?: string,
57+
field?: string,
58+
format?: string,
59+
$ref?: boolean,
60+
enum?: boolean,
61+
};
62+
63+
declare type FormInput = {
64+
displayName: string,
65+
// given a data and ui schema, determine if the object is of this input type
66+
matchIf: Array<MatchType>,
67+
// allowed keys for ui:options
68+
possibleOptions?: Array<string>,
69+
defaultDataSchema: {
70+
[string]: any,
71+
},
72+
defaultUiSchema: {
73+
[string]: any,
74+
},
75+
// the data schema type
76+
type: DataType,
77+
// inputs on the preview card
78+
cardBody: React.AbstractComponent<{
79+
parameters: Parameters,
80+
onChange: (newParams: Parameters) => void,
81+
mods: { [string]: any },
82+
}>,
83+
// inputs for the modal
84+
modalBody?: React.AbstractComponent<{
85+
parameters: Parameters,
86+
onChange: (newParams: Parameters) => void,
87+
}>,
88+
};
89+
90+
// optional properties that can add custom features to the form builder
91+
declare type Mods = {
92+
customFormInputs?: {
93+
[string]: FormInput,
94+
},
95+
tooltipDescriptions?: {
96+
add?: string,
97+
cardObjectName?: string,
98+
cardDisplayName?: string,
99+
cardDescription?: string,
100+
cardInputType?: string,
101+
},
102+
};
103+
104+
declare type FormBuilderProps = {
105+
schema: string,
106+
uischema: string,
107+
onChange: (string, string) => any,
108+
mods?: Mods,
109+
className?: string,
110+
};
111+
112+
declare export class FormBuilder extends React$Component<FormBuilderProps> {
113+
static defaultProps: FormBuilderProps;
114+
}
115+
116+
declare export class PredefinedGallery
117+
extends React$Component<FormBuilderProps> {
118+
static defaultProps: FormBuilderProps;
119+
}
120+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// @flow
2+
3+
import React from 'react';
4+
import {
5+
FormBuilder,
6+
PredefinedGallery,
7+
} from '@ginkgo-bioworks/react-json-schema-form-builder';
8+
import { it, describe, expect } from 'flow-typed-test';
9+
import { mount } from 'enzyme';
10+
11+
describe('@ginkgo-bioworks/react-json-schema-form-builder', () => {
12+
const props = {
13+
schema: '',
14+
uischema: '',
15+
onChange: (newSchema, newUiSchema) => {},
16+
};
17+
it('render form builder', () => {
18+
const wrapper = mount(<FormBuilder {...props} />);
19+
expect(wrapper.exists('.form-body')).toBeTruthy();
20+
});
21+
22+
it('render predefined gallery', () => {
23+
const wrapper = mount(<PredefinedGallery {...props} />);
24+
expect(wrapper.exists('.form_gallery_container')).toBeTruthy();
25+
});
26+
});

0 commit comments

Comments
 (0)