ag-common 0.0.229 → 0.0.232
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.
|
@@ -106,12 +106,12 @@ const TextEdit = ({ defaultValue = '', defaultEditing, disableEdit = false, plac
|
|
|
106
106
|
setEditingRaw(false);
|
|
107
107
|
}
|
|
108
108
|
});
|
|
109
|
-
const setEditing = (b) => {
|
|
109
|
+
const setEditing = (0, react_1.useCallback)((b) => {
|
|
110
110
|
setEditingRaw(b);
|
|
111
111
|
if (onEditingChange) {
|
|
112
112
|
onEditingChange(b);
|
|
113
113
|
}
|
|
114
|
-
};
|
|
114
|
+
}, [onEditingChange]);
|
|
115
115
|
(0, react_1.useEffect)(() => {
|
|
116
116
|
setValue(defaultValue);
|
|
117
117
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -120,9 +120,8 @@ const TextEdit = ({ defaultValue = '', defaultEditing, disableEdit = false, plac
|
|
|
120
120
|
if ((defaultEditing === null || defaultEditing === void 0 ? void 0 : defaultEditing.focus) && taref.current) {
|
|
121
121
|
taref.current.focus();
|
|
122
122
|
}
|
|
123
|
-
setEditing(!!defaultEditing);
|
|
124
123
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
125
|
-
}, [
|
|
124
|
+
}, []);
|
|
126
125
|
if (!editing || disableEdit) {
|
|
127
126
|
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', "data-nogrow": noGrow }, attributes),
|
|
128
127
|
leftContent || null,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ICallOpenApi } from './types';
|
|
1
|
+
import { ICallOpenApi, OverrideAuth } from './types';
|
|
2
2
|
import { CacheItems } from '../routes';
|
|
3
3
|
import { AxiosWrapperLite } from '../jwt';
|
|
4
4
|
export declare type TCallOpenApiCached<T, TDefaultApi> = ICallOpenApi<T, TDefaultApi> & {
|
|
@@ -19,6 +19,10 @@ export declare type TCallOpenApiCached<T, TDefaultApi> = ICallOpenApi<T, TDefaul
|
|
|
19
19
|
*/
|
|
20
20
|
onlyCached?: boolean;
|
|
21
21
|
};
|
|
22
|
+
export declare const setOpenApiCacheRaw: <T>(p: {
|
|
23
|
+
cacheKey: string;
|
|
24
|
+
overrideAuth?: OverrideAuth | undefined;
|
|
25
|
+
}, data: T) => Promise<void>;
|
|
22
26
|
/**
|
|
23
27
|
* sync call to callOpenApiCache.
|
|
24
28
|
* @param p
|
|
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.callOpenApiCached = exports.callOpenApiCachedRaw = void 0;
|
|
15
|
+
exports.callOpenApiCached = exports.callOpenApiCachedRaw = exports.setOpenApiCacheRaw = void 0;
|
|
16
16
|
const direct_1 = require("./direct");
|
|
17
17
|
const cookie_1 = require("../cookie");
|
|
18
18
|
const string_1 = require("../../../common/helpers/string");
|
|
@@ -31,6 +31,13 @@ function getCacheKey({ cacheKey, overrideAuth, }) {
|
|
|
31
31
|
}
|
|
32
32
|
return cacheKeyRet;
|
|
33
33
|
}
|
|
34
|
+
const setOpenApiCacheRaw = (p, data) => __awaiter(void 0, void 0, void 0, function* () {
|
|
35
|
+
const userPrefixedCacheKey = getCacheKey(p);
|
|
36
|
+
if (callOpenApiCache && userPrefixedCacheKey) {
|
|
37
|
+
callOpenApiCache.set(userPrefixedCacheKey, data);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
exports.setOpenApiCacheRaw = setOpenApiCacheRaw;
|
|
34
41
|
/**
|
|
35
42
|
* sync call to callOpenApiCache.
|
|
36
43
|
* @param p
|
|
@@ -68,10 +75,7 @@ const callOpenApiCached = (p) => __awaiter(void 0, void 0, void 0, function* ()
|
|
|
68
75
|
if (resp.error) {
|
|
69
76
|
return { error: resp.error, data: undefined };
|
|
70
77
|
}
|
|
71
|
-
|
|
72
|
-
if (callOpenApiCache && userPrefixedCacheKey) {
|
|
73
|
-
callOpenApiCache.set(userPrefixedCacheKey, resp.data);
|
|
74
|
-
}
|
|
78
|
+
yield (0, exports.setOpenApiCacheRaw)(p, resp.data);
|
|
75
79
|
return resp;
|
|
76
80
|
});
|
|
77
81
|
exports.callOpenApiCached = callOpenApiCached;
|
|
@@ -6,8 +6,12 @@ export declare type TUseCallOpenApi<T> = AxiosWrapper<T> & {
|
|
|
6
6
|
loaded: boolean;
|
|
7
7
|
loadcount: number;
|
|
8
8
|
setData: (d: TUseCallOpenApiDispatch<T | undefined>) => void;
|
|
9
|
+
/**
|
|
10
|
+
* call when you want to refetch, but at a later point (ie same hook/cachekey across different components)
|
|
11
|
+
*/
|
|
12
|
+
invalidateCacheKey: () => void;
|
|
9
13
|
};
|
|
10
|
-
declare type
|
|
14
|
+
declare type TUseCallOpenApiInt<T, TDefaultApi> = ICallOpenApi<T, TDefaultApi> & {
|
|
11
15
|
cacheKey: string;
|
|
12
16
|
/**
|
|
13
17
|
* will shortcut and return the appropriate axioswrapper data if cachekey is found
|
|
@@ -23,5 +27,5 @@ declare type TUseCallOpenApi1<T, TDefaultApi> = ICallOpenApi<T, TDefaultApi> & {
|
|
|
23
27
|
* @param p
|
|
24
28
|
* @returns
|
|
25
29
|
*/
|
|
26
|
-
export declare const useCallOpenApi: <T, TDefaultApi>(pIn:
|
|
30
|
+
export declare const useCallOpenApi: <T, TDefaultApi>(pIn: TUseCallOpenApiInt<T, TDefaultApi>) => TUseCallOpenApi<T>;
|
|
27
31
|
export {};
|
|
@@ -13,10 +13,16 @@ exports.useCallOpenApi = void 0;
|
|
|
13
13
|
const cached_1 = require("./cached");
|
|
14
14
|
const direct_1 = require("./direct");
|
|
15
15
|
const react_1 = require("react");
|
|
16
|
-
const defaultState = (p
|
|
16
|
+
const defaultState = (p,
|
|
17
|
+
/**
|
|
18
|
+
* default false
|
|
19
|
+
*/
|
|
20
|
+
noSsr = false) => {
|
|
17
21
|
var _a;
|
|
18
|
-
const cachedData =
|
|
19
|
-
|
|
22
|
+
const cachedData = noSsr
|
|
23
|
+
? undefined
|
|
24
|
+
: (_a = (0, cached_1.callOpenApiCachedRaw)(Object.assign(Object.assign({}, p), { onlyCached: true }))) === null || _a === void 0 ? void 0 : _a.data;
|
|
25
|
+
return Object.assign(Object.assign({ data: undefined, url: '', datetime: 0, loadcount: 0, loading: false }, (cachedData && { data: cachedData })), { loaded: !!cachedData });
|
|
20
26
|
};
|
|
21
27
|
/**
|
|
22
28
|
* hooks+cached call to callOpenApi
|
|
@@ -24,31 +30,36 @@ const defaultState = (p) => {
|
|
|
24
30
|
* @returns
|
|
25
31
|
*/
|
|
26
32
|
const useCallOpenApi = (pIn) => {
|
|
27
|
-
const [
|
|
28
|
-
const [data, setData] = (0, react_1.useState)(defaultState(p));
|
|
33
|
+
const [data, setData] = (0, react_1.useState)([pIn, defaultState(pIn)]);
|
|
29
34
|
(0, react_1.useEffect)(() => {
|
|
30
|
-
if (JSON.stringify(
|
|
31
|
-
|
|
32
|
-
setData(defaultState(pIn));
|
|
35
|
+
if (JSON.stringify(data[0]) !== JSON.stringify(pIn)) {
|
|
36
|
+
setData([pIn, defaultState(pIn, true)]);
|
|
33
37
|
}
|
|
34
|
-
}, [
|
|
38
|
+
}, [data, pIn]);
|
|
35
39
|
(0, react_1.useEffect)(() => {
|
|
36
40
|
function run() {
|
|
37
41
|
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
-
const resp = yield (0, direct_1.callOpenApi)(
|
|
39
|
-
setData((d) =>
|
|
42
|
+
const resp = yield (0, direct_1.callOpenApi)(data[0]);
|
|
43
|
+
setData((d) => [
|
|
44
|
+
d[0],
|
|
45
|
+
Object.assign(Object.assign({}, resp), { loaded: true, loading: false, loadcount: d[1].loadcount + 1, url: '', datetime: new Date().getTime() }),
|
|
46
|
+
]);
|
|
40
47
|
});
|
|
41
48
|
}
|
|
42
|
-
const { error, loaded, loading, loadcount } = data;
|
|
43
|
-
const ng =
|
|
49
|
+
const { error, loaded, loading, loadcount } = data[1];
|
|
50
|
+
const ng = data[0].disabled || loaded || loading || (error && loadcount > 2);
|
|
44
51
|
if (ng) {
|
|
45
52
|
return;
|
|
46
53
|
}
|
|
47
54
|
setData((d) => (Object.assign(Object.assign({}, d), { loading: true })));
|
|
48
55
|
void run();
|
|
49
|
-
}, [data,
|
|
50
|
-
|
|
51
|
-
setData(
|
|
52
|
-
|
|
56
|
+
}, [data, setData]);
|
|
57
|
+
const ret = Object.assign(Object.assign({}, data[1]), { reFetch: () => __awaiter(void 0, void 0, void 0, function* () { return setData([data[0], defaultState(data[0], true)]); }), setData: (d) => {
|
|
58
|
+
setData([
|
|
59
|
+
data[0],
|
|
60
|
+
Object.assign(Object.assign({}, data[1]), { data: d(data[1].data), datetime: new Date().getTime() }),
|
|
61
|
+
]);
|
|
62
|
+
}, invalidateCacheKey: () => (0, cached_1.setOpenApiCacheRaw)(data[0], undefined) });
|
|
63
|
+
return ret;
|
|
53
64
|
};
|
|
54
65
|
exports.useCallOpenApi = useCallOpenApi;
|