@m4l/core 0.0.35 → 0.0.38
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/contexts/ModuleDictionaryContext/index.js +2 -1
- package/dist/contexts/ModuleDictionaryContext/types.d.ts +1 -1
- package/dist/contexts/ModulePrivilegesContext/index.d.ts +5 -0
- package/dist/contexts/ModulePrivilegesContext/index.js +67 -0
- package/dist/contexts/ModulePrivilegesContext/types.d.ts +9 -0
- package/dist/contexts/index.d.ts +1 -0
- package/dist/hooks/index.d.ts +2 -1
- package/dist/hooks/useModulePrivileges/index.d.ts +1 -0
- package/dist/hooks/useModulePrivileges/index.js +9 -0
- package/dist/hooks/usePaginate/index.d.ts +2 -7
- package/dist/hooks/usePaginate/index.js +9 -7
- package/dist/hooks/usePaginate/types.d.ts +6 -0
- package/dist/index.js +4 -2
- package/package.json +1 -1
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { createContext, useState, useLayoutEffect, useCallback } from "react";
|
|
2
|
+
import { u as useEnvironment } from "../../hooks/useEnvironment/index.js";
|
|
2
3
|
import { u as useFlags } from "../../hooks/useFlags/index.js";
|
|
3
4
|
import { u as useHostTools } from "../../hooks/useHostTools/index.js";
|
|
5
|
+
import "../ModulePrivilegesContext/index.js";
|
|
4
6
|
import { u as useNetwork } from "../../hooks/useNetwork/index.js";
|
|
5
|
-
import { u as useEnvironment } from "../../hooks/useEnvironment/index.js";
|
|
6
7
|
import { jsx } from "react/jsx-runtime";
|
|
7
8
|
const initialState = {
|
|
8
9
|
getLabel: () => "..",
|
|
@@ -3,7 +3,7 @@ import type { GetLabelType, ModuleDictionary } from '../../types/dictionary';
|
|
|
3
3
|
export interface ModuleDictionaryProviderProps {
|
|
4
4
|
currentLang?: string;
|
|
5
5
|
isAuth?: boolean;
|
|
6
|
-
moduleId:
|
|
6
|
+
moduleId: string;
|
|
7
7
|
moduleName?: string;
|
|
8
8
|
componentsDictionary: string[];
|
|
9
9
|
children: ReactNode;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { ModulePrivilegesContextProps, ModulePrivilegesProviderProps } from './types';
|
|
3
|
+
declare const ModulePrivilegesContext: import("react").Context<ModulePrivilegesContextProps>;
|
|
4
|
+
declare function ModulePrivilegesProvider(props: ModulePrivilegesProviderProps): JSX.Element;
|
|
5
|
+
export { ModulePrivilegesProvider, ModulePrivilegesContext };
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { createContext, useState, useLayoutEffect, useCallback } from "react";
|
|
2
|
+
import "../EnvironmentContext/index.js";
|
|
3
|
+
import { u as useFlags } from "../../hooks/useFlags/index.js";
|
|
4
|
+
import { u as useHostTools } from "../../hooks/useHostTools/index.js";
|
|
5
|
+
import "../ModuleDictionaryContext/index.js";
|
|
6
|
+
import { u as useNetwork } from "../../hooks/useNetwork/index.js";
|
|
7
|
+
import { jsx } from "react/jsx-runtime";
|
|
8
|
+
const initialState = {
|
|
9
|
+
privileges: {},
|
|
10
|
+
hasPrivilege: () => false
|
|
11
|
+
};
|
|
12
|
+
const ModulePrivilegesContext = createContext(initialState);
|
|
13
|
+
function ModulePrivilegesProvider(props) {
|
|
14
|
+
const {
|
|
15
|
+
children,
|
|
16
|
+
queryPrivileges
|
|
17
|
+
} = props;
|
|
18
|
+
const {
|
|
19
|
+
addFlag
|
|
20
|
+
} = useFlags();
|
|
21
|
+
const [privileges, setPrivileges] = useState({});
|
|
22
|
+
const {
|
|
23
|
+
startProgress,
|
|
24
|
+
stopProgress
|
|
25
|
+
} = useHostTools();
|
|
26
|
+
const {
|
|
27
|
+
networkOperation
|
|
28
|
+
} = useNetwork();
|
|
29
|
+
useLayoutEffect(() => {
|
|
30
|
+
let mounted = true;
|
|
31
|
+
if (queryPrivileges.length === 0) {
|
|
32
|
+
addFlag("privileges_loaded");
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
startProgress();
|
|
36
|
+
networkOperation({
|
|
37
|
+
method: "GET",
|
|
38
|
+
endPoint: `auth/login`,
|
|
39
|
+
parms: {
|
|
40
|
+
privileges: queryPrivileges
|
|
41
|
+
}
|
|
42
|
+
}).then((response) => {
|
|
43
|
+
if (mounted) {
|
|
44
|
+
setPrivileges({
|
|
45
|
+
...response.data
|
|
46
|
+
});
|
|
47
|
+
addFlag("privileges_loaded");
|
|
48
|
+
}
|
|
49
|
+
}).finally(() => {
|
|
50
|
+
stopProgress();
|
|
51
|
+
});
|
|
52
|
+
return function cleanUp() {
|
|
53
|
+
mounted = false;
|
|
54
|
+
};
|
|
55
|
+
}, []);
|
|
56
|
+
const hasPrivilege = useCallback((key) => {
|
|
57
|
+
return key in privileges;
|
|
58
|
+
}, [privileges]);
|
|
59
|
+
return /* @__PURE__ */ jsx(ModulePrivilegesContext.Provider, {
|
|
60
|
+
value: {
|
|
61
|
+
hasPrivilege,
|
|
62
|
+
privileges
|
|
63
|
+
},
|
|
64
|
+
children
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
export { ModulePrivilegesContext as M, ModulePrivilegesProvider as a };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
export interface ModulePrivilegesProviderProps {
|
|
3
|
+
queryPrivileges: string[];
|
|
4
|
+
children: ReactNode;
|
|
5
|
+
}
|
|
6
|
+
export interface ModulePrivilegesContextProps {
|
|
7
|
+
privileges: Record<string, boolean>;
|
|
8
|
+
hasPrivilege: (id: string) => boolean;
|
|
9
|
+
}
|
package/dist/contexts/index.d.ts
CHANGED
|
@@ -3,3 +3,4 @@ export { HostToolsContext, HostToolsProvider } from './HostToolsContext';
|
|
|
3
3
|
export { NetworkContext, NetworkProvider } from './NetworkContext';
|
|
4
4
|
export { FlagsContext, FlagsProvider } from './FlagsContext';
|
|
5
5
|
export { ModuleDictionaryContext, ModuleDictionaryProvider } from './ModuleDictionaryContext';
|
|
6
|
+
export { ModulePrivilegesContext, ModulePrivilegesProvider } from './ModulePrivilegesContext';
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
export { useEnvironment } from './useEnvironment';
|
|
1
2
|
export { useFlags, useFlagsPresent } from './useFlags';
|
|
2
3
|
export { useHostTools } from './useHostTools';
|
|
3
4
|
export { useLocalStorage } from './useLocalStorage';
|
|
4
5
|
export { useModuleDictionary } from './useModuleDictionary';
|
|
6
|
+
export { useModulePrivileges } from './useModulePrivileges';
|
|
5
7
|
export { useNetwork } from './useNetwork';
|
|
6
|
-
export { useEnvironment } from './useEnvironment';
|
|
7
8
|
export { usePaginate } from './usePaginate';
|
|
8
9
|
export type { PagerState } from './usePaginate/types';
|
|
9
10
|
export { initialPagerState } from './usePaginate/types';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useModulePrivileges: () => import("../../contexts/ModulePrivilegesContext/types").ModulePrivilegesContextProps;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
import { M as ModulePrivilegesContext } from "../../contexts/ModulePrivilegesContext/index.js";
|
|
3
|
+
const useModulePrivileges = () => {
|
|
4
|
+
const context = useContext(ModulePrivilegesContext);
|
|
5
|
+
if (!context)
|
|
6
|
+
throw new Error("useModulePrivileges context must be use inside ModulePrivilegesContext");
|
|
7
|
+
return context;
|
|
8
|
+
};
|
|
9
|
+
export { useModulePrivileges as u };
|
|
@@ -1,11 +1,6 @@
|
|
|
1
|
+
import { UsePaginateProps } from './types';
|
|
1
2
|
import type { PagerState } from './types';
|
|
2
|
-
export
|
|
3
|
-
endPoint: string;
|
|
4
|
-
timeout?: number;
|
|
5
|
-
fireOnEnter?: boolean;
|
|
6
|
-
queryParams?: Record<string, unknown>;
|
|
7
|
-
}
|
|
8
|
-
export declare const usePaginate: <TRow>(props: propsUsePaginate) => {
|
|
3
|
+
export declare const usePaginate: <TRow>(props: UsePaginateProps) => {
|
|
9
4
|
onPageChange: (newPage: number) => void;
|
|
10
5
|
onRowsPerPageChange: (newRowsPerPage: number) => void;
|
|
11
6
|
pagerState: PagerState;
|
|
@@ -7,23 +7,25 @@ const initialPagerState = {
|
|
|
7
7
|
totalRecords: 0
|
|
8
8
|
};
|
|
9
9
|
const usePaginate = (props) => {
|
|
10
|
-
const { endPoint, timeout = 5e3, queryParams = {},
|
|
11
|
-
const [refresh, setRefresh] = useState(0);
|
|
10
|
+
const { endPoint, timeout = 5e3, queryParams = {}, fireOnChangeParms } = props;
|
|
11
|
+
const [refresh, setRefresh] = useState(fireOnChangeParms ? 1 : 0);
|
|
12
12
|
const [rows, setRows] = useState([]);
|
|
13
13
|
const [pagerState, setPagerState] = useState(initialPagerState);
|
|
14
14
|
const refPagerState = useRef(initialPagerState);
|
|
15
|
-
const [fire, setFire] = useState(fireOnEnter);
|
|
16
15
|
const { startProgress, stopProgress } = useHostTools();
|
|
17
16
|
const { networkOperation } = useNetwork();
|
|
18
17
|
const Refresh = useCallback(() => {
|
|
19
18
|
setRefresh((oldValue) => oldValue + 1);
|
|
20
19
|
}, []);
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
if (fireOnChangeParms) {
|
|
22
|
+
Refresh();
|
|
23
|
+
}
|
|
24
|
+
}, [queryParams]);
|
|
21
25
|
useEffect(() => {
|
|
22
26
|
let mounted = true;
|
|
23
|
-
if (
|
|
24
|
-
setFire(true);
|
|
27
|
+
if (refresh === 0)
|
|
25
28
|
return;
|
|
26
|
-
}
|
|
27
29
|
startProgress();
|
|
28
30
|
networkOperation({
|
|
29
31
|
method: "GET",
|
|
@@ -53,7 +55,7 @@ const usePaginate = (props) => {
|
|
|
53
55
|
stopProgress();
|
|
54
56
|
mounted = false;
|
|
55
57
|
};
|
|
56
|
-
}, [refresh
|
|
58
|
+
}, [refresh]);
|
|
57
59
|
const onPageChange = (newPage) => {
|
|
58
60
|
refPagerState.current.page = newPage;
|
|
59
61
|
setRefresh((oldValue) => oldValue + 1);
|
|
@@ -4,3 +4,9 @@ export declare interface PagerState {
|
|
|
4
4
|
totalRecords: number;
|
|
5
5
|
}
|
|
6
6
|
export declare const initialPagerState: PagerState;
|
|
7
|
+
export interface UsePaginateProps {
|
|
8
|
+
endPoint: string;
|
|
9
|
+
timeout?: number;
|
|
10
|
+
fireOnChangeParms?: boolean;
|
|
11
|
+
queryParams?: Record<string, unknown>;
|
|
12
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import "react";
|
|
2
|
+
export { E as EnvironmentContext, a as EnvironmentProvider } from "./contexts/EnvironmentContext/index.js";
|
|
2
3
|
export { F as FlagsContext, a as FlagsProvider } from "./contexts/FlagsContext/index.js";
|
|
3
4
|
export { H as HostToolsContext, a as HostToolsProvider } from "./contexts/HostToolsContext/index.js";
|
|
4
5
|
export { M as ModuleDictionaryContext, a as ModuleDictionaryProvider } from "./contexts/ModuleDictionaryContext/index.js";
|
|
6
|
+
export { M as ModulePrivilegesContext, a as ModulePrivilegesProvider } from "./contexts/ModulePrivilegesContext/index.js";
|
|
5
7
|
export { N as NetworkContext, a as NetworkProvider } from "./contexts/NetworkContext/index.js";
|
|
6
|
-
export {
|
|
8
|
+
export { u as useEnvironment } from "./hooks/useEnvironment/index.js";
|
|
7
9
|
export { u as useFlags, a as useFlagsPresent } from "./hooks/useFlags/index.js";
|
|
8
10
|
export { u as useHostTools } from "./hooks/useHostTools/index.js";
|
|
9
11
|
export { u as useLocalStorage } from "./hooks/useLocalStorage/index.js";
|
|
10
12
|
export { u as useModuleDictionary } from "./hooks/useModuleDictionary/index.js";
|
|
13
|
+
export { u as useModulePrivileges } from "./hooks/useModulePrivileges/index.js";
|
|
11
14
|
export { u as useNetwork } from "./hooks/useNetwork/index.js";
|
|
12
|
-
export { u as useEnvironment } from "./hooks/useEnvironment/index.js";
|
|
13
15
|
export { i as initialPagerState, u as usePaginate } from "./hooks/usePaginate/index.js";
|
|
14
16
|
export { E as EmitEvents } from "./types/index.js";
|
|
15
17
|
export { a as getLocalStorage, g as getPropertyByString, s as setLocalStorage, v as voidFunction } from "./utils/index.js";
|