Skip to content

Commit

Permalink
#1463 - get the chosen filter values from the cache. UI fixes. Applie…
Browse files Browse the repository at this point in the history
…d filter values display based on new model.
  • Loading branch information
petmongrels committed Jul 18, 2024
1 parent fe4fa6d commit 4343d07
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 144 deletions.
14 changes: 7 additions & 7 deletions packages/openchs-android/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/openchs-android/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"lodash": "4.17.21",
"moment": "2.29.4",
"native-base": "3.4.9",
"openchs-models": "1.31.95",
"openchs-models": "1.31.96",
"jshashes": "1.0.8",
"prop-types": "15.8.1",
"react": "18.2.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,23 @@ function getReportsCards(dashboardUUID, context) {
return context.get(DashboardSectionCardMappingService).getAllCardsForDashboard(dashboardUUID);
}

function loadCurrentDashboardInfo(context, newState) {
function filterUpdated(context, state) {
const customDashboardCacheService = context.get(CustomDashboardCacheService);
customDashboardCacheService.clearResults(state.activeDashboardUUID);
return state;
}

function loadCurrentDashboardInfo(context, state) {
const dashboardFilterService = context.get(DashboardFilterService);
const filterConfigs = dashboardFilterService.getFilterConfigsForDashboard(newState.activeDashboardUUID);
newState.filtersPresent = _.keys(filterConfigs).length > 0;
newState.customDashboardFilters = dashboardFilterService.getFilters(newState.activeDashboardUUID);
if (newState.activeDashboardUUID) {
newState.reportCardSectionMappings = getReportsCards(newState.activeDashboardUUID, context);
newState.hasFilters = dashboardFilterService.hasFilters(newState.activeDashboardUUID);
const filterConfigs = dashboardFilterService.getFilterConfigsForDashboard(state.activeDashboardUUID);
state.filtersPresent = _.keys(filterConfigs).length > 0;
const {selectedFilterValues} = context.get(CustomDashboardService).getDashboardData(state.activeDashboardUUID);
state.customDashboardFilters = selectedFilterValues;
if (state.activeDashboardUUID) {
state.reportCardSectionMappings = getReportsCards(state.activeDashboardUUID, context);
state.hasFilters = dashboardFilterService.hasFilters(state.activeDashboardUUID);
}
return newState;
return state;
}

function getViewName(standardReportCardType) {
Expand Down Expand Up @@ -106,31 +113,29 @@ class CustomDashboardActions {
}

static setFilterApplied(state, action, context) {
const customDashboardCacheService = context.get(CustomDashboardCacheService);
customDashboardCacheService.clearResults(state.activeDashboardUUID);
return state;
return filterUpdated(context, state);
}

static setFilterCleared(state, action, context) {
const customDashboardCacheService = context.get(CustomDashboardCacheService);
customDashboardCacheService.clearResults(state.activeDashboardUUID);
return state;
return filterUpdated(context, state);
}

// loads the dashboard report cards data
static refreshCount(state, action, context) {
const customDashboardService = context.get(CustomDashboardService);
const customDashboardCacheService = context.get(CustomDashboardCacheService);

const userInfoService = context.get(UserInfoService);
const reportCardService = context.get(ReportCardService);

const newState = {...state};

const {selectedFilterValues} = customDashboardService.getDashboardData(state.activeDashboardUUID);
newState.customDashboardFilters = selectedFilterValues;
const userSettings = userInfoService.getUserSettingsObject();

const I18n = context.get(MessageService).getI18n();
const reportCardSectionMappings = state.reportCardSectionMappings;
const newState = {...state};


newState.cardToCountResultMap = {};

Expand Down Expand Up @@ -179,12 +184,6 @@ class CustomDashboardActions {
return newState;
}

static setCustomDashboardFilters(state, action, context) {
const newState = {...state};
newState.customDashboardFilters = action.filterApplied ? action.customDashboardFilters : [];
return newState;
}

static disableAutoRefreshValueUpdated(state, action, context) {
if (!action.disabled) {
const customDashboardService = context.get(CustomDashboardService);
Expand Down Expand Up @@ -229,7 +228,6 @@ const CustomDashboardActionNames = {
ON_CARD_PRESS: `${ActionPrefix}.ON_CARD_PRESS`,
LOAD_INDICATOR: `${ActionPrefix}.LOAD_INDICATOR`,
REFRESH_COUNT: `${ActionPrefix}.REFRESH_COUNT`,
SET_DASHBOARD_FILTERS: `${ActionPrefix}.SET_DASHBOARD_FILTERS`,
FILTER_APPLIED: `${ActionPrefix}.FILTER_APPLIED`,
FILTER_CLEARED: `${ActionPrefix}.FILTER_CLEARED`,
DISABLE_AUTO_REFRESH_VALUE_UPDATED: `${ActionPrefix}.DISABLE_AUTO_REFRESH_VALUE_UPDATED`,
Expand All @@ -243,7 +241,6 @@ const CustomDashboardActionMap = new Map([
[CustomDashboardActionNames.ON_CARD_PRESS, CustomDashboardActions.onCardPress],
[CustomDashboardActionNames.LOAD_INDICATOR, CustomDashboardActions.loadIndicator],
[CustomDashboardActionNames.REFRESH_COUNT, CustomDashboardActions.refreshCount],
[CustomDashboardActionNames.SET_DASHBOARD_FILTERS, CustomDashboardActions.setCustomDashboardFilters],
[CustomDashboardActionNames.FILTER_APPLIED, CustomDashboardActions.setFilterApplied],
[CustomDashboardActionNames.FILTER_CLEARED, CustomDashboardActions.setFilterCleared],
[CustomDashboardActionNames.DISABLE_AUTO_REFRESH_VALUE_UPDATED, CustomDashboardActions.disableAutoRefreshValueUpdated],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class DashboardFilterService extends BaseService {
} else {
const addressLevelService = this.getService(AddressLevelService);
const addressFilterValues = [...filterValue];
const descendants = addressLevelService.getAllDescendants(filterValue.selectedAddresses);
const descendants = addressLevelService.getAllDescendants(filterValue);
dashboardReportFilter.filterValue = addressFilterValues.concat(descendants
.map(addressLevel => _.pick(addressLevel, ['uuid', 'name', 'level', 'type', 'parentUuid'])));
General.logDebug('DashboardFilterService', `Effective address filters: ${JSON.stringify(_.countBy(dashboardReportFilter.filterValue, "type"))}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function RefreshSection({I18n, onRefreshPressed, lastUpdatedOn}) {
</TouchableNativeFeedback>;
}

function SubHeader({I18n, onFilterPressed}) {
function FilterSection({I18n, onFilterPressed}) {
const filterLabelStyle = {
color: Styles.grey,
fontSize: Styles.normalTextSize,
Expand Down Expand Up @@ -263,14 +263,16 @@ class CustomDashboardView extends AbstractComponent {
onFilterChosen: (ruleInputArray) => performCustomDashboardActionAndClearRefresh(this, Actions.FILTER_APPLIED, {
ruleInput: {ruleInputArray: ruleInputArray},
filterApplied: true
}),
loadFiltersData: (filters) => this.dispatchAction(Actions.SET_DASHBOARD_FILTERS, {customDashboardFilters: filters, filterApplied: true}),
})
}).to(FiltersViewV2, true);
}

render() {
const settings = this.getService(UserInfoService).getUserSettingsObject();
General.logDebug("CustomDashboardView", "render");

const settings = this.getService(UserInfoService).getUserSettingsObject();
const dashboard = this.state.dashboards.find((x) => x.uuid === this.state.activeDashboardUUID);

const {hideBackButton, startSync, renderSync, icon, customDashboardType, onSearch, showSearch} = this.props;
const title = this.props.title || 'dashboards';
const {hasFilters, loading} = this.state;
Expand All @@ -287,41 +289,36 @@ class CustomDashboardView extends AbstractComponent {
renderSearch={showSearch}
onSearch={onSearch}
/>
<Line/>
{(_.isNil(customDashboardType) || customDashboardType === CustomDashboardType.None) &&
<SafeAreaView style={{height: 50}}>
<ScrollView horizontal style={{backgroundColor: Colors.cardBackgroundColor}}>
{this.renderDashboards()}
{this.renderZeroResultsMessageIfNeeded()}
</ScrollView>
</SafeAreaView>}
<View style={{display: "flex", flexDirection: "row", flex: 1, justifyContent: "space-between"}}>
<View style={{flex: 0.65}}>
{settings.autoRefreshDisabled && !_.isNil(this.state.resultUpdatedAt) &&
<RefreshSection I18n={this.I18n}
onRefreshPressed={() => performCustomDashboardActionAndClearRefresh(this, Actions.FORCE_REFRESH)}
lastUpdatedOn={this.state.resultUpdatedAt}/>}
<ScrollView>
<Line/>
{(_.isNil(customDashboardType) || customDashboardType === CustomDashboardType.None) &&
<SafeAreaView style={{height: 50}}>
<ScrollView horizontal style={{backgroundColor: Colors.cardBackgroundColor}}>
{this.renderDashboards()}
{this.renderZeroResultsMessageIfNeeded()}
</ScrollView>
</SafeAreaView>}
<View style={{display: "flex", flexDirection: "row", flex: 1, justifyContent: "space-between"}}>
<View style={{flex: 0.65}}>
{settings.autoRefreshDisabled && !_.isNil(this.state.resultUpdatedAt) &&
<RefreshSection I18n={this.I18n}
onRefreshPressed={() => performCustomDashboardActionAndClearRefresh(this, Actions.FORCE_REFRESH)}
lastUpdatedOn={this.state.resultUpdatedAt}/>}
</View>
{this.state.filtersPresent && <FilterSection I18n={this.I18n} onFilterPressed={() => this.onFilterPressed()}/>}
</View>
{this.state.filtersPresent && <SubHeader I18n={this.I18n} onFilterPressed={() => this.onFilterPressed()}/>}
</View>
<Fragment>
<CustomActivityIndicator loading={loading}/>

{hasFilters && <View style={{display: "flex", padding: 10}}>
<SafeAreaView style={{maxHeight: 160}}>
<ScrollView style={this.state.customDashboardFilters.applied && CustomDashboardView.styles.itemContent}>
<AppliedFiltersV2 dashboardUUID={this.state.activeDashboardUUID}
postClearAction={() => this.onClearFilters()}
applied={this.state.customDashboardFilters.applied}
selectedLocations={this.state.customDashboardFilters.selectedLocations}
selectedCustomFilters={this.state.customDashboardFilters.selectedCustomFilters}
selectedGenders={this.state.customDashboardFilters.selectedGenders}/>
</ScrollView>
<SafeAreaView>
<AppliedFiltersV2 dashboardUUID={this.state.activeDashboardUUID}
postClearAction={() => this.onClearFilters()}
dashboard={dashboard}
selectedFilterValues={this.state.customDashboardFilters}/>
</SafeAreaView>
</View>}
<CustomActivityIndicator loading={loading}/>
<ScrollView>
{this.renderCards()}
</ScrollView>
</Fragment>
{this.renderCards()}
</ScrollView>
</CHSContainer>
);
}
Expand Down
Loading

0 comments on commit 4343d07

Please sign in to comment.