@m4l/core 0.0.41 → 0.1.0

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 (95) hide show
  1. package/index.html +13 -0
  2. package/package.json +7 -14
  3. package/src/contexts/EnvironmentContext/index.tsx +45 -0
  4. package/{dist/contexts/EnvironmentContext/types.d.ts → src/contexts/EnvironmentContext/types.ts} +3 -1
  5. package/src/contexts/FlagsContext/index.tsx +50 -0
  6. package/{dist/contexts/FlagsContext/types.d.ts → src/contexts/FlagsContext/types.ts} +7 -1
  7. package/src/contexts/HostToolsContext/index.tsx +35 -0
  8. package/{dist/contexts/HostToolsContext/types.d.ts → src/contexts/HostToolsContext/types.ts} +3 -1
  9. package/src/contexts/ModuleDictionaryContext/index.tsx +109 -0
  10. package/{dist/contexts/ModuleDictionaryContext/types.d.ts → src/contexts/ModuleDictionaryContext/types.ts} +4 -1
  11. package/src/contexts/ModulePrivilegesContext/index.tsx +88 -0
  12. package/{dist/contexts/ModulePrivilegesContext/types.d.ts → src/contexts/ModulePrivilegesContext/types.ts} +3 -0
  13. package/src/contexts/ModuleSkeletonContext/index.tsx +35 -0
  14. package/{dist/contexts/ModuleSkeletonContext/types.d.ts → src/contexts/ModuleSkeletonContext/types.ts} +3 -0
  15. package/src/contexts/NetworkContext/index.tsx +44 -0
  16. package/{dist/contexts/NetworkContext/types.d.ts → src/contexts/NetworkContext/types.ts} +6 -2
  17. package/{dist/contexts/index.d.ts → src/contexts/index.ts} +0 -0
  18. package/{dist/hooks/index.d.ts → src/hooks/index.ts} +1 -0
  19. package/src/hooks/useEnvironment/index.test.tsx +44 -0
  20. package/src/hooks/useEnvironment/index.ts +13 -0
  21. package/src/hooks/useFlags/index.ts +35 -0
  22. package/src/hooks/useHostTools/index.ts +13 -0
  23. package/src/hooks/useLocalStorage/index.ts +23 -0
  24. package/src/hooks/useModuleDictionary/index.ts +11 -0
  25. package/src/hooks/useModulePrivileges/index.ts +11 -0
  26. package/src/hooks/useModuleSkeleton/index.ts +11 -0
  27. package/src/hooks/useNetwork/index.ts +13 -0
  28. package/src/hooks/usePaginate/index.ts +109 -0
  29. package/{dist/hooks/usePaginate/types.d.ts → src/hooks/usePaginate/types.ts} +7 -1
  30. package/src/index.ts +43 -0
  31. package/src/isolation/App.tsx +105 -0
  32. package/src/isolation/components/Paginate.tsx +65 -0
  33. package/src/isolation/components/TestHooks/CallBack.tsx +43 -0
  34. package/src/isolation/components/TestHooks/SimpleUseEffect.tsx +33 -0
  35. package/src/jest.d.ts +1 -0
  36. package/src/main.tsx +5 -0
  37. package/src/test/setup.ts +1 -0
  38. package/src/test/utils.tsx +20 -0
  39. package/{dist/types/dictionary.d.ts → src/types/dictionary.ts} +5 -1
  40. package/{dist/types/index.d.ts → src/types/index.ts} +22 -5
  41. package/src/utils/axiosOperation/index.ts +150 -0
  42. package/{dist/utils/axiosOperation/types.d.ts → src/utils/axiosOperation/types.ts} +1 -1
  43. package/src/utils/getLocalStorage.ts +8 -0
  44. package/src/utils/getPropertyByString.ts +10 -0
  45. package/{dist/utils/index.d.ts → src/utils/index.ts} +0 -0
  46. package/src/utils/setLocalStorage.ts +12 -0
  47. package/src/utils/voidFunction.ts +2 -0
  48. package/{dist → src}/vite-env.d.ts +1 -0
  49. package/tsconfig.json +20 -0
  50. package/tsconfig.node.json +10 -0
  51. package/vite.config.ts +200 -0
  52. package/README.md +0 -0
  53. package/dist/contexts/EnvironmentContext/index.d.ts +0 -5
  54. package/dist/contexts/EnvironmentContext/index.js +0 -32
  55. package/dist/contexts/FlagsContext/index.d.ts +0 -5
  56. package/dist/contexts/FlagsContext/index.js +0 -34
  57. package/dist/contexts/HostToolsContext/index.d.ts +0 -6
  58. package/dist/contexts/HostToolsContext/index.js +0 -25
  59. package/dist/contexts/ModuleDictionaryContext/index.d.ts +0 -5
  60. package/dist/contexts/ModuleDictionaryContext/index.js +0 -90
  61. package/dist/contexts/ModulePrivilegesContext/index.d.ts +0 -5
  62. package/dist/contexts/ModulePrivilegesContext/index.js +0 -68
  63. package/dist/contexts/ModuleSkeletonContext/index.d.ts +0 -5
  64. package/dist/contexts/ModuleSkeletonContext/index.js +0 -26
  65. package/dist/contexts/NetworkContext/index.d.ts +0 -5
  66. package/dist/contexts/NetworkContext/index.js +0 -26
  67. package/dist/external/axios.js +0 -1220
  68. package/dist/hooks/useEnvironment/index.d.ts +0 -2
  69. package/dist/hooks/useEnvironment/index.js +0 -9
  70. package/dist/hooks/useFlags/index.d.ts +0 -3
  71. package/dist/hooks/useFlags/index.js +0 -23
  72. package/dist/hooks/useHostTools/index.d.ts +0 -2
  73. package/dist/hooks/useHostTools/index.js +0 -9
  74. package/dist/hooks/useLocalStorage/index.d.ts +0 -1
  75. package/dist/hooks/useLocalStorage/index.js +0 -21
  76. package/dist/hooks/useModuleDictionary/index.d.ts +0 -1
  77. package/dist/hooks/useModuleDictionary/index.js +0 -9
  78. package/dist/hooks/useModulePrivileges/index.d.ts +0 -1
  79. package/dist/hooks/useModulePrivileges/index.js +0 -9
  80. package/dist/hooks/useModuleSkeleton/index.d.ts +0 -1
  81. package/dist/hooks/useModuleSkeleton/index.js +0 -9
  82. package/dist/hooks/useNetwork/index.d.ts +0 -2
  83. package/dist/hooks/useNetwork/index.js +0 -9
  84. package/dist/hooks/usePaginate/index.d.ts +0 -10
  85. package/dist/hooks/usePaginate/index.js +0 -74
  86. package/dist/index.d.ts +0 -6
  87. package/dist/index.js +0 -23
  88. package/dist/types/index.js +0 -6
  89. package/dist/utils/axiosOperation/index.d.ts +0 -2
  90. package/dist/utils/axiosOperation.js +0 -90
  91. package/dist/utils/getLocalStorage.d.ts +0 -1
  92. package/dist/utils/getPropertyByString.d.ts +0 -1
  93. package/dist/utils/index.js +0 -33
  94. package/dist/utils/setLocalStorage.d.ts +0 -1
  95. package/dist/utils/voidFunction.d.ts +0 -1
package/index.html ADDED
@@ -0,0 +1,13 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <link rel="icon" type="image/svg+xml" href="/src/favicon.svg" />
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
+ <title>Vite App</title>
8
+ </head>
9
+ <body>
10
+ <div id="root"></div>
11
+ <script type="module" src="/src/main.tsx"></script>
12
+ </body>
13
+ </html>
package/package.json CHANGED
@@ -1,7 +1,6 @@
1
1
  {
2
2
  "name": "@m4l/core",
3
- "private": false,
4
- "version": "0.0.41",
3
+ "version": "0.1.0",
5
4
  "license": "UNLICENSED",
6
5
  "author": "M4L Team",
7
6
  "scripts": {
@@ -24,6 +23,7 @@
24
23
  "react": ">=18"
25
24
  },
26
25
  "devDependencies": {
26
+ "@testing-library/dom": "^8.17.1",
27
27
  "@testing-library/jest-dom": "^5.16.4",
28
28
  "@testing-library/react": "^13.3.0",
29
29
  "@testing-library/user-event": "^14.2.1",
@@ -53,26 +53,20 @@
53
53
  "react": "^18.2.0",
54
54
  "react-dom": "^18.2.0",
55
55
  "react-toastify": "^9.0.5",
56
+ "rollup": "^2.79.0",
56
57
  "rollup-plugin-terser": "^7.0.2",
57
58
  "snakecase-keys": "^5.4.2",
58
59
  "typescript": "^4.6.3",
59
- "vite": "^2.9.9",
60
+ "vite": "2.9.9",
60
61
  "vite-plugin-dts": "^1.2.0",
61
- "vite-plugin-mkcert": "^1.6.4",
62
- "vitest": "^0.15.2"
62
+ "vite-plugin-mkcert": "^1.9.0",
63
+ "vitest": "^0.17.1"
63
64
  },
64
- "files": [
65
- "dist"
66
- ],
65
+ "source": "src/index.ts",
67
66
  "main": "./dist/index.js",
68
67
  "module": "./dist/index.js",
69
68
  "type": "module",
70
69
  "types": "./dist/index.d.ts",
71
- "exports": {
72
- ".": {
73
- "import": "./dist/index.js"
74
- }
75
- },
76
70
  "sideEffects": false,
77
71
  "publishConfig": {
78
72
  "access": "public"
@@ -80,5 +74,4 @@
80
74
  "engines": {
81
75
  "node": ">=12.0.0"
82
76
  }
83
-
84
77
  }
@@ -0,0 +1,45 @@
1
+ //react
2
+ import { createContext, useState } from 'react';
3
+ // mui
4
+ // hooks
5
+ // utils
6
+ // config
7
+ // @type
8
+ import { EnvironmentContextType, EnvironmentProviderProps } from './types';
9
+
10
+ // ----------------------------------------------------------------------
11
+
12
+ const initialValue: EnvironmentContextType = {
13
+ isLocalhost: true,
14
+ host: '',
15
+ domain_token: '',
16
+ host_api_local: '',
17
+ host_api_remote: '',
18
+ host_static_assets: '',
19
+ environment_assets: '',
20
+ dfnsFormat: {
21
+ date_format: 'yyyy-MM-dd',
22
+ date_mask: '____-__-__',
23
+ time_format: 'HH:mm:ss',
24
+ time_mask: '__:__:__',
25
+ datetime_format: 'yyyy-MM-dd HH:mm:ss',
26
+ datetime_mask: '____-__-__ __:__:__',
27
+ },
28
+ };
29
+
30
+ const EnvironmentContext = createContext<EnvironmentContextType>(initialValue);
31
+
32
+ function EnvironmentProvider(props: EnvironmentProviderProps) {
33
+ const { children, ...other } = props;
34
+
35
+ const [finalEnvironment] = useState<EnvironmentContextType>(other);
36
+
37
+ // console.log('Por aca', finalEnvironment);
38
+ return (
39
+ <EnvironmentContext.Provider value={finalEnvironment}>
40
+ {children}
41
+ </EnvironmentContext.Provider>
42
+ );
43
+ }
44
+
45
+ export { EnvironmentProvider, EnvironmentContext };
@@ -1,6 +1,8 @@
1
1
  import { ReactNode } from 'react';
2
2
  import { EnvironmentType } from '../../types';
3
+
3
4
  export interface EnvironmentProviderProps extends EnvironmentType {
4
5
  children: ReactNode;
5
6
  }
6
- export declare type EnvironmentContextType = EnvironmentType;
7
+
8
+ export type EnvironmentContextType = EnvironmentType;
@@ -0,0 +1,50 @@
1
+ import { createContext, useCallback, useState } from 'react';
2
+ import { voidFunction } from '../../utils/voidFunction';
3
+
4
+ // mui
5
+ // hooks
6
+ // utils
7
+ // config
8
+ // @type
9
+ import { FlagsContextProps, Flag, FlagsProviderProps } from './types';
10
+
11
+ // ----------------------------------------------------------------------
12
+
13
+ const initialState: FlagsContextProps = {
14
+ flags: [],
15
+ clearFlags: voidFunction,
16
+ addFlag: voidFunction,
17
+ };
18
+
19
+ const FlagsContext = createContext<FlagsContextProps>(initialState);
20
+
21
+ function FlagsProvider({ children }: FlagsProviderProps) {
22
+ const [flags, setFlags] = useState<Array<Flag>>([]);
23
+
24
+ const clearFlags = useCallback(() => {
25
+ setFlags([]);
26
+ }, []);
27
+
28
+ const addFlag = useCallback((newFlag: Flag) => {
29
+ setFlags(oldFlags => {
30
+ if (oldFlags.findIndex(f => f === newFlag) < 0) {
31
+ return [...oldFlags, newFlag];
32
+ }
33
+ return [...oldFlags];
34
+ });
35
+ }, []);
36
+
37
+ return (
38
+ <FlagsContext.Provider
39
+ value={{
40
+ flags,
41
+ addFlag,
42
+ clearFlags,
43
+ }}
44
+ >
45
+ {children}
46
+ </FlagsContext.Provider>
47
+ );
48
+ }
49
+
50
+ export { FlagsProvider, FlagsContext };
@@ -1,8 +1,14 @@
1
1
  import { ReactNode } from 'react';
2
+
3
+ // eslint-disable-next-line @typescript-eslint/no-empty-interface
2
4
  export interface FlagsProviderProps {
3
5
  children: ReactNode;
4
6
  }
5
- export declare type Flag = string;
7
+
8
+ export type Flag = string;
9
+
10
+ // Interface para almacenar el estado del contexto
11
+ // Interface para indicar las propiedas y metodos que comparte el contexto
6
12
  export interface FlagsContextProps {
7
13
  flags: Array<Flag>;
8
14
  clearFlags: () => void;
@@ -0,0 +1,35 @@
1
+ import { createContext, useState } from 'react';
2
+ import { HostToolsType } from '../../types';
3
+ import { voidFunction } from '../../utils/voidFunction';
4
+
5
+ // mui
6
+
7
+ // hooks
8
+ // utils
9
+ // config
10
+ // @type
11
+ import type { HostToolsContextType, HostToolsProviderProps } from './types';
12
+
13
+ // ----------------------------------------------------------------------
14
+
15
+ const initialValue: HostToolsContextType = {
16
+ toast: () => 0,
17
+ startProgress: voidFunction,
18
+ stopProgress: voidFunction,
19
+ formatDate: () => '',
20
+ events_add_listener: voidFunction,
21
+ events_remove_listener: voidFunction,
22
+ events_emit: voidFunction,
23
+ };
24
+
25
+ const HostToolsContext = createContext<HostToolsContextType>(initialValue);
26
+
27
+ function HostToolsProvider(props: HostToolsProviderProps) {
28
+ const { children, ...hostTools } = props;
29
+
30
+ const [finalTools] = useState<HostToolsType>(hostTools);
31
+
32
+ return <HostToolsContext.Provider value={finalTools}>{children}</HostToolsContext.Provider>;
33
+ }
34
+
35
+ export { HostToolsProvider, HostToolsContext };
@@ -1,6 +1,8 @@
1
1
  import { ReactNode } from 'react';
2
2
  import { HostToolsType } from '../../types';
3
+
3
4
  export interface HostToolsProviderProps extends HostToolsType {
4
5
  children: ReactNode;
5
6
  }
6
- export declare type HostToolsContextType = HostToolsType;
7
+
8
+ export type HostToolsContextType = HostToolsType;
@@ -0,0 +1,109 @@
1
+ //react
2
+ import { createContext, useCallback, useEffect, useState } from 'react';
3
+ //m4l
4
+ // mui
5
+ // hooks
6
+ // utils
7
+ // config
8
+ // @type
9
+ import { ModuleDictionaryContextProps, ModuleDictionaryProviderProps } from './types';
10
+
11
+ import { useEnvironment, useFlags, useHostTools, useNetwork } from '../../hooks';
12
+ import { ModuleDictionary } from '../../types/dictionary';
13
+ // ----------------------------------------------------------------------
14
+
15
+ const initialState: ModuleDictionaryContextProps = {
16
+ getLabel: () => '..',
17
+ getModuleLabel: () => 'No dictionary context',
18
+ };
19
+
20
+ const ModuleDictionaryContext = createContext<ModuleDictionaryContextProps>(initialState);
21
+
22
+ function ModuleDictionaryProvider(props: ModuleDictionaryProviderProps) {
23
+ const {
24
+ children,
25
+ componentsDictionary,
26
+ moduleId,
27
+ moduleName = 'module_name',
28
+ currentLang = 'us',
29
+ isAuth = true,
30
+ } = props;
31
+ const { addFlag } = useFlags();
32
+ // Cargar el diccionario
33
+ const [moduleDictionary, setModuleDictionary] = useState<ModuleDictionary | undefined>(
34
+ undefined,
35
+ );
36
+ const { domain_token } = useEnvironment();
37
+ const { startProgress, stopProgress } = useHostTools();
38
+ const { networkOperation } = useNetwork();
39
+
40
+ useEffect(() => {
41
+ let mounted = true;
42
+ startProgress();
43
+
44
+ networkOperation({
45
+ method: 'GET',
46
+ endPoint: isAuth ? `dictionaries/${moduleId}` : `na/dictionaries/${moduleId}`,
47
+ parms: {
48
+ comps: componentsDictionary,
49
+ ...(isAuth ? {} : { domain_token }),
50
+ },
51
+ // isRemote: false
52
+ })
53
+ .then((response: any) => {
54
+ if (mounted) {
55
+ /// /console.log("useEffect - ModuleProvider - response");
56
+
57
+ setModuleDictionary({
58
+ ...response,
59
+ });
60
+
61
+ addFlag('dictionary_loaded');
62
+ }
63
+ })
64
+ .finally(() => {
65
+ stopProgress();
66
+ });
67
+
68
+ return function cleanUp() {
69
+ mounted = false;
70
+ };
71
+ // eslint-disable-next-line react-hooks/exhaustive-deps
72
+ }, [currentLang]);
73
+
74
+ const getLabel = useCallback(
75
+ (key: string) => {
76
+ if (moduleDictionary === undefined) return 'No dictionary';
77
+ if (key === undefined) return 'No key';
78
+
79
+ const parts = key.split('.');
80
+
81
+ if (parts.length === 2) {
82
+ if (moduleDictionary[parts[0]] && (moduleDictionary as any)[parts[0]][parts[1]]) {
83
+ return (moduleDictionary as any)[parts[0]][parts[1]];
84
+ }
85
+ } else if (parts.length === 1) {
86
+ if (moduleDictionary.data && (moduleDictionary as any).data[key]) {
87
+ return (moduleDictionary as any).data[key];
88
+ }
89
+ }
90
+
91
+ return `No dictionary:${key}`;
92
+ },
93
+ [moduleDictionary],
94
+ );
95
+ const getModuleLabel = useCallback(() => getLabel(moduleName), [moduleName, getLabel]);
96
+ return (
97
+ <ModuleDictionaryContext.Provider
98
+ value={{
99
+ moduleDictionary: moduleDictionary,
100
+ getLabel,
101
+ getModuleLabel,
102
+ }}
103
+ >
104
+ {children}
105
+ </ModuleDictionaryContext.Provider>
106
+ );
107
+ }
108
+
109
+ export { ModuleDictionaryProvider, ModuleDictionaryContext };
@@ -1,13 +1,16 @@
1
1
  import { ReactNode } from 'react';
2
2
  import type { GetLabelType, ModuleDictionary } from '../../types/dictionary';
3
+
4
+ // eslint-disable-next-line @typescript-eslint/no-empty-interface
3
5
  export interface ModuleDictionaryProviderProps {
4
6
  currentLang?: string;
5
7
  isAuth?: boolean;
6
8
  moduleId: string;
7
- moduleName?: string;
9
+ moduleName?: string; //la llave donde reposa el nombre del modulo en el diccionario
8
10
  componentsDictionary: string[];
9
11
  children: ReactNode;
10
12
  }
13
+
11
14
  export interface ModuleDictionaryContextProps {
12
15
  moduleDictionary?: ModuleDictionary;
13
16
  getLabel: GetLabelType;
@@ -0,0 +1,88 @@
1
+ //react
2
+ import { createContext, useCallback, useEffect, useState } from 'react';
3
+ //m4l
4
+ // mui
5
+ // hooks
6
+ // utils
7
+ // config
8
+ // @type
9
+ import { ModulePrivilegesContextProps, ModulePrivilegesProviderProps } from './types';
10
+
11
+ import { useFlags, useHostTools, useNetwork } from '../../hooks';
12
+
13
+ // ----------------------------------------------------------------------
14
+
15
+ const initialState: ModulePrivilegesContextProps = {
16
+ privileges: {},
17
+ hasPrivilege: () => false,
18
+ };
19
+
20
+ const ModulePrivilegesContext = createContext<ModulePrivilegesContextProps>(initialState);
21
+
22
+ function ModulePrivilegesProvider(props: ModulePrivilegesProviderProps) {
23
+ const { children, queryPrivileges } = props;
24
+ const { addFlag } = useFlags();
25
+ // Cargar el diccionario
26
+ const [privileges, setPrivileges] = useState<Record<string, boolean>>({});
27
+
28
+ const { startProgress, stopProgress } = useHostTools();
29
+ const { networkOperation } = useNetwork();
30
+
31
+ useEffect(() => {
32
+ let mounted = true;
33
+
34
+ if (queryPrivileges.length === 0) {
35
+ addFlag('privileges_loaded');
36
+ return;
37
+ }
38
+
39
+ startProgress();
40
+ networkOperation({
41
+ method: 'GET',
42
+ endPoint: `auth/login`,
43
+ parms: {
44
+ privileges: queryPrivileges,
45
+ },
46
+ // isRemote: false
47
+ })
48
+ .then((response: any) => {
49
+ if (mounted) {
50
+ /// /console.log("useEffect - ModuleProvider - response");
51
+
52
+ setPrivileges({
53
+ ...response.data,
54
+ });
55
+
56
+ addFlag('privileges_loaded');
57
+ }
58
+ })
59
+ .finally(() => {
60
+ stopProgress();
61
+ });
62
+
63
+ return function cleanUp() {
64
+ mounted = false;
65
+ };
66
+ // eslint-disable-next-line react-hooks/exhaustive-deps
67
+ }, []);
68
+
69
+ const hasPrivilege = useCallback(
70
+ (key: string) => {
71
+ return key in privileges;
72
+ },
73
+ [privileges],
74
+ );
75
+
76
+ return (
77
+ <ModulePrivilegesContext.Provider
78
+ value={{
79
+ hasPrivilege,
80
+ privileges,
81
+ }}
82
+ >
83
+ {children}
84
+ </ModulePrivilegesContext.Provider>
85
+ );
86
+ }
87
+
88
+ export { ModulePrivilegesProvider, ModulePrivilegesContext };
@@ -1,8 +1,11 @@
1
1
  import { ReactNode } from 'react';
2
+
3
+ // eslint-disable-next-line @typescript-eslint/no-empty-interface
2
4
  export interface ModulePrivilegesProviderProps {
3
5
  queryPrivileges: string[];
4
6
  children: ReactNode;
5
7
  }
8
+
6
9
  export interface ModulePrivilegesContextProps {
7
10
  privileges: Record<string, boolean>;
8
11
  hasPrivilege: (id: string) => boolean;
@@ -0,0 +1,35 @@
1
+ //react
2
+ import { createContext } from 'react';
3
+ //m4l
4
+ // mui
5
+ // hooks
6
+ // utils
7
+ // config
8
+ // @type
9
+ import { ModuleSkeletonContextProps, ModuleSkeletonProviderProps } from './types';
10
+
11
+ import { useFlagsPresent } from '../../hooks';
12
+
13
+ // ----------------------------------------------------------------------
14
+
15
+ const initialState: ModuleSkeletonContextProps = {
16
+ isSkeleton: false,
17
+ };
18
+
19
+ const ModuleSkeletonContext = createContext<ModuleSkeletonContextProps>(initialState);
20
+
21
+ function ModuleSkeletonProvider(props: ModuleSkeletonProviderProps) {
22
+ const { children, flags } = props;
23
+ const isSkeleton = !useFlagsPresent(flags);
24
+ return (
25
+ <ModuleSkeletonContext.Provider
26
+ value={{
27
+ isSkeleton,
28
+ }}
29
+ >
30
+ {children}
31
+ </ModuleSkeletonContext.Provider>
32
+ );
33
+ }
34
+
35
+ export { ModuleSkeletonProvider, ModuleSkeletonContext };
@@ -1,8 +1,11 @@
1
1
  import { ReactNode } from 'react';
2
+
3
+ // eslint-disable-next-line @typescript-eslint/no-empty-interface
2
4
  export interface ModuleSkeletonProviderProps {
3
5
  flags: string[];
4
6
  children: ReactNode;
5
7
  }
8
+
6
9
  export interface ModuleSkeletonContextProps {
7
10
  isSkeleton: boolean;
8
11
  }
@@ -0,0 +1,44 @@
1
+ import { createContext, useCallback } from 'react';
2
+
3
+ // mui
4
+ // hooks
5
+ import useEnvironment from '../../hooks/useEnvironment';
6
+ import useHostTools from '../../hooks/useHostTools';
7
+ // utils
8
+ // config
9
+ // @type
10
+ import type { NetworkProps } from '../../types';
11
+ import type { NetworkContextType, NetworkProviderProps } from './types';
12
+
13
+ // ----------------------------------------------------------------------
14
+
15
+ const initialValue: NetworkContextType = {
16
+ networkOperation: () => Promise.resolve(),
17
+ };
18
+
19
+ const NetworkContext = createContext<NetworkContextType>(initialValue);
20
+
21
+ function NetworkProvider(props: NetworkProviderProps) {
22
+ const { children, axiosOperation } = props;
23
+ const environment = useEnvironment();
24
+ const hostTools = useHostTools();
25
+
26
+ const networkOperation = useCallback(
27
+ async (networkProps: NetworkProps) => {
28
+ return axiosOperation(networkProps, environment, hostTools);
29
+ },
30
+ [axiosOperation],
31
+ );
32
+
33
+ return (
34
+ <NetworkContext.Provider
35
+ value={{
36
+ networkOperation,
37
+ }}
38
+ >
39
+ {children}
40
+ </NetworkContext.Provider>
41
+ );
42
+ }
43
+
44
+ export { NetworkProvider, NetworkContext };
@@ -1,11 +1,15 @@
1
1
  import { ReactNode } from 'react';
2
2
  import { AxiosOperation, NetworkProps } from '../../types';
3
- export declare type EventFunListener = (...args: any[]) => void;
3
+
4
+ export type EventFunListener = (...args: any[]) => void;
5
+
4
6
  export interface NetworkType {
5
7
  networkOperation: (props: NetworkProps) => Promise<any>;
6
8
  }
9
+
7
10
  export interface NetworkProviderProps {
8
11
  axiosOperation: AxiosOperation;
9
12
  children: ReactNode;
10
13
  }
11
- export declare type NetworkContextType = NetworkType;
14
+
15
+ export type NetworkContextType = NetworkType;
@@ -7,5 +7,6 @@ export { useModulePrivileges } from './useModulePrivileges';
7
7
  export { useModuleSkeleton } from './useModuleSkeleton';
8
8
  export { useNetwork } from './useNetwork';
9
9
  export { usePaginate } from './usePaginate';
10
+
10
11
  export type { PagerState } from './usePaginate/types';
11
12
  export { initialPagerState } from './usePaginate/types';
@@ -0,0 +1,44 @@
1
+ //import { render, screen } from '../../../test/utils';
2
+ import { render, screen } from '../../test/utils';
3
+ import { it } from 'vitest';
4
+ import { EnvironmentProvider } from '../../contexts/EnvironmentContext';
5
+ import useEnvironment from '.';
6
+
7
+ it('useEnvironment tenga acceso a las variables del contexto', () => {
8
+ const obValue = {
9
+ isLocalhost: true,
10
+ host: 'h1',
11
+ domain_token: '1',
12
+ host_api_local: '2',
13
+ host_api_remote: '3',
14
+ host_static_assets: '4',
15
+ environment_assets: '5',
16
+ dfnsFormat: {
17
+ date_format: 'yyyy-MM-dd',
18
+ date_mask: '____-__-__',
19
+ time_format: 'HH:mm:ss',
20
+ time_mask: '__:__:__',
21
+ datetime_format: 'yyyy-MM-dd HH:mm:ss',
22
+ datetime_mask: '____-__-__ __:__:__',
23
+ },
24
+ };
25
+
26
+ const stringValue = JSON.stringify(obValue);
27
+
28
+ const Component = () => {
29
+ const value = useEnvironment();
30
+ return <div data-testid="useDivHostId">{JSON.stringify(value)}</div>;
31
+ };
32
+
33
+ // const { container } =
34
+ render(
35
+ <EnvironmentProvider {...obValue}>
36
+ <Component />
37
+ </EnvironmentProvider>,
38
+ );
39
+
40
+ // container.querySelector('#useDivHostId');
41
+ //console.log('Q trajo', window);
42
+
43
+ expect(screen.getByTestId('useDivHostId').textContent).toBe(stringValue);
44
+ });
@@ -0,0 +1,13 @@
1
+ import { useContext } from 'react';
2
+ import { EnvironmentContext } from '../../contexts/EnvironmentContext';
3
+
4
+ // ---------------------------------------------------------------------
5
+ export const useEnvironment = () => {
6
+ const context = useContext(EnvironmentContext);
7
+
8
+ if (!context) throw new Error('useEnvironment context must be use inside EnvironmentContext');
9
+
10
+ return context;
11
+ };
12
+
13
+ export default useEnvironment;