@beinformed/ui 1.25.4 → 1.25.6

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.
Files changed (46) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/esm/hooks/useModularUIBasic.js +4 -1
  3. package/esm/hooks/useModularUIBasic.js.map +1 -1
  4. package/esm/hooks/useModularUIModel.js +9 -1
  5. package/esm/hooks/useModularUIModel.js.map +1 -1
  6. package/esm/hooks/useModularUIRequest.js +7 -5
  7. package/esm/hooks/useModularUIRequest.js.map +1 -1
  8. package/esm/modularui/ModularUIRequest.js +19 -2
  9. package/esm/modularui/ModularUIRequest.js.map +1 -1
  10. package/esm/redux/_modularui/ModularUIActions.js +2 -0
  11. package/esm/redux/_modularui/ModularUIActions.js.map +1 -1
  12. package/esm/redux/_modularui/ModularUIMiddleware.js +1 -0
  13. package/esm/redux/_modularui/ModularUIMiddleware.js.map +1 -1
  14. package/esm/redux/_modularui/types.js.map +1 -1
  15. package/esm/utils/fetch/types.js.map +1 -1
  16. package/lib/hooks/useModularUIBasic.js +4 -1
  17. package/lib/hooks/useModularUIBasic.js.flow +8 -1
  18. package/lib/hooks/useModularUIBasic.js.map +1 -1
  19. package/lib/hooks/useModularUIModel.js +11 -2
  20. package/lib/hooks/useModularUIModel.js.flow +9 -0
  21. package/lib/hooks/useModularUIModel.js.map +1 -1
  22. package/lib/hooks/useModularUIRequest.js +7 -5
  23. package/lib/hooks/useModularUIRequest.js.flow +10 -11
  24. package/lib/hooks/useModularUIRequest.js.map +1 -1
  25. package/lib/modularui/ModularUIRequest.js +19 -2
  26. package/lib/modularui/ModularUIRequest.js.flow +21 -3
  27. package/lib/modularui/ModularUIRequest.js.map +1 -1
  28. package/lib/redux/_modularui/ModularUIActions.js +2 -0
  29. package/lib/redux/_modularui/ModularUIActions.js.flow +2 -0
  30. package/lib/redux/_modularui/ModularUIActions.js.map +1 -1
  31. package/lib/redux/_modularui/ModularUIMiddleware.js +1 -0
  32. package/lib/redux/_modularui/ModularUIMiddleware.js.flow +2 -0
  33. package/lib/redux/_modularui/ModularUIMiddleware.js.map +1 -1
  34. package/lib/redux/_modularui/types.js.flow +1 -0
  35. package/lib/redux/_modularui/types.js.map +1 -1
  36. package/lib/utils/fetch/types.js.flow +1 -1
  37. package/lib/utils/fetch/types.js.map +1 -1
  38. package/package.json +2 -2
  39. package/src/hooks/useModularUIBasic.js +8 -1
  40. package/src/hooks/useModularUIModel.js +9 -0
  41. package/src/hooks/useModularUIRequest.js +10 -11
  42. package/src/modularui/ModularUIRequest.js +21 -3
  43. package/src/redux/_modularui/ModularUIActions.js +2 -0
  44. package/src/redux/_modularui/ModularUIMiddleware.js +2 -0
  45. package/src/redux/_modularui/types.js +1 -0
  46. package/src/utils/fetch/types.js +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"ModularUIMiddleware.js","names":["createRequest","modularui","request","ModularUIRequest","href","method","HTTP_METHODS","GET","data","locale","childmodels","isReload","targetModel","responseHandler","next","dispatch","successAction","model","successResult","then","result","catch","error","handleError","Error","finishProgress","errorHandler","errorAction","err","errorResult","handleFetch","action","startProgress","requestOptions","payload","modularuiRequest","fetch","modularUIMiddleware","api","type","getState","i18n"],"sources":["../../../src/redux/_modularui/ModularUIMiddleware.js"],"sourcesContent":["// @flow\nimport ModularUIRequest from \"../../modularui/ModularUIRequest\";\nimport { HTTP_METHODS } from \"../../constants/Constants\";\n\nimport { startProgress, finishProgress } from \"../actions/ProgressIndicator\";\n\nimport { handleError } from \"../actions/Error\";\n\nimport type { Middleware, MiddlewareAPI } from \"redux\";\nimport type {\n ReduxAction,\n ReduxState,\n Dispatch,\n PossibleAction,\n} from \"../types\";\nimport type { ModularUIModel } from \"../../models/types\";\nimport type Href from \"../../models/href/Href\";\nimport type { ModularUIAction, SuccessAction, ErrorAction } from \"./types\";\nimport type { TargetModel } from \"../../modularui/types\";\n\ntype RequestOptions = {\n href: Href,\n method?: $Keys<typeof HTTP_METHODS>,\n data?: string | { [key: string]: string },\n locale: string,\n childmodels?: boolean,\n targetModel?: TargetModel,\n isReload?: boolean,\n};\n\n/**\n * Symbol key that carries API call info interpreted by this Redux middleware.\n */\nconst createRequest = (modularui: RequestOptions): ModularUIRequest => {\n const request = new ModularUIRequest(modularui.href, {\n method: modularui.method || HTTP_METHODS.GET,\n data: modularui.data || {},\n locale: modularui.locale,\n childmodels: modularui.childmodels ?? true,\n isReload: modularui.isReload,\n });\n\n if (modularui.targetModel) {\n request.targetModel = modularui.targetModel;\n }\n\n return request;\n};\n\n/**\n */\nconst responseHandler = (\n next: Dispatch,\n dispatch: Dispatch,\n successAction: SuccessAction,\n model: ModularUIModel\n) => {\n if (successAction) {\n const successResult = successAction(model);\n\n if (successResult instanceof Promise) {\n successResult\n .then((result) => {\n dispatch(result);\n })\n .catch((error) => {\n next(handleError(error));\n });\n } else {\n try {\n dispatch(successResult);\n } catch (error) {\n throw new Error(\n `Result of successResult is not a valid redux action: ${error}`\n );\n }\n }\n }\n\n return next(finishProgress());\n};\n\n/**\n */\nconst errorHandler = (\n next: Dispatch,\n dispatch: Dispatch,\n errorAction: ?ErrorAction,\n err: any\n) => {\n dispatch(finishProgress());\n\n if (errorAction) {\n const errorResult = errorAction(err);\n\n if (errorResult instanceof Promise) {\n errorResult.then((result) => dispatch(result));\n } else {\n dispatch(errorResult);\n }\n }\n\n return next(handleError(err));\n};\n\n/**\n */\nconst handleFetch = (\n action: ModularUIAction,\n locale: string,\n dispatch: Dispatch,\n next: Dispatch\n) => {\n dispatch(startProgress());\n\n const { successAction, errorAction, ...requestOptions } = action.payload;\n requestOptions.locale = locale;\n\n const modularuiRequest = createRequest(requestOptions);\n\n return modularuiRequest\n .fetch()\n .then((model) => responseHandler(next, dispatch, successAction, model))\n .catch((error) => errorHandler(next, dispatch, errorAction, error));\n};\n\n/**\n */\nexport const modularUIMiddleware: Middleware<\n ReduxState,\n ReduxAction,\n Dispatch\n> =\n (api: MiddlewareAPI<ReduxState, ReduxAction, Dispatch>) =>\n (next: Dispatch) =>\n (action: PossibleAction) => {\n if (action.type === \"MODULARUI/FETCH\") {\n return handleFetch(\n // $FlowExpectedError[incompatible-exact]\n action,\n api.getState().i18n.locale,\n api.dispatch,\n next\n );\n }\n\n return next(action);\n };\n"],"mappings":";;;;;;;;AACA;AACA;AAEA;AAEA;AAwBA;AACA;AACA;AACA,MAAMA,aAAa,GAAIC,SAAyB,IAAuB;EACrE,MAAMC,OAAO,GAAG,IAAIC,yBAAgB,CAACF,SAAS,CAACG,IAAI,EAAE;IACnDC,MAAM,EAAEJ,SAAS,CAACI,MAAM,IAAIC,uBAAY,CAACC,GAAG;IAC5CC,IAAI,EAAEP,SAAS,CAACO,IAAI,IAAI,CAAC,CAAC;IAC1BC,MAAM,EAAER,SAAS,CAACQ,MAAM;IACxBC,WAAW,EAAET,SAAS,CAACS,WAAW,IAAI,IAAI;IAC1CC,QAAQ,EAAEV,SAAS,CAACU;EACtB,CAAC,CAAC;EAEF,IAAIV,SAAS,CAACW,WAAW,EAAE;IACzBV,OAAO,CAACU,WAAW,GAAGX,SAAS,CAACW,WAAW;EAC7C;EAEA,OAAOV,OAAO;AAChB,CAAC;;AAED;AACA;AACA,MAAMW,eAAe,GAAG,CACtBC,IAAc,EACdC,QAAkB,EAClBC,aAA4B,EAC5BC,KAAqB,KAClB;EACH,IAAID,aAAa,EAAE;IACjB,MAAME,aAAa,GAAGF,aAAa,CAACC,KAAK,CAAC;IAE1C,IAAIC,aAAa,4BAAmB,EAAE;MACpCA,aAAa,CACVC,IAAI,CAAEC,MAAM,IAAK;QAChBL,QAAQ,CAACK,MAAM,CAAC;MAClB,CAAC,CAAC,CACDC,KAAK,CAAEC,KAAK,IAAK;QAChBR,IAAI,CAAC,IAAAS,kBAAW,EAACD,KAAK,CAAC,CAAC;MAC1B,CAAC,CAAC;IACN,CAAC,MAAM;MACL,IAAI;QACFP,QAAQ,CAACG,aAAa,CAAC;MACzB,CAAC,CAAC,OAAOI,KAAK,EAAE;QACd,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AqD,IACrDxB,IAAc,IACdiB,MAAsB,IAAK;EAC1B,IAAIA,MAAM,CAACQ,IAAI,KAAK,iBAAiB,EAAE;IACrC,OAAOT,WAAW;IAChB;IACAC,MAAM,EACNO,GAAG,CAACE,QAAQ,EAAE,CAACC,IAAI,CAAChC,MAAM,EAC1B6B,GAAG,CAACvB,QAAQ,EACZD,IAAI,CACL;EACH;EAEA,OAAOA,IAAI,CAACiB,MAAM,CAAC;AACrB,CAAC;AAAC"}
1
+ {"version":3,"file":"ModularUIMiddleware.js","names":["createRequest","modularui","request","ModularUIRequest","href","method","HTTP_METHODS","GET","data","locale","childmodels","isReload","targetModel","forceTargetModel","responseHandler","next","dispatch","successAction","model","successResult","then","result","catch","error","handleError","Error","finishProgress","errorHandler","errorAction","err","errorResult","handleFetch","action","startProgress","requestOptions","payload","modularuiRequest","fetch","modularUIMiddleware","api","type","getState","i18n"],"sources":["../../../src/redux/_modularui/ModularUIMiddleware.js"],"sourcesContent":["// @flow\nimport ModularUIRequest from \"../../modularui/ModularUIRequest\";\nimport { HTTP_METHODS } from \"../../constants/Constants\";\n\nimport { startProgress, finishProgress } from \"../actions/ProgressIndicator\";\n\nimport { handleError } from \"../actions/Error\";\n\nimport type { Middleware, MiddlewareAPI } from \"redux\";\nimport type {\n ReduxAction,\n ReduxState,\n Dispatch,\n PossibleAction,\n} from \"../types\";\nimport type { ModularUIModel } from \"../../models/types\";\nimport type Href from \"../../models/href/Href\";\nimport type { ModularUIAction, SuccessAction, ErrorAction } from \"./types\";\nimport type { TargetModel } from \"../../modularui/types\";\n\ntype RequestOptions = {\n href: Href,\n method?: $Keys<typeof HTTP_METHODS>,\n data?: string | { [key: string]: string },\n locale: string,\n childmodels?: boolean,\n targetModel?: TargetModel,\n forceTargetModel?: boolean,\n isReload?: boolean,\n};\n\n/**\n * Symbol key that carries API call info interpreted by this Redux middleware.\n */\nconst createRequest = (modularui: RequestOptions): ModularUIRequest => {\n const request = new ModularUIRequest(modularui.href, {\n method: modularui.method || HTTP_METHODS.GET,\n data: modularui.data || {},\n locale: modularui.locale,\n childmodels: modularui.childmodels ?? true,\n isReload: modularui.isReload,\n });\n\n if (modularui.targetModel) {\n request.targetModel = modularui.targetModel;\n request.forceTargetModel = modularui.forceTargetModel ?? false;\n }\n\n return request;\n};\n\n/**\n */\nconst responseHandler = (\n next: Dispatch,\n dispatch: Dispatch,\n successAction: SuccessAction,\n model: ModularUIModel\n) => {\n if (successAction) {\n const successResult = successAction(model);\n\n if (successResult instanceof Promise) {\n successResult\n .then((result) => {\n dispatch(result);\n })\n .catch((error) => {\n next(handleError(error));\n });\n } else {\n try {\n dispatch(successResult);\n } catch (error) {\n throw new Error(\n `Result of successResult is not a valid redux action: ${error}`\n );\n }\n }\n }\n\n return next(finishProgress());\n};\n\n/**\n */\nconst errorHandler = (\n next: Dispatch,\n dispatch: Dispatch,\n errorAction: ?ErrorAction,\n err: any\n) => {\n dispatch(finishProgress());\n\n if (errorAction) {\n const errorResult = errorAction(err);\n\n if (errorResult instanceof Promise) {\n errorResult.then((result) => dispatch(result));\n } else {\n dispatch(errorResult);\n }\n }\n\n return next(handleError(err));\n};\n\n/**\n */\nconst handleFetch = (\n action: ModularUIAction,\n locale: string,\n dispatch: Dispatch,\n next: Dispatch\n) => {\n dispatch(startProgress());\n\n const { successAction, errorAction, ...requestOptions } = action.payload;\n requestOptions.locale = locale;\n\n const modularuiRequest = createRequest(requestOptions);\n\n return modularuiRequest\n .fetch()\n .then((model) => responseHandler(next, dispatch, successAction, model))\n .catch((error) => errorHandler(next, dispatch, errorAction, error));\n};\n\n/**\n */\nexport const modularUIMiddleware: Middleware<\n ReduxState,\n ReduxAction,\n Dispatch\n> =\n (api: MiddlewareAPI<ReduxState, ReduxAction, Dispatch>) =>\n (next: Dispatch) =>\n (action: PossibleAction) => {\n if (action.type === \"MODULARUI/FETCH\") {\n return handleFetch(\n // $FlowExpectedError[incompatible-exact]\n action,\n api.getState().i18n.locale,\n api.dispatch,\n next\n );\n }\n\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AAiB,EAAE;IACrC,OAAOT,WAAW;IAChB;IACAC,MAAM,EACNO,GAAG,CAACE,QAAQ,EAAE,CAACC,IAAI,CAACjC,MAAM,EAC1B8B,GAAG,CAACvB,QAAQ,EACZD,IAAI,CACL;EACH;EAEA,OAAOA,IAAI,CAACiB,MAAM,CAAC;AACrB,CAAC;AAAC"}
@@ -58,6 +58,7 @@ export type ModularUIAction = {
58
58
  locale: string,
59
59
  childmodels?: boolean,
60
60
  targetModel?: TargetModel,
61
+ forceTargetModel?: boolean,
61
62
  successAction: (
62
63
  model: ModularUIModel
63
64
  ) => UpdateModelAction | SetModelAction,
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","names":[],"sources":["../../../src/redux/_modularui/types.js"],"sourcesContent":["// @flow\nimport type { ModularUIModel } from \"../../models/types\";\nimport type Href from \"../../models/href/Href\";\nimport type { FetchException } from \"../../exceptions\";\nimport type { NoAction } from \"../types\";\nimport typeof {\n HTTP_METHODS,\n MODULARUI_STATUS,\n} from \"../../constants/Constants\";\nimport type { ComponentType } from \"react\";\nimport type { TargetModel } from \"../../modularui/types\";\nimport type { RequestModularUIOptions } from \"../../utils/fetch/types\";\n\nexport type ModularUIOptions = {\n propName?: string,\n removeOnUnmount?: boolean,\n ...RequestModularUIOptions,\n};\n\nexport type ModelEntry = {\n +status: string,\n +model: ModularUIModel,\n +lastModification: number,\n};\n\nexport type ModularUIState = {\n [string]: ModelEntry,\n ...\n};\n\nexport type SetModelAction = {\n type: \"MODULARUI/SET\",\n payload: {\n key: string,\n model: ?ModularUIModel,\n },\n};\n\nexport type UpdateModelAction = {\n type: \"MODULARUI/UPDATE\",\n payload: ModularUIModel,\n};\n\nexport type SuccessAction = (\n model: ModularUIModel\n) => UpdateModelAction | SetModelAction;\n\nexport type ErrorAction = (\n error: FetchException\n) => UpdateStatusAction | RemoveModelByKeyAction | NoAction;\n\nexport type ModularUIAction = {\n type: \"MODULARUI/FETCH\",\n payload: {\n href: Href,\n method?: $Keys<HTTP_METHODS>,\n data?: string | { [key: string]: string },\n locale: string,\n childmodels?: boolean,\n targetModel?: TargetModel,\n successAction: (\n model: ModularUIModel\n ) => UpdateModelAction | SetModelAction,\n errorAction?: ErrorAction,\n },\n};\n\nexport type RemoveModelByKeyAction = {\n type: \"MODULARUI/REMOVE_KEY\",\n payload: string,\n};\n\nexport type ResetModularUIAction = {\n type: \"MODULARUI/RESET\",\n};\n\nexport type UpdateStatusAction = {\n type: \"MODULARUI/STATUS\",\n payload: {\n key: string,\n status: $Keys<MODULARUI_STATUS>,\n },\n};\n\nexport type ModularUIConnector = (\n Component: ComponentType<any>\n) => ComponentType<any>;\n"],"mappings":""}
1
+ {"version":3,"file":"types.js","names":[],"sources":["../../../src/redux/_modularui/types.js"],"sourcesContent":["// @flow\nimport type { ModularUIModel } from \"../../models/types\";\nimport type Href from \"../../models/href/Href\";\nimport type { FetchException } from \"../../exceptions\";\nimport type { NoAction } from \"../types\";\nimport typeof {\n HTTP_METHODS,\n MODULARUI_STATUS,\n} from \"../../constants/Constants\";\nimport type { ComponentType } from \"react\";\nimport type { TargetModel } from \"../../modularui/types\";\nimport type { RequestModularUIOptions } from \"../../utils/fetch/types\";\n\nexport type ModularUIOptions = {\n propName?: string,\n removeOnUnmount?: boolean,\n ...RequestModularUIOptions,\n};\n\nexport type ModelEntry = {\n +status: string,\n +model: ModularUIModel,\n +lastModification: number,\n};\n\nexport type ModularUIState = {\n [string]: ModelEntry,\n ...\n};\n\nexport type SetModelAction = {\n type: \"MODULARUI/SET\",\n payload: {\n key: string,\n model: ?ModularUIModel,\n },\n};\n\nexport type UpdateModelAction = {\n type: \"MODULARUI/UPDATE\",\n payload: ModularUIModel,\n};\n\nexport type SuccessAction = (\n model: ModularUIModel\n) => UpdateModelAction | SetModelAction;\n\nexport type ErrorAction = (\n error: FetchException\n) => UpdateStatusAction | RemoveModelByKeyAction | NoAction;\n\nexport type ModularUIAction = {\n type: \"MODULARUI/FETCH\",\n payload: {\n href: Href,\n method?: $Keys<HTTP_METHODS>,\n data?: string | { [key: string]: string },\n locale: string,\n childmodels?: boolean,\n targetModel?: TargetModel,\n forceTargetModel?: boolean,\n successAction: (\n model: ModularUIModel\n ) => UpdateModelAction | SetModelAction,\n errorAction?: ErrorAction,\n },\n};\n\nexport type RemoveModelByKeyAction = {\n type: \"MODULARUI/REMOVE_KEY\",\n payload: string,\n};\n\nexport type ResetModularUIAction = {\n type: \"MODULARUI/RESET\",\n};\n\nexport type UpdateStatusAction = {\n type: \"MODULARUI/STATUS\",\n payload: {\n key: string,\n status: $Keys<MODULARUI_STATUS>,\n },\n};\n\nexport type ModularUIConnector = (\n Component: ComponentType<any>\n) => ComponentType<any>;\n"],"mappings":""}
@@ -34,9 +34,9 @@ export type RequestOptions = { ...RequestURLOptions, ...RequestBaseOptions };
34
34
  export type RequestModularUIOptions = {
35
35
  ...RequestBaseOptions,
36
36
  targetModel?: TargetModel,
37
+ forceTargetModel?: boolean,
37
38
  updateModel?: ModularUIModel,
38
39
  childmodels?: boolean,
39
40
  isValidationRequest?: boolean,
40
-
41
41
  removeOnUnmount?: boolean,
42
42
  };
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","names":[],"sources":["../../../src/utils/fetch/types.js"],"sourcesContent":["// @flow\nimport typeof { HTTP_METHODS } from \"../../constants/Constants\";\nimport type { ModularUIModel } from \"../../models/types\";\nimport type { TargetModel } from \"../../modularui/types\";\n\nexport type RequestURLOptions = {\n url: string,\n};\n\nexport type RequestBaseOptions = {\n method?: $Keys<HTTP_METHODS>,\n params?: string,\n data?: string | { [key: string]: string },\n timeout?: number,\n responseType?: string,\n headers?: {\n [headerName: string]: string,\n Accept?: string,\n \"Accept-Language\"?: string,\n \"Content-Type\"?: string,\n \"x-filename\"?: string,\n \"x-filesize\"?: string,\n },\n events?: { [eventName: string]: () => void },\n onProgress?: ProgressEventHandler,\n includeContext?: boolean,\n locale?: string,\n cache?: boolean,\n isReload?: boolean,\n};\n\nexport type RequestOptions = { ...RequestURLOptions, ...RequestBaseOptions };\n\nexport type RequestModularUIOptions = {\n ...RequestBaseOptions,\n targetModel?: TargetModel,\n updateModel?: ModularUIModel,\n childmodels?: boolean,\n isValidationRequest?: boolean,\n\n removeOnUnmount?: boolean,\n};\n"],"mappings":""}
1
+ {"version":3,"file":"types.js","names":[],"sources":["../../../src/utils/fetch/types.js"],"sourcesContent":["// @flow\nimport typeof { HTTP_METHODS } from \"../../constants/Constants\";\nimport type { ModularUIModel } from \"../../models/types\";\nimport type { TargetModel } from \"../../modularui/types\";\n\nexport type RequestURLOptions = {\n url: string,\n};\n\nexport type RequestBaseOptions = {\n method?: $Keys<HTTP_METHODS>,\n params?: string,\n data?: string | { [key: string]: string },\n timeout?: number,\n responseType?: string,\n headers?: {\n [headerName: string]: string,\n Accept?: string,\n \"Accept-Language\"?: string,\n \"Content-Type\"?: string,\n \"x-filename\"?: string,\n \"x-filesize\"?: string,\n },\n events?: { [eventName: string]: () => void },\n onProgress?: ProgressEventHandler,\n includeContext?: boolean,\n locale?: string,\n cache?: boolean,\n isReload?: boolean,\n};\n\nexport type RequestOptions = { ...RequestURLOptions, ...RequestBaseOptions };\n\nexport type RequestModularUIOptions = {\n ...RequestBaseOptions,\n targetModel?: TargetModel,\n forceTargetModel?: boolean,\n updateModel?: ModularUIModel,\n childmodels?: boolean,\n isValidationRequest?: boolean,\n removeOnUnmount?: boolean,\n};\n"],"mappings":""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@beinformed/ui",
3
- "version": "1.25.4",
3
+ "version": "1.25.6",
4
4
  "description": "Toolbox for be informed javascript layouts",
5
5
  "license": "SEE LICENSE IN LICENSE.md",
6
6
  "bugs": "http://support.beinformed.com",
@@ -125,7 +125,7 @@
125
125
  "eslint-plugin-import": "^2.26.0",
126
126
  "eslint-plugin-jest": "^27.2.1",
127
127
  "eslint-plugin-jsdoc": "^39.6.4",
128
- "eslint-plugin-react": "^7.31.11",
128
+ "eslint-plugin-react": "^7.32.0",
129
129
  "eslint-plugin-react-hooks": "^4.5.0",
130
130
  "eslint-plugin-you-dont-need-lodash-underscore": "^6.12.0",
131
131
  "flow-bin": "^0.196.3",
@@ -10,6 +10,7 @@ import type { ModularUIModel, Href } from "../models";
10
10
  type UseModularUIBasicOptions<T: ModularUIModel> = {
11
11
  expectedModels: Array<string>,
12
12
  targetModel?: Class<T> | Array<Class<T>>,
13
+ forceTargetModel?: boolean,
13
14
  };
14
15
 
15
16
  /**
@@ -20,6 +21,7 @@ export const useModularUIBasic = <T: ModularUIModel>(
20
21
  options: UseModularUIBasicOptions<T> = {
21
22
  expectedModels: [],
22
23
  targetModel: undefined,
24
+ forceTargetModel: false,
23
25
  }
24
26
  ): T | null => {
25
27
  const location = useLocation();
@@ -27,9 +29,14 @@ export const useModularUIBasic = <T: ModularUIModel>(
27
29
  throw new IllegalArgumentException("Missing href");
28
30
  }
29
31
 
30
- const useModularUIOptions = { targetModel: undefined, isReload: false };
32
+ const useModularUIOptions = {
33
+ targetModel: undefined,
34
+ forceTargetModel: undefined,
35
+ isReload: false,
36
+ };
31
37
  if (options.targetModel) {
32
38
  useModularUIOptions.targetModel = options.targetModel;
39
+ useModularUIOptions.forceTargetModel = options.forceTargetModel;
33
40
  }
34
41
 
35
42
  // reload when the modular service starts with the current location
@@ -69,6 +69,7 @@ export const useListDetail = (href: string): ListDetailModel | null =>
69
69
  useModularUIBasic("listdetail", href, {
70
70
  expectedModels: ["ListDetail"],
71
71
  targetModel: ListDetailModel,
72
+ forceTargetModel: true,
72
73
  });
73
74
 
74
75
  /**
@@ -95,6 +96,14 @@ export const useQuicksearch = (href: string): CaseSearchModel | null =>
95
96
  targetModel: CaseSearchModel,
96
97
  });
97
98
 
99
+ /**
100
+ */
101
+ export const useSearch = (href: string): CaseSearchModel | null =>
102
+ useModularUIBasic("search", href, {
103
+ expectedModels: ["CaseSearch"],
104
+ targetModel: CaseSearchModel,
105
+ });
106
+
98
107
  /**
99
108
  */
100
109
  export const useUserProfile = (href: string): UserProfileModel | null =>
@@ -5,8 +5,16 @@ import { useSelector } from "react-redux";
5
5
  import ModularUIRequest from "../modularui/ModularUIRequest";
6
6
  import { getLocale } from "../redux/selectors/i18n";
7
7
 
8
- import type Href from "../models/href/Href";
9
8
  import type { RequestModularUIOptions } from "../utils";
9
+ import type Href from "../models/href/Href";
10
+
11
+ const getModularUIRequest = createSelector([getLocale], (localeCode) => {
12
+ return (href: Href, options?: $Shape<RequestModularUIOptions>) => {
13
+ const request = new ModularUIRequest(href, options);
14
+ request.locale = localeCode;
15
+ return request;
16
+ };
17
+ });
10
18
 
11
19
  /**
12
20
  * Creates a ModularUIRequest with the locale as available in the redux store
@@ -14,13 +22,4 @@ import type { RequestModularUIOptions } from "../utils";
14
22
  export const useModularUIRequest = (): ((
15
23
  href: Href,
16
24
  options?: $Shape<RequestModularUIOptions>
17
- ) => ModularUIRequest) =>
18
- useSelector(
19
- createSelector([getLocale], (localeCode) => {
20
- return (href: Href, options?: $Shape<RequestModularUIOptions>) => {
21
- const request = new ModularUIRequest(href, options);
22
- request.locale = localeCode;
23
- return request;
24
- };
25
- })
26
- );
25
+ ) => ModularUIRequest) => useSelector(getModularUIRequest);
@@ -42,6 +42,7 @@ class ModularUIRequest {
42
42
  _href: Href;
43
43
  _options: RequestModularUIOptions;
44
44
  _targetModel: ?TargetModel;
45
+ _forceTargetModel: boolean = false;
45
46
  _contributionsHref: string;
46
47
  _locale: string;
47
48
  _method: $Keys<typeof HTTP_METHODS> = HTTP_METHODS.GET;
@@ -153,6 +154,7 @@ class ModularUIRequest {
153
154
  /* eslint-disable no-unused-vars */
154
155
  const {
155
156
  targetModel,
157
+ forceTargetModel,
156
158
  updateModel,
157
159
  childmodels,
158
160
  isValidationRequest,
@@ -189,6 +191,18 @@ class ModularUIRequest {
189
191
  return this._targetModel;
190
192
  }
191
193
 
194
+ /**
195
+ */
196
+ set forceTargetModel(forceTargetModel: boolean) {
197
+ this._forceTargetModel = forceTargetModel ?? false;
198
+ }
199
+
200
+ /**
201
+ */
202
+ get forceTargetModel(): boolean {
203
+ return this._forceTargetModel;
204
+ }
205
+
192
206
  /**
193
207
  */
194
208
  resolveModel(): Class<ModularUIModel> {
@@ -197,6 +211,10 @@ class ModularUIRequest {
197
211
  availableModels = Array.isArray(this.targetModel)
198
212
  ? [...this.targetModel]
199
213
  : [this.targetModel];
214
+
215
+ if (this.forceTargetModel) {
216
+ return availableModels[0];
217
+ }
200
218
  }
201
219
 
202
220
  const Model: Class<ModularUIModel> | null = resolveModel(
@@ -210,14 +228,14 @@ class ModularUIRequest {
210
228
 
211
229
  if (availableModels) {
212
230
  throw new IllegalStateException(
213
- `data is not applicable for model(s): ${availableModels
231
+ `data for ${this.href.toString()} is not applicable for model(s): ${availableModels
214
232
  .map((m) => m.modelName)
215
- .join(", ")}`
233
+ .join(", ")}, received response: ${JSON.stringify(this.response)}`
216
234
  );
217
235
  }
218
236
 
219
237
  throw new IllegalStateException(
220
- `no javascript model is applicable for received response: ${JSON.stringify(
238
+ `no javascript model is applicable for received request of ${this.href.toString()}, with response: ${JSON.stringify(
221
239
  this.response
222
240
  )}`
223
241
  );
@@ -90,6 +90,7 @@ const loadModelSuccessAction = (
90
90
  };
91
91
 
92
92
  /**
93
+ * This action is handled by the modularui middleware
93
94
  */
94
95
  export const loadModel = (
95
96
  key: string,
@@ -104,6 +105,7 @@ export const loadModel = (
104
105
  locale: options?.locale ?? "en",
105
106
  childmodels: options?.childmodels,
106
107
  targetModel: options?.targetModel,
108
+ forceTargetModel: options?.forceTargetModel,
107
109
  /**
108
110
  */
109
111
  successAction: (model) =>
@@ -25,6 +25,7 @@ type RequestOptions = {
25
25
  locale: string,
26
26
  childmodels?: boolean,
27
27
  targetModel?: TargetModel,
28
+ forceTargetModel?: boolean,
28
29
  isReload?: boolean,
29
30
  };
30
31
 
@@ -42,6 +43,7 @@ const createRequest = (modularui: RequestOptions): ModularUIRequest => {
42
43
 
43
44
  if (modularui.targetModel) {
44
45
  request.targetModel = modularui.targetModel;
46
+ request.forceTargetModel = modularui.forceTargetModel ?? false;
45
47
  }
46
48
 
47
49
  return request;
@@ -58,6 +58,7 @@ export type ModularUIAction = {
58
58
  locale: string,
59
59
  childmodels?: boolean,
60
60
  targetModel?: TargetModel,
61
+ forceTargetModel?: boolean,
61
62
  successAction: (
62
63
  model: ModularUIModel
63
64
  ) => UpdateModelAction | SetModelAction,
@@ -34,9 +34,9 @@ export type RequestOptions = { ...RequestURLOptions, ...RequestBaseOptions };
34
34
  export type RequestModularUIOptions = {
35
35
  ...RequestBaseOptions,
36
36
  targetModel?: TargetModel,
37
+ forceTargetModel?: boolean,
37
38
  updateModel?: ModularUIModel,
38
39
  childmodels?: boolean,
39
40
  isValidationRequest?: boolean,
40
-
41
41
  removeOnUnmount?: boolean,
42
42
  };