Skip to content

Commit

Permalink
fix(json-schema): fix typings and x-reactions.when (#2360)
Browse files Browse the repository at this point in the history
* fix(json-schemaa): fix reactions otherwise is not work

* chore: update tsconfig.json
  • Loading branch information
janryWang authored Oct 28, 2021
1 parent a218946 commit 19e8a4b
Show file tree
Hide file tree
Showing 28 changed files with 77 additions and 107 deletions.
6 changes: 1 addition & 5 deletions devtools/chrome-extension/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
"compilerOptions": {
"outDir": "./lib",
"paths": {
"@formily/*": [
"../../packages/*",
"../../designable/*",
"../../devtools/*"
]
"@formily/*": ["packages/*", "devtools/*"]
},
"declaration": true
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@
"ts-jest": "^26.0.0",
"ts-loader": "^7.0.4",
"ts-node": "^9.1.1",
"typescript": "^4.3.0",
"typescript": "^4.1.5",
"vue-eslint-parser": "^7.1.1",
"webpack": "^4.41.5",
"webpack-cli": "^3.3.10",
Expand Down
6 changes: 1 addition & 5 deletions packages/antd/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
"compilerOptions": {
"outDir": "./lib",
"paths": {
"@formily/*": [
"../../packages/*",
"../../designable/*",
"../../devtools/*"
]
"@formily/*": ["packages/*", "devtools/*"]
},
"declaration": true
}
Expand Down
6 changes: 1 addition & 5 deletions packages/benchmark/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
"compilerOptions": {
"outDir": "./lib",
"paths": {
"@formily/*": [
"../../packages/*",
"../../designable/*",
"../../devtools/*"
]
"@formily/*": ["packages/*", "devtools/*"]
},
"declaration": true
}
Expand Down
6 changes: 1 addition & 5 deletions packages/core/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
"compilerOptions": {
"outDir": "./lib",
"paths": {
"@formily/*": [
"../../packages/*",
"../../designable/*",
"../../devtools/*"
]
"@formily/*": ["packages/*", "devtools/*"]
},
"declaration": true
}
Expand Down
6 changes: 1 addition & 5 deletions packages/element/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
"compilerOptions": {
"outDir": "./lib",
"paths": {
"@formily/*": [
"../../packages/*",
"../../designable/*",
"../../devtools/*"
]
"@formily/*": ["packages/*", "devtools/*"]
},
"declaration": true
}
Expand Down
2 changes: 1 addition & 1 deletion packages/grid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"build:global": "ts-node ../../scripts/build-global"
},
"peerDependencies": {
"typescript": "^4.4.0"
"typescript": "^4.1.0"
},
"dependencies": {
"@formily/reactive": "2.0.0-rc.17"
Expand Down
6 changes: 1 addition & 5 deletions packages/grid/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
"compilerOptions": {
"outDir": "./lib",
"paths": {
"@formily/*": [
"../../packages/*",
"../../designable/*",
"../../devtools/*"
]
"@formily/*": ["packages/*", "devtools/*"]
},
"declaration": true
}
Expand Down
2 changes: 1 addition & 1 deletion packages/json-schema/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"build:global": "ts-node ../../scripts/build-global"
},
"peerDependencies": {
"typescript": "^4.4.0"
"typescript": "^4.1.5"
},
"dependencies": {
"@formily/core": "2.0.0-rc.17",
Expand Down
3 changes: 1 addition & 2 deletions packages/json-schema/src/transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { untracked, autorun, observable } from '@formily/reactive'
import {
isArr,
isStr,
isValid,
toArr,
each,
isFn,
Expand Down Expand Up @@ -189,7 +188,7 @@ const getUserReactions =
$dependencies,
}
const compiledWhen = shallowCompile(when, scope)
const condition = isValid(compiledWhen) ? compiledWhen : true
const condition = when ? compiledWhen : true
const request = condition ? fulfill : otherwise
const runner = condition ? fulfill?.run : otherwise?.run
setSchemaFieldState({
Expand Down
2 changes: 1 addition & 1 deletion packages/json-schema/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export type Stringify<P extends { [key: string]: any }> = {
/**
* Use `string & {}` instead of string to keep Literal Type for ISchema#component and ISchema#decorator
*/
[key in keyof P]?: P[key] | `{{${string}}}`
[key in keyof P]?: P[key] | string
}

export type ISchema<
Expand Down
6 changes: 1 addition & 5 deletions packages/json-schema/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
"compilerOptions": {
"outDir": "./lib",
"paths": {
"@formily/*": [
"../../packages/*",
"../../designable/*",
"../../devtools/*"
]
"@formily/*": ["packages/*", "devtools/*"]
},
"declaration": true
}
Expand Down
6 changes: 1 addition & 5 deletions packages/next/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
"compilerOptions": {
"outDir": "./lib",
"paths": {
"@formily/*": [
"../../packages/*",
"../../designable/*",
"../../devtools/*"
]
"@formily/*": ["packages/*", "devtools/*"]
},
"declaration": true
}
Expand Down
6 changes: 1 addition & 5 deletions packages/path/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
"compilerOptions": {
"outDir": "./lib",
"paths": {
"@formily/*": [
"../../packages/*",
"../../designable/*",
"../../devtools/*"
]
"@formily/*": ["packages/*", "devtools/*"]
},
"declaration": true
}
Expand Down
44 changes: 44 additions & 0 deletions packages/react/src/__tests__/schema.markup.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -802,3 +802,47 @@ test('schema x-validator/required', async () => {
])
})
})

test('schema x-reactions when undefined', async () => {
const form = createForm({
values: {
aaa: 'xxx',
},
})
const SchemaField = createSchemaField({
components: {
Input: () => <div data-testid="input"></div>,
Select: () => <div data-testid="select"></div>,
},
})

const { queryByTestId } = render(
<FormProvider form={form}>
<SchemaField>
<SchemaField.String name="input" required x-component="Input" />
<SchemaField.String
name="select"
required
x-component="Select"
x-reactions={{
when: '{{$values.input}}',
fulfill: {
state: {
visible: true,
},
},
otherwise: {
state: {
visible: false,
},
},
}}
/>
</SchemaField>
</FormProvider>
)
await waitFor(() => {
expect(queryByTestId('input')).not.toBeNull()
expect(queryByTestId('select')).toBeNull()
})
})
2 changes: 2 additions & 0 deletions packages/react/src/components/SchemaField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export function createSchemaField<Components extends SchemaReactComponents>(
}

SchemaField.displayName = 'SchemaField'

function MarkupField<
Decorator extends ReactComponentPath<Components>,
Component extends ReactComponentPath<Components>
Expand Down Expand Up @@ -195,5 +196,6 @@ export function createSchemaField<Components extends SchemaReactComponents>(
SchemaField.DateTime = DateTimeField
SchemaField.Void = VoidField
SchemaField.Number = NumberField

return SchemaField
}
3 changes: 2 additions & 1 deletion packages/react/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import React from 'react'
import {
Form,
Field as FieldType,
Expand Down Expand Up @@ -171,4 +172,4 @@ export type ISchemaTypeFieldProps<
Components extends SchemaReactComponents,
Decorator extends ReactComponentPath<Components>,
Component extends ReactComponentPath<Components>
> = Omit<ISchemaMarkupFieldProps<Components, Decorator, Component>, 'type'>
> = ISchemaMarkupFieldProps<Components, Decorator, Component>
6 changes: 1 addition & 5 deletions packages/react/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
"compilerOptions": {
"outDir": "./lib",
"paths": {
"@formily/*": [
"../../packages/*",
"../../designable/*",
"../../devtools/*"
]
"@formily/*": ["packages/*", "devtools/*"]
},
"declaration": true
}
Expand Down
6 changes: 1 addition & 5 deletions packages/reactive-react/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
"compilerOptions": {
"outDir": "./lib",
"paths": {
"@formily/*": [
"../../packages/*",
"../../designable/*",
"../../devtools/*"
]
"@formily/*": ["packages/*", "devtools/*"]
},
"declaration": true
}
Expand Down
6 changes: 1 addition & 5 deletions packages/reactive-test-cases-for-react18/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
"compilerOptions": {
"outDir": "./lib",
"paths": {
"@formily/*": [
"../../packages/*",
"../../designable/*",
"../../devtools/*"
]
"@formily/*": ["packages/*", "devtools/*"]
},
"declaration": true
}
Expand Down
6 changes: 1 addition & 5 deletions packages/reactive-vue/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
"compilerOptions": {
"outDir": "./lib",
"paths": {
"@formily/*": [
"../../packages/*",
"../../designable/*",
"../../devtools/*"
]
"@formily/*": ["packages/*", "devtools/*"]
},
"declaration": true
}
Expand Down
6 changes: 1 addition & 5 deletions packages/reactive/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
"compilerOptions": {
"outDir": "./lib",
"paths": {
"@formily/*": [
"../../packages/*",
"../../designable/*",
"../../devtools/*"
]
"@formily/*": ["packages/*", "devtools/*"]
},
"declaration": true
}
Expand Down
6 changes: 1 addition & 5 deletions packages/shared/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
"compilerOptions": {
"outDir": "./lib",
"paths": {
"@formily/*": [
"../../packages/*",
"../../designable/*",
"../../devtools/*"
]
"@formily/*": ["packages/*", "devtools/*"]
},
"declaration": true
}
Expand Down
6 changes: 1 addition & 5 deletions packages/validator/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
"compilerOptions": {
"outDir": "./lib",
"paths": {
"@formily/*": [
"../../packages/*",
"../../designable/*",
"../../devtools/*"
]
"@formily/*": ["packages/*", "devtools/*"]
},
"declaration": true
}
Expand Down
6 changes: 1 addition & 5 deletions packages/vue/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
"compilerOptions": {
"outDir": "./lib",
"paths": {
"@formily/*": [
"../../packages/*",
"../../designable/*",
"../../devtools/*"
]
"@formily/*": ["packages/*", "devtools/*"]
},
"declaration": true
}
Expand Down
6 changes: 1 addition & 5 deletions tsconfig.jest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@
"module": "commonjs",
"target": "es5",
"paths": {
"@formily/*": [
"./packages/*/src",
"./designable/*/src",
"./devtools/*/src"
]
"@formily/*": ["./packages/*/src"]
}
},
"exclude": ["./packages/*/esm", "./packages/*/lib"]
Expand Down
8 changes: 2 additions & 6 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,14 @@
"allowJs": false,
"noUnusedLocals": false,
"preserveConstEnums": true,
"sourceMap": true,
"skipLibCheck": true,
"sourceMap": true,
"declaration": true,
"experimentalDecorators": true,
"downlevelIteration": true,
"baseUrl": ".",
"paths": {
"@formily/*": [
"./packages/*/src",
"./designable/*/src",
"./devtools/*/src"
]
"@formily/*": ["packages/*/src", "devtools/*/src"]
}
}
}
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -19512,10 +19512,10 @@ typedarray@^0.0.6:
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=

typescript@^4.3.0:
version "4.4.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.4.3.tgz#bdc5407caa2b109efd4f82fe130656f977a29324"
integrity sha512-4xfscpisVgqqDfPaJo5vkd+Qd/ItkoagnHpufr+i2QCHBsNYp+G7UAoyFl8aPtx879u38wPV65rZ8qbGZijalA==
typescript@^4.1.5:
version "4.4.4"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.4.4.tgz#2cd01a1a1f160704d3101fd5a58ff0f9fcb8030c"
integrity sha512-DqGhF5IKoBl8WNf8C1gu8q0xZSInh9j1kJJMqT3a94w1JzVaBU4EXOSMrz9yDqMT0xt3selp83fuFMQ0uzv6qA==

ua-parser-js@^0.7.18:
version "0.7.28"
Expand Down

0 comments on commit 19e8a4b

Please sign in to comment.