@m4l/core 0.1.0 → 0.1.3
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/package.json +7 -2
- package/index.html +0 -13
- package/src/contexts/EnvironmentContext/index.tsx +0 -45
- package/src/contexts/EnvironmentContext/types.ts +0 -8
- package/src/contexts/FlagsContext/index.tsx +0 -50
- package/src/contexts/FlagsContext/types.ts +0 -16
- package/src/contexts/HostToolsContext/index.tsx +0 -35
- package/src/contexts/HostToolsContext/types.ts +0 -8
- package/src/contexts/ModuleDictionaryContext/index.tsx +0 -109
- package/src/contexts/ModuleDictionaryContext/types.ts +0 -18
- package/src/contexts/ModulePrivilegesContext/index.tsx +0 -88
- package/src/contexts/ModulePrivilegesContext/types.ts +0 -12
- package/src/contexts/ModuleSkeletonContext/index.tsx +0 -35
- package/src/contexts/ModuleSkeletonContext/types.ts +0 -11
- package/src/contexts/NetworkContext/index.tsx +0 -44
- package/src/contexts/NetworkContext/types.ts +0 -15
- package/src/contexts/index.ts +0 -7
- package/src/hooks/index.ts +0 -12
- package/src/hooks/useEnvironment/index.test.tsx +0 -44
- package/src/hooks/useEnvironment/index.ts +0 -13
- package/src/hooks/useFlags/index.ts +0 -35
- package/src/hooks/useHostTools/index.ts +0 -13
- package/src/hooks/useLocalStorage/index.ts +0 -23
- package/src/hooks/useModuleDictionary/index.ts +0 -11
- package/src/hooks/useModulePrivileges/index.ts +0 -11
- package/src/hooks/useModuleSkeleton/index.ts +0 -11
- package/src/hooks/useNetwork/index.ts +0 -13
- package/src/hooks/usePaginate/index.ts +0 -109
- package/src/hooks/usePaginate/types.ts +0 -18
- package/src/index.ts +0 -43
- package/src/isolation/App.tsx +0 -105
- package/src/isolation/components/Paginate.tsx +0 -65
- package/src/isolation/components/TestHooks/CallBack.tsx +0 -43
- package/src/isolation/components/TestHooks/SimpleUseEffect.tsx +0 -33
- package/src/jest.d.ts +0 -1
- package/src/main.tsx +0 -5
- package/src/test/setup.ts +0 -1
- package/src/test/utils.tsx +0 -20
- package/src/types/dictionary.ts +0 -17
- package/src/types/index.ts +0 -66
- package/src/utils/axiosOperation/index.ts +0 -150
- package/src/utils/axiosOperation/types.ts +0 -5
- package/src/utils/getLocalStorage.ts +0 -8
- package/src/utils/getPropertyByString.ts +0 -10
- package/src/utils/index.ts +0 -5
- package/src/utils/setLocalStorage.ts +0 -12
- package/src/utils/voidFunction.ts +0 -2
- package/src/vite-env.d.ts +0 -4
- package/tsconfig.json +0 -20
- package/tsconfig.node.json +0 -10
- package/vite.config.ts +0 -200
package/package.json
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@m4l/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"author": "M4L Team",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"dev": "vite",
|
|
8
|
-
"build": "tsc && vite build",
|
|
8
|
+
"build": "tsc && vite build && yarn build:copy-files",
|
|
9
9
|
"preview": "vite preview",
|
|
10
10
|
"lint": "npx eslint src",
|
|
11
11
|
"lint:fix": "npm run lint -- --fix",
|
|
12
12
|
"prettier": "npx prettier src --check",
|
|
13
13
|
"prettier:fix": "npm run prettier -- --write",
|
|
14
14
|
"format": "npm run prettier:fix && npm run lint:fix",
|
|
15
|
+
"build:copy-files": "node ../../scripts/copy-files.js",
|
|
16
|
+
"release": "yarn build && npm publish build",
|
|
15
17
|
"test": "vitest",
|
|
16
18
|
"coverage": "vitest run --coverage",
|
|
17
19
|
"Oldprepack": "json -f package.json -I -e \"delete this.devDependencies; delete this.dependencies\""
|
|
@@ -62,6 +64,9 @@
|
|
|
62
64
|
"vite-plugin-mkcert": "^1.9.0",
|
|
63
65
|
"vitest": "^0.17.1"
|
|
64
66
|
},
|
|
67
|
+
"files": [
|
|
68
|
+
"."
|
|
69
|
+
],
|
|
65
70
|
"source": "src/index.ts",
|
|
66
71
|
"main": "./dist/index.js",
|
|
67
72
|
"module": "./dist/index.js",
|
package/index.html
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
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>
|
|
@@ -1,45 +0,0 @@
|
|
|
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,50 +0,0 @@
|
|
|
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,16 +0,0 @@
|
|
|
1
|
-
import { ReactNode } from 'react';
|
|
2
|
-
|
|
3
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
4
|
-
export interface FlagsProviderProps {
|
|
5
|
-
children: ReactNode;
|
|
6
|
-
}
|
|
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
|
|
12
|
-
export interface FlagsContextProps {
|
|
13
|
-
flags: Array<Flag>;
|
|
14
|
-
clearFlags: () => void;
|
|
15
|
-
addFlag: (flag: Flag) => void;
|
|
16
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
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,109 +0,0 @@
|
|
|
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,18 +0,0 @@
|
|
|
1
|
-
import { ReactNode } from 'react';
|
|
2
|
-
import type { GetLabelType, ModuleDictionary } from '../../types/dictionary';
|
|
3
|
-
|
|
4
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
5
|
-
export interface ModuleDictionaryProviderProps {
|
|
6
|
-
currentLang?: string;
|
|
7
|
-
isAuth?: boolean;
|
|
8
|
-
moduleId: string;
|
|
9
|
-
moduleName?: string; //la llave donde reposa el nombre del modulo en el diccionario
|
|
10
|
-
componentsDictionary: string[];
|
|
11
|
-
children: ReactNode;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export interface ModuleDictionaryContextProps {
|
|
15
|
-
moduleDictionary?: ModuleDictionary;
|
|
16
|
-
getLabel: GetLabelType;
|
|
17
|
-
getModuleLabel: () => string;
|
|
18
|
-
}
|
|
@@ -1,88 +0,0 @@
|
|
|
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,12 +0,0 @@
|
|
|
1
|
-
import { ReactNode } from 'react';
|
|
2
|
-
|
|
3
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
4
|
-
export interface ModulePrivilegesProviderProps {
|
|
5
|
-
queryPrivileges: string[];
|
|
6
|
-
children: ReactNode;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export interface ModulePrivilegesContextProps {
|
|
10
|
-
privileges: Record<string, boolean>;
|
|
11
|
-
hasPrivilege: (id: string) => boolean;
|
|
12
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
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,11 +0,0 @@
|
|
|
1
|
-
import { ReactNode } from 'react';
|
|
2
|
-
|
|
3
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
4
|
-
export interface ModuleSkeletonProviderProps {
|
|
5
|
-
flags: string[];
|
|
6
|
-
children: ReactNode;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export interface ModuleSkeletonContextProps {
|
|
10
|
-
isSkeleton: boolean;
|
|
11
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
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,15 +0,0 @@
|
|
|
1
|
-
import { ReactNode } from 'react';
|
|
2
|
-
import { AxiosOperation, NetworkProps } from '../../types';
|
|
3
|
-
|
|
4
|
-
export type EventFunListener = (...args: any[]) => void;
|
|
5
|
-
|
|
6
|
-
export interface NetworkType {
|
|
7
|
-
networkOperation: (props: NetworkProps) => Promise<any>;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export interface NetworkProviderProps {
|
|
11
|
-
axiosOperation: AxiosOperation;
|
|
12
|
-
children: ReactNode;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export type NetworkContextType = NetworkType;
|
package/src/contexts/index.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export { EnvironmentContext, EnvironmentProvider } from './EnvironmentContext';
|
|
2
|
-
export { HostToolsContext, HostToolsProvider } from './HostToolsContext';
|
|
3
|
-
export { NetworkContext, NetworkProvider } from './NetworkContext';
|
|
4
|
-
export { FlagsContext, FlagsProvider } from './FlagsContext';
|
|
5
|
-
export { ModuleDictionaryContext, ModuleDictionaryProvider } from './ModuleDictionaryContext';
|
|
6
|
-
export { ModulePrivilegesContext, ModulePrivilegesProvider } from './ModulePrivilegesContext';
|
|
7
|
-
export { ModuleSkeletonContext, ModuleSkeletonProvider } from './ModuleSkeletonContext';
|
package/src/hooks/index.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export { useEnvironment } from './useEnvironment';
|
|
2
|
-
export { useFlags, useFlagsPresent } from './useFlags';
|
|
3
|
-
export { useHostTools } from './useHostTools';
|
|
4
|
-
export { useLocalStorage } from './useLocalStorage';
|
|
5
|
-
export { useModuleDictionary } from './useModuleDictionary';
|
|
6
|
-
export { useModulePrivileges } from './useModulePrivileges';
|
|
7
|
-
export { useModuleSkeleton } from './useModuleSkeleton';
|
|
8
|
-
export { useNetwork } from './useNetwork';
|
|
9
|
-
export { usePaginate } from './usePaginate';
|
|
10
|
-
|
|
11
|
-
export type { PagerState } from './usePaginate/types';
|
|
12
|
-
export { initialPagerState } from './usePaginate/types';
|
|
@@ -1,44 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,13 +0,0 @@
|
|
|
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;
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { useContext, useEffect, useState } from 'react';
|
|
2
|
-
import { FlagsContext } from '../../contexts/FlagsContext';
|
|
3
|
-
import type { Flag, FlagsContextProps } from '../../contexts/FlagsContext/types';
|
|
4
|
-
|
|
5
|
-
// ----------------------------------------------------------------------
|
|
6
|
-
export const useFlags = (): FlagsContextProps => {
|
|
7
|
-
const context = useContext(FlagsContext);
|
|
8
|
-
|
|
9
|
-
if (!context) throw new Error('useFlags context must be use inside FlagsProvider');
|
|
10
|
-
|
|
11
|
-
return context;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
function isFlagsPresent(compareFlags: Array<Flag>, flags: Array<Flag>) {
|
|
15
|
-
// if (compareFlags.length === 0) return true;
|
|
16
|
-
|
|
17
|
-
const filterFlags = compareFlags.filter(
|
|
18
|
-
findFlag => flags.findIndex(sFlag => sFlag === findFlag) !== -1,
|
|
19
|
-
);
|
|
20
|
-
|
|
21
|
-
return filterFlags.length === compareFlags.length;
|
|
22
|
-
}
|
|
23
|
-
export const useFlagsPresent = (compareFlags: Array<Flag>): boolean => {
|
|
24
|
-
const context = useFlags();
|
|
25
|
-
|
|
26
|
-
const [isPresent, setIsPresent] = useState(isFlagsPresent(compareFlags, context.flags));
|
|
27
|
-
|
|
28
|
-
useEffect(() => {
|
|
29
|
-
if (isFlagsPresent(compareFlags, context.flags)) {
|
|
30
|
-
setIsPresent(true);
|
|
31
|
-
}
|
|
32
|
-
}, [context.flags, compareFlags]);
|
|
33
|
-
|
|
34
|
-
return isPresent;
|
|
35
|
-
};
|