From 62e116f1bd579b88c9ee3779fb340bf157f2e057 Mon Sep 17 00:00:00 2001 From: Frits Stegmann Date: Mon, 28 Aug 2023 15:06:21 +0200 Subject: [PATCH] fix: make the requestForEffect optional --- .npmrc | 1 - packages/core/package.json | 2 +- .../TrixtaInteractionComponent.tsx | 4 +-- .../TrixtaReactionComponent.tsx | 2 +- .../TrixtaReactionResponseComponent.tsx | 2 +- .../use-trixta-reaction.ts | 2 +- .../core/src/React/reducers/trixtaReducer.ts | 1 + .../src/React/selectors/trixtaReactions.ts | 35 +++++++++++++------ packages/rjsf/package.json | 3 +- packages/rjsf/rollup.dev.config.js | 2 +- tsconfig.json | 20 +++-------- yarn.lock | 8 ++--- 12 files changed, 43 insertions(+), 39 deletions(-) diff --git a/.npmrc b/.npmrc index 0c3d7461..e69de29b 100644 --- a/.npmrc +++ b/.npmrc @@ -1 +0,0 @@ -workspaces-update false diff --git a/packages/core/package.json b/packages/core/package.json index bc4bf678..5f8e7f7a 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -157,7 +157,7 @@ "@testing-library/jest-dom": "^5.13.0", "@testing-library/react": "^11.2.7", "@testing-library/react-hooks": "^7.0.0", - "@trixtateam/phoenix-to-redux": "1.1.1", + "@trixtateam/phoenix-to-redux": "1.2.0", "@types/debug": "4.1.5", "@types/jest": "^26.0.20", "@types/json-schema": "^7.0.4", diff --git a/packages/core/src/React/components/interactions/TrixtaInteractionComponent/TrixtaInteractionComponent.tsx b/packages/core/src/React/components/interactions/TrixtaInteractionComponent/TrixtaInteractionComponent.tsx index 0cfb24c1..bc2f726a 100644 --- a/packages/core/src/React/components/interactions/TrixtaInteractionComponent/TrixtaInteractionComponent.tsx +++ b/packages/core/src/React/components/interactions/TrixtaInteractionComponent/TrixtaInteractionComponent.tsx @@ -28,8 +28,8 @@ function TrixtaInteractionComponent({ debugMode = false, instances, ...rest -}: // eslint-disable-next-line @typescript-eslint/no-explicit-any -ConnectProps & TrixtaInteractionComponentProps) { +}: + ConnectProps & TrixtaInteractionComponentProps) { if (!hasRoleAccess) return null; if (isNullOrEmpty(common)) return null; if (isNullOrEmpty(instances) || !Array.isArray(instances)) { diff --git a/packages/core/src/React/components/reactions/TrixtaReactionComponent/TrixtaReactionComponent.tsx b/packages/core/src/React/components/reactions/TrixtaReactionComponent/TrixtaReactionComponent.tsx index cd130e4b..81907bbd 100644 --- a/packages/core/src/React/components/reactions/TrixtaReactionComponent/TrixtaReactionComponent.tsx +++ b/packages/core/src/React/components/reactions/TrixtaReactionComponent/TrixtaReactionComponent.tsx @@ -20,7 +20,7 @@ function TrixtaReactionComponent({ roleName, reactionName, defaultComponent, - requestForEffect = false, + requestForEffect, includeResponse = false, errorEvent, responseEvent, diff --git a/packages/core/src/React/components/reactions/TrixtaReactionResponseComponent/TrixtaReactionResponseComponent.tsx b/packages/core/src/React/components/reactions/TrixtaReactionResponseComponent/TrixtaReactionResponseComponent.tsx index 88c5b849..60df03f2 100644 --- a/packages/core/src/React/components/reactions/TrixtaReactionResponseComponent/TrixtaReactionResponseComponent.tsx +++ b/packages/core/src/React/components/reactions/TrixtaReactionResponseComponent/TrixtaReactionResponseComponent.tsx @@ -20,7 +20,7 @@ function TrixtaReactionResponseComponent({ roleName, reactionName, defaultComponent, - requestForEffect = false, + requestForEffect, errorEvent, responseEvent, requestEvent, diff --git a/packages/core/src/React/hooks/use-trixta-reaction/use-trixta-reaction.ts b/packages/core/src/React/hooks/use-trixta-reaction/use-trixta-reaction.ts index 0923b625..446279a4 100644 --- a/packages/core/src/React/hooks/use-trixta-reaction/use-trixta-reaction.ts +++ b/packages/core/src/React/hooks/use-trixta-reaction/use-trixta-reaction.ts @@ -44,7 +44,7 @@ export const useTrixtaReaction = < >({ roleName, reactionName, - requestForEffect = false, + requestForEffect, debugMode = false, loadingStatusRef, onSuccess, diff --git a/packages/core/src/React/reducers/trixtaReducer.ts b/packages/core/src/React/reducers/trixtaReducer.ts index b3df41ae..74f66815 100644 --- a/packages/core/src/React/reducers/trixtaReducer.ts +++ b/packages/core/src/React/reducers/trixtaReducer.ts @@ -443,6 +443,7 @@ export const trixtaReducer = ( { const reactionDetails = action.payload.trixtaReaction; const keyName = action.payload.keyName; + if (!state.reactions[keyName]) { draft.reactions[keyName] = getTrixtaReactionReducerStructure({ details: reactionDetails, diff --git a/packages/core/src/React/selectors/trixtaReactions.ts b/packages/core/src/React/selectors/trixtaReactions.ts index 7624cef8..73966eff 100644 --- a/packages/core/src/React/selectors/trixtaReactions.ts +++ b/packages/core/src/React/selectors/trixtaReactions.ts @@ -199,6 +199,28 @@ export const selectTrixtaReactionResponseInstance = ( ][props.instanceIndex] : undefined; +function getInstanceList( + selectedReaction: TrixtaReaction | undefined, + requestForEffect: boolean | undefined, +) { + if (requestForEffect) { + return selectedReaction + ? selectedReaction?.instances[ + requestForEffect ? 'requestForEffect' : 'requestForResponse' + ] + : []; + } else { + if (!selectedReaction?.instances) { + return []; + } + if (selectedReaction?.instances['requestForEffect'].length > 0) { + return selectedReaction?.instances['requestForEffect']; + } else { + return selectedReaction?.instances['requestForResponse']; + } + } +} + /** * Selects the reactions[props.roleName:props.reactionName].instances * for the given props.roleName , props.reactionName and returns the reaction instances for requestForEffect or requestForResponse @@ -216,13 +238,8 @@ export const makeSelectTrixtaReactionResponseInstancesForRole = (): OutputParame > => createSelector( [selectTrixtaReactionStateSelector, selectTrixtaReactionTypeProp], - (selectedReaction, requestForEffect) => { - return selectedReaction - ? selectedReaction?.instances[ - requestForEffect ? 'requestForEffect' : 'requestForResponse' - ] - : []; - }, + (selectedReaction, requestForEffect) => + getInstanceList(selectedReaction, requestForEffect), ); /** @@ -248,9 +265,7 @@ export const makesSelectTrixtaReactionResponseInstance = (): OutputParametricSel selectTrixtaReactionInstanceIndexProp, ], (selectedReaction, requestForEffect, instanceIndex) => { - return selectedReaction?.instances[ - requestForEffect ? 'requestForEffect' : 'requestForResponse' - ][instanceIndex]; + return getInstanceList(selectedReaction, requestForEffect)[instanceIndex]; }, ); diff --git a/packages/rjsf/package.json b/packages/rjsf/package.json index 91a564e9..73f48db5 100644 --- a/packages/rjsf/package.json +++ b/packages/rjsf/package.json @@ -119,6 +119,7 @@ "react-redux": ">=7.2.1", "redux": "~4.1.2", "redux-saga": ">=1.2.1", + "@trixtateam/trixta-js-core": "2.0.0-alpha.1", "reselect": "~4.0.0" }, "dependencies": { @@ -160,7 +161,7 @@ "@testing-library/jest-dom": "^5.13.0", "@testing-library/react": "^11.2.7", "@testing-library/react-hooks": "^7.0.0", - "@trixtateam/phoenix-to-redux": "1.1.1", + "@trixtateam/phoenix-to-redux": "1.2.0", "@trixtateam/trixta-js-core": "2.0.0-alpha.1", "@types/debug": "4.1.5", "@types/jest": "^26.0.20", diff --git a/packages/rjsf/rollup.dev.config.js b/packages/rjsf/rollup.dev.config.js index a7092fed..107381d2 100644 --- a/packages/rjsf/rollup.dev.config.js +++ b/packages/rjsf/rollup.dev.config.js @@ -53,7 +53,7 @@ export default { dest: config.parsed.DEST_NODE_MODULES_FOLDER, }, ], - hook: 'closeBundle', + hook: 'buildEnd', }), ], }; diff --git a/tsconfig.json b/tsconfig.json index 7f9f9a4e..31026ae5 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -13,11 +13,7 @@ "jsx": "react", "noEmit": true, "target": "ESNext", - "lib": [ - "DOM", - "DOM.Iterable", - "ESNext" - ], + "lib": ["DOM", "DOM.Iterable", "ESNext"], "allowJs": true, "checkJs": false, // typecheck js files "noImplicitAny": true, @@ -33,19 +29,11 @@ "suppressImplicitAnyIndexErrors": true, "resolveJsonModule": true, "noFallthroughCasesInSwitch": true, - "types": [ - "jest", - "@testing-library/jest-dom", - "node" - ], + "types": ["jest", "@testing-library/jest-dom", "node"], "typeRoots": [ - "node_modules/@types" - ] + "node_modules/@types"] }, - "include": [ - "packages/*/src", - "packages/stories" - ], + "include": ["packages/*/src", "packages/stories"], "exclude": [ "node_modules", "packages/*/node_modules", diff --git a/yarn.lock b/yarn.lock index 98c8db1b..43fcde97 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4993,10 +4993,10 @@ resolved "https://registry.yarnpkg.com/@tootallnate/once/-/once-2.0.0.tgz#f544a148d3ab35801c1f633a7441fd87c2e484bf" integrity sha512-XCuKFP5PS55gnMVu3dty8KPatLqUoy/ZYzDzAGCQ8JNFCkLXzmI7vNHCR+XpbZaMWQK/vQubr7PkYq8g470J/A== -"@trixtateam/phoenix-to-redux@1.1.1": - version "1.1.1" - resolved "https://registry.yarnpkg.com/@trixtateam/phoenix-to-redux/-/phoenix-to-redux-1.1.1.tgz#06556b077c7f42c43a037d77c72075738c3dd017" - integrity sha512-7GDFo+EVJxzlMSNbsSF7qx+f3OgXaTaCZKiqZFp4GJVUuPuGlUAz+PEL7TwogW1nSU5GTcuaZYCyp1a2KMJ8vg== +"@trixtateam/phoenix-to-redux@1.2.0": + version "1.2.0" + resolved "https://registry.yarnpkg.com/@trixtateam/phoenix-to-redux/-/phoenix-to-redux-1.2.0.tgz#ad0a1479c435fa5fdc665843eb9d1672a15bc18b" + integrity sha512-sa7eQuYy0+PBIWfMOuTXz/QacZQdAjh5Waxl06jt7BwNlIyXojkeDGDqXIcqfMXcrjSctVH/kDZydgxOvrjpAA== dependencies: immer "~9.0.6" phoenix "~1.5.9"