@contember/interface 2.1.0-beta.2 → 2.2.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/development/src/bootstrap/ApplicationEntrypoint.cjs.map +1 -1
- package/dist/development/src/bootstrap/ApplicationEntrypoint.js.map +1 -1
- package/dist/development/src/components/binding/RedirectOnPersist.cjs +19 -10
- package/dist/development/src/components/binding/RedirectOnPersist.cjs.map +1 -1
- package/dist/development/src/components/binding/RedirectOnPersist.js +21 -12
- package/dist/development/src/components/binding/RedirectOnPersist.js.map +1 -1
- package/dist/production/src/bootstrap/ApplicationEntrypoint.cjs.map +1 -1
- package/dist/production/src/bootstrap/ApplicationEntrypoint.js.map +1 -1
- package/dist/production/src/components/binding/RedirectOnPersist.cjs +15 -10
- package/dist/production/src/components/binding/RedirectOnPersist.cjs.map +1 -1
- package/dist/production/src/components/binding/RedirectOnPersist.js +17 -12
- package/dist/production/src/components/binding/RedirectOnPersist.js.map +1 -1
- package/dist/types/bootstrap/index.d.ts +1 -1
- package/dist/types/bootstrap/index.d.ts.map +1 -1
- package/dist/types/components/binding/RedirectOnPersist.d.ts +9 -4
- package/dist/types/components/binding/RedirectOnPersist.d.ts.map +1 -1
- package/dist/types/components/binding/index.d.ts +4 -4
- package/dist/types/components/binding/index.d.ts.map +1 -1
- package/dist/types/components/index.d.ts +1 -1
- package/dist/types/components/index.d.ts.map +1 -1
- package/dist/types/hooks/index.d.ts +2 -2
- package/dist/types/hooks/index.d.ts.map +1 -1
- package/dist/types/index.d.ts +3 -3
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +7 -7
- package/src/bootstrap/ApplicationEntrypoint.tsx +1 -1
- package/src/bootstrap/index.ts +1 -1
- package/src/components/binding/RedirectOnPersist.tsx +25 -12
- package/src/components/binding/index.ts +4 -4
- package/src/components/index.ts +1 -1
- package/src/hooks/index.ts +2 -2
- package/src/index.ts +3 -3
- package/tests/components/RedirectOnPersist.spec.tsx +47 -0
- package/tests/tsconfig.json +10 -0
- package/tsconfig.json +1 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contember/interface",
|
|
3
3
|
"license": "Apache-2.0",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.2.0-alpha.1",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"main": "./dist/production/index.js",
|
|
@@ -29,12 +29,12 @@
|
|
|
29
29
|
"ae:test": "api-extractor run"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@contember/react-binding": "2.1.0-beta.
|
|
33
|
-
"@contember/react-client": "2.1.0-beta.
|
|
34
|
-
"@contember/react-dataview": "2.1.0-beta.
|
|
35
|
-
"@contember/react-devbar": "2.1.0-beta.
|
|
36
|
-
"@contember/react-identity": "2.1.0-beta.
|
|
37
|
-
"@contember/react-routing": "2.1.0-beta.
|
|
32
|
+
"@contember/react-binding": "2.1.0-beta.2",
|
|
33
|
+
"@contember/react-client": "2.1.0-beta.2",
|
|
34
|
+
"@contember/react-dataview": "2.1.0-beta.2",
|
|
35
|
+
"@contember/react-devbar": "2.1.0-beta.2",
|
|
36
|
+
"@contember/react-identity": "2.1.0-beta.2",
|
|
37
|
+
"@contember/react-routing": "2.1.0-beta.2",
|
|
38
38
|
"@radix-ui/react-slot": "^1.2.4"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
@@ -2,7 +2,7 @@ import { Environment, EnvironmentContext, EnvironmentExtensionProvider } from '@
|
|
|
2
2
|
import { ContemberClient, ContemberClientProps } from '@contember/react-client'
|
|
3
3
|
import { ReactNode } from 'react'
|
|
4
4
|
import { RouteMap, RoutingContextValue, RoutingProvider } from '@contember/react-routing'
|
|
5
|
-
import { DataViewPageNameKeyProvider } from './DataViewPageNameKeyProvider'
|
|
5
|
+
import { DataViewPageNameKeyProvider } from './DataViewPageNameKeyProvider.js'
|
|
6
6
|
import { IdentityEnvironmentProvider, IdentityProvider, projectEnvironmentExtension } from '@contember/react-identity'
|
|
7
7
|
|
|
8
8
|
export interface ApplicationEntrypointProps extends ContemberClientProps {
|
package/src/bootstrap/index.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './ApplicationEntrypoint'
|
|
1
|
+
export * from './ApplicationEntrypoint.js'
|
|
@@ -1,14 +1,27 @@
|
|
|
1
|
-
import { useEntityPersistSuccess } from '@contember/react-binding'
|
|
2
|
-
import { RequestParameters, useRedirect } from '@contember/react-routing'
|
|
3
|
-
import { RoutingLinkTarget } from '@contember/react-routing'
|
|
1
|
+
import { Component, useEntityPersistSuccess } from '@contember/react-binding'
|
|
2
|
+
import { RequestParameters, RoutingLinkFields, RoutingLinkTarget, useRedirect } from '@contember/react-routing'
|
|
4
3
|
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
if (options.successType !== 'justSuccess') {
|
|
9
|
-
return
|
|
10
|
-
}
|
|
11
|
-
redirect(to, parameters)
|
|
12
|
-
})
|
|
13
|
-
return null
|
|
4
|
+
export interface RedirectOnPersistProps {
|
|
5
|
+
to: RoutingLinkTarget
|
|
6
|
+
parameters?: RequestParameters
|
|
14
7
|
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Redirects to the given target after a successful persist. Exposes a static
|
|
11
|
+
* render so the fields referenced by the routing target are registered during
|
|
12
|
+
* the static analysis pass, just like `Link`.
|
|
13
|
+
*/
|
|
14
|
+
export const RedirectOnPersist = Component<RedirectOnPersistProps>(
|
|
15
|
+
({ to, parameters }) => {
|
|
16
|
+
const redirect = useRedirect()
|
|
17
|
+
useEntityPersistSuccess((getEntity, options) => {
|
|
18
|
+
if (options.successType !== 'justSuccess') {
|
|
19
|
+
return
|
|
20
|
+
}
|
|
21
|
+
redirect(to, parameters)
|
|
22
|
+
})
|
|
23
|
+
return null
|
|
24
|
+
},
|
|
25
|
+
props => <RoutingLinkFields to={props.to} />,
|
|
26
|
+
'RedirectOnPersist',
|
|
27
|
+
)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from './ClearFieldTrigger'
|
|
2
|
-
export * from './DisconnectEntityTrigger'
|
|
3
|
-
export * from './EntityBeforePersist'
|
|
4
|
-
export * from './RedirectOnPersist'
|
|
1
|
+
export * from './ClearFieldTrigger.js'
|
|
2
|
+
export * from './DisconnectEntityTrigger.js'
|
|
3
|
+
export * from './EntityBeforePersist.js'
|
|
4
|
+
export * from './RedirectOnPersist.js'
|
package/src/components/index.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './binding'
|
|
1
|
+
export * from './binding/index.js'
|
package/src/hooks/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './useIsApplicationOutdated'
|
|
2
|
-
export * from './useBlockNavigationOnDirtyState'
|
|
1
|
+
export * from './useIsApplicationOutdated.js'
|
|
2
|
+
export * from './useBlockNavigationOnDirtyState.js'
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export * from './bootstrap'
|
|
2
|
-
export * from './components'
|
|
3
|
-
export * from './hooks'
|
|
1
|
+
export * from './bootstrap/index.js'
|
|
2
|
+
export * from './components/index.js'
|
|
3
|
+
export * from './hooks/index.js'
|
|
4
4
|
export * from '@contember/react-routing'
|
|
5
5
|
export * from '@contember/react-binding'
|
|
6
6
|
export * from '@contember/react-identity'
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Children, isValidElement, ReactNode } from 'react'
|
|
2
|
+
import { describe, expect, it } from 'bun:test'
|
|
3
|
+
import { Environment } from '@contember/react-binding'
|
|
4
|
+
import { RedirectOnPersist } from '../../src/components/binding/RedirectOnPersist.js'
|
|
5
|
+
|
|
6
|
+
interface StaticRenderProvider {
|
|
7
|
+
staticRender?: (props: any, environment: Environment) => ReactNode
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// Mimics the marker static-analysis pass: descend the rendered tree and
|
|
11
|
+
// recursively invoke the `staticRender` of any nested component that exposes one.
|
|
12
|
+
const collectFieldNames = (node: ReactNode, env: Environment): string[] => {
|
|
13
|
+
const fields: string[] = []
|
|
14
|
+
Children.forEach(node, child => {
|
|
15
|
+
if (!isValidElement(child)) {
|
|
16
|
+
return
|
|
17
|
+
}
|
|
18
|
+
const props = child.props as { field?: string; children?: ReactNode }
|
|
19
|
+
if (typeof props.field === 'string') {
|
|
20
|
+
fields.push(props.field)
|
|
21
|
+
}
|
|
22
|
+
const staticRender = (child.type as StaticRenderProvider | undefined)?.staticRender
|
|
23
|
+
if (typeof staticRender === 'function') {
|
|
24
|
+
fields.push(...collectFieldNames(staticRender(child.props, env), env))
|
|
25
|
+
}
|
|
26
|
+
if (props.children !== undefined) {
|
|
27
|
+
fields.push(...collectFieldNames(props.children, env))
|
|
28
|
+
}
|
|
29
|
+
})
|
|
30
|
+
return fields
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
describe('RedirectOnPersist static render', () => {
|
|
34
|
+
it('exposes a static render', () => {
|
|
35
|
+
expect(typeof (RedirectOnPersist as StaticRenderProvider).staticRender).toBe('function')
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
it('registers fields referenced by a binding routing target', () => {
|
|
39
|
+
const env = Environment.create()
|
|
40
|
+
const rendered = (RedirectOnPersist as StaticRenderProvider).staticRender!(
|
|
41
|
+
{ to: 'myPage(id: $entity.someField)' },
|
|
42
|
+
env,
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
expect(collectFieldNames(rendered, env)).toEqual(['someField'])
|
|
46
|
+
})
|
|
47
|
+
})
|