Skip to content

Commit

Permalink
#1461 | WIP: Fix Reset of AppliedFilters
Browse files Browse the repository at this point in the history
conditionally display asOnDate
  • Loading branch information
himeshr committed Aug 1, 2024
1 parent 69deb5a commit a4ef905
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,15 @@ function filterUpdated(context, state) {
function loadCurrentDashboardInfo(context, state) {
const dashboardFilterService = context.get(DashboardFilterService);
state.filtersPresent = dashboardFilterService.areFiltersPresent(state.activeDashboardUUID);
const {selectedFilterValues} = context.get(CustomDashboardService).getDashboardData(state.activeDashboardUUID);
const {selectedFilterValues, dashboardCache} = context.get(CustomDashboardService).getDashboardData(state.activeDashboardUUID);
state.customDashboardFilters = selectedFilterValues;
if (state.activeDashboardUUID) {
state.reportCardSectionMappings = getReportsCards(state.activeDashboardUUID, context);
state.hasFiltersSet = getHasFiltersSet(selectedFilterValues);
state.hasFiltersSet = dashboardCache.filterApplied;
}
return state;
}

function getHasFiltersSet(selectedFilterValues) {
return selectedFilterValues && Object.values(selectedFilterValues).length > 0
&& Object.values(selectedFilterValues).some(sfv => !_.isNil(sfv) && !_.isEmpty(sfv));
}

function getViewName(standardReportCardType) {
switch (true) {
case _.isNil(standardReportCardType) :
Expand Down Expand Up @@ -136,7 +131,6 @@ class CustomDashboardActions {

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

const I18n = context.get(MessageService).getI18n();
Expand Down Expand Up @@ -181,6 +175,8 @@ class CustomDashboardActions {
});
const {dashboardCache} = customDashboardCacheService.getDashboardCache(state.activeDashboardUUID);
newState.resultUpdatedAt = dashboardCache.updatedAt;
newState.hasFiltersSet = dashboardCache.filterApplied

return newState;
}

Expand Down Expand Up @@ -209,9 +205,9 @@ class CustomDashboardActions {
static clearCounts(state, action, context) {
const newState = {...state};
const customDashboardService = context.get(CustomDashboardService);
const {selectedFilterValues} = customDashboardService.getDashboardData(state.activeDashboardUUID);
const {selectedFilterValues, dashboardCache} = customDashboardService.getDashboardData(state.activeDashboardUUID);
newState.customDashboardFilters = selectedFilterValues;
newState.hasFiltersSet = getHasFiltersSet(selectedFilterValues);
newState.hasFiltersSet = dashboardCache.filterApplied;
newState.cardToCountResultMap = {};
return newState;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,25 +96,28 @@ function FilterSection({dispatcher, asOnDateValue, asOnDateFilter, I18n, onFilte
<View>
<View style={CustomDashboardView.styles.itemContent}>
<View style={CustomDashboardView.styles.buttons}>
<View style={{flexDirection: 'row', alignItems: 'center', flexWrap: 'wrap', flex: 0.8}}>
<Text style={{...CustomDashboardView.styles.labelText}}>{I18n.t('asOnDate')}:</Text>
<View style={{
...CustomDashboardView.styles.filterButton,
}}>
<DatePicker overridingStyle={CustomDashboardView.styles.buttonText} nonRemovable={true}
pickTime={false} dateValue={asOnDateValue}
onChange={onAsOnDateChange.bind(this)}/>
</View>
{/*{this.renderQuickDateOptions('Today', new Date(), isToday)}*/}
{/*{this.renderQuickDateOptions('Tomorrow', moment().add(1, "day").toDate(), isTomorrow)}*/}
</View>
<TouchableNativeFeedback onPress={() => onFilterPressed()}>
<View style={{
...CustomDashboardView.styles.filterButton,
}}>
<Text style={CustomDashboardView.styles.buttonText}>{I18n.t('filter')}</Text>
<Text style={CustomDashboardView.styles.filterText}>{I18n.t('filter')}</Text>
</View>
</TouchableNativeFeedback>
{asOnDateFilter && <View style={{
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'flex-start',
flexWrap: 'wrap',
gap: 2,
flex: 0.6
}}>
<Text style={{...CustomDashboardView.styles.labelText}}>{I18n.t('asOnDate')}: </Text>
<DatePicker overridingStyle={CustomDashboardView.styles.buttonText} nonRemovable={true}
pickTime={false} dateValue={asOnDateValue}
onChange={onAsOnDateChange.bind(this)}/>
{/*{this.renderQuickDateOptions('Today', new Date(), isToday)}*/}
{/*{this.renderQuickDateOptions('Tomorrow', moment().add(1, "day").toDate(), isTomorrow)}*/}
</View>}
</View>
</View>
</View>
Expand All @@ -138,7 +141,7 @@ class CustomDashboardView extends AbstractComponent {
marginHorizontal: 5
},
buttons: {
flexDirection: "row",
flexDirection: "row-reverse",
alignItems: "center",
justifyContent: "space-between",
},
Expand All @@ -147,17 +150,21 @@ class CustomDashboardView extends AbstractComponent {
borderRadius: 3,
padding: 5
},
buttonText: {
filterText: {
color: Styles.accentColor,
fontSize: Styles.smallTextSize,
fontWeight: 'bold',
textTransform: 'uppercase',
},
buttonText: {
color: Styles.accentColor,
fontSize: Styles.smallerTextSize,
fontWeight: 'bold',
},
labelText: {
color: Styles.grey,
fontSize: Styles.smallerTextSize,
fontWeight: 'bold',
// textTransform: 'uppercase',
}
});

Expand Down Expand Up @@ -323,9 +330,10 @@ class CustomDashboardView extends AbstractComponent {
const filterConfigs = dashboardFilterService.getFilterConfigsForDashboard(dashboard.uuid);
const asOnDateFilterUUID = _.findKey(filterConfigs, entity => entity.isAsOnDateFilter());
const asOnDateFilter = _.find(filters, ({uuid}) => uuid === asOnDateFilterUUID);
const asOnDateFilterValue = this.state.customDashboardFilters[asOnDateFilterUUID];
const asOnDateFilterValue = (asOnDateFilterUUID && this.state.customDashboardFilters[asOnDateFilterUUID])
? this.state.customDashboardFilters[asOnDateFilterUUID] : new Date();
const filterUUIDsToIgnore = asOnDateFilterUUID ? [asOnDateFilterUUID] : [];

const filterUUIDsToIgnore = [asOnDateFilterUUID];
return (
<CHSContainer style={{
marginBottom: Styles.ContentDistanceFromEdge
Expand Down

0 comments on commit a4ef905

Please sign in to comment.