@hortiview/modulebase 0.0.12109 → 0.0.12333
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/ModuleBase-brrfWM_W.js +697 -0
- package/dist/{QueryClientProvider-DQv4Y3Qu.js → QueryClientProvider-QWqHaM3I.js} +19 -19
- package/dist/{_baseGet-Bh5zJ_C8.js → _baseGet-B7FwMMGI.js} +9 -9
- package/dist/api-D9Lmqe6S.js +458 -0
- package/dist/components/ModuleBase.js +10 -694
- package/dist/hooks/useCustom.d.ts +2 -1
- package/dist/hooks/useCustom.js +15 -13
- package/dist/hooks/useCustomMutation.d.ts +8 -0
- package/dist/hooks/useCustomMutation.js +112 -0
- package/dist/hooks/useEntity.d.ts +1 -1
- package/dist/hooks/useEntity.js +36 -30
- package/dist/hooks/useOption.d.ts +1 -1
- package/dist/hooks/useOption.js +20 -18
- package/dist/hooks/useStores.js +11 -841
- package/dist/main.d.ts +2 -0
- package/dist/main.js +118 -114
- package/dist/omit-B7MWDtHq.js +835 -0
- package/dist/types/ModuleApi.d.ts +2 -0
- package/dist/types/Requests.d.ts +2 -1
- package/dist/{useQuery-znAyMQW1.js → useQuery-DtzakC1A.js} +98 -94
- package/dist/utils/api.d.ts +20 -0
- package/dist/utils/api.js +9 -0
- package/dist/utils/baseFetches.d.ts +19 -0
- package/dist/utils/baseFetches.js +19 -0
- package/dist/utils/fetches.d.ts +31 -22
- package/dist/utils/fetches.js +19 -14
- package/package.json +2 -2
- package/dist/fetches-DUCQo_6B.js +0 -477
package/dist/hooks/useCustom.js
CHANGED
|
@@ -1,20 +1,22 @@
|
|
|
1
|
-
import { u as
|
|
2
|
-
import { useBasePropsStore as
|
|
3
|
-
import { universalSelector as
|
|
4
|
-
import {
|
|
5
|
-
const
|
|
1
|
+
import { u as i } from "../useQuery-DtzakC1A.js";
|
|
2
|
+
import { useBasePropsStore as n } from "../stores/BasePropsStore.js";
|
|
3
|
+
import { universalSelector as p } from "../types/Requests.js";
|
|
4
|
+
import { fetchFromCustomApi as a } from "../utils/fetches.js";
|
|
5
|
+
const l = ({
|
|
6
6
|
endpoint: e,
|
|
7
7
|
queryKey: t,
|
|
8
|
-
token:
|
|
9
|
-
selector: o
|
|
8
|
+
token: u,
|
|
9
|
+
selector: o,
|
|
10
|
+
enabled: m = !0
|
|
10
11
|
}) => {
|
|
11
|
-
const
|
|
12
|
-
return
|
|
13
|
-
queryKey: [...t,
|
|
14
|
-
queryFn: () =>
|
|
15
|
-
select: (r) => o ? o(r) :
|
|
12
|
+
const s = n((r) => r.organizationId);
|
|
13
|
+
return i({
|
|
14
|
+
queryKey: [...t, s],
|
|
15
|
+
queryFn: () => a(e, u),
|
|
16
|
+
select: (r) => o ? o(r) : p(r),
|
|
17
|
+
enabled: m
|
|
16
18
|
});
|
|
17
19
|
};
|
|
18
20
|
export {
|
|
19
|
-
|
|
21
|
+
l as useCustom
|
|
20
22
|
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { UseMutationResult } from '@tanstack/react-query';
|
|
2
|
+
import { BaseResponse, httpMethod } from '../types/Requests';
|
|
3
|
+
export declare const useCustomMutation: <Input, Output>({ endpoint, method, token, headers, }: {
|
|
4
|
+
endpoint: string;
|
|
5
|
+
method: Omit<httpMethod, "GET">;
|
|
6
|
+
token?: string;
|
|
7
|
+
headers?: Headers;
|
|
8
|
+
}) => UseMutationResult<BaseResponse<Output>, Error, Input, unknown>;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import * as o from "react";
|
|
2
|
+
import { g as m } from "../ModuleBase-brrfWM_W.js";
|
|
3
|
+
import { S as p, s as l, h as a, n as h, u as d } from "../QueryClientProvider-QWqHaM3I.js";
|
|
4
|
+
import { n as b, s as f } from "../useQuery-DtzakC1A.js";
|
|
5
|
+
import "../stores/BasePropsStore.js";
|
|
6
|
+
import "../provider/SignalR/SignalRProvider.js";
|
|
7
|
+
import "../omit-B7MWDtHq.js";
|
|
8
|
+
import "../stores/EnvironmentStore.js";
|
|
9
|
+
import { mutateOnCustomApi as O } from "../utils/fetches.js";
|
|
10
|
+
import "./useEntity.js";
|
|
11
|
+
import "../api-D9Lmqe6S.js";
|
|
12
|
+
var v = class extends p {
|
|
13
|
+
#e;
|
|
14
|
+
#i = void 0;
|
|
15
|
+
#t;
|
|
16
|
+
#s;
|
|
17
|
+
constructor(t, s) {
|
|
18
|
+
super(), this.#e = t, this.setOptions(s), this.bindMethods(), this.#r();
|
|
19
|
+
}
|
|
20
|
+
bindMethods() {
|
|
21
|
+
this.mutate = this.mutate.bind(this), this.reset = this.reset.bind(this);
|
|
22
|
+
}
|
|
23
|
+
setOptions(t) {
|
|
24
|
+
const s = this.options;
|
|
25
|
+
this.options = this.#e.defaultMutationOptions(t), l(this.options, s) || this.#e.getMutationCache().notify({
|
|
26
|
+
type: "observerOptionsUpdated",
|
|
27
|
+
mutation: this.#t,
|
|
28
|
+
observer: this
|
|
29
|
+
}), s?.mutationKey && this.options.mutationKey && a(s.mutationKey) !== a(this.options.mutationKey) ? this.reset() : this.#t?.state.status === "pending" && this.#t.setOptions(this.options);
|
|
30
|
+
}
|
|
31
|
+
onUnsubscribe() {
|
|
32
|
+
this.hasListeners() || this.#t?.removeObserver(this);
|
|
33
|
+
}
|
|
34
|
+
onMutationUpdate(t) {
|
|
35
|
+
this.#r(), this.#o(t);
|
|
36
|
+
}
|
|
37
|
+
getCurrentResult() {
|
|
38
|
+
return this.#i;
|
|
39
|
+
}
|
|
40
|
+
reset() {
|
|
41
|
+
this.#t?.removeObserver(this), this.#t = void 0, this.#r(), this.#o();
|
|
42
|
+
}
|
|
43
|
+
mutate(t, s) {
|
|
44
|
+
return this.#s = s, this.#t?.removeObserver(this), this.#t = this.#e.getMutationCache().build(this.#e, this.options), this.#t.addObserver(this), this.#t.execute(t);
|
|
45
|
+
}
|
|
46
|
+
#r() {
|
|
47
|
+
const t = this.#t?.state ?? m();
|
|
48
|
+
this.#i = {
|
|
49
|
+
...t,
|
|
50
|
+
isPending: t.status === "pending",
|
|
51
|
+
isSuccess: t.status === "success",
|
|
52
|
+
isError: t.status === "error",
|
|
53
|
+
isIdle: t.status === "idle",
|
|
54
|
+
mutate: this.mutate,
|
|
55
|
+
reset: this.reset
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
#o(t) {
|
|
59
|
+
h.batch(() => {
|
|
60
|
+
if (this.#s && this.hasListeners()) {
|
|
61
|
+
const s = this.#i.variables, i = this.#i.context;
|
|
62
|
+
t?.type === "success" ? (this.#s.onSuccess?.(t.data, s, i), this.#s.onSettled?.(t.data, null, s, i)) : t?.type === "error" && (this.#s.onError?.(t.error, s, i), this.#s.onSettled?.(
|
|
63
|
+
void 0,
|
|
64
|
+
t.error,
|
|
65
|
+
s,
|
|
66
|
+
i
|
|
67
|
+
));
|
|
68
|
+
}
|
|
69
|
+
this.listeners.forEach((s) => {
|
|
70
|
+
s(this.#i);
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
function y(t, s) {
|
|
76
|
+
const i = d(), [e] = o.useState(
|
|
77
|
+
() => new v(
|
|
78
|
+
i,
|
|
79
|
+
t
|
|
80
|
+
)
|
|
81
|
+
);
|
|
82
|
+
o.useEffect(() => {
|
|
83
|
+
e.setOptions(t);
|
|
84
|
+
}, [e, t]);
|
|
85
|
+
const r = o.useSyncExternalStore(
|
|
86
|
+
o.useCallback(
|
|
87
|
+
(u) => e.subscribe(h.batchCalls(u)),
|
|
88
|
+
[e]
|
|
89
|
+
),
|
|
90
|
+
() => e.getCurrentResult(),
|
|
91
|
+
() => e.getCurrentResult()
|
|
92
|
+
), n = o.useCallback(
|
|
93
|
+
(u, c) => {
|
|
94
|
+
e.mutate(u, c).catch(b);
|
|
95
|
+
},
|
|
96
|
+
[e]
|
|
97
|
+
);
|
|
98
|
+
if (r.error && f(e.options.throwOnError, [r.error]))
|
|
99
|
+
throw r.error;
|
|
100
|
+
return { ...r, mutate: n, mutateAsync: r.mutate };
|
|
101
|
+
}
|
|
102
|
+
const k = ({
|
|
103
|
+
endpoint: t,
|
|
104
|
+
method: s,
|
|
105
|
+
token: i,
|
|
106
|
+
headers: e
|
|
107
|
+
}) => y({
|
|
108
|
+
mutationFn: (r, n) => O(n ?? t, r, s, i, e)
|
|
109
|
+
});
|
|
110
|
+
export {
|
|
111
|
+
k as useCustomMutation
|
|
112
|
+
};
|
|
@@ -26,7 +26,7 @@ export declare const AllEntitiesTypeResultMap: {
|
|
|
26
26
|
farm_organizations: string;
|
|
27
27
|
alert_rules: string;
|
|
28
28
|
};
|
|
29
|
-
export declare const useEntity: <K extends HortiviewDataAreaGroup | ModuleDataAreaGroup, E extends HortiviewDataAreaEntity<K>>(group: K, entity: E) => {
|
|
29
|
+
export declare const useEntity: <K extends HortiviewDataAreaGroup | ModuleDataAreaGroup, E extends HortiviewDataAreaEntity<K>>(group: K, entity: E, enabled?: boolean) => {
|
|
30
30
|
data: ResultMap<E>[];
|
|
31
31
|
error: Error;
|
|
32
32
|
isError: true;
|
package/dist/hooks/useEntity.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { u as
|
|
1
|
+
import { u as l } from "../useQuery-DtzakC1A.js";
|
|
2
2
|
import { useMemo as g } from "react";
|
|
3
|
-
import { useBasePropsStore as
|
|
4
|
-
import { universalSelector as
|
|
5
|
-
import {
|
|
6
|
-
import { useOption as
|
|
3
|
+
import { useBasePropsStore as p } from "../stores/BasePropsStore.js";
|
|
4
|
+
import { universalSelector as y } from "../types/Requests.js";
|
|
5
|
+
import { getModuleDependedEntities as R, getFarmOrgEntities as k } from "../utils/fetches.js";
|
|
6
|
+
import { useOption as E, useModuleDependency as D } from "./useOption.js";
|
|
7
7
|
const F = {
|
|
8
8
|
farms: "farm",
|
|
9
9
|
fields: "field",
|
|
@@ -20,39 +20,45 @@ const F = {
|
|
|
20
20
|
...F,
|
|
21
21
|
...Q,
|
|
22
22
|
...q
|
|
23
|
-
},
|
|
24
|
-
const
|
|
25
|
-
if (
|
|
26
|
-
return n ? n.find((s) => s.registeredEntityName ===
|
|
27
|
-
if (!
|
|
28
|
-
const r =
|
|
29
|
-
return r ?
|
|
30
|
-
}, [
|
|
31
|
-
|
|
32
|
-
|
|
23
|
+
}, K = (e, t, a = !0) => {
|
|
24
|
+
const o = p((r) => r.moduleId), d = p((r) => r.organizationId), { data: u } = E("DataAreaGroup"), { data: i } = E("DataAreaEntity"), { data: n } = D(e === "ModuleDepended"), m = e === "ModuleDepended", M = g(() => {
|
|
25
|
+
if (m)
|
|
26
|
+
return n ? n.find((s) => s.registeredEntityName === t)?.id : void 0;
|
|
27
|
+
if (!u || !i) return;
|
|
28
|
+
const r = u.find((s) => s.key === e)?.id;
|
|
29
|
+
return r ? i.find((s) => s.description === r && s.value === t)?.id : void 0;
|
|
30
|
+
}, [m, u, i, n, t, e]), f = O(
|
|
31
|
+
o,
|
|
32
|
+
M,
|
|
33
|
+
d,
|
|
34
|
+
m,
|
|
35
|
+
a
|
|
36
|
+
), b = (f.data ?? []).map((r) => {
|
|
37
|
+
const c = A[t];
|
|
38
|
+
return r[c];
|
|
33
39
|
});
|
|
34
40
|
return {
|
|
35
|
-
...
|
|
36
|
-
data:
|
|
41
|
+
...f,
|
|
42
|
+
data: b
|
|
37
43
|
};
|
|
38
|
-
},
|
|
39
|
-
const
|
|
40
|
-
queryKey: [
|
|
41
|
-
queryFn: () =>
|
|
42
|
-
enabled: o && !!
|
|
43
|
-
select: (n) =>
|
|
44
|
-
}),
|
|
45
|
-
queryKey: [
|
|
46
|
-
queryFn: () =>
|
|
47
|
-
enabled: !o && !!
|
|
48
|
-
select: (n) =>
|
|
44
|
+
}, O = (e, t, a, o, d = !0) => {
|
|
45
|
+
const u = l({
|
|
46
|
+
queryKey: [e, a, t],
|
|
47
|
+
queryFn: () => R(e ?? "", t ?? ""),
|
|
48
|
+
enabled: d && o && !!e && !!t && !!a,
|
|
49
|
+
select: (n) => y(n)
|
|
50
|
+
}), i = l({
|
|
51
|
+
queryKey: [e, a, t],
|
|
52
|
+
queryFn: () => k(e ?? "", t ?? ""),
|
|
53
|
+
enabled: d && !o && !!e && !!t && !!a,
|
|
54
|
+
select: (n) => y(n)
|
|
49
55
|
});
|
|
50
|
-
return o ?
|
|
56
|
+
return o ? u : i;
|
|
51
57
|
};
|
|
52
58
|
export {
|
|
53
59
|
A as AllEntitiesTypeResultMap,
|
|
54
60
|
Q as FarmMemberEntitiesTypeResultMap,
|
|
55
61
|
F as FarmOrgEntitiesTypeResultMap,
|
|
56
62
|
q as ModuleDependedEntityTypeResultMap,
|
|
57
|
-
|
|
63
|
+
K as useEntity
|
|
58
64
|
};
|
|
@@ -14,4 +14,4 @@ import { RegisterOption } from '../types/ModuleApi';
|
|
|
14
14
|
* or fetches it from the API. The result is then processed by a universal selector.
|
|
15
15
|
*/
|
|
16
16
|
export declare const useOption: (dropdown: keyof typeof CommonOptionType) => UseQueryResult<CommonOption[], Error>;
|
|
17
|
-
export declare const useModuleDependency: () => UseQueryResult<RegisterOption[], Error>;
|
|
17
|
+
export declare const useModuleDependency: (enabled?: boolean) => UseQueryResult<RegisterOption[], Error>;
|
package/dist/hooks/useOption.js
CHANGED
|
@@ -1,23 +1,25 @@
|
|
|
1
|
-
import { u as
|
|
2
|
-
import {
|
|
3
|
-
import { useBasePropsStore as
|
|
4
|
-
import { universalSelector as
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import { u as m } from "../useQuery-DtzakC1A.js";
|
|
2
|
+
import { g as u } from "../api-D9Lmqe6S.js";
|
|
3
|
+
import { useBasePropsStore as n } from "../stores/BasePropsStore.js";
|
|
4
|
+
import { universalSelector as s } from "../types/Requests.js";
|
|
5
|
+
import { fetchFromCommonApi as i, fetchFromModuleApi as c } from "../utils/fetches.js";
|
|
6
|
+
const f = (e) => {
|
|
7
|
+
const r = n((o) => o.commonOptions), t = u(r, e);
|
|
8
|
+
return m({
|
|
9
|
+
queryKey: [e],
|
|
10
|
+
queryFn: () => t ? Promise.resolve(t) : i(`${e}/dropdown`),
|
|
11
|
+
select: (o) => s(o)
|
|
11
12
|
});
|
|
12
|
-
},
|
|
13
|
-
const
|
|
14
|
-
return
|
|
15
|
-
queryKey: [
|
|
16
|
-
queryFn: () =>
|
|
17
|
-
select: (
|
|
13
|
+
}, g = (e = !0) => {
|
|
14
|
+
const r = n((o) => o.moduleId), t = n((o) => o.organizationId);
|
|
15
|
+
return m({
|
|
16
|
+
queryKey: [r, t],
|
|
17
|
+
queryFn: () => c(`ModuleDependencies/${r}`),
|
|
18
|
+
select: (o) => s(o),
|
|
19
|
+
enabled: e
|
|
18
20
|
});
|
|
19
21
|
};
|
|
20
22
|
export {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
+
g as useModuleDependency,
|
|
24
|
+
f as useOption
|
|
23
25
|
};
|