@m4l/core 0.0.36 → 0.0.39
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/HostToolsContext/index.js +1 -0
- package/dist/contexts/ModuleDictionaryContext/index.js +2 -2
- package/dist/contexts/ModulePrivilegesContext/index.js +7 -3
- 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/types/index.d.ts +1 -0
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createContext, useState,
|
|
1
|
+
import { createContext, useState, useEffect, useCallback } from "react";
|
|
2
2
|
import { u as useEnvironment } from "../../hooks/useEnvironment/index.js";
|
|
3
3
|
import { u as useFlags } from "../../hooks/useFlags/index.js";
|
|
4
4
|
import { u as useHostTools } from "../../hooks/useHostTools/index.js";
|
|
@@ -33,7 +33,7 @@ function ModuleDictionaryProvider(props) {
|
|
|
33
33
|
const {
|
|
34
34
|
networkOperation
|
|
35
35
|
} = useNetwork();
|
|
36
|
-
|
|
36
|
+
useEffect(() => {
|
|
37
37
|
let mounted = true;
|
|
38
38
|
startProgress();
|
|
39
39
|
networkOperation({
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createContext, useState,
|
|
1
|
+
import { createContext, useState, useEffect, useCallback } from "react";
|
|
2
2
|
import "../EnvironmentContext/index.js";
|
|
3
3
|
import { u as useFlags } from "../../hooks/useFlags/index.js";
|
|
4
4
|
import { u as useHostTools } from "../../hooks/useHostTools/index.js";
|
|
@@ -26,12 +26,16 @@ function ModulePrivilegesProvider(props) {
|
|
|
26
26
|
const {
|
|
27
27
|
networkOperation
|
|
28
28
|
} = useNetwork();
|
|
29
|
-
|
|
29
|
+
useEffect(() => {
|
|
30
30
|
let mounted = true;
|
|
31
|
+
if (queryPrivileges.length === 0) {
|
|
32
|
+
addFlag("privileges_loaded");
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
31
35
|
startProgress();
|
|
32
36
|
networkOperation({
|
|
33
37
|
method: "GET",
|
|
34
|
-
endPoint: `auth/
|
|
38
|
+
endPoint: `auth/login`,
|
|
35
39
|
parms: {
|
|
36
40
|
privileges: queryPrivileges
|
|
37
41
|
}
|
|
@@ -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/types/index.d.ts
CHANGED
|
@@ -37,6 +37,7 @@ export declare interface HostToolsType {
|
|
|
37
37
|
toast: ToastFunction;
|
|
38
38
|
startProgress: VoidFunction;
|
|
39
39
|
stopProgress: VoidFunction;
|
|
40
|
+
formatDate: (date: Date | number, format: string, options?: any) => string;
|
|
40
41
|
events_add_listener: (eventName: string, handler: EventFunListener) => void;
|
|
41
42
|
events_remove_listener: (eventName: string, handler: Maybe<EventFunListener>) => void;
|
|
42
43
|
events_emit: (eventName: string, arg: any) => void;
|