From 6da7bbb9e67df908b868e3e9c5a9ac3be3d66c6d Mon Sep 17 00:00:00 2001 From: Anshuman Rai Date: Tue, 7 May 2024 10:59:36 +0530 Subject: [PATCH 1/3] TP-53768 | Revert revert-763-TP-53768 --- android/app/build.gradle | 4 +- package.json | 6 +-- src/common/Constants.ts | 5 +++ .../allCasesFilters/FilterOptions.tsx | 11 +++-- .../allCases/allCasesFilters/FilterUtils.ts | 43 ++++++++++++++++++- .../screens/allCases/allCasesFilters/types.ts | 8 ++++ src/components/utlis/commonFunctions.ts | 4 ++ 7 files changed, 70 insertions(+), 11 deletions(-) create mode 100644 src/components/screens/allCases/allCasesFilters/types.ts diff --git a/android/app/build.gradle b/android/app/build.gradle index 99e5b6ee..cc69b3ea 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -134,8 +134,8 @@ def reactNativeArchitectures() { return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"] } -def VERSION_CODE = 151 -def VERSION_NAME = "2.9.10" +def VERSION_CODE = 152 +def VERSION_NAME = "2.9.11" android { ndkVersion rootProject.ext.ndkVersion diff --git a/package.json b/package.json index a9246be0..5d9362a5 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "AV_APP", - "version": "2.9.10", - "buildNumber": "151", + "version": "2.9.11", + "buildNumber": "152", "private": true, "scripts": { "android:dev": "yarn move:dev && react-native run-android", @@ -64,7 +64,7 @@ "appcenter": "^4.4.5", "appcenter-analytics": "^4.4.5", "appcenter-crashes": "^4.4.5", - "axios": "1.6.0", + "axios": "1.2.1", "d3-scale": "4.0.2", "d3-shape": "3.2.0", "dayjs": "1.11.9", diff --git a/src/common/Constants.ts b/src/common/Constants.ts index d21cc569..abe53f7c 100644 --- a/src/common/Constants.ts +++ b/src/common/Constants.ts @@ -25,6 +25,11 @@ export const RANGE_FILTER_SEPARATOR = '-'; export interface Option { label: string; value: any; + meta?: Record; +} + +export interface SubLabelOption extends Option { + subLabel?: string; } export enum FirestoreUpdateTypes { diff --git a/src/components/screens/allCases/allCasesFilters/FilterOptions.tsx b/src/components/screens/allCases/allCasesFilters/FilterOptions.tsx index a3115509..3799daac 100644 --- a/src/components/screens/allCases/allCasesFilters/FilterOptions.tsx +++ b/src/components/screens/allCases/allCasesFilters/FilterOptions.tsx @@ -9,6 +9,7 @@ import { IFilterOptionsProps } from './Interface'; import { useSelector } from 'react-redux'; import { RootState } from '../../../../store/store'; import styles from './styles'; +import {getKeys, getOptions} from "@components/screens/allCases/allCasesFilters/FilterUtils"; const FilterOptions: React.FC = ({ selectedFilterKey, @@ -19,19 +20,21 @@ const FilterOptions: React.FC = ({ const { filters } = useSelector((state: RootState) => ({ filters: state.filters.filters, })); + if (Object.keys(filters).length === 0) { - return <>; + return null; } if (selectedFilterKey) { const options = filterSearchString.length > 0 ? Search( filterSearchString, - filters[selectedFilterKey.filterGroup].filters[selectedFilterKey.filterKey].options || + getOptions(filters[selectedFilterKey.filterGroup].filters[selectedFilterKey.filterKey].options, selectedFilterKey.filterKey) || [], - { keys: ['label'] } + { keys: getKeys(selectedFilterKey.filterKey) } ).map((option) => option.obj) - : filters[selectedFilterKey.filterGroup].filters[selectedFilterKey.filterKey].options; + : getOptions(filters[selectedFilterKey.filterGroup].filters[selectedFilterKey.filterKey].options, selectedFilterKey.filterKey); + switch ( filters[selectedFilterKey.filterGroup].filters[selectedFilterKey.filterKey].selectionType ) { diff --git a/src/components/screens/allCases/allCasesFilters/FilterUtils.ts b/src/components/screens/allCases/allCasesFilters/FilterUtils.ts index a1333e6a..40cc38c0 100644 --- a/src/components/screens/allCases/allCasesFilters/FilterUtils.ts +++ b/src/components/screens/allCases/allCasesFilters/FilterUtils.ts @@ -7,12 +7,14 @@ import { } from '../../../../screens/allCases/interface'; import { CONDITIONAL_OPERATORS, - FILTER_TYPES, + FILTER_TYPES, Option, RANGE_FILTER_SEPARATOR, - SELECTION_TYPES, + SELECTION_TYPES, SubLabelOption, } from '../../../../common/Constants'; import { getObjectValueFromKeys } from '../../../utlis/parsers'; import { _map } from '../../../../../RN-UI-LIB/src/utlis/common'; +import { pluralise } from "@utils/commonFunctions"; +import { FilterKeys, OptionTypes } from "@components/screens/allCases/allCasesFilters/types"; export const evaluateFilterForCases = ( caseRecord: CaseDetail, @@ -169,3 +171,40 @@ export function filterTransformer(filterResponseList: FilterResponse[]) { }); return { filterGroupMap, quickFilters }; } + +const populateSubLabelsAndSort = (options: Option[], subLabelKey: string) => options.map(option => { + const subLabelList = option?.meta? option.meta[subLabelKey]: [""]; + const subLabel = subLabelList?.length > 0 ? subLabelList[0] : ""; + return { + ...option, + subLabel + }; +}).sort((firstOption, secondOption) => { + if (firstOption.subLabel && secondOption.subLabel && firstOption.subLabel.localeCompare(secondOption.subLabel) === 0) { + return firstOption.label.localeCompare(secondOption.label); + } else if (firstOption.subLabel && secondOption.subLabel) { + return firstOption.subLabel.localeCompare(secondOption.subLabel); + } else if (firstOption?.subLabel) { + return -1; + } else if (secondOption?.subLabel) { + return 1; + } else { + return firstOption.label.localeCompare(secondOption.label); + } +}); + +export const getOptions = (options: Option[], filterKey: string) => { + if (filterKey === FilterKeys.PIN_CODE) { + return populateSubLabelsAndSort(options, OptionTypes.LOCALITY); + } + + return options; +} + +export const getKeys = (filterKey: string) => { + if (filterKey === FilterKeys.PIN_CODE) { + return ["label", "subLabel"]; + } + + return ["label"]; +} diff --git a/src/components/screens/allCases/allCasesFilters/types.ts b/src/components/screens/allCases/allCasesFilters/types.ts new file mode 100644 index 00000000..31bda42d --- /dev/null +++ b/src/components/screens/allCases/allCasesFilters/types.ts @@ -0,0 +1,8 @@ +export enum OptionTypes { + COLLECTION_CASE = 'COLLECTION_CASE', + LOCALITY = 'LOCALITY' +} + +export enum FilterKeys { + PIN_CODE = 'PINCODE' +} diff --git a/src/components/utlis/commonFunctions.ts b/src/components/utlis/commonFunctions.ts index 3af01df2..c179e191 100644 --- a/src/components/utlis/commonFunctions.ts +++ b/src/components/utlis/commonFunctions.ts @@ -520,4 +520,8 @@ export const sendDeviceDetailsToClickstream = async () => { }); }; +export const pluralise = (count: number, singularWord: string, pluralWord: string) => { + return count === 1 ? singularWord : pluralWord; +} + export const isFunction = (fn: unknown): fn is (...args: any[]) => void => typeof fn === 'function'; From 2665c2b56b4cd576900e02200fd0205a95d73359 Mon Sep 17 00:00:00 2001 From: Anshuman Rai Date: Tue, 7 May 2024 11:07:38 +0530 Subject: [PATCH 2/3] TP-53768 | Corrected axios version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5d9362a5..8eec0fac 100644 --- a/package.json +++ b/package.json @@ -64,7 +64,7 @@ "appcenter": "^4.4.5", "appcenter-analytics": "^4.4.5", "appcenter-crashes": "^4.4.5", - "axios": "1.2.1", + "axios": "1.6.0", "d3-scale": "4.0.2", "d3-shape": "3.2.0", "dayjs": "1.11.9", From 7bfd1030136de306395b60fd3d6a6c8d2a55b332 Mon Sep 17 00:00:00 2001 From: Anshuman Rai Date: Wed, 8 May 2024 15:14:02 +0530 Subject: [PATCH 3/3] TP-53768 | Increased version --- android/app/build.gradle | 4 ++-- package.json | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index cc69b3ea..391533ef 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -134,8 +134,8 @@ def reactNativeArchitectures() { return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"] } -def VERSION_CODE = 152 -def VERSION_NAME = "2.9.11" +def VERSION_CODE = 153 +def VERSION_NAME = "2.9.12" android { ndkVersion rootProject.ext.ndkVersion diff --git a/package.json b/package.json index 8eec0fac..eda5ce67 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "AV_APP", - "version": "2.9.11", - "buildNumber": "152", + "version": "2.9.12", + "buildNumber": "153", "private": true, "scripts": { "android:dev": "yarn move:dev && react-native run-android",