@m4l/layouts 9.2.1-beta.1 → 9.2.2
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/hooks/index.d.ts +0 -1
- package/index.d.ts +0 -1
- package/index.js +8 -13
- package/layouts/MasterDetailLayout/MasterDetailLayout.js +9 -8
- package/layouts/MasterDetailLayout/types.d.ts +2 -0
- package/package.json +2 -2
- package/storybook/layouts/MasterDetailLayout/MasterDetailLayout.stories.d.ts +1 -0
- package/storybook/layouts/MasterDetailLayout/subcomponents/RenderMasterDetailLayout.d.ts +5 -1
- package/contexts/AuthContext/index.d.ts +0 -7
- package/contexts/AuthContext/index.js +0 -142
- package/contexts/AuthContext/types.d.ts +0 -51
- package/contexts/AuthContext/types.js +0 -9
- package/contexts/index.d.ts +0 -1
- package/contexts/index.js +0 -1
- package/hooks/useAuth/index.d.ts +0 -5
- package/hooks/useAuth/index.js +0 -12
package/hooks/index.d.ts
CHANGED
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -3,7 +3,6 @@ import { M } from "./components/MFNoAuthApp/index.js";
|
|
|
3
3
|
import { M as M2 } from "./components/MFHostApp/MFHostApp.js";
|
|
4
4
|
import { M as M3 } from "./components/ModuleDetailTabs/ModuleDetailTabs.js";
|
|
5
5
|
import { D } from "./components/DynamicTabs/DynamicTabs.js";
|
|
6
|
-
import { A, a } from "./contexts/AuthContext/index.js";
|
|
7
6
|
import { M as M4 } from "./layouts/ModuleLayout/ModuleLayout.js";
|
|
8
7
|
import { N } from "./layouts/NoAuthModuleLayout/index.js";
|
|
9
8
|
import { d, g } from "./layouts/ModuleLayout/dicctionary.js";
|
|
@@ -11,15 +10,12 @@ import { M as M5 } from "./layouts/MasterDetailLayout/MasterDetailLayout.js";
|
|
|
11
10
|
import { g as g2 } from "./layouts/MasterDetailLayout/dicctionary.js";
|
|
12
11
|
import { d as d2, g as g3 } from "./layouts/NoAuthModuleLayout/dicctionary.js";
|
|
13
12
|
import { u } from "./hooks/useMasterDetail/index.js";
|
|
14
|
-
import { u as u2 } from "./hooks/
|
|
15
|
-
import { u as u3 } from "./hooks/
|
|
16
|
-
import { u as u4 } from "./hooks/
|
|
17
|
-
import {
|
|
18
|
-
import { u as u6 } from "./hooks/useNetworkActionConfirm/useNetworkActionConfirm.js";
|
|
13
|
+
import { u as u2 } from "./hooks/useModule/index.js";
|
|
14
|
+
import { u as u3 } from "./hooks/useDynamicAccordions/useDynamicAccordions.js";
|
|
15
|
+
import { c, u as u4 } from "./hooks/useDynamicPaperForm/useDynamicPaperForm.js";
|
|
16
|
+
import { u as u5 } from "./hooks/useNetworkActionConfirm/useNetworkActionConfirm.js";
|
|
19
17
|
import { c as c2 } from "./utils/createAppMF.js";
|
|
20
18
|
export {
|
|
21
|
-
A as AuthContext,
|
|
22
|
-
a as AuthProvider,
|
|
23
19
|
D as DynamicTabs,
|
|
24
20
|
L as LIMIT_RECORDS_500_CONFIG,
|
|
25
21
|
M2 as MFHostApp,
|
|
@@ -35,10 +31,9 @@ export {
|
|
|
35
31
|
g2 as getMasterDetailLayoutComponentsDictionary,
|
|
36
32
|
g as getModuleLayoutComponentsDictionary,
|
|
37
33
|
g3 as getNoAuthModuleLayoutComponentsDictionary,
|
|
38
|
-
|
|
39
|
-
u4 as
|
|
40
|
-
u5 as useDynamicPaperForm,
|
|
34
|
+
u3 as useDynamicAccordions,
|
|
35
|
+
u4 as useDynamicPaperForm,
|
|
41
36
|
u as useMasterDetail,
|
|
42
|
-
|
|
43
|
-
|
|
37
|
+
u2 as useModule,
|
|
38
|
+
u5 as useNetworkActionConfirm
|
|
44
39
|
};
|
|
@@ -16,15 +16,16 @@ function MasterDetailLayout(props) {
|
|
|
16
16
|
masterComponent,
|
|
17
17
|
detailComponent,
|
|
18
18
|
moduleActions,
|
|
19
|
-
version
|
|
19
|
+
version,
|
|
20
|
+
splitPosition
|
|
20
21
|
} = props;
|
|
21
22
|
const { host_static_assets, environment_assets } = useEnvironment();
|
|
22
|
-
const [
|
|
23
|
+
const [splitPositionState, setSplitPositionState] = useState(splitPosition ?? "vertical");
|
|
23
24
|
const isMobile = useIsMobile();
|
|
24
25
|
const moduleLayoutRef = useRef(null);
|
|
25
26
|
const { getLabel } = useModuleDictionary();
|
|
26
27
|
const onChangePostionInternal = useCallback((newPostion) => {
|
|
27
|
-
|
|
28
|
+
setSplitPositionState(newPostion);
|
|
28
29
|
}, []);
|
|
29
30
|
const splitActions = useMemo(
|
|
30
31
|
() => [
|
|
@@ -35,7 +36,7 @@ function MasterDetailLayout(props) {
|
|
|
35
36
|
label: getLabel(dictionary.LABEL_SPLIT_VERTICAL),
|
|
36
37
|
tag: "vertical",
|
|
37
38
|
className: "splitactions",
|
|
38
|
-
disabled:
|
|
39
|
+
disabled: splitPositionState === "vertical",
|
|
39
40
|
key: "vertical"
|
|
40
41
|
},
|
|
41
42
|
{
|
|
@@ -45,7 +46,7 @@ function MasterDetailLayout(props) {
|
|
|
45
46
|
label: getLabel(dictionary.LABEL_SPLIT_HORIZONTAL),
|
|
46
47
|
tag: "horizontal",
|
|
47
48
|
className: "splitactions",
|
|
48
|
-
disabled:
|
|
49
|
+
disabled: splitPositionState === "horizontal",
|
|
49
50
|
key: "horizontal"
|
|
50
51
|
},
|
|
51
52
|
{
|
|
@@ -55,11 +56,11 @@ function MasterDetailLayout(props) {
|
|
|
55
56
|
label: getLabel(dictionary.LABEL_NO_SPLIT),
|
|
56
57
|
tag: "none",
|
|
57
58
|
className: "splitactions",
|
|
58
|
-
disabled:
|
|
59
|
+
disabled: splitPositionState === "none",
|
|
59
60
|
key: "none"
|
|
60
61
|
}
|
|
61
62
|
],
|
|
62
|
-
[getLabel,
|
|
63
|
+
[getLabel, splitPositionState, environment_assets, host_static_assets, onChangePostionInternal]
|
|
63
64
|
);
|
|
64
65
|
const onClickViewDetail = useCallback(() => {
|
|
65
66
|
moduleLayoutRef.current?.openModal({
|
|
@@ -95,7 +96,7 @@ function MasterDetailLayout(props) {
|
|
|
95
96
|
children: /* @__PURE__ */ jsx(
|
|
96
97
|
SplitLayout,
|
|
97
98
|
{
|
|
98
|
-
splitPosition: isMobile ? "none" :
|
|
99
|
+
splitPosition: isMobile ? "none" : splitPositionState,
|
|
99
100
|
firstPart: masterComponent,
|
|
100
101
|
secondPart: detailComponent
|
|
101
102
|
}
|
|
@@ -4,10 +4,12 @@ import { OverridesStyleRules } from '@mui/material/styles/overrides';
|
|
|
4
4
|
import { MasterDetailLayoutSlots } from './slots/MasterDetailLayoutEnum';
|
|
5
5
|
import { MASTER_DETAIL_LAYOUT_PREFIX } from './constants';
|
|
6
6
|
import { Theme } from '@mui/material/styles';
|
|
7
|
+
import { SplitPosition } from '@m4l/components';
|
|
7
8
|
export interface ContainerProps {
|
|
8
9
|
vertical: boolean;
|
|
9
10
|
}
|
|
10
11
|
export interface MasterDetailLayoutProps extends Omit<ModuleLayoutProps, 'children'> {
|
|
12
|
+
splitPosition?: SplitPosition;
|
|
11
13
|
masterComponent: ((props?: any) => JSX.Element) | ReactNode;
|
|
12
14
|
detailComponent: ((props?: any) => JSX.Element) | ReactNode;
|
|
13
15
|
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@m4l/layouts",
|
|
3
|
-
"version": "9.2.
|
|
3
|
+
"version": "9.2.2",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"author": "M4L Team ",
|
|
6
6
|
"lint-staged": {
|
|
7
7
|
"*.{js,ts,tsx}": "eslint --fix --max-warnings 0"
|
|
8
8
|
},
|
|
9
9
|
"peerDependencies": {
|
|
10
|
-
"@m4l/components": "9.
|
|
10
|
+
"@m4l/components": "^9.0.0",
|
|
11
11
|
"@m4l/core": "^2.0.0",
|
|
12
12
|
"@m4l/graphics": "^7.0.0",
|
|
13
13
|
"@m4l/styles": "^7.0.0"
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
import { SplitPosition } from '@m4l/components';
|
|
2
|
+
interface RenderMasterDetailLayoutProps {
|
|
3
|
+
splitPosition?: SplitPosition;
|
|
4
|
+
}
|
|
1
5
|
/**
|
|
2
6
|
* Render para utilizar el componente ModuleLayout
|
|
3
7
|
* en AreasViewer en el storybook
|
|
4
8
|
*/
|
|
5
|
-
declare const RenderMasterDetailLayout: () => import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
declare const RenderMasterDetailLayout: (props: RenderMasterDetailLayoutProps) => import("react/jsx-runtime").JSX.Element;
|
|
6
10
|
export default RenderMasterDetailLayout;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { AuthProviderProps, SessionContextType } from './types';
|
|
2
|
-
declare const AuthContext: import('react').Context<SessionContextType | null>;
|
|
3
|
-
/**
|
|
4
|
-
* Proveedor de autenticación
|
|
5
|
-
*/
|
|
6
|
-
declare function AuthProvider(props: AuthProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
7
|
-
export { AuthContext, AuthProvider };
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import { createContext, useReducer, useEffect } from "react";
|
|
3
|
-
import { useHostTools, useNetwork, useEnvironment, useLocalStorageWithListener, EmitEvents, getLocalStorage, setLocalStorage } from "@m4l/core";
|
|
4
|
-
import { E as EnumTypes } from "./types.js";
|
|
5
|
-
const initialState = {
|
|
6
|
-
isAuthenticated: false,
|
|
7
|
-
isInitialized: false,
|
|
8
|
-
user: null
|
|
9
|
-
};
|
|
10
|
-
const JWTReducer = (state, action) => {
|
|
11
|
-
switch (action.type) {
|
|
12
|
-
case "INITIALIZE":
|
|
13
|
-
return {
|
|
14
|
-
isAuthenticated: action.payload.isAuthenticated,
|
|
15
|
-
isInitialized: true,
|
|
16
|
-
user: action.payload.user
|
|
17
|
-
};
|
|
18
|
-
case "LOGIN":
|
|
19
|
-
return {
|
|
20
|
-
...state,
|
|
21
|
-
isAuthenticated: true,
|
|
22
|
-
user: action.payload.user
|
|
23
|
-
};
|
|
24
|
-
case "LOGOUT":
|
|
25
|
-
return {
|
|
26
|
-
...state,
|
|
27
|
-
isAuthenticated: false,
|
|
28
|
-
user: null
|
|
29
|
-
};
|
|
30
|
-
default:
|
|
31
|
-
return state;
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
const AuthContext = createContext(null);
|
|
35
|
-
function dispatchInitial(dispatch) {
|
|
36
|
-
dispatch({
|
|
37
|
-
type: EnumTypes.Initial,
|
|
38
|
-
payload: {
|
|
39
|
-
isAuthenticated: false,
|
|
40
|
-
user: null
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
function AuthProvider(props) {
|
|
45
|
-
const { children } = props;
|
|
46
|
-
const [state, dispatch] = useReducer(JWTReducer, initialState);
|
|
47
|
-
const { events_add_listener } = useHostTools();
|
|
48
|
-
const { networkOperation } = useNetwork();
|
|
49
|
-
const { domain_token } = useEnvironment();
|
|
50
|
-
const [nextValSession, setNextValSession] = useLocalStorageWithListener(
|
|
51
|
-
//Variable para saber si ha cambiado la session en otro navegador
|
|
52
|
-
"vSession",
|
|
53
|
-
(/* @__PURE__ */ new Date()).getTime() + ""
|
|
54
|
-
);
|
|
55
|
-
useEffect(() => {
|
|
56
|
-
const initialize = async () => {
|
|
57
|
-
networkOperation({
|
|
58
|
-
method: "GET",
|
|
59
|
-
endPoint: `auth/login`,
|
|
60
|
-
parms: { user_data: true },
|
|
61
|
-
checkUnAuthorized: false
|
|
62
|
-
}).then((response) => {
|
|
63
|
-
dispatch({
|
|
64
|
-
type: EnumTypes.Initial,
|
|
65
|
-
payload: {
|
|
66
|
-
isAuthenticated: true,
|
|
67
|
-
user: response.user
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
const useSaved = getLocalStorage("userData", {
|
|
71
|
-
email: response.user.email,
|
|
72
|
-
remember: true
|
|
73
|
-
});
|
|
74
|
-
if (useSaved?.email !== response.user.email) {
|
|
75
|
-
setLocalStorage("userData", { email: response.user.email }, true);
|
|
76
|
-
}
|
|
77
|
-
}).catch(() => {
|
|
78
|
-
dispatchInitial(dispatch);
|
|
79
|
-
});
|
|
80
|
-
};
|
|
81
|
-
initialize();
|
|
82
|
-
}, [nextValSession]);
|
|
83
|
-
const login = async (email, password, remember) => {
|
|
84
|
-
await networkOperation({
|
|
85
|
-
endPoint: `auth/login`,
|
|
86
|
-
method: "POST",
|
|
87
|
-
data: {
|
|
88
|
-
email,
|
|
89
|
-
password,
|
|
90
|
-
domain_token
|
|
91
|
-
}
|
|
92
|
-
}).then((response) => {
|
|
93
|
-
const user = response.data;
|
|
94
|
-
if (remember) {
|
|
95
|
-
setLocalStorage("userData", { email, remember });
|
|
96
|
-
} else {
|
|
97
|
-
setLocalStorage("userData", { email: "", remember });
|
|
98
|
-
}
|
|
99
|
-
dispatch({
|
|
100
|
-
type: EnumTypes.Login,
|
|
101
|
-
payload: {
|
|
102
|
-
user
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
setNextValSession((/* @__PURE__ */ new Date()).getTime() + "");
|
|
106
|
-
});
|
|
107
|
-
};
|
|
108
|
-
const logout = async (isAuthenticated) => {
|
|
109
|
-
if (isAuthenticated) {
|
|
110
|
-
await networkOperation({
|
|
111
|
-
endPoint: `auth/logout`,
|
|
112
|
-
method: "POST"
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
dispatch({ type: EnumTypes.Logout });
|
|
116
|
-
setNextValSession((/* @__PURE__ */ new Date()).getTime() + "");
|
|
117
|
-
};
|
|
118
|
-
const onNetserviceUnautorized = () => {
|
|
119
|
-
logout(false);
|
|
120
|
-
};
|
|
121
|
-
useEffect(() => {
|
|
122
|
-
events_add_listener(
|
|
123
|
-
EmitEvents.EMMIT_EVENT_NET_SERVICE_UNAUTHORIZED,
|
|
124
|
-
onNetserviceUnautorized
|
|
125
|
-
);
|
|
126
|
-
}, []);
|
|
127
|
-
return /* @__PURE__ */ jsx(
|
|
128
|
-
AuthContext.Provider,
|
|
129
|
-
{
|
|
130
|
-
value: {
|
|
131
|
-
...state,
|
|
132
|
-
login,
|
|
133
|
-
logout
|
|
134
|
-
},
|
|
135
|
-
children
|
|
136
|
-
}
|
|
137
|
-
);
|
|
138
|
-
}
|
|
139
|
-
export {
|
|
140
|
-
AuthContext as A,
|
|
141
|
-
AuthProvider as a
|
|
142
|
-
};
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { DomainCountry, Maybe } from '@m4l/core';
|
|
2
|
-
import { ReactNode } from 'react';
|
|
3
|
-
export declare enum EnumTypes {
|
|
4
|
-
Initial = "INITIALIZE",
|
|
5
|
-
Login = "LOGIN",
|
|
6
|
-
Logout = "LOGOUT"
|
|
7
|
-
}
|
|
8
|
-
export type AuthProviderProps = {
|
|
9
|
-
children: ReactNode;
|
|
10
|
-
};
|
|
11
|
-
export type ActionMap<M extends {
|
|
12
|
-
[index: string]: any;
|
|
13
|
-
}> = {
|
|
14
|
-
[Key in keyof M]: M[Key] extends undefined ? {
|
|
15
|
-
type: Key;
|
|
16
|
-
} : {
|
|
17
|
-
type: Key;
|
|
18
|
-
payload: M[Key];
|
|
19
|
-
};
|
|
20
|
-
};
|
|
21
|
-
export type SessionAuthPayload = {
|
|
22
|
-
[EnumTypes.Initial]: {
|
|
23
|
-
isAuthenticated: boolean;
|
|
24
|
-
user: AuthUser;
|
|
25
|
-
};
|
|
26
|
-
[EnumTypes.Login]: {
|
|
27
|
-
user: AuthUser;
|
|
28
|
-
};
|
|
29
|
-
[EnumTypes.Logout]: undefined;
|
|
30
|
-
};
|
|
31
|
-
export type SessionActions = ActionMap<SessionAuthPayload>[keyof ActionMap<SessionAuthPayload>];
|
|
32
|
-
export interface User {
|
|
33
|
-
email: string;
|
|
34
|
-
id: number;
|
|
35
|
-
first_name: string;
|
|
36
|
-
last_name: string;
|
|
37
|
-
account_id: number;
|
|
38
|
-
domain_country: DomainCountry;
|
|
39
|
-
avatar_url?: Maybe<string>;
|
|
40
|
-
user_type_id?: number;
|
|
41
|
-
}
|
|
42
|
-
export type AuthUser = Maybe<User>;
|
|
43
|
-
export type AuthState = {
|
|
44
|
-
isAuthenticated: boolean;
|
|
45
|
-
isInitialized: boolean;
|
|
46
|
-
user: AuthUser;
|
|
47
|
-
};
|
|
48
|
-
export interface SessionContextType extends AuthState {
|
|
49
|
-
login: (email: string, password: string, remember: boolean) => object | undefined;
|
|
50
|
-
logout: (isAuthenticated: boolean) => Promise<void>;
|
|
51
|
-
}
|
package/contexts/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './AuthContext';
|
package/contexts/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
|
package/hooks/useAuth/index.d.ts
DELETED
package/hooks/useAuth/index.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { useContext } from "react";
|
|
2
|
-
import { A as AuthContext } from "../../contexts/AuthContext/index.js";
|
|
3
|
-
const useAuth = () => {
|
|
4
|
-
const context = useContext(AuthContext);
|
|
5
|
-
if (!context) {
|
|
6
|
-
throw new Error("Auth context must be use inside AuthProvider");
|
|
7
|
-
}
|
|
8
|
-
return context;
|
|
9
|
-
};
|
|
10
|
-
export {
|
|
11
|
-
useAuth as u
|
|
12
|
-
};
|