ag-common 0.0.16 → 0.0.20
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/api/helpers/api.d.ts +1 -2
- package/dist/api/helpers/api.js +2 -0
- package/dist/api/helpers/validateOpenApi.d.ts +1 -1
- package/dist/api/helpers/validateOpenApi.js +1 -0
- package/dist/api/helpers/validations.d.ts +1 -1
- package/dist/api/helpers/validations.js +1 -0
- package/dist/api/types.d.ts +29 -0
- package/dist/common/helpers/log.js +9 -9
- package/dist/ui/components/DropdownList/index.d.ts +3 -2
- package/dist/ui/components/DropdownList/index.js +25 -27
- package/dist/ui/components/LogoutButton/index.d.ts +8 -0
- package/dist/ui/components/LogoutButton/index.js +31 -0
- package/dist/ui/components/TextEdit/CheckboxEdit.js +2 -2
- package/dist/ui/components/TextEdit/ColourEdit.js +2 -2
- package/dist/ui/components/TextEdit/ListboxEdit.js +2 -2
- package/dist/ui/components/TextEdit/TextEdit.js +10 -4
- package/dist/ui/components/TextEdit/common.d.ts +9 -1
- package/dist/ui/components/TextEdit/common.js +5 -5
- package/dist/ui/components/UserImage/index.d.ts +8 -5
- package/dist/ui/components/UserImage/index.js +16 -12
- package/dist/ui/components/index.d.ts +1 -0
- package/dist/ui/components/index.js +1 -0
- package/dist/ui/helpers/routes.d.ts +2 -1
- package/package.json +2 -4
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { APIGatewayProxyResult } from '
|
|
2
|
-
import { DYNAMOKEYS } from '../types';
|
|
1
|
+
import { APIGatewayProxyResult, DYNAMOKEYS } from '../types';
|
|
3
2
|
export declare const returnCode: <T>(statusCode: number, body?: T | undefined, extraHeaders?: {
|
|
4
3
|
[a: string]: string;
|
|
5
4
|
} | undefined, fullSiteUrl?: string | undefined) => APIGatewayProxyResult;
|
package/dist/api/helpers/api.js
CHANGED
|
@@ -12,6 +12,8 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
12
12
|
};
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
14
|
exports.generateDynamoPKS = exports.stripPKs = exports.returnCode = void 0;
|
|
15
|
+
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
16
|
+
// eslint-disable-next-line
|
|
15
17
|
const array_1 = require("../../common/helpers/array");
|
|
16
18
|
const returnCode = (statusCode, body, extraHeaders, fullSiteUrl) => {
|
|
17
19
|
let headers = {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { APIGatewayEvent, APIGatewayProxyResult } from 'aws-lambda';
|
|
2
1
|
import { User } from '../../ui/helpers/jwt';
|
|
3
2
|
import { TLang } from '../../common/helpers/i18n';
|
|
3
|
+
import { APIGatewayEvent, APIGatewayProxyResult } from '../types';
|
|
4
4
|
export declare type NextType<T> = ({ event, body, params, userProfile, lang, }: {
|
|
5
5
|
params: Record<string, string>;
|
|
6
6
|
event: APIGatewayEvent;
|
|
@@ -13,6 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.validateOpenApi = void 0;
|
|
16
|
+
// eslint-disable-next-line import/no-unresolved
|
|
16
17
|
const openapi_request_validator_1 = __importDefault(require("openapi-request-validator"));
|
|
17
18
|
const validations_1 = require("./validations");
|
|
18
19
|
const log_1 = require("../../common/helpers/log");
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { APIGatewayProxyResult } from 'aws-lambda';
|
|
2
1
|
import { error } from '../../common/helpers/log';
|
|
3
2
|
import { User } from '../../ui/helpers/jwt';
|
|
3
|
+
import { APIGatewayProxyResult } from '../types';
|
|
4
4
|
export declare const getAndValidateToken: ({ tokenRaw, COGNITO_USER_POOL_ID, }: {
|
|
5
5
|
tokenRaw?: string | undefined;
|
|
6
6
|
COGNITO_USER_POOL_ID: string;
|
|
@@ -13,6 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.getAndValidateToken = void 0;
|
|
16
|
+
/* eslint-disable import/no-unresolved */
|
|
16
17
|
const jwks_rsa_1 = __importDefault(require("jwks-rsa"));
|
|
17
18
|
const jsonwebtoken_1 = require("jsonwebtoken");
|
|
18
19
|
const log_1 = require("../../common/helpers/log");
|
package/dist/api/types.d.ts
CHANGED
|
@@ -43,3 +43,32 @@ export interface IQueryDynamo {
|
|
|
43
43
|
filterValue?: string | number;
|
|
44
44
|
filterOperator?: string;
|
|
45
45
|
}
|
|
46
|
+
export interface APIGatewayProxyResult {
|
|
47
|
+
statusCode: number;
|
|
48
|
+
headers?: {
|
|
49
|
+
[header: string]: boolean | number | string;
|
|
50
|
+
} | undefined;
|
|
51
|
+
multiValueHeaders?: {
|
|
52
|
+
[header: string]: Array<boolean | number | string>;
|
|
53
|
+
} | undefined;
|
|
54
|
+
body: string;
|
|
55
|
+
isBase64Encoded?: boolean | undefined;
|
|
56
|
+
}
|
|
57
|
+
export interface APIGatewayEvent {
|
|
58
|
+
body: string | null;
|
|
59
|
+
headers: Record<string, string | undefined>;
|
|
60
|
+
httpMethod: string;
|
|
61
|
+
queryStringParameters: Record<string, string> | null;
|
|
62
|
+
pathParameters: Record<string, string> | null;
|
|
63
|
+
resource: string;
|
|
64
|
+
path: string;
|
|
65
|
+
requestContext: {
|
|
66
|
+
connectionId: string;
|
|
67
|
+
domainName: string;
|
|
68
|
+
identity: {
|
|
69
|
+
userAgent: string;
|
|
70
|
+
sourceIp: string;
|
|
71
|
+
};
|
|
72
|
+
httpMethod: string;
|
|
73
|
+
};
|
|
74
|
+
}
|
|
@@ -38,8 +38,8 @@ function nicify(...args) {
|
|
|
38
38
|
}
|
|
39
39
|
function logprocess(type, date, args) {
|
|
40
40
|
var _a;
|
|
41
|
-
const
|
|
42
|
-
const
|
|
41
|
+
const msg = `[${date}] ${type} `;
|
|
42
|
+
const argsClean = args.filter(_1.notEmpty);
|
|
43
43
|
const min = (0, exports.GetLogLevel)((_a = process.env.LOG_LEVEL) === null || _a === void 0 ? void 0 : _a.toUpperCase()) || 'WARN';
|
|
44
44
|
const typesLogLevel = (0, exports.GetLogLevel)(type);
|
|
45
45
|
// env ignores it
|
|
@@ -48,31 +48,31 @@ function logprocess(type, date, args) {
|
|
|
48
48
|
}
|
|
49
49
|
switch (type) {
|
|
50
50
|
case 'TRACE': {
|
|
51
|
-
console.trace(
|
|
51
|
+
console.trace(msg, ...argsClean);
|
|
52
52
|
break;
|
|
53
53
|
}
|
|
54
54
|
case 'DEBUG': {
|
|
55
|
-
console.debug(
|
|
55
|
+
console.debug(msg, ...argsClean);
|
|
56
56
|
break;
|
|
57
57
|
}
|
|
58
58
|
case 'INFO': {
|
|
59
|
-
console.log(
|
|
59
|
+
console.log(msg, ...argsClean);
|
|
60
60
|
break;
|
|
61
61
|
}
|
|
62
62
|
case 'WARN': {
|
|
63
|
-
console.warn(
|
|
63
|
+
console.warn(msg, ...argsClean);
|
|
64
64
|
break;
|
|
65
65
|
}
|
|
66
66
|
case 'ERROR': {
|
|
67
|
-
console.error(
|
|
67
|
+
console.error(msg, ...argsClean);
|
|
68
68
|
break;
|
|
69
69
|
}
|
|
70
70
|
case 'FATAL': {
|
|
71
|
-
console.error(
|
|
71
|
+
console.error(msg, ...argsClean);
|
|
72
72
|
break;
|
|
73
73
|
}
|
|
74
74
|
default: {
|
|
75
|
-
console.log(
|
|
75
|
+
console.log(msg, ...argsClean);
|
|
76
76
|
break;
|
|
77
77
|
}
|
|
78
78
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
export declare function DropdownList<T>({ options, value, onChange, placeholder, className, renderF, }: {
|
|
2
|
+
export declare function DropdownList<T>({ options, value, onChange, placeholder, className, renderF, children, }: {
|
|
3
3
|
options: T[];
|
|
4
|
-
value
|
|
4
|
+
value?: T;
|
|
5
5
|
onChange: (v: T, index: number) => void;
|
|
6
6
|
placeholder?: string;
|
|
7
7
|
className?: string;
|
|
8
8
|
renderF: (v: T) => string;
|
|
9
|
+
children?: JSX.Element;
|
|
9
10
|
}): JSX.Element;
|
|
@@ -23,18 +23,15 @@ exports.DropdownList = void 0;
|
|
|
23
23
|
const colours_1 = require("../../styles/colours");
|
|
24
24
|
const react_1 = __importStar(require("react"));
|
|
25
25
|
const styled_components_1 = __importStar(require("styled-components"));
|
|
26
|
+
const Icon_1 = require("../Icon");
|
|
26
27
|
const SBase = styled_components_1.default.div `
|
|
27
28
|
display: flex;
|
|
28
29
|
flex-flow: row;
|
|
29
30
|
position: relative;
|
|
30
|
-
min-width: 5rem;
|
|
31
31
|
align-items: center;
|
|
32
32
|
justify-content: space-between;
|
|
33
|
-
cursor: default;
|
|
34
|
-
background-color: ${colours_1.colours.darker};
|
|
35
|
-
color: ${colours_1.colours.dark};
|
|
36
33
|
cursor: pointer;
|
|
37
|
-
flex-grow:
|
|
34
|
+
flex-grow: 0;
|
|
38
35
|
`;
|
|
39
36
|
const SItems = styled_components_1.default.div `
|
|
40
37
|
flex-flow: column;
|
|
@@ -42,21 +39,20 @@ const SItems = styled_components_1.default.div `
|
|
|
42
39
|
top: 100%;
|
|
43
40
|
display: none;
|
|
44
41
|
position: absolute;
|
|
45
|
-
background-color:
|
|
42
|
+
background-color: white;
|
|
46
43
|
cursor: default;
|
|
47
44
|
width: 100%;
|
|
45
|
+
right: 0;
|
|
46
|
+
max-width: 95vw;
|
|
48
47
|
${({ open }) => open &&
|
|
49
48
|
(0, styled_components_1.css) `
|
|
50
49
|
display: flex;
|
|
51
50
|
`}
|
|
52
51
|
`;
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
padding: 0.5rem;
|
|
56
|
-
`;
|
|
52
|
+
const Dots = (react_1.default.createElement("svg", { viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg", fillRule: "evenodd", clipRule: "evenodd" },
|
|
53
|
+
react_1.default.createElement("path", { d: "M16 12a3.001 3.001 0 016 0 3.001 3.001 0 01-6 0zm1 0a2 2 0 114.001.001A2 2 0 0117 12zm-8 0a3.001 3.001 0 016 0 3.001 3.001 0 01-6 0zm1 0a2 2 0 114.001.001A2 2 0 0110 12zm-8 0a3.001 3.001 0 016 0 3.001 3.001 0 01-6 0zm1 0a2 2 0 114.001.001A2 2 0 013 12z" })));
|
|
57
54
|
const SItem = styled_components_1.default.div `
|
|
58
55
|
z-index: 1;
|
|
59
|
-
word-break: break-all;
|
|
60
56
|
font-weight: 500;
|
|
61
57
|
padding-left: 0.5rem;
|
|
62
58
|
flex-grow: 1;
|
|
@@ -84,17 +80,7 @@ const SItem = styled_components_1.default.div `
|
|
|
84
80
|
background-color: rgba(0, 0, 0, 0.2);
|
|
85
81
|
}
|
|
86
82
|
`;
|
|
87
|
-
function
|
|
88
|
-
return (react_1.default.createElement(react_1.default.Fragment, null, options.map((s, i) => (react_1.default.createElement(SItem, { key: renderF(s), selected: s === state, onClick: () => {
|
|
89
|
-
if (s !== state) {
|
|
90
|
-
onChange(s, i);
|
|
91
|
-
}
|
|
92
|
-
} }, renderF(s))))));
|
|
93
|
-
}
|
|
94
|
-
const ChevronStyled = styled_components_1.default.div `
|
|
95
|
-
margin-right: 0.5rem;
|
|
96
|
-
`;
|
|
97
|
-
function DropdownList({ options, value, onChange, placeholder, className, renderF, }) {
|
|
83
|
+
function DropdownList({ options, value, onChange, placeholder, className, renderF, children, }) {
|
|
98
84
|
const ref = (0, react_1.useRef)(null);
|
|
99
85
|
const [state, setState] = (0, react_1.useState)(value);
|
|
100
86
|
const [open, setOpen] = (0, react_1.useState)(false);
|
|
@@ -111,14 +97,26 @@ function DropdownList({ options, value, onChange, placeholder, className, render
|
|
|
111
97
|
return () => document.removeEventListener('click', click, true);
|
|
112
98
|
}, []);
|
|
113
99
|
(0, react_1.useEffect)(() => {
|
|
114
|
-
|
|
115
|
-
|
|
100
|
+
const newv = value;
|
|
101
|
+
if (JSON.stringify(newv) !== JSON.stringify(value))
|
|
102
|
+
setState(newv);
|
|
103
|
+
}, [options, value]);
|
|
104
|
+
const maxLen = Math.max(...options.map((s) => renderF(s).length));
|
|
116
105
|
return (react_1.default.createElement(SBase, { className: className, ref: ref, title: placeholder, onClick: (e) => {
|
|
117
106
|
e.stopPropagation();
|
|
107
|
+
e.preventDefault();
|
|
118
108
|
setOpen(!open);
|
|
119
109
|
} },
|
|
120
|
-
react_1.default.createElement(
|
|
121
|
-
|
|
122
|
-
|
|
110
|
+
react_1.default.createElement(SItems, { open: open, style: { width: `calc(${maxLen}ch + 2rem)` } }, open &&
|
|
111
|
+
options.map((s, i) => (react_1.default.createElement(SItem, { key: renderF(s), selected: s === state, onClick: () => {
|
|
112
|
+
if (s !== state) {
|
|
113
|
+
onChange(s, i);
|
|
114
|
+
}
|
|
115
|
+
} }, renderF(s))))),
|
|
116
|
+
children || (react_1.default.createElement(Icon_1.Icon, { width: "2rem", height: "2rem", onClick: (e) => {
|
|
117
|
+
e.stopPropagation();
|
|
118
|
+
e.preventDefault();
|
|
119
|
+
setOpen(!open);
|
|
120
|
+
} }, Dots))));
|
|
123
121
|
}
|
|
124
122
|
exports.DropdownList = DropdownList;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { TLang } from '../../..';
|
|
3
|
+
export declare const LogoutButton: ({ className, invert, lang, logout, }: {
|
|
4
|
+
lang: TLang;
|
|
5
|
+
invert?: boolean | undefined;
|
|
6
|
+
className?: string | undefined;
|
|
7
|
+
logout: () => void;
|
|
8
|
+
}) => JSX.Element;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.LogoutButton = void 0;
|
|
7
|
+
const react_1 = __importDefault(require("react"));
|
|
8
|
+
const styled_components_1 = __importDefault(require("styled-components"));
|
|
9
|
+
const colours_1 = require("../../styles/colours");
|
|
10
|
+
const Button_1 = require("../Button");
|
|
11
|
+
const Door = (react_1.default.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 20 20" },
|
|
12
|
+
react_1.default.createElement("path", { d: "M3 3h8V1H3a2 2 0 00-2 2v14a2 2 0 002 2h8v-2H3z" }),
|
|
13
|
+
react_1.default.createElement("path", { d: "M19 10l-6-5v4H5v2h8v4l6-5z" })));
|
|
14
|
+
const Icon = styled_components_1.default.div `
|
|
15
|
+
width: 1.5rem;
|
|
16
|
+
height: 1.5rem;
|
|
17
|
+
`;
|
|
18
|
+
const ButtonStyled = (0, styled_components_1.default)(Button_1.Button) `
|
|
19
|
+
padding: 0;
|
|
20
|
+
margin: 0;
|
|
21
|
+
border: 0;
|
|
22
|
+
background-color: transparent;
|
|
23
|
+
svg {
|
|
24
|
+
fill: ${colours_1.colours.notificationBlue};
|
|
25
|
+
}
|
|
26
|
+
`;
|
|
27
|
+
const LogoutButton = ({ className, invert, lang, logout, }) => {
|
|
28
|
+
return (react_1.default.createElement(ButtonStyled, { invert: invert, className: className, onKeyPress: () => logout(), onClick: () => logout(), lang: lang },
|
|
29
|
+
react_1.default.createElement(Icon, null, Door)));
|
|
30
|
+
};
|
|
31
|
+
exports.LogoutButton = LogoutButton;
|
|
@@ -51,9 +51,9 @@ const CheckboxEdit = ({ defaultValue, onSubmit, }) => {
|
|
|
51
51
|
return (react_1.default.createElement(common_1.ValueBox, Object.assign({}, common_2.noDrag, { ref: ref }),
|
|
52
52
|
react_1.default.createElement(common_1.ValueInputCB, { type: "checkbox", "data-type": "checkbox", checked: value, onChange: () => setValue(!value), onKeyPress: (e) => e.key === 'Enter' && value !== defaultValue && onSubmit(value) }),
|
|
53
53
|
react_1.default.createElement(Icons, { center: true },
|
|
54
|
-
value !== defaultValue && (react_1.default.createElement(common_1.
|
|
54
|
+
value !== defaultValue && (react_1.default.createElement(common_1.IconD, { style: common_1.iconLeft, onClick: () => value !== defaultValue && onSubmit(value) },
|
|
55
55
|
react_1.default.createElement(images_1.SaveIcon, null))),
|
|
56
|
-
value !== defaultValue && (react_1.default.createElement(common_1.
|
|
56
|
+
value !== defaultValue && (react_1.default.createElement(common_1.IconD, { style: common_1.iconRight, onClick: () => setValue(defaultValue) },
|
|
57
57
|
react_1.default.createElement(images_1.UndoIcon, null))))));
|
|
58
58
|
};
|
|
59
59
|
exports.CheckboxEdit = CheckboxEdit;
|
|
@@ -40,9 +40,9 @@ const ColourEdit = ({ defaultValue, onSubmit, }) => {
|
|
|
40
40
|
});
|
|
41
41
|
return (react_1.default.createElement(common_1.ValueBox, Object.assign({}, common_2.noDrag, { ref: ref }),
|
|
42
42
|
react_1.default.createElement("input", { type: "color", size: 5, value: value, onChange: (v) => setValue(v.target.value) }),
|
|
43
|
-
value !== defaultValue && (react_1.default.createElement(common_1.
|
|
43
|
+
value !== defaultValue && (react_1.default.createElement(common_1.IconD, { style: common_1.iconLeft, onClick: () => valueChange && onSubmit(value.trim()) },
|
|
44
44
|
react_1.default.createElement(images_1.SaveIcon, null))),
|
|
45
|
-
valueChange && (react_1.default.createElement(common_1.
|
|
45
|
+
valueChange && (react_1.default.createElement(common_1.IconD, { style: common_1.iconRight, onClick: () => setValue(defaultValue) },
|
|
46
46
|
react_1.default.createElement(images_1.UndoIcon, null)))));
|
|
47
47
|
};
|
|
48
48
|
exports.ColourEdit = ColourEdit;
|
|
@@ -32,10 +32,10 @@ const ListboxEdit = ({ defaultValue, onSubmit, values, }) => {
|
|
|
32
32
|
}, [defaultValue]);
|
|
33
33
|
return (react_1.default.createElement(common_1.ValueBox, Object.assign({}, common_2.noDrag),
|
|
34
34
|
react_1.default.createElement("select", { size: 5, value: value, onChange: (v) => setValue(v.target.value) }, values.map((v) => (react_1.default.createElement("option", { key: v, value: v }, v)))),
|
|
35
|
-
value !== defaultValue && (react_1.default.createElement(common_1.
|
|
35
|
+
value !== defaultValue && (react_1.default.createElement(common_1.IconD, { style: common_1.iconLeft, onClick: () => value !== defaultValue &&
|
|
36
36
|
onSubmit(value.split(',').map((s) => s.trim())) },
|
|
37
37
|
react_1.default.createElement(images_1.SaveIcon, null))),
|
|
38
|
-
value !== defaultValue && (react_1.default.createElement(common_1.
|
|
38
|
+
value !== defaultValue && (react_1.default.createElement(common_1.IconD, { style: common_1.iconRight, onClick: () => setValue(defaultValue) },
|
|
39
39
|
react_1.default.createElement(images_1.UndoIcon, null)))));
|
|
40
40
|
};
|
|
41
41
|
exports.ListboxEdit = ListboxEdit;
|
|
@@ -34,6 +34,9 @@ const ValueTextArea = styled_components_1.default.textarea `
|
|
|
34
34
|
${common_1.valueCss};
|
|
35
35
|
resize: none;
|
|
36
36
|
overflow: hidden;
|
|
37
|
+
&[data-editing='true'] {
|
|
38
|
+
min-height: 5rem;
|
|
39
|
+
}
|
|
37
40
|
`;
|
|
38
41
|
const TextEdit = ({ defaultValue, defaultEditing = false, onSubmit, canEdit = true, placeholder, onEditingChange, onClickOutsideWithNoValue, onClickNotEditing, className, singleLine = false, }) => {
|
|
39
42
|
const ref = (0, react_1.useRef)(null);
|
|
@@ -46,6 +49,9 @@ const TextEdit = ({ defaultValue, defaultEditing = false, onSubmit, canEdit = tr
|
|
|
46
49
|
onSubmit(value);
|
|
47
50
|
}
|
|
48
51
|
else {
|
|
52
|
+
if (canEdit && editing && defaultEditing) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
49
55
|
if (onClickOutsideWithNoValue) {
|
|
50
56
|
onClickOutsideWithNoValue();
|
|
51
57
|
}
|
|
@@ -73,7 +79,7 @@ const TextEdit = ({ defaultValue, defaultEditing = false, onSubmit, canEdit = tr
|
|
|
73
79
|
if (!editing || !canEdit) {
|
|
74
80
|
return (react_1.default.createElement(common_1.ValueBox, Object.assign({}, common_2.noDrag, { className: className, "data-editing": "false", onClick: () => onClickNotEditing === null || onClickNotEditing === void 0 ? void 0 : onClickNotEditing(), "data-pointer": onClickNotEditing ? 'true' : 'false' }),
|
|
75
81
|
react_1.default.createElement(common_1.ValueReadonly, { "data-type": "text" }, value),
|
|
76
|
-
canEdit && (react_1.default.createElement(common_1.
|
|
82
|
+
canEdit && (react_1.default.createElement(common_1.IconD, { style: common_1.iconRight, onClick: (e) => {
|
|
77
83
|
e.stopPropagation();
|
|
78
84
|
setEditing(true);
|
|
79
85
|
} },
|
|
@@ -83,10 +89,10 @@ const TextEdit = ({ defaultValue, defaultEditing = false, onSubmit, canEdit = tr
|
|
|
83
89
|
return react_1.default.createElement(react_1.default.Fragment, null);
|
|
84
90
|
}
|
|
85
91
|
return (react_1.default.createElement(common_1.ValueBox, Object.assign({ "data-editing": "true" }, common_2.noDrag, { ref: ref, tabIndex: editing ? 0 : undefined, className: className }),
|
|
86
|
-
react_1.default.createElement(ValueTextArea, { "data-valuechange": valueChange.toString(), ref: taref, "data-type": "text", value: value, onChange: (v) => setValue(v.currentTarget.value), placeholder: placeholder, rows: singleLine ? 1 : undefined, onKeyDown: (e) => singleLine && e.code.endsWith('Enter') && onSubmit(value) && false }),
|
|
87
|
-
valueChange && (react_1.default.createElement(common_1.
|
|
92
|
+
react_1.default.createElement(ValueTextArea, { "data-editing": "true", "data-valuechange": valueChange.toString(), ref: taref, "data-type": "text", value: value, onChange: (v) => setValue(v.currentTarget.value), placeholder: placeholder, rows: singleLine ? 1 : undefined, onKeyDown: (e) => singleLine && e.code.endsWith('Enter') && onSubmit(value) && false }),
|
|
93
|
+
valueChange && (react_1.default.createElement(common_1.IconD, { style: common_1.iconLeft, onClick: () => valueChange && onSubmit(value) },
|
|
88
94
|
react_1.default.createElement(images_1.SaveIcon, null))),
|
|
89
|
-
(valueChange || editing !== defaultEditing) && (react_1.default.createElement(common_1.
|
|
95
|
+
(valueChange || editing !== defaultEditing) && (react_1.default.createElement(common_1.IconD, { style: common_1.iconRight, onClick: () => {
|
|
90
96
|
setEditing(defaultEditing);
|
|
91
97
|
setValue(defaultValue);
|
|
92
98
|
} },
|
|
@@ -2,4 +2,12 @@ export declare const ValueBox: import("styled-components").StyledComponent<"div"
|
|
|
2
2
|
export declare const valueCss: import("styled-components").FlattenSimpleInterpolation;
|
|
3
3
|
export declare const ValueInputCB: import("styled-components").StyledComponent<"input", any, {}, never>;
|
|
4
4
|
export declare const ValueReadonly: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
5
|
-
export declare const
|
|
5
|
+
export declare const IconD: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
6
|
+
export declare const iconRight: {
|
|
7
|
+
right: string;
|
|
8
|
+
top: string;
|
|
9
|
+
};
|
|
10
|
+
export declare const iconLeft: {
|
|
11
|
+
right: string;
|
|
12
|
+
top: string;
|
|
13
|
+
};
|
|
@@ -19,7 +19,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
19
19
|
return result;
|
|
20
20
|
};
|
|
21
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports.
|
|
22
|
+
exports.iconLeft = exports.iconRight = exports.IconD = exports.ValueReadonly = exports.ValueInputCB = exports.valueCss = exports.ValueBox = void 0;
|
|
23
23
|
const styled_components_1 = __importStar(require("styled-components"));
|
|
24
24
|
const colours_1 = require("../../styles/colours");
|
|
25
25
|
exports.ValueBox = styled_components_1.default.div `
|
|
@@ -32,9 +32,7 @@ exports.ValueBox = styled_components_1.default.div `
|
|
|
32
32
|
justify-content: flex-start;
|
|
33
33
|
flex-grow: 1;
|
|
34
34
|
max-width: 100%;
|
|
35
|
-
|
|
36
|
-
padding-right: 2rem;
|
|
37
|
-
}
|
|
35
|
+
|
|
38
36
|
&[data-pointer='true'] {
|
|
39
37
|
cursor: pointer;
|
|
40
38
|
}
|
|
@@ -57,7 +55,7 @@ exports.ValueInputCB = styled_components_1.default.input `
|
|
|
57
55
|
exports.ValueReadonly = styled_components_1.default.div `
|
|
58
56
|
${exports.valueCss};
|
|
59
57
|
`;
|
|
60
|
-
exports.
|
|
58
|
+
exports.IconD = styled_components_1.default.div `
|
|
61
59
|
z-index: 1;
|
|
62
60
|
font-size: 1rem;
|
|
63
61
|
width: 1.5rem;
|
|
@@ -68,3 +66,5 @@ exports.Icon = styled_components_1.default.div `
|
|
|
68
66
|
fill: ${colours_1.colours.notificationBlue};
|
|
69
67
|
}
|
|
70
68
|
`;
|
|
69
|
+
exports.iconRight = { right: '0', top: '-1rem' };
|
|
70
|
+
exports.iconLeft = { right: '1.5rem', top: '-1rem' };
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
export declare const
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { AxiosWrapper, User } from '../../helpers/jwt';
|
|
3
|
+
export declare const UserImageIcon: JSX.Element;
|
|
4
|
+
export declare const UserImage: ({ image, className, }: {
|
|
4
5
|
image?: string | undefined;
|
|
5
6
|
className?: string | undefined;
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
}) => JSX.Element;
|
|
8
|
+
export declare const UserProfileImage: ({ className, user, }: {
|
|
9
|
+
className?: string | undefined;
|
|
10
|
+
user: AxiosWrapper<User>;
|
|
8
11
|
}) => JSX.Element;
|
|
@@ -22,12 +22,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
22
22
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
23
|
};
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.UserImage = void 0;
|
|
25
|
+
exports.UserProfileImage = exports.UserImage = exports.UserImageIcon = void 0;
|
|
26
26
|
const styled_components_1 = __importDefault(require("styled-components"));
|
|
27
27
|
const react_1 = __importStar(require("react"));
|
|
28
28
|
const log_1 = require("../../../common/helpers/log");
|
|
29
29
|
const array_1 = require("../../../common/helpers/array");
|
|
30
|
-
|
|
30
|
+
exports.UserImageIcon = (react_1.default.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 512 512" },
|
|
31
31
|
react_1.default.createElement("path", { d: "M256 48C141.1 48 48 141.1 48 256s93.1 208 208 208 208-93.1 208-208S370.9 48 256 48zm0 398.7c-58.6 0-111.1-26.6-146.1-68.3 17.8-7.7 62.2-23.7 90.3-31.9 2.2-.7 2.6-.8 2.6-10.7 0-10.6-1.2-18.1-3.8-23.6-3.5-7.5-7.7-20.2-9.2-31.6-4.2-4.9-9.9-14.5-13.6-32.9-3.2-16.2-1.7-22.1.4-27.6.2-.6.5-1.2.6-1.8.8-3.7-.3-23.5-3.1-38.8-1.9-10.5.5-32.8 15-51.3 9.1-11.7 26.6-26 58-28h17.5c31.9 2 49.4 16.3 58.5 28 14.5 18.5 16.9 40.8 14.9 51.3-2.8 15.3-3.9 35-3.1 38.8.1.6.4 1.2.6 1.7 2.1 5.5 3.7 11.4.4 27.6-3.7 18.4-9.4 28-13.6 32.9-1.5 11.4-5.7 24-9.2 31.6-3.3 6.9-6.6 15.1-6.6 23.3 0 9.9.4 10 2.7 10.7 26.7 7.9 72.7 23.8 93 32.1-35 41.8-87.5 68.5-146.2 68.5z" })));
|
|
32
32
|
const Base = styled_components_1.default.div `
|
|
33
33
|
width: 2.5rem;
|
|
@@ -44,23 +44,27 @@ const Img = styled_components_1.default.img `
|
|
|
44
44
|
const images = {
|
|
45
45
|
domains: ['platform-lookaside.fbsbx.com', 'lh3.googleusercontent.com'],
|
|
46
46
|
};
|
|
47
|
-
const UserImage = ({ image, className,
|
|
47
|
+
const UserImage = ({ image, className, }) => {
|
|
48
|
+
const [fallback, setFallback] = (0, react_1.useState)(false);
|
|
49
|
+
const showImage = image && !fallback;
|
|
50
|
+
return (react_1.default.createElement(Base, { className: className, title: 'user image' },
|
|
51
|
+
showImage && (react_1.default.createElement(Img, { alt: "user", src: image, onError: () => setFallback(true) })),
|
|
52
|
+
!showImage && exports.UserImageIcon));
|
|
53
|
+
};
|
|
54
|
+
exports.UserImage = UserImage;
|
|
55
|
+
const UserProfileImage = ({ className, user, }) => {
|
|
48
56
|
var _a, _b, _c, _d;
|
|
49
|
-
|
|
50
|
-
let imageSet = image;
|
|
51
|
-
if (!imageSet && showProfilePicture) {
|
|
52
|
-
imageSet = (_a = user === null || user === void 0 ? void 0 : user.data) === null || _a === void 0 ? void 0 : _a.picture;
|
|
53
|
-
}
|
|
57
|
+
let image = (_a = user === null || user === void 0 ? void 0 : user.data) === null || _a === void 0 ? void 0 : _a.picture;
|
|
54
58
|
if ((_b = user === null || user === void 0 ? void 0 : user.data) === null || _b === void 0 ? void 0 : _b.picture) {
|
|
55
59
|
if (!images.domains.find((i) => user.data.picture.includes(i))) {
|
|
56
|
-
|
|
60
|
+
image = image || '';
|
|
57
61
|
(0, log_1.warn)(`bad domain:${user.data.picture}`);
|
|
58
62
|
}
|
|
59
63
|
}
|
|
60
64
|
const titleA = [(_c = user === null || user === void 0 ? void 0 : user.data) === null || _c === void 0 ? void 0 : _c.fullname, (_d = user === null || user === void 0 ? void 0 : user.data) === null || _d === void 0 ? void 0 : _d.userId].filter(array_1.notEmpty);
|
|
61
65
|
const title = titleA.length === 0 ? '' : titleA.join(' - ');
|
|
62
66
|
return (react_1.default.createElement(Base, { className: className, title: title },
|
|
63
|
-
|
|
64
|
-
!
|
|
67
|
+
image && react_1.default.createElement(Img, { alt: "user", src: image }),
|
|
68
|
+
!image && exports.UserImageIcon));
|
|
65
69
|
};
|
|
66
|
-
exports.
|
|
70
|
+
exports.UserProfileImage = UserProfileImage;
|
|
@@ -21,6 +21,7 @@ __exportStar(require("./Icon"), exports);
|
|
|
21
21
|
__exportStar(require("./Input"), exports);
|
|
22
22
|
__exportStar(require("./Loader"), exports);
|
|
23
23
|
__exportStar(require("./LoginButton"), exports);
|
|
24
|
+
__exportStar(require("./LogoutButton"), exports);
|
|
24
25
|
__exportStar(require("./Modal"), exports);
|
|
25
26
|
__exportStar(require("./RowOrColumn"), exports);
|
|
26
27
|
__exportStar(require("./Table"), exports);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
+
import { TLang } from '../..';
|
|
2
3
|
import { ICognitoAuth, ICognitoAuthProviderProps } from './cognito';
|
|
3
4
|
import { AuthedUserContext } from './jwt';
|
|
4
5
|
export interface LocationSubset {
|
|
@@ -24,7 +25,7 @@ export interface IRequestCommon {
|
|
|
24
25
|
url: LocationSubset;
|
|
25
26
|
headerTitle?: string;
|
|
26
27
|
seed?: number;
|
|
27
|
-
lang:
|
|
28
|
+
lang: TLang;
|
|
28
29
|
}
|
|
29
30
|
export interface IStateCommon<TRequest extends IRequestCommon> extends IInitialStateCommon {
|
|
30
31
|
request: TRequest;
|
package/package.json
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ag-common",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.20",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"author": "Andrei Gec <@andreigec> (https://gec.dev/)",
|
|
7
7
|
"repository": "github:andreigec/ag-common",
|
|
8
8
|
"license": "ISC",
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"aws-lambda": "1.0.7",
|
|
11
10
|
"styled-components": "5.3.3",
|
|
12
11
|
"axios": "0.24.0",
|
|
13
12
|
"typescript": "4.5.4",
|
|
@@ -26,7 +25,6 @@
|
|
|
26
25
|
"@typescript-eslint/parser": "5.8.1",
|
|
27
26
|
"prettier": "2.5.1",
|
|
28
27
|
"@types/node": "17.0.5",
|
|
29
|
-
"@types/aws-lambda": "8.10.89",
|
|
30
28
|
"@types/react": "17.0.38",
|
|
31
29
|
"@types/react-dom": "17.0.11",
|
|
32
30
|
"@types/styled-components": "5.1.19",
|
|
@@ -44,7 +42,7 @@
|
|
|
44
42
|
"@types/jsonwebtoken": "8.5.6"
|
|
45
43
|
},
|
|
46
44
|
"scripts": {
|
|
47
|
-
"build": "rimraf dist && tsc",
|
|
45
|
+
"build": "rimraf dist && yarn checklint && tsc",
|
|
48
46
|
"fix": "./node_modules/.bin/eslint --fix './src/**/*.ts' './src/**/*.tsx'",
|
|
49
47
|
"checklint": "npx eslint --ext .ts,.tsx ./src",
|
|
50
48
|
"start": "tsc --watch"
|