kupos-ui-components-lib 9.1.3 → 9.1.4

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,4 +1,4 @@
1
1
  import React from "react";
2
2
  import { FilterBarProps } from "./tyoes";
3
- declare const FilterBarDesktop: ({ t, serviceList, setServiceList, allSchedules, showReturnTripModal, filterArrData, isBlankTicket, operatorId, filtersArray, setFiltersArray, metaData, busTerminals, setTypes, colors, icons, translation, isTrain, isPeru, hideOperator, setCoachLoading, setCoachKey, }: FilterBarProps) => React.JSX.Element;
3
+ declare const FilterBarDesktop: ({ t, serviceList, setServiceList, allSchedules, showReturnTripModal, filterArrData, isBlankTicket, operatorId, filtersArray, setFiltersArray, metaData, busTerminals, setTypes, colors, icons, translation, isTrain, isPeru, hideOperator, setCoachLoading, setCoachKey, isAllinBus, }: FilterBarProps) => React.JSX.Element;
4
4
  export default FilterBarDesktop;
@@ -1,7 +1,42 @@
1
1
  import React from "react";
2
2
  import commonService from "../../utils/CommonService";
3
3
  import ServiceFilter from "./ServiceFilter";
4
- const FilterBarDesktop = ({ t, serviceList, setServiceList, allSchedules, showReturnTripModal, filterArrData, isBlankTicket, operatorId, filtersArray, setFiltersArray, metaData, busTerminals, setTypes, colors, icons, translation, isTrain, isPeru, hideOperator, setCoachLoading, setCoachKey, }) => {
4
+ const FilterBarDesktop = ({ t, serviceList, setServiceList, allSchedules, showReturnTripModal, filterArrData, isBlankTicket, operatorId, filtersArray, setFiltersArray, metaData, busTerminals, setTypes, colors, icons, translation, isTrain, isPeru, hideOperator, setCoachLoading, setCoachKey, isAllinBus, }) => {
5
+ const getEnrichedFilters = () => {
6
+ if (!isAllinBus || !(allSchedules === null || allSchedules === void 0 ? void 0 : allSchedules.length))
7
+ return filtersArray;
8
+ const hasSpecialDeparture = filtersArray.some((f) => { var _a; return f.type === "special_departure" && ((_a = f.options) === null || _a === void 0 ? void 0 : _a.length) > 0; });
9
+ if (hasSpecialDeparture)
10
+ return filtersArray;
11
+ const stageMap = new Map();
12
+ allSchedules.forEach((schedule) => {
13
+ var _a, _b, _c;
14
+ if ((_a = schedule.stage_details_arr) === null || _a === void 0 ? void 0 : _a.length) {
15
+ const stageObj = schedule.stage_details_arr[0];
16
+ const stageId = Object.keys(stageObj)[0];
17
+ const stageName = (_c = (_b = stageObj[stageId]) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.split(", ")[0];
18
+ if (stageId && stageName) {
19
+ stageMap.set(stageId, stageName);
20
+ }
21
+ }
22
+ });
23
+ if (stageMap.size === 0)
24
+ return filtersArray;
25
+ const specialDeptOptions = Array.from(stageMap.entries()).map(([id, name]) => ({
26
+ label: name,
27
+ value: id,
28
+ active: false,
29
+ }));
30
+ return [
31
+ ...filtersArray,
32
+ {
33
+ type: "special_departure",
34
+ title: "SPECIAL_DEPARTURE",
35
+ options: specialDeptOptions,
36
+ },
37
+ ];
38
+ };
39
+ const enrichedFilters = getEnrichedFilters();
5
40
  const filterBy = (filters) => {
6
41
  try {
7
42
  let routes = allSchedules;
@@ -179,12 +214,12 @@ const FilterBarDesktop = ({ t, serviceList, setServiceList, allSchedules, showRe
179
214
  const onFilterSelected = (key, i) => {
180
215
  setCoachLoading(null);
181
216
  setCoachKey(null);
182
- let filters = commonService.copyObject(filtersArray);
217
+ let filters = commonService.copyObject(enrichedFilters);
183
218
  filters[key].options[i].active = !filters[key].options[i].active;
184
219
  filterBy(filters);
185
220
  setFiltersArray(filters);
186
221
  };
187
- return (React.createElement(ServiceFilter, { filtersArray: filtersArray, onFilterSelected: onFilterSelected, onFilterClear: (val) => {
222
+ return (React.createElement(ServiceFilter, { filtersArray: enrichedFilters, onFilterSelected: onFilterSelected, onFilterClear: (val) => {
188
223
  setFiltersArray(val);
189
224
  filterBy(val);
190
225
  }, showReturnTripModal: showReturnTripModal, initialOpenFilters: isBlankTicket ? ["operator"] : [], colors: colors, icons: icons, translation: translation, isTrain: isTrain, hideOperator: hideOperator, t: t }));
@@ -35,4 +35,5 @@ export interface FilterBarProps {
35
35
  isPeru?: boolean;
36
36
  setCoachLoading?: any;
37
37
  setCoachKey?: any;
38
+ isAllinBus?: boolean;
38
39
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kupos-ui-components-lib",
3
- "version": "9.1.3",
3
+ "version": "9.1.4",
4
4
  "description": "A reusable UI components package",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -1,4 +1,4 @@
1
- import React, { useEffect } from "react";
1
+ import React from "react";
2
2
  import { FilterBarProps } from "./tyoes";
3
3
  import commonService from "../../utils/CommonService";
4
4
  import ServiceFilter from "./ServiceFilter";
@@ -25,7 +25,50 @@ const FilterBarDesktop = ({
25
25
  hideOperator,
26
26
  setCoachLoading,
27
27
  setCoachKey,
28
+ isAllinBus,
28
29
  }: FilterBarProps) => {
30
+ const getEnrichedFilters = () => {
31
+ if (!isAllinBus || !allSchedules?.length) return filtersArray;
32
+
33
+ const hasSpecialDeparture = filtersArray.some(
34
+ (f: any) => f.type === "special_departure" && f.options?.length > 0,
35
+ );
36
+ if (hasSpecialDeparture) return filtersArray;
37
+
38
+ const stageMap = new Map<string, string>();
39
+ allSchedules.forEach((schedule: any) => {
40
+ if (schedule.stage_details_arr?.length) {
41
+ const stageObj = schedule.stage_details_arr[0];
42
+ const stageId = Object.keys(stageObj)[0];
43
+ const stageName = stageObj[stageId]?.[0]?.split(", ")[0];
44
+ if (stageId && stageName) {
45
+ stageMap.set(stageId, stageName);
46
+ }
47
+ }
48
+ });
49
+
50
+ if (stageMap.size === 0) return filtersArray;
51
+
52
+ const specialDeptOptions = Array.from(stageMap.entries()).map(
53
+ ([id, name]) => ({
54
+ label: name,
55
+ value: id,
56
+ active: false,
57
+ }),
58
+ );
59
+
60
+ return [
61
+ ...filtersArray,
62
+ {
63
+ type: "special_departure",
64
+ title: "SPECIAL_DEPARTURE",
65
+ options: specialDeptOptions,
66
+ },
67
+ ];
68
+ };
69
+
70
+ const enrichedFilters = getEnrichedFilters();
71
+
29
72
  const filterBy = (filters) => {
30
73
  try {
31
74
  let routes = allSchedules;
@@ -213,7 +256,7 @@ const FilterBarDesktop = ({
213
256
  const onFilterSelected = (key: number, i: number) => {
214
257
  setCoachLoading(null);
215
258
  setCoachKey(null);
216
- let filters = commonService.copyObject(filtersArray);
259
+ let filters = commonService.copyObject(enrichedFilters);
217
260
  filters[key].options[i].active = !filters[key].options[i].active;
218
261
  filterBy(filters);
219
262
  setFiltersArray(filters);
@@ -221,7 +264,7 @@ const FilterBarDesktop = ({
221
264
 
222
265
  return (
223
266
  <ServiceFilter
224
- filtersArray={filtersArray}
267
+ filtersArray={enrichedFilters}
225
268
  onFilterSelected={onFilterSelected}
226
269
  onFilterClear={(val) => {
227
270
  setFiltersArray(val);
@@ -34,5 +34,6 @@ export interface FilterBarProps {
34
34
  isPeru?: boolean;
35
35
  setCoachLoading?: any;
36
36
  setCoachKey?: any;
37
+ isAllinBus?: boolean;
37
38
 
38
39
  }