@hortiview/modulebase 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.
Files changed (56) hide show
  1. package/README.md +8 -0
  2. package/dist/QueryClientProvider-DQv4Y3Qu.js +707 -0
  3. package/dist/_baseGet-Bh5zJ_C8.js +805 -0
  4. package/dist/_commonjsHelpers-BkfeUUK-.js +28 -0
  5. package/dist/chunk-IR6S3I6Y-BvQXS3A3.js +3908 -0
  6. package/dist/components/ModuleBase.d.ts +11 -0
  7. package/dist/components/ModuleBase.js +691 -0
  8. package/dist/constants.d.ts +25 -0
  9. package/dist/constants.js +34 -0
  10. package/dist/fetches-DUCQo_6B.js +477 -0
  11. package/dist/hooks/useBreadcrumbTranslation.d.ts +1 -0
  12. package/dist/hooks/useBreadcrumbTranslation.js +20 -0
  13. package/dist/hooks/useCustom.d.ts +6 -0
  14. package/dist/hooks/useCustom.js +19 -0
  15. package/dist/hooks/useEntity.d.ts +186 -0
  16. package/dist/hooks/useEntity.js +58 -0
  17. package/dist/hooks/useNavigate.d.ts +5 -0
  18. package/dist/hooks/useNavigate.js +27 -0
  19. package/dist/hooks/useOption.d.ts +17 -0
  20. package/dist/hooks/useOption.js +23 -0
  21. package/dist/hooks/useSignalRMessages.d.ts +6 -0
  22. package/dist/hooks/useSignalRMessages.js +13 -0
  23. package/dist/hooks/useStores.d.ts +29 -0
  24. package/dist/hooks/useStores.js +844 -0
  25. package/dist/main.d.ts +9 -0
  26. package/dist/main.js +19 -0
  27. package/dist/provider/SignalR/SignalRProvider.d.ts +13 -0
  28. package/dist/provider/SignalR/SignalRProvider.js +6408 -0
  29. package/dist/provider/SignalR/signalR.d.ts +53 -0
  30. package/dist/provider/SignalR/signalR.js +11 -0
  31. package/dist/react-QiIgv49H.js +27 -0
  32. package/dist/stores/BasePropsStore.d.ts +6 -0
  33. package/dist/stores/BasePropsStore.js +7 -0
  34. package/dist/stores/EnvironmentStore.d.ts +8 -0
  35. package/dist/stores/EnvironmentStore.js +9 -0
  36. package/dist/types/AppInsights.d.ts +12 -0
  37. package/dist/types/AppInsights.js +1 -0
  38. package/dist/types/BaseProps.d.ts +38 -0
  39. package/dist/types/BaseProps.js +1 -0
  40. package/dist/types/CommonOptions.d.ts +61 -0
  41. package/dist/types/CommonOptions.js +4 -0
  42. package/dist/types/Deprecated.d.ts +93 -0
  43. package/dist/types/Deprecated.js +1 -0
  44. package/dist/types/Environment.d.ts +17 -0
  45. package/dist/types/Environment.js +1 -0
  46. package/dist/types/ModuleApi.d.ts +80 -0
  47. package/dist/types/ModuleApi.js +1 -0
  48. package/dist/types/Requests.d.ts +49 -0
  49. package/dist/types/Requests.js +4 -0
  50. package/dist/types/SystemMessage.d.ts +14 -0
  51. package/dist/types/SystemMessage.js +1 -0
  52. package/dist/useQuery-znAyMQW1.js +397 -0
  53. package/dist/utils/fetches.d.ts +26 -0
  54. package/dist/utils/fetches.js +16 -0
  55. package/dist/vite-env.d.js +1 -0
  56. package/package.json +55 -0
@@ -0,0 +1,186 @@
1
+ import { Block, BlockPlantLayout, Farm, FarmOrgEntity, Field, ModuleEntity, Season } from '../types/ModuleApi';
2
+ type HortiviewDataAreaGroup = 'FarmOrganization' | 'FarmMember';
3
+ type ModuleDataAreaGroup = 'ModuleDepended';
4
+ type FarmOrganizationEntities = 'farms' | 'fields' | 'zones' | 'irrigation_stations' | 'farm_organizations' | 'alert_rules';
5
+ type FarmMemberEntities = 'farm_members';
6
+ type ModuleDependendEntities = 'Season' | 'BlockPlantLayout' | (string & {});
7
+ type HortiviewDataAreaEntity<T extends HortiviewDataAreaGroup | ModuleDataAreaGroup> = T extends 'FarmOrganization' ? FarmOrganizationEntities : T extends 'FarmMember' ? FarmMemberEntities : T extends 'ModuleDepended' ? ModuleDependendEntities : never;
8
+ type ResultMap<T extends FarmMemberEntities | FarmOrganizationEntities | ModuleDependendEntities> = T extends 'zones' ? Block : T extends 'fields' ? Field : T extends 'farms' ? Farm : T extends 'irrigation_stations' ? {
9
+ id: string;
10
+ } : T extends 'farm_organizations' ? {
11
+ id: string;
12
+ } : T extends 'alert_rules' ? {
13
+ id: string;
14
+ } : T extends 'Season' ? Season : T extends 'BlockPlantLayout' ? BlockPlantLayout : never;
15
+ export declare const FarmOrgEntitiesTypeResultMap: Record<FarmOrganizationEntities, string>;
16
+ export declare const FarmMemberEntitiesTypeResultMap: Record<FarmMemberEntities, string>;
17
+ export declare const ModuleDependedEntityTypeResultMap: Record<ModuleDependendEntities, string>;
18
+ export declare const AllEntitiesTypeResultMap: {
19
+ Season: string;
20
+ BlockPlantLayout: string;
21
+ farm_members: string;
22
+ farms: string;
23
+ fields: string;
24
+ zones: string;
25
+ irrigation_stations: string;
26
+ farm_organizations: string;
27
+ alert_rules: string;
28
+ };
29
+ export declare const useEntity: <K extends HortiviewDataAreaGroup | ModuleDataAreaGroup, E extends HortiviewDataAreaEntity<K>>(group: K, entity: E) => {
30
+ data: ResultMap<E>[];
31
+ error: Error;
32
+ isError: true;
33
+ isPending: false;
34
+ isLoading: false;
35
+ isLoadingError: false;
36
+ isRefetchError: true;
37
+ isSuccess: false;
38
+ isPlaceholderData: false;
39
+ status: "error";
40
+ dataUpdatedAt: number;
41
+ errorUpdatedAt: number;
42
+ failureCount: number;
43
+ failureReason: Error | null;
44
+ errorUpdateCount: number;
45
+ isFetched: boolean;
46
+ isFetchedAfterMount: boolean;
47
+ isFetching: boolean;
48
+ isInitialLoading: boolean;
49
+ isPaused: boolean;
50
+ isRefetching: boolean;
51
+ isStale: boolean;
52
+ refetch: (options?: import('@tanstack/query-core').RefetchOptions) => Promise<import('@tanstack/query-core').QueryObserverResult<FarmOrgEntity[] | ModuleEntity[], Error>>;
53
+ fetchStatus: import('@tanstack/query-core').FetchStatus;
54
+ promise: Promise<FarmOrgEntity[] | ModuleEntity[]>;
55
+ } | {
56
+ data: ResultMap<E>[];
57
+ error: null;
58
+ isError: false;
59
+ isPending: false;
60
+ isLoading: false;
61
+ isLoadingError: false;
62
+ isRefetchError: false;
63
+ isSuccess: true;
64
+ isPlaceholderData: false;
65
+ status: "success";
66
+ dataUpdatedAt: number;
67
+ errorUpdatedAt: number;
68
+ failureCount: number;
69
+ failureReason: Error | null;
70
+ errorUpdateCount: number;
71
+ isFetched: boolean;
72
+ isFetchedAfterMount: boolean;
73
+ isFetching: boolean;
74
+ isInitialLoading: boolean;
75
+ isPaused: boolean;
76
+ isRefetching: boolean;
77
+ isStale: boolean;
78
+ refetch: (options?: import('@tanstack/query-core').RefetchOptions) => Promise<import('@tanstack/query-core').QueryObserverResult<FarmOrgEntity[] | ModuleEntity[], Error>>;
79
+ fetchStatus: import('@tanstack/query-core').FetchStatus;
80
+ promise: Promise<FarmOrgEntity[] | ModuleEntity[]>;
81
+ } | {
82
+ data: ResultMap<E>[];
83
+ error: Error;
84
+ isError: true;
85
+ isPending: false;
86
+ isLoading: false;
87
+ isLoadingError: true;
88
+ isRefetchError: false;
89
+ isSuccess: false;
90
+ isPlaceholderData: false;
91
+ status: "error";
92
+ dataUpdatedAt: number;
93
+ errorUpdatedAt: number;
94
+ failureCount: number;
95
+ failureReason: Error | null;
96
+ errorUpdateCount: number;
97
+ isFetched: boolean;
98
+ isFetchedAfterMount: boolean;
99
+ isFetching: boolean;
100
+ isInitialLoading: boolean;
101
+ isPaused: boolean;
102
+ isRefetching: boolean;
103
+ isStale: boolean;
104
+ refetch: (options?: import('@tanstack/query-core').RefetchOptions) => Promise<import('@tanstack/query-core').QueryObserverResult<FarmOrgEntity[] | ModuleEntity[], Error>>;
105
+ fetchStatus: import('@tanstack/query-core').FetchStatus;
106
+ promise: Promise<FarmOrgEntity[] | ModuleEntity[]>;
107
+ } | {
108
+ data: ResultMap<E>[];
109
+ error: null;
110
+ isError: false;
111
+ isPending: true;
112
+ isLoading: true;
113
+ isLoadingError: false;
114
+ isRefetchError: false;
115
+ isSuccess: false;
116
+ isPlaceholderData: false;
117
+ status: "pending";
118
+ dataUpdatedAt: number;
119
+ errorUpdatedAt: number;
120
+ failureCount: number;
121
+ failureReason: Error | null;
122
+ errorUpdateCount: number;
123
+ isFetched: boolean;
124
+ isFetchedAfterMount: boolean;
125
+ isFetching: boolean;
126
+ isInitialLoading: boolean;
127
+ isPaused: boolean;
128
+ isRefetching: boolean;
129
+ isStale: boolean;
130
+ refetch: (options?: import('@tanstack/query-core').RefetchOptions) => Promise<import('@tanstack/query-core').QueryObserverResult<FarmOrgEntity[] | ModuleEntity[], Error>>;
131
+ fetchStatus: import('@tanstack/query-core').FetchStatus;
132
+ promise: Promise<FarmOrgEntity[] | ModuleEntity[]>;
133
+ } | {
134
+ data: ResultMap<E>[];
135
+ error: null;
136
+ isError: false;
137
+ isPending: true;
138
+ isLoadingError: false;
139
+ isRefetchError: false;
140
+ isSuccess: false;
141
+ isPlaceholderData: false;
142
+ status: "pending";
143
+ dataUpdatedAt: number;
144
+ errorUpdatedAt: number;
145
+ failureCount: number;
146
+ failureReason: Error | null;
147
+ errorUpdateCount: number;
148
+ isFetched: boolean;
149
+ isFetchedAfterMount: boolean;
150
+ isFetching: boolean;
151
+ isLoading: boolean;
152
+ isInitialLoading: boolean;
153
+ isPaused: boolean;
154
+ isRefetching: boolean;
155
+ isStale: boolean;
156
+ refetch: (options?: import('@tanstack/query-core').RefetchOptions) => Promise<import('@tanstack/query-core').QueryObserverResult<FarmOrgEntity[] | ModuleEntity[], Error>>;
157
+ fetchStatus: import('@tanstack/query-core').FetchStatus;
158
+ promise: Promise<FarmOrgEntity[] | ModuleEntity[]>;
159
+ } | {
160
+ data: ResultMap<E>[];
161
+ isError: false;
162
+ error: null;
163
+ isPending: false;
164
+ isLoading: false;
165
+ isLoadingError: false;
166
+ isRefetchError: false;
167
+ isSuccess: true;
168
+ isPlaceholderData: true;
169
+ status: "success";
170
+ dataUpdatedAt: number;
171
+ errorUpdatedAt: number;
172
+ failureCount: number;
173
+ failureReason: Error | null;
174
+ errorUpdateCount: number;
175
+ isFetched: boolean;
176
+ isFetchedAfterMount: boolean;
177
+ isFetching: boolean;
178
+ isInitialLoading: boolean;
179
+ isPaused: boolean;
180
+ isRefetching: boolean;
181
+ isStale: boolean;
182
+ refetch: (options?: import('@tanstack/query-core').RefetchOptions) => Promise<import('@tanstack/query-core').QueryObserverResult<FarmOrgEntity[] | ModuleEntity[], Error>>;
183
+ fetchStatus: import('@tanstack/query-core').FetchStatus;
184
+ promise: Promise<FarmOrgEntity[] | ModuleEntity[]>;
185
+ };
186
+ export {};
@@ -0,0 +1,58 @@
1
+ import { u as f } from "../useQuery-znAyMQW1.js";
2
+ import { useMemo as g } from "react";
3
+ import { useBasePropsStore as l } from "../stores/BasePropsStore.js";
4
+ import { universalSelector as p } from "../types/Requests.js";
5
+ import { g as b, a as R } from "../fetches-DUCQo_6B.js";
6
+ import { useOption as y, useModuleDependency as k } from "./useOption.js";
7
+ const F = {
8
+ farms: "farm",
9
+ fields: "field",
10
+ zones: "block",
11
+ irrigation_stations: "irrigationStation",
12
+ farm_organizations: "farmOrg",
13
+ alert_rules: "farmAlertRule"
14
+ }, Q = {
15
+ farm_members: "member"
16
+ }, q = {
17
+ Season: "season",
18
+ BlockPlantLayout: "blockPlantLayout"
19
+ }, A = {
20
+ ...F,
21
+ ...Q,
22
+ ...q
23
+ }, B = (t, e) => {
24
+ const a = l((r) => r.moduleId), o = l((r) => r.organizationId), { data: i } = y("DataAreaGroup"), { data: u } = y("DataAreaEntity"), { data: n } = k(), d = t === "ModuleDepended", E = g(() => {
25
+ if (d)
26
+ return n ? n.find((s) => s.registeredEntityName === e)?.id : void 0;
27
+ if (!i || !u) return;
28
+ const r = i.find((s) => s.key === t)?.id;
29
+ return r ? u.find((s) => s.description === r && s.value === e)?.id : void 0;
30
+ }, [d, i, u, n, e, t]), c = D(a, E, o, d), M = (c.data ?? []).map((r) => {
31
+ const m = A[e];
32
+ return r[m];
33
+ });
34
+ return {
35
+ ...c,
36
+ data: M
37
+ };
38
+ }, D = (t, e, a, o) => {
39
+ const i = f({
40
+ queryKey: [t, a, e],
41
+ queryFn: () => b(t ?? "", e ?? ""),
42
+ enabled: o && !!t && !!e && !!a,
43
+ select: (n) => p(n)
44
+ }), u = f({
45
+ queryKey: [t, a, e],
46
+ queryFn: () => R(t ?? "", e ?? ""),
47
+ enabled: !o && !!t && !!e && !!a,
48
+ select: (n) => p(n)
49
+ });
50
+ return o ? i : u;
51
+ };
52
+ export {
53
+ A as AllEntitiesTypeResultMap,
54
+ Q as FarmMemberEntitiesTypeResultMap,
55
+ F as FarmOrgEntitiesTypeResultMap,
56
+ q as ModuleDependedEntityTypeResultMap,
57
+ B as useEntity
58
+ };
@@ -0,0 +1,5 @@
1
+ /**
2
+ *
3
+ * @returns A function to navigate to a specific path
4
+ */
5
+ export declare const useNavigate: () => (path: string) => void;
@@ -0,0 +1,27 @@
1
+ import { useEffect as o, useCallback as s } from "react";
2
+ import { u as v } from "../chunk-IR6S3I6Y-BvQXS3A3.js";
3
+ import { useBasePropsStore as r } from "../stores/BasePropsStore.js";
4
+ const m = () => {
5
+ const e = r(
6
+ (t) => t.currentNavigationPath
7
+ ), a = r(
8
+ (t) => t.navigateTo
9
+ ), i = r(
10
+ (t) => t.navigateInHortiview
11
+ ), n = v();
12
+ return o(() => {
13
+ e && n(e, { replace: !0 });
14
+ }, [e, n]), s(
15
+ (t) => {
16
+ if (i) {
17
+ i(t);
18
+ return;
19
+ }
20
+ a && a(t);
21
+ },
22
+ [i, a]
23
+ );
24
+ };
25
+ export {
26
+ m as useNavigate
27
+ };
@@ -0,0 +1,17 @@
1
+ import { UseQueryResult } from '@tanstack/react-query';
2
+ import { CommonOption, CommonOptionType } from '../types/CommonOptions';
3
+ import { RegisterOption } from '../types/ModuleApi';
4
+ /**
5
+ * Custom hook to fetch and manage options for a dropdown.
6
+ *
7
+ * @param dropdown - The key of the dropdown option to fetch from the common options.
8
+ * @returns A query object from `useQuery` containing the fetched dropdown options.
9
+ *
10
+ * This hook first attempts to retrieve the dropdown options from the HortiView-platform (module-property `commonOptions`).
11
+ * If the options are not available locally, it fetches them from a common API endpoint.
12
+ *
13
+ * The query key is set to the dropdown key, and the query function either resolves the local option
14
+ * or fetches it from the API. The result is then processed by a universal selector.
15
+ */
16
+ export declare const useOption: (dropdown: keyof typeof CommonOptionType) => UseQueryResult<CommonOption[], Error>;
17
+ export declare const useModuleDependency: () => UseQueryResult<RegisterOption[], Error>;
@@ -0,0 +1,23 @@
1
+ import { u as s } from "../useQuery-znAyMQW1.js";
2
+ import { b as u, f as c, c as i } from "../fetches-DUCQo_6B.js";
3
+ import { useBasePropsStore as t } from "../stores/BasePropsStore.js";
4
+ import { universalSelector as m } from "../types/Requests.js";
5
+ const y = (o) => {
6
+ const r = t((n) => n.commonOptions), e = u(r, o);
7
+ return s({
8
+ queryKey: [o],
9
+ queryFn: () => e ? Promise.resolve(e) : c(`${o}/dropdown`),
10
+ select: (n) => m(n)
11
+ });
12
+ }, f = () => {
13
+ const o = t((e) => e.moduleId), r = t((e) => e.organizationId);
14
+ return s({
15
+ queryKey: [o, r],
16
+ queryFn: () => i(`ModuleDependencies/${o}`),
17
+ select: (e) => m(e)
18
+ });
19
+ };
20
+ export {
21
+ f as useModuleDependency,
22
+ y as useOption
23
+ };
@@ -0,0 +1,6 @@
1
+ import { SignalRMessage } from '../provider/SignalR/signalR';
2
+ /**
3
+ * hook to react on messages from signalR
4
+ * @param callback callback function to be called when a message is received
5
+ */
6
+ export declare const useSignalRMessages: (callback: (message: SignalRMessage) => void) => void;
@@ -0,0 +1,13 @@
1
+ import { SignalRModuleContext as i } from "../provider/SignalR/SignalRProvider.js";
2
+ const s = (e) => {
3
+ i.useSignalREffect(
4
+ "ModuleApiPushNotification",
5
+ (...[o]) => {
6
+ e(o);
7
+ },
8
+ [e]
9
+ );
10
+ };
11
+ export {
12
+ s as useSignalRMessages
13
+ };
@@ -0,0 +1,29 @@
1
+ export declare const useBaseProps: () => Pick<import('../types/Deprecated').DeprecatedBaseProps & {
2
+ modulePermissionToken?: string;
3
+ moduleId?: string;
4
+ organizationId?: string;
5
+ basePath?: string;
6
+ currentNavigationPath?: string;
7
+ sourcePath?: string | null;
8
+ currentLanguage?: string;
9
+ currentLanguageId?: string;
10
+ alertRules?: string;
11
+ commonOptions?: import('../types/CommonOptions').AllDropdownsData<import('../types/CommonOptions').CommonOption>["items"];
12
+ navigateInHortiview?: (path: string) => void;
13
+ addBreadcrumbTranslation?: (translation: {
14
+ key: string;
15
+ value: string;
16
+ }) => void;
17
+ showSnackbar?: (message: string, icon?: string) => void;
18
+ showMessage?: (message: import('../types/SystemMessage').SystemMessage) => void;
19
+ logEvent?: (event: import('../types/AppInsights').AppInsightsEvent, customProperties?: import('../types/AppInsights').AppInsightsProperties) => void;
20
+ logError?: (exception: import('../types/AppInsights').AppInsightsException) => void;
21
+ throwError?: (message: string, code: number) => void;
22
+ } & {
23
+ setBaseProps: (props: import('../main').BaseProps) => void;
24
+ }, keyof import('../types/Deprecated').DeprecatedBaseProps | "modulePermissionToken" | "moduleId" | "organizationId" | "basePath" | "currentNavigationPath" | "sourcePath" | "currentLanguage" | "currentLanguageId" | "alertRules" | "commonOptions" | "navigateInHortiview" | "addBreadcrumbTranslation" | "showSnackbar" | "showMessage" | "logEvent" | "logError" | "throwError">;
25
+ export declare const useConfig: () => Pick<{
26
+ environment?: import('../types/Environment').HortiViewEnvironments;
27
+ setEnvironment: (environment: import('../types/Environment').HortiViewEnvironments) => void;
28
+ addEnvironment: (customEnv: import('../types/Environment').CustomEnv) => void;
29
+ }, "environment">;