diff --git a/i18n/en.pot b/i18n/en.pot index fbce2a3d2..7686c57f4 100644 --- a/i18n/en.pot +++ b/i18n/en.pot @@ -5,8 +5,8 @@ msgstr "" "Content-Type: text/plain; charset=utf-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n != 1)\n" -"POT-Creation-Date: 2023-09-06T13:08:55.205Z\n" -"PO-Revision-Date: 2023-09-06T13:08:55.205Z\n" +"POT-Creation-Date: 2023-09-27T14:55:16.411Z\n" +"PO-Revision-Date: 2023-09-27T14:55:16.411Z\n" msgid "Untitled map, {{date}}" msgstr "Untitled map, {{date}}" @@ -802,9 +802,6 @@ msgstr "Previous year" msgid "Next year" msgstr "Next year" -msgid "Relative" -msgstr "Relative" - msgid "Period type" msgstr "Period type" @@ -1202,6 +1199,9 @@ msgstr "Equal counts" msgid "Symbol" msgstr "Symbol" +msgid "Relative" +msgstr "Relative" + msgid "Daily" msgstr "Daily" diff --git a/src/actions/layerEdit.js b/src/actions/layerEdit.js index 80037f548..e6fd006ad 100644 --- a/src/actions/layerEdit.js +++ b/src/actions/layerEdit.js @@ -179,10 +179,10 @@ export const setPeriodName = (periodName) => ({ }) // Set period type (thematic) -export const setPeriodType = (periodType, clearPeriod = true) => ({ +export const setPeriodType = (periodType, keepPeriod) => ({ type: types.LAYER_EDIT_PERIOD_TYPE_SET, periodType, - clearPeriod, + keepPeriod, }) // Set period (event & thematic) diff --git a/src/components/edit/thematic/ThematicDialog.js b/src/components/edit/thematic/ThematicDialog.js index 263c4120f..d074437c0 100644 --- a/src/components/edit/thematic/ThematicDialog.js +++ b/src/components/edit/thematic/ThematicDialog.js @@ -224,7 +224,6 @@ class ThematicDialog extends Component { noDataColor, operand, periodType, - settings, renderingStrategy, startDate, endDate, @@ -420,7 +419,7 @@ class ThematicDialog extends Component { { + const { hiddenPeriods } = useSystemSettings() + + const periodTypes = useMemo( + () => getPeriodTypes(includeRelativePeriods, hiddenPeriods), + [includeRelativePeriods, hiddenPeriods] + ) + + // Set default period type useEffect(() => { - const relativePeriodType = { - id: RELATIVE_PERIODS, - name: i18n.t('Relative'), - } + if (!value) { + const isRelativePeriod = !!( + includeRelativePeriods && + period && + getRelativePeriods().find((p) => p.id === period.id) + ) - if (!value && period) { - if (getRelativePeriods().find((p) => p.id === period.id)) { - // false will not clear the period dropdown - onChange(relativePeriodType, false) + if (!period || isRelativePeriod) { + // default to first period type + onChange(periodTypes[0], isRelativePeriod) } - } else if (!value) { - // set relativePeriods as default - onChange(relativePeriodType) } - }, [value, period, onChange]) + }, [value, period, periodTypes, includeRelativePeriods, onChange]) return ( [ - { - id: RELATIVE_PERIODS, - name: i18n.t('Relative'), - }, +export const periodTypes = (includeRelativePeriods) => [ + ...(includeRelativePeriods + ? [ + { + id: RELATIVE_PERIODS, + name: i18n.t('Relative'), + }, + ] + : []), { id: DAILY, name: i18n.t('Daily'), diff --git a/src/reducers/layerEdit.js b/src/reducers/layerEdit.js index 2549cbb36..f40823e43 100644 --- a/src/reducers/layerEdit.js +++ b/src/reducers/layerEdit.js @@ -107,9 +107,9 @@ const layerEdit = (state = null, action) => { return { ...state, periodType: action.periodType.id, - filters: action.clearPeriod - ? removePeriodFromFilters(state.filters) - : state.filters, + filters: action.keepPeriod + ? state.filters + : removePeriodFromFilters(state.filters), } case types.LAYER_EDIT_PERIOD_SET: diff --git a/src/util/periods.js b/src/util/periods.js index 366633e8a..2fdd0f826 100644 --- a/src/util/periods.js +++ b/src/util/periods.js @@ -6,8 +6,10 @@ import { periodTypes, periodGroups } from '../constants/periods.js' const getYearOffsetFromNow = (year) => year - new Date(Date.now()).getFullYear() -export const getPeriodTypes = (hiddenPeriods = []) => - periodTypes().filter(({ group }) => !hiddenPeriods.includes(group)) +export const getPeriodTypes = (includeRelativePeriods, hiddenPeriods = []) => + periodTypes(includeRelativePeriods).filter( + ({ group }) => !hiddenPeriods.includes(group) + ) export const getFixedPeriodsByType = (periodType, year) => { const period = getFixedPeriodsOptionsById(periodType)