@bit.rhplus/ui.antd.user-select 0.0.1

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.
@@ -0,0 +1,11 @@
1
+ export default UserSelect;
2
+ declare function UserSelect({ users, isLoading, value, onChange, disabled, placeholder, style, ...rest }: {
3
+ [x: string]: any;
4
+ users?: any[];
5
+ isLoading?: boolean;
6
+ value: any;
7
+ onChange: any;
8
+ disabled: any;
9
+ placeholder?: string;
10
+ style: any;
11
+ }): import("react/jsx-runtime").JSX.Element;
package/dist/index.js ADDED
@@ -0,0 +1,54 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /* eslint-disable */
3
+ import React, { useMemo, useState, useCallback } from 'react';
4
+ import { Select } from 'antd';
5
+ import Popover from 'antd/es/popover';
6
+ import Avatar from '@bit.rhplus/ui.avatar';
7
+ import useUserDetails from './useUserDetails';
8
+ import './style.css';
9
+ const fieldMap = {
10
+ userName: 'Uživatel',
11
+ firstName: 'Jméno',
12
+ lastName: 'Příjmení',
13
+ email: 'Email',
14
+ key: 'Klíč',
15
+ };
16
+ const getDisplayName = (user) => `${user.firstName || ''} ${user.lastName || ''}`.trim() || user.userName || user.name || '';
17
+ const getAvatarUrl = (userKey) => userKey ? `/user_service_api/Users/Avatar?userKey=${userKey}` : null;
18
+ const UserPopoverContent = ({ user, loading }) => {
19
+ if (loading)
20
+ return _jsx("div", { children: "Na\u010D\u00EDt\u00E1m..." });
21
+ if (!user)
22
+ return _jsx("div", { children: "U\u017Eivatel nenalezen" });
23
+ return (_jsx("div", { className: "user-select-popover", children: _jsx("table", { children: _jsx("tbody", { children: Object.entries(fieldMap).map(([field, label]) => (_jsxs("tr", { children: [_jsx("td", { children: _jsxs("b", { children: [label, ":"] }) }), _jsx("td", { children: user[field] || 'N/A' })] }, field))) }) }) }));
24
+ };
25
+ const OPTION_STYLE = { display: 'flex', alignItems: 'center', gap: 8 };
26
+ const AVATAR_SIZE = 22;
27
+ const UserSelect = ({ users = [], isLoading = false, value, onChange, disabled, placeholder = 'Vyberte uživatele', style, ...rest }) => {
28
+ const { user: userDetail, loading: detailLoading, hasFetched, fetchUser } = useUserDetails(value);
29
+ const [popoverOpen, setPopoverOpen] = useState(false);
30
+ const options = useMemo(() => users.map((u) => ({
31
+ value: u.key,
32
+ label: getDisplayName(u),
33
+ userKey: u.key,
34
+ })), [users]);
35
+ const handlePopoverOpenChange = useCallback((open) => {
36
+ if (!value)
37
+ return;
38
+ setPopoverOpen(open);
39
+ if (open && !hasFetched) {
40
+ fetchUser();
41
+ }
42
+ }, [value, hasFetched, fetchUser]);
43
+ const selectElement = (_jsx(Select, { ...rest, value: value, onChange: onChange, disabled: disabled, loading: isLoading, placeholder: placeholder, style: style, showSearch: true, autoComplete: "new-password", filterOption: (input, option) => (option?.label ?? '').toLowerCase().includes(input.toLowerCase()), labelRender: (option) => {
44
+ const selectedOption = options.find((opt) => opt.value === option.value);
45
+ if (!selectedOption)
46
+ return option.label;
47
+ return (_jsxs("div", { style: OPTION_STYLE, children: [_jsx(Avatar, { src: getAvatarUrl(selectedOption.userKey), name: selectedOption.label, size: AVATAR_SIZE, round: true }), _jsx("span", { children: selectedOption.label })] }));
48
+ }, optionRender: (option) => (_jsxs("div", { style: OPTION_STYLE, children: [_jsx(Avatar, { src: getAvatarUrl(option.data.userKey), name: option.data.label, size: AVATAR_SIZE, round: true }), _jsx("span", { children: option.data.label })] })), getPopupContainer: (trigger) => trigger.parentNode }));
49
+ if (!value)
50
+ return selectElement;
51
+ return (_jsx(Popover, { content: _jsx(UserPopoverContent, { user: userDetail, loading: detailLoading }), trigger: "hover", open: popoverOpen, onOpenChange: handlePopoverOpenChange, placement: "bottomLeft", mouseEnterDelay: 0.3, children: selectElement }));
52
+ };
53
+ export default UserSelect;
54
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.jsx"],"names":[],"mappings":";A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C,OAAO,CAAC,UAAU,GAClD,CACH,CAAC;IAEF,IAAI,CAAC,KAAK;QAAE,OAAO,aAAa,CAAC;IAEjC,OAAO,CACL,KAAC,OAAO,IACN,OAAO,EAAE,KAAC,kBAAkB,IAAC,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,aAAa,GAAI,EACzE,OAAO,EAAC,OAAO,EACf,IAAI,EAAE,WAAW,EACjB,YAAY,EAAE,uBAAuB,EACrC,SAAS,EAAC,YAAY,EACtB,eAAe,EAAE,GAAG,YAEnB,aAAa,GACN,CACX,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,UAAU,CAAC"}
@@ -0,0 +1,7 @@
1
+ ;
2
+ ;
3
+
4
+ export const compositions = [];
5
+ export const overview = [];
6
+
7
+ export const compositions_metadata = {"compositions":[]};
package/dist/style.css ADDED
@@ -0,0 +1,11 @@
1
+ .user-select-popover td {
2
+ white-space: nowrap;
3
+ padding: 2px 8px 2px 0;
4
+ vertical-align: top;
5
+ }
6
+
7
+ .user-select-popover td:first-child {
8
+ font-weight: 600;
9
+ color: #555;
10
+ padding-right: 12px;
11
+ }
@@ -0,0 +1,12 @@
1
+ export default useUserDetails;
2
+ /**
3
+ * Hook pro lazy fetch detailu uživatele (pro popover).
4
+ * fetchUser() se volá imperativně při hoveru, ne při mount.
5
+ * Sdílí cache s AG Grid tooltips (userCache).
6
+ */
7
+ declare function useUserDetails(userKey: any): {
8
+ user: any;
9
+ loading: boolean;
10
+ hasFetched: any;
11
+ fetchUser: () => void;
12
+ };
@@ -0,0 +1,46 @@
1
+ import { useState, useCallback } from 'react';
2
+ import { useOidcAccessToken } from '@axa-fr/react-oidc';
3
+ import { fetchData } from '@bit.rhplus/data';
4
+ import { getUserFromCache, setUserInCache, hasUserInCache } from '@bit.rhplus/ui.grid/tooltips/userCache';
5
+ const permUsersApi = {
6
+ url: '/user_service_api/users/users',
7
+ methodType: 'POST',
8
+ version: '1.0',
9
+ compression: true,
10
+ withCredentials: true,
11
+ };
12
+ /**
13
+ * Hook pro lazy fetch detailu uživatele (pro popover).
14
+ * fetchUser() se volá imperativně při hoveru, ne při mount.
15
+ * Sdílí cache s AG Grid tooltips (userCache).
16
+ */
17
+ const useUserDetails = (userKey) => {
18
+ const { accessToken } = useOidcAccessToken();
19
+ const [user, setUser] = useState(() => hasUserInCache(userKey) ? getUserFromCache(userKey) : null);
20
+ const [loading, setLoading] = useState(false);
21
+ const [hasFetched, setHasFetched] = useState(hasUserInCache(userKey));
22
+ const fetchUser = useCallback(() => {
23
+ if (!userKey || !accessToken)
24
+ return;
25
+ if (hasUserInCache(userKey)) {
26
+ setUser(getUserFromCache(userKey));
27
+ setHasFetched(true);
28
+ return;
29
+ }
30
+ setLoading(true);
31
+ fetchData(permUsersApi, { filters: [{ field: 'Key', condition: 1, value: userKey }], operator: 1 }, accessToken)
32
+ .then((response) => {
33
+ const found = response?.data?.records?.[0] ?? null;
34
+ setUserInCache(userKey, found);
35
+ setUser(found);
36
+ })
37
+ .catch(() => setUserInCache(userKey, null))
38
+ .finally(() => {
39
+ setLoading(false);
40
+ setHasFetched(true);
41
+ });
42
+ }, [userKey, accessToken]);
43
+ return { user, loading, hasFetched, fetchUser };
44
+ };
45
+ export default useUserDetails;
46
+ //# sourceMappingURL=useUserDetails.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useUserDetails.js","sourceRoot":"","sources":["../useUserDetails.js"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAC9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,wCAAwC,CAAC;AAE1G,MAAM,YAAY,GAAG;IACnB,GAAG,EAAE,+BAA+B;IACpC,UAAU,EAAE,MAAM;IAClB,OAAO,EAAE,KAAK;IACd,WA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KAAK,CAAC,CAAC;QACjB,CAAC,CAAC;aACD,KAAK,CAAC,GAAG,EAAE,CAAC,cAAc,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;aAC1C,OAAO,CAAC,GAAG,EAAE;YACZ,UAAU,CAAC,KAAK,CAAC,CAAC;YAClB,aAAa,CAAC,IAAI,CAAC,CAAC;QACtB,CAAC,CAAC,CAAC;IACP,CAAC,EAAE,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC,CAAC;IAE3B,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,CAAC;AAClD,CAAC,CAAC;AAEF,eAAe,cAAc,CAAC"}
package/index.jsx ADDED
@@ -0,0 +1,129 @@
1
+ /* eslint-disable */
2
+ import React, { useMemo, useState, useCallback } from 'react';
3
+ import { Select } from 'antd';
4
+ import Popover from 'antd/es/popover';
5
+ import Avatar from '@bit.rhplus/ui.avatar';
6
+ import useUserDetails from './useUserDetails';
7
+ import './style.css';
8
+
9
+ const fieldMap = {
10
+ userName: 'Uživatel',
11
+ firstName: 'Jméno',
12
+ lastName: 'Příjmení',
13
+ email: 'Email',
14
+ key: 'Klíč',
15
+ };
16
+
17
+ const getDisplayName = (user) =>
18
+ `${user.firstName || ''} ${user.lastName || ''}`.trim() || user.userName || user.name || '';
19
+
20
+ const getAvatarUrl = (userKey) =>
21
+ userKey ? `/user_service_api/Users/Avatar?userKey=${userKey}` : null;
22
+
23
+ const UserPopoverContent = ({ user, loading }) => {
24
+ if (loading) return <div>Načítám...</div>;
25
+ if (!user) return <div>Uživatel nenalezen</div>;
26
+
27
+ return (
28
+ <div className="user-select-popover">
29
+ <table>
30
+ <tbody>
31
+ {Object.entries(fieldMap).map(([field, label]) => (
32
+ <tr key={field}>
33
+ <td><b>{label}:</b></td>
34
+ <td>{user[field] || 'N/A'}</td>
35
+ </tr>
36
+ ))}
37
+ </tbody>
38
+ </table>
39
+ </div>
40
+ );
41
+ };
42
+
43
+ const OPTION_STYLE = { display: 'flex', alignItems: 'center', gap: 8 };
44
+ const AVATAR_SIZE = 22;
45
+
46
+ const UserSelect = ({ users = [], isLoading = false, value, onChange, disabled, placeholder = 'Vyberte uživatele', style, ...rest }) => {
47
+
48
+ const { user: userDetail, loading: detailLoading, hasFetched, fetchUser } = useUserDetails(value);
49
+ const [popoverOpen, setPopoverOpen] = useState(false);
50
+
51
+ const options = useMemo(() =>
52
+ users.map((u) => ({
53
+ value: u.key,
54
+ label: getDisplayName(u),
55
+ userKey: u.key,
56
+ })),
57
+ [users]
58
+ );
59
+
60
+ const handlePopoverOpenChange = useCallback((open) => {
61
+ if (!value) return;
62
+ setPopoverOpen(open);
63
+ if (open && !hasFetched) {
64
+ fetchUser();
65
+ }
66
+ }, [value, hasFetched, fetchUser]);
67
+
68
+ const selectElement = (
69
+ <Select
70
+ {...rest}
71
+ value={value}
72
+ onChange={onChange}
73
+ disabled={disabled}
74
+ loading={isLoading}
75
+ placeholder={placeholder}
76
+ style={style}
77
+ showSearch
78
+ autoComplete="new-password"
79
+ filterOption={(input, option) =>
80
+ (option?.label ?? '').toLowerCase().includes(input.toLowerCase())
81
+ }
82
+ labelRender={(option) => {
83
+ const selectedOption = options.find((opt) => opt.value === option.value);
84
+ if (!selectedOption) return option.label;
85
+
86
+ return (
87
+ <div style={OPTION_STYLE}>
88
+ <Avatar
89
+ src={getAvatarUrl(selectedOption.userKey)}
90
+ name={selectedOption.label}
91
+ size={AVATAR_SIZE}
92
+ round
93
+ />
94
+ <span>{selectedOption.label}</span>
95
+ </div>
96
+ );
97
+ }}
98
+ optionRender={(option) => (
99
+ <div style={OPTION_STYLE}>
100
+ <Avatar
101
+ src={getAvatarUrl(option.data.userKey)}
102
+ name={option.data.label}
103
+ size={AVATAR_SIZE}
104
+ round
105
+ />
106
+ <span>{option.data.label}</span>
107
+ </div>
108
+ )}
109
+ getPopupContainer={(trigger) => trigger.parentNode}
110
+ />
111
+ );
112
+
113
+ if (!value) return selectElement;
114
+
115
+ return (
116
+ <Popover
117
+ content={<UserPopoverContent user={userDetail} loading={detailLoading} />}
118
+ trigger="hover"
119
+ open={popoverOpen}
120
+ onOpenChange={handlePopoverOpenChange}
121
+ placement="bottomLeft"
122
+ mouseEnterDelay={0.3}
123
+ >
124
+ {selectElement}
125
+ </Popover>
126
+ );
127
+ };
128
+
129
+ export default UserSelect;
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@bit.rhplus/ui.antd.user-select",
3
+ "version": "0.0.1",
4
+ "main": "dist/index.js",
5
+ "componentId": {
6
+ "name": "ui/antd/user-select",
7
+ "version": "0.0.1",
8
+ "scope": "remote-scope"
9
+ },
10
+ "dependencies": {
11
+ "antd": "^5.20.6",
12
+ "@axa-fr/react-oidc": "7.25.13",
13
+ "@bit.rhplus/ui.avatar": "0.0.19",
14
+ "@bit.rhplus/data": "0.0.89",
15
+ "@bit.rhplus/ui.grid": "0.0.136"
16
+ },
17
+ "devDependencies": {
18
+ "@bitdev/react.react-env": "5.0.5"
19
+ },
20
+ "peerDependencies": {
21
+ "react": "^17.0.0 || ^18.0.0 || ^19.0.0"
22
+ },
23
+ "license": "SEE LICENSE IN UNLICENSED",
24
+ "optionalDependencies": {},
25
+ "peerDependenciesMeta": {},
26
+ "type": "module",
27
+ "private": false,
28
+ "publishConfig": {
29
+ "scope": "@bit.rhplus",
30
+ "registry": "https://registry.npmjs.org/"
31
+ }
32
+ }
package/style.css ADDED
@@ -0,0 +1,11 @@
1
+ .user-select-popover td {
2
+ white-space: nowrap;
3
+ padding: 2px 8px 2px 0;
4
+ vertical-align: top;
5
+ }
6
+
7
+ .user-select-popover td:first-child {
8
+ font-weight: 600;
9
+ color: #555;
10
+ padding-right: 12px;
11
+ }
@@ -0,0 +1,43 @@
1
+ declare module '*.png' {
2
+ const value: any;
3
+ export = value;
4
+ }
5
+ declare module '*.svg' {
6
+ import type { FunctionComponent, SVGProps } from 'react';
7
+
8
+ export const ReactComponent: FunctionComponent<
9
+ SVGProps<SVGSVGElement> & { title?: string }
10
+ >;
11
+ const src: string;
12
+ export default src;
13
+ }
14
+
15
+ // @TODO Gilad
16
+ declare module '*.jpg' {
17
+ const value: any;
18
+ export = value;
19
+ }
20
+ declare module '*.jpeg' {
21
+ const value: any;
22
+ export = value;
23
+ }
24
+ declare module '*.gif' {
25
+ const value: any;
26
+ export = value;
27
+ }
28
+ declare module '*.bmp' {
29
+ const value: any;
30
+ export = value;
31
+ }
32
+ declare module '*.otf' {
33
+ const value: any;
34
+ export = value;
35
+ }
36
+ declare module '*.woff' {
37
+ const value: any;
38
+ export = value;
39
+ }
40
+ declare module '*.woff2' {
41
+ const value: any;
42
+ export = value;
43
+ }
package/types/env.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ /// <reference types="vite/client" />
2
+
3
+ export type ImportMetaEnv = Record<string, string>;
4
+
5
+ interface ImportMeta {
6
+ readonly env: ImportMetaEnv
7
+ }
8
+
9
+ declare global {
10
+ namespace NodeJS {
11
+ interface ProcessEnv {
12
+ [key: string]: string;
13
+ }
14
+ }
15
+ }
@@ -0,0 +1,42 @@
1
+ declare module '*.module.css' {
2
+ const classes: { readonly [key: string]: string };
3
+ export default classes;
4
+ }
5
+ declare module '*.module.scss' {
6
+ const classes: { readonly [key: string]: string };
7
+ export default classes;
8
+ }
9
+ declare module '*.module.sass' {
10
+ const classes: { readonly [key: string]: string };
11
+ export default classes;
12
+ }
13
+
14
+ declare module '*.module.less' {
15
+ const classes: { readonly [key: string]: string };
16
+ export default classes;
17
+ }
18
+
19
+ declare module '*.less' {
20
+ const classes: { readonly [key: string]: string };
21
+ export default classes;
22
+ }
23
+
24
+ declare module '*.css' {
25
+ const classes: { readonly [key: string]: string };
26
+ export default classes;
27
+ }
28
+
29
+ declare module '*.sass' {
30
+ const classes: { readonly [key: string]: string };
31
+ export default classes;
32
+ }
33
+
34
+ declare module '*.scss' {
35
+ const classes: { readonly [key: string]: string };
36
+ export default classes;
37
+ }
38
+
39
+ declare module '*.mdx' {
40
+ const component: any;
41
+ export default component;
42
+ }
@@ -0,0 +1,57 @@
1
+ import { useState, useCallback } from 'react';
2
+ import { useOidcAccessToken } from '@axa-fr/react-oidc';
3
+ import { fetchData } from '@bit.rhplus/data';
4
+ import { getUserFromCache, setUserInCache, hasUserInCache } from '@bit.rhplus/ui.grid/tooltips/userCache';
5
+
6
+ const permUsersApi = {
7
+ url: '/user_service_api/users/users',
8
+ methodType: 'POST',
9
+ version: '1.0',
10
+ compression: true,
11
+ withCredentials: true,
12
+ };
13
+
14
+ /**
15
+ * Hook pro lazy fetch detailu uživatele (pro popover).
16
+ * fetchUser() se volá imperativně při hoveru, ne při mount.
17
+ * Sdílí cache s AG Grid tooltips (userCache).
18
+ */
19
+ const useUserDetails = (userKey) => {
20
+ const { accessToken } = useOidcAccessToken();
21
+ const [user, setUser] = useState(() =>
22
+ hasUserInCache(userKey) ? getUserFromCache(userKey) : null
23
+ );
24
+ const [loading, setLoading] = useState(false);
25
+ const [hasFetched, setHasFetched] = useState(hasUserInCache(userKey));
26
+
27
+ const fetchUser = useCallback(() => {
28
+ if (!userKey || !accessToken) return;
29
+
30
+ if (hasUserInCache(userKey)) {
31
+ setUser(getUserFromCache(userKey));
32
+ setHasFetched(true);
33
+ return;
34
+ }
35
+
36
+ setLoading(true);
37
+ fetchData(
38
+ permUsersApi,
39
+ { filters: [{ field: 'Key', condition: 1, value: userKey }], operator: 1 },
40
+ accessToken
41
+ )
42
+ .then((response) => {
43
+ const found = response?.data?.records?.[0] ?? null;
44
+ setUserInCache(userKey, found);
45
+ setUser(found);
46
+ })
47
+ .catch(() => setUserInCache(userKey, null))
48
+ .finally(() => {
49
+ setLoading(false);
50
+ setHasFetched(true);
51
+ });
52
+ }, [userKey, accessToken]);
53
+
54
+ return { user, loading, hasFetched, fetchUser };
55
+ };
56
+
57
+ export default useUserDetails;