vineanova-redux-artifacts 1.119.308 → 1.119.310

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vineanova-redux-artifacts",
3
- "version": "1.119.308",
3
+ "version": "1.119.310",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -63,6 +63,15 @@ const ducksActions = createActions({
63
63
  UPDATEPARTIALENTITY:[(payload) => payload, ()=> ({ reducerName: 'blockRowPlant' })],
64
64
  },
65
65
  },
66
+ plantsForBlock: {
67
+ get: {
68
+ REQUEST: [(payload) => payload, ()=> ({ reducerName: 'plantsForBlock' })],
69
+ RECEIVE: [(payload) => payload, ()=> ({ reducerName: 'plantsForBlock' })],
70
+ ERROR: [(payload) => payload, ()=> ({ reducerName: 'plantsForBlock' })],
71
+ CLEARDATA: [(payload) => payload, ()=> ({ reducerName: 'plantsForBlock' })],
72
+ UPDATEPARTIALENTITY:[(payload) => payload, ()=> ({ reducerName: 'plantsForBlock' })],
73
+ },
74
+ },
66
75
  blockVintage: {
67
76
  get: {
68
77
  REQUEST: [(payload) => payload, ()=> ({ reducerName: 'blockVintage' })],
@@ -1,6 +1,7 @@
1
1
 
2
2
  export * from "./useFetchactivityDefaultRates";
3
3
  export * from "./useFetchblockRowPlant";
4
+ export * from "./useFetchplantsForBlock";
4
5
  export * from "./useFetchblockVintage";
5
6
  export * from "./useFetchcharts";
6
7
  export * from "./useFetchchartsByChartFilters";
@@ -0,0 +1,38 @@
1
+ import { useEffect } from 'react';
2
+ import { useSelector, useDispatch } from 'react-redux';
3
+ import { VineaNovaActions } from '../actions';
4
+ import * as VineaNovaSelectors from '../selectors';
5
+
6
+ export const useFetchPlantsForBlock = (props) => {
7
+ // selectors
8
+ const data = useSelector(
9
+ VineaNovaSelectors.getPlantsForBlockEntityData,
10
+ );
11
+ const dispatchAPI = useDispatch();
12
+ const { queryParams = {} } = props;
13
+
14
+ useEffect(() => {
15
+ dispatchAPI(
16
+ VineaNovaActions.api.v1.plantsForBlock.get.request({
17
+ queryParams: {
18
+ ...queryParams,
19
+ },
20
+ }),
21
+ );
22
+ }, []);
23
+
24
+ const useQuery = (queryParams) => {
25
+ dispatchAPI(
26
+ VineaNovaActions.api.v1.plantsForBlock.get.request({
27
+ queryParams: {
28
+ ...queryParams,
29
+ },
30
+ }),
31
+ );
32
+ };
33
+
34
+ return {
35
+ data,
36
+ useQuery,
37
+ };
38
+ };
@@ -5,6 +5,7 @@ const rootReducer = {
5
5
  entities: combineReducers({
6
6
  activityDefaultRates: createNamedReducer('activityDefaultRates'),
7
7
  blockRowPlant: createNamedReducer('blockRowPlant'),
8
+ plantsForBlock: createNamedReducer('plantsForBlock'),
8
9
  blockVintage: createNamedReducer('blockVintage'),
9
10
  charts: createNamedReducer('charts'),
10
11
  chartsByChartFilters: createNamedReducer('chartsByChartFilters'),
@@ -253,6 +253,37 @@ import { VineaNovaActions } from '../actions'
253
253
  }
254
254
 
255
255
 
256
+ export function* getPlantsForBlockSagas(action) {
257
+ const {
258
+ payload = {},
259
+ meta: { reducerName },
260
+ } = action;
261
+ try {
262
+ yield put({
263
+ type: "FETCHING",
264
+ name: reducerName,
265
+ });
266
+
267
+ const response = yield call(APIServices.getPlantsForBlock, payload);
268
+ yield put({
269
+ type: "SUCCESS",
270
+ payload: response,
271
+ name: reducerName,
272
+ });
273
+
274
+
275
+ } catch (err) {
276
+ console.error(err);
277
+ /* istanbul ignore next */
278
+ yield put({
279
+ type: "ERROR",
280
+ payload: err,
281
+ name: reducerName,
282
+ });
283
+ }
284
+ }
285
+
286
+
256
287
  export function* getBlockVintageSagas(action) {
257
288
  const {
258
289
  payload = {},
@@ -13779,6 +13810,7 @@ export default function* root() {
13779
13810
  takeLatest(VineaNovaActions.api.v1.blockRowPlant.post.request().type, postBlockRowPlantSagas),
13780
13811
  takeLatest(VineaNovaActions.api.v1.blockRowPlant.put.request().type, putBlockRowPlantSagas),
13781
13812
  takeLatest(VineaNovaActions.api.v1.blockRowPlant.delete.request().type, deleteBlockRowPlantSagas),
13813
+ takeLatest(VineaNovaActions.api.v1.plantsForBlock.get.request().type, getPlantsForBlockSagas),
13782
13814
  takeLatest(VineaNovaActions.api.v1.blockVintage.get.request().type, getBlockVintageSagas),
13783
13815
  takeLatest(VineaNovaActions.api.v1.blockVintage.post.request().type, postBlockVintageSagas),
13784
13816
  takeLatest(VineaNovaActions.api.v1.blockVintage.put.request().type, putBlockVintageSagas),
@@ -1,6 +1,7 @@
1
1
 
2
2
  export * from "./activityDefaultRatesSelector";
3
3
  export * from "./blockRowPlantSelector";
4
+ export * from "./plantsForBlockSelector";
4
5
  export * from "./blockVintageSelector";
5
6
  export * from "./chartsSelector";
6
7
  export * from "./chartsByChartFiltersSelector";
@@ -0,0 +1,62 @@
1
+ import { createSelector } from 'reselect';
2
+ import isEmpty from 'lodash/isEmpty';
3
+ import {isValid, format} from 'date-fns';
4
+ import isNil from 'lodash/isNil';
5
+ import has from 'lodash/has';
6
+
7
+ const viewDateFormat = 'dd/MM/yyyy';
8
+
9
+ export const getPlantsForBlockEntity = state => state.entities.plantsForBlock;
10
+
11
+ export const getPlantsForBlockEntityMeta = createSelector(
12
+ [getPlantsForBlockEntity],
13
+ reference => {
14
+ const { isLoading, isLoaded, hasError, error } = reference;
15
+ return {
16
+ isLoading,
17
+ isLoaded,
18
+ hasError,
19
+ error,
20
+ };
21
+ },
22
+ );
23
+
24
+ export const getPlantsForBlockEntityData = createSelector(
25
+ [getPlantsForBlockEntity],
26
+ reference => {
27
+ const { data = [] } = reference;
28
+ const refData = isEmpty(data) ? [] : data;
29
+ if (!Array.isArray(refData) || isNil(refData)) return [];
30
+
31
+ const formattedData = refData.map(d => {
32
+ let hasDates = false;
33
+ let fromDate = '';
34
+ let toDate = '';
35
+ let fromTo = '';
36
+ if(has(d, 'effectiveToDate') && has(d, 'effectiveFromDate')){
37
+ hasDates = true;
38
+ toDate =
39
+ !isEmpty(d.effectiveToDate) && isValid(new Date(d.effectiveToDate))
40
+ ? format(new Date(d.effectiveToDate), viewDateFormat)
41
+ : '';
42
+ fromDate =
43
+ !isEmpty(d.effectiveFromDate) &&
44
+ isValid(new Date(d.effectiveFromDate))
45
+ ? format(new Date(d.effectiveFromDate), viewDateFormat)
46
+ : '';
47
+ }
48
+
49
+ return {
50
+ ...d,
51
+ ...(hasDates && {
52
+ fromDate,
53
+ toDate,
54
+ fromTo,
55
+ })
56
+ };
57
+ });
58
+
59
+ return formattedData;
60
+ },
61
+ );
62
+
@@ -184,6 +184,29 @@ import serviceConfig from "./config/serviceConfig";
184
184
  };
185
185
 
186
186
 
187
+ export const getPlantsForBlock = async (payload) => {
188
+ try {
189
+ const { queryParams, postBody, options } = payload || {};
190
+ let apiUrl = '/PlantsForBlock';
191
+ const response = await serviceConfig.request({
192
+ url: apiUrl,
193
+ method: "get",
194
+ params: {
195
+ ...queryParams,
196
+ },
197
+ headers: {
198
+ "Content-Type": "application/json",
199
+ Accept: "application/json",
200
+ },
201
+ ...options,
202
+ });
203
+ return response;
204
+ } catch (err) {
205
+ throw err;
206
+ }
207
+ };
208
+
209
+
187
210
  export const getBlockVintage = async (payload) => {
188
211
  try {
189
212
  const { queryParams, postBody, options } = payload || {};