@hortiview/modulebase 0.0.14168 → 0.0.15690

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.
@@ -1,68 +1,70 @@
1
- import { u as f } from "../useQuery-XBGd5Kep.js";
2
- import { useMemo as p } from "react";
3
- import { useBasePropsStore as y } from "../stores/BasePropsStore.js";
4
- import { getModuleDependedEntities as R, getFarmOrgEntities as b } from "../utils/fetches.js";
5
- import { universalSelector as E } from "../utils/helper.js";
6
- import { useOption as M, useModuleDependency as k } from "./useOption.js";
7
- const D = {
1
+ import { u as p } from "../useQuery-XBGd5Kep.js";
2
+ import { useMemo as y } from "react";
3
+ import { useBasePropsStore as E } from "../stores/BasePropsStore.js";
4
+ import { getModuleDependedEntitiesRaw as A, getModuleDependedEntities as R, getFarmOrgEntities as k } from "../utils/fetches.js";
5
+ import { universalSelector as M } from "../utils/helper.js";
6
+ import { useOption as g, useModuleDependency as F } from "./useOption.js";
7
+ const Q = {
8
8
  farms: "farm",
9
9
  fields: "field",
10
10
  zones: "block",
11
11
  irrigation_stations: "irrigationStation",
12
12
  farm_organizations: "farmOrg",
13
13
  alert_rules: "farmAlertRule"
14
- }, F = {
14
+ }, S = {
15
15
  farm_members: "member"
16
- }, Q = {
16
+ }, q = {
17
17
  Season: "season",
18
18
  BlockPlantLayout: "blockPlantLayout",
19
- Record: "recordLight"
20
- }, q = {
21
- ...D,
22
- ...F,
23
- ...Q
24
- }, B = (r, e, a = !0) => {
25
- const o = y((n) => n.moduleId), c = y((n) => n.organizationId), { data: u } = M("DataAreaGroup"), { data: i } = M("DataAreaEntity"), { data: s } = k(r === "ModuleDepended"), d = r === "ModuleDepended", g = p(() => {
26
- if (d)
27
- return s ? s.find((t) => t.registeredEntityName === e)?.id : void 0;
28
- if (!u || !i) return;
29
- const n = u.find((t) => t.key === r)?.id;
19
+ Record: "recordLight",
20
+ Scouting: "scouting"
21
+ }, O = {
22
+ ...Q,
23
+ ...S,
24
+ ...q
25
+ }, x = (r, e, u = !0, s = !1) => {
26
+ const l = E((n) => n.moduleId), d = E((n) => n.organizationId), { data: a } = g("DataAreaGroup"), { data: i } = g("DataAreaEntity"), { data: o } = F(r === "ModuleDepended"), c = r === "ModuleDepended", b = y(() => {
27
+ if (c)
28
+ return o ? o.find((t) => t.registeredEntityName === e)?.id : void 0;
29
+ if (!a || !i) return;
30
+ const n = a.find((t) => t.key === r)?.id;
30
31
  return n ? i.find((t) => t.description === n && t.value === e)?.id : void 0;
31
- }, [d, u, i, s, e, r]), l = A(
32
- o,
33
- g,
34
- c,
32
+ }, [c, a, i, o, e, r]), m = T(
33
+ l,
34
+ b,
35
35
  d,
36
- a
36
+ c,
37
+ s,
38
+ u
37
39
  );
38
- return p(() => {
39
- const n = (l.data ?? []).map((m) => {
40
- const t = q[e];
41
- return m[t];
40
+ return y(() => {
41
+ const n = (m.data ?? []).map((f) => {
42
+ const t = O[e];
43
+ return c && s ? f : f[t];
42
44
  });
43
45
  return {
44
- ...l,
46
+ ...m,
45
47
  data: n
46
48
  };
47
- }, [e, l, d]);
48
- }, A = (r, e, a, o, c = !0) => {
49
- const u = f({
50
- queryKey: [r, a, e],
51
- queryFn: () => R(r ?? "", e ?? ""),
52
- enabled: c && o && !!r && !!e && !!a,
53
- select: (s) => E(s)
54
- }), i = f({
55
- queryKey: [r, a, e],
56
- queryFn: () => b(r ?? "", e ?? ""),
57
- enabled: c && !o && !!r && !!e && !!a,
58
- select: (s) => E(s)
49
+ }, [e, m, c, s]);
50
+ }, T = (r, e, u, s, l, d = !0) => {
51
+ const a = p({
52
+ queryKey: [r, u, e],
53
+ queryFn: () => l ? A(r ?? "", e ?? "") : R(r ?? "", e ?? ""),
54
+ enabled: d && s && !!r && !!e && !!u,
55
+ select: (o) => M(o)
56
+ }), i = p({
57
+ queryKey: [r, u, e],
58
+ queryFn: () => k(r ?? "", e ?? ""),
59
+ enabled: d && !s && !!r && !!e && !!u,
60
+ select: (o) => M(o)
59
61
  });
60
- return o ? u : i;
62
+ return s ? a : i;
61
63
  };
62
64
  export {
63
- q as AllEntitiesTypeResultMap,
64
- F as FarmMemberEntitiesTypeResultMap,
65
- D as FarmOrgEntitiesTypeResultMap,
66
- Q as ModuleDependedEntityTypeResultMap,
67
- B as useEntity
65
+ O as AllEntitiesTypeResultMap,
66
+ S as FarmMemberEntitiesTypeResultMap,
67
+ Q as FarmOrgEntitiesTypeResultMap,
68
+ q as ModuleDependedEntityTypeResultMap,
69
+ x as useEntity
68
70
  };
@@ -20,7 +20,7 @@ export declare const AllEntitiesTypeResultMap: {
20
20
  farm_organizations: string;
21
21
  alert_rules: string;
22
22
  };
23
- export declare const useEntity: <K extends HortiviewDataAreaGroup | ModuleDataAreaGroup, E extends HortiviewDataAreaEntity<K>>(group: K, entity: E, enabled?: boolean) => {
23
+ export declare const useEntity: <K extends HortiviewDataAreaGroup | ModuleDataAreaGroup, E extends HortiviewDataAreaEntity<K>>(group: K, entity: E, enabled?: boolean, shouldGetRawData?: boolean) => {
24
24
  data: ResultMap<E>[];
25
25
  error: Error;
26
26
  isError: true;
@@ -1,6 +1,6 @@
1
1
  export type EnvironmentVariable = {
2
2
  id?: string;
3
- appEnvironmentId: string;
4
3
  key: string;
5
4
  value: string;
5
+ appEnvironmentId: string | null;
6
6
  };
@@ -14,6 +14,14 @@ export declare const getFarmOrgEntities: <T>(moduleId: string, entityId: string)
14
14
  * @returns entity to get
15
15
  */
16
16
  export declare const getModuleDependedEntities: <T>(moduleId: string, entityId: string) => Promise<import('../main').BaseResponse<T>>;
17
+ /**
18
+ * a fetch function to get a certain MODULEDEPENDED entity from the moduleApi (will be used in useEntity)
19
+ * the data will be returned in a raw format
20
+ * @param moduleId
21
+ * @param entityId
22
+ * @returns
23
+ */
24
+ export declare const getModuleDependedEntitiesRaw: <T>(moduleId: string, entityId: string) => Promise<import('../main').BaseResponse<T>>;
17
25
  /**
18
26
  * a fetch function to handle GET requests and returns the response.
19
27
  * @param endpoint custom endpoint to GET data from
@@ -1,21 +1,22 @@
1
1
  import { useBasePropsStore as u } from "../stores/BasePropsStore.js";
2
- import { useEnvironmentStore as r } from "../stores/EnvironmentStore.js";
3
- import { baseMutation as c, baseFetch as o } from "./baseFetches.js";
4
- const d = (e, t, n = "POST", m, s) => c(e, t, n, m, s), I = (e, t) => i(`FarmOrgEntities/${e}/byId/${t}`), g = (e, t) => i(`ModuleDependentEntities/${e}/byId/${t}`), A = (e, t) => o(`${e}`, {}, t), i = (e) => {
5
- const t = r.getState().environment, n = u.getState().organizationId;
2
+ import { useEnvironmentStore as i } from "../stores/EnvironmentStore.js";
3
+ import { baseMutation as d, baseFetch as o } from "./baseFetches.js";
4
+ const p = (e, t, n = "POST", s, m) => d(e, t, n, s, m), I = (e, t) => r(`FarmOrgEntities/${e}/byId/${t}`), g = (e, t) => r(`ModuleDependentEntities/${e}/byId/${t}`), E = (e, t) => r(`ModuleDependentEntitiesRaw/${e}/byId/${t}`), A = (e, t) => o(`${e}`, {}, t), r = (e) => {
5
+ const t = i.getState().environment, n = u.getState().organizationId;
6
6
  return o(
7
7
  `${t?.MODULE_AUTH_API}${t?.API_PREFIX}/${n}/${e}`,
8
8
  {}
9
9
  );
10
- }, E = (e) => {
11
- const t = r.getState().environment;
10
+ }, M = (e) => {
11
+ const t = i.getState().environment;
12
12
  return o(`${t?.COMMON_API}${t?.API_PREFIX}/${e}`, {});
13
13
  };
14
14
  export {
15
- E as fetchFromCommonApi,
15
+ M as fetchFromCommonApi,
16
16
  A as fetchFromCustomApi,
17
- i as fetchFromModuleApi,
17
+ r as fetchFromModuleApi,
18
18
  I as getFarmOrgEntities,
19
19
  g as getModuleDependedEntities,
20
- d as mutateOnCustomApi
20
+ E as getModuleDependedEntitiesRaw,
21
+ p as mutateOnCustomApi
21
22
  };
@@ -24,7 +24,7 @@ const h = /^[v^~<>=]*?(\d+)(?:\.([x*]|\d+)(?:\.([x*]|\d+)(?:\.([x*]|\d+))?(?:-([
24
24
  }, g = (r, e) => {
25
25
  const n = u(r), t = u(e), i = n.pop(), o = t.pop(), s = l(n, t);
26
26
  return s !== 0 ? s : i && o ? l(i.split("."), o.split(".")) : i || o ? i ? -1 : 1 : 0;
27
- }, p = "0.0.14168", w = (r) => d.every((e) => v(e, r)), v = (r, e) => {
27
+ }, p = "0.0.15690", w = (r) => d.every((e) => v(e, r)), v = (r, e) => {
28
28
  if (!e[r]) {
29
29
  if (e.throwError)
30
30
  return e.throwError(`Missing required prop: ${r}`, 404), !1;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hortiview/modulebase",
3
3
  "description": "This is a base module for hortiview",
4
- "version": "0.0.14168",
4
+ "version": "0.0.15690",
5
5
  "type": "module",
6
6
  "author": "Falk Menge <falk.menge.ext@bayer.com>",
7
7
  "contributors": [