From 573ca7334d17b8b323835f1dffd9f25b370d3a39 Mon Sep 17 00:00:00 2001 From: henrikmv Date: Mon, 10 Feb 2025 15:42:06 +0100 Subject: [PATCH] fix: feature available check --- i18n/en.pot | 14 +- .../featuresSupport/support.js | 2 + .../common/Changelog/Changelog.component.js | 4 + .../common/Changelog/Changelog.container.js | 4 + .../common/Changelog/Changelog.types.js | 1 + .../ChangelogTable/ChangelogTableHeader.js | 139 +++++++++++------- 6 files changed, 100 insertions(+), 64 deletions(-) diff --git a/i18n/en.pot b/i18n/en.pot index f867cc6a84..8f16276ecf 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: 2025-02-06T15:05:36.774Z\n" -"PO-Revision-Date: 2025-02-06T15:05:36.774Z\n" +"POT-Creation-Date: 2025-02-10T14:42:07.458Z\n" +"PO-Revision-Date: 2025-02-10T14:42:07.458Z\n" msgid "Choose one or more dates..." msgstr "Choose one or more dates..." @@ -1587,18 +1587,18 @@ msgstr "Created" msgid "Deleted" msgstr "Deleted" -msgid "Sort by date" -msgstr "Sort by date" - msgid "Date" msgstr "Date" -msgid "Sort by username" -msgstr "Sort by username" +msgid "Sort by date" +msgstr "Sort by date" msgid "User" msgstr "User" +msgid "Sort by username" +msgstr "Sort by username" + msgid "Sort by data item" msgstr "Sort by data item" diff --git a/src/core_modules/capture-core-utils/featuresSupport/support.js b/src/core_modules/capture-core-utils/featuresSupport/support.js index fdba5604de..111b9af378 100644 --- a/src/core_modules/capture-core-utils/featuresSupport/support.js +++ b/src/core_modules/capture-core-utils/featuresSupport/support.js @@ -6,6 +6,7 @@ export const FEATURES = Object.freeze({ newTransferQueryParam: 'newTransferQueryParam', exportablePayload: 'exportablePayload', changelogs: 'changelogs', + changelogsV2: 'changelogsV2', trackerImageEndpoint: 'trackerImageEndpoint', trackerFileEndpoint: 'trackerFileEndpoint', trackedEntitiesCSV: 'trackedEntitiesCSV', @@ -25,6 +26,7 @@ const MINOR_VERSION_SUPPORT = Object.freeze({ [FEATURES.trackerFileEndpoint]: 41, [FEATURES.newTransferQueryParam]: 41, [FEATURES.changelogs]: 41, + [FEATURES.changelogsV2]: 42, [FEATURES.trackedEntitiesCSV]: 40, [FEATURES.newUIDsSeparator]: 41, [FEATURES.newEntityFilterQueryParam]: 41, diff --git a/src/core_modules/capture-core/components/WidgetsChangelog/common/Changelog/Changelog.component.js b/src/core_modules/capture-core/components/WidgetsChangelog/common/Changelog/Changelog.component.js index 47344026e9..ed22384204 100644 --- a/src/core_modules/capture-core/components/WidgetsChangelog/common/Changelog/Changelog.component.js +++ b/src/core_modules/capture-core/components/WidgetsChangelog/common/Changelog/Changelog.component.js @@ -28,6 +28,7 @@ export const ChangelogComponent = ({ setColumnToSortBy, attributeToFilterBy, setAttributeToFilterBy, + supportsChangelogV2, entityType, filterValue, setFilterValue, @@ -45,6 +46,7 @@ export const ChangelogComponent = ({ > {i18n.t('Changelog')} + {supportsChangelogV2 && ( + )} {records && records.length > 0 ? ( diff --git a/src/core_modules/capture-core/components/WidgetsChangelog/common/Changelog/Changelog.container.js b/src/core_modules/capture-core/components/WidgetsChangelog/common/Changelog/Changelog.container.js index 28a27313ea..bef01207e3 100644 --- a/src/core_modules/capture-core/components/WidgetsChangelog/common/Changelog/Changelog.container.js +++ b/src/core_modules/capture-core/components/WidgetsChangelog/common/Changelog/Changelog.container.js @@ -1,6 +1,7 @@ // @flow import React from 'react'; import { Modal } from '@dhis2/ui'; +import { FEATURES, featureAvailable } from 'capture-core-utils'; import { useChangelogData, useListDataValues } from '../hooks'; import { ChangelogComponent } from './Changelog.component'; import { CHANGELOG_ENTITY_TYPES } from './Changelog.constants'; @@ -66,6 +67,8 @@ export const Changelog = ({ ); } + + const supportsChangelogV2 = featureAvailable(FEATURES.changelogsV2); return ( ); }; diff --git a/src/core_modules/capture-core/components/WidgetsChangelog/common/Changelog/Changelog.types.js b/src/core_modules/capture-core/components/WidgetsChangelog/common/Changelog/Changelog.types.js index ce4cbc3d6e..7e5130a168 100644 --- a/src/core_modules/capture-core/components/WidgetsChangelog/common/Changelog/Changelog.types.js +++ b/src/core_modules/capture-core/components/WidgetsChangelog/common/Changelog/Changelog.types.js @@ -77,4 +77,5 @@ export type ChangelogProps = { setFilterValue: (any) => void, dataItemDefinitions: ItemDefinitions, entityType: $Values, + supportsChangelogV2: boolean, }; diff --git a/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogTableHeader.js b/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogTableHeader.js index 6937cad1c2..cc3227ef19 100644 --- a/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogTableHeader.js +++ b/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogTableHeader.js @@ -1,8 +1,16 @@ // @flow import React from 'react'; import i18n from '@dhis2/d2-i18n'; -import { DataTableColumnHeader, DataTableHead, DataTableRow } from '@dhis2/ui'; -import { SORT_DIRECTIONS, SORT_TARGETS, CHANGELOG_ENTITY_TYPES } from '../Changelog/Changelog.constants'; +import { + DataTableColumnHeader, + DataTableHead, + DataTableRow, +} from '@dhis2/ui'; +import { + SORT_DIRECTIONS, + SORT_TARGETS, + CHANGELOG_ENTITY_TYPES, +} from '../Changelog/Changelog.constants'; import type { SortDirection } from '../Changelog/Changelog.types'; type Props = { @@ -11,8 +19,17 @@ type Props = { setSortDirection: (SortDirection) => void, setColumnToSortBy: (column: string) => void, entityType: $Values, + supportsChangelogV2: boolean, }; +type ColumnConfig = {| + label: string, + width: string, + isSortable: boolean, + name?: string, + sortIconTitle?: string, +|}; + const getCurrentSortDirection = ( columnName: string, currentColumn: string, @@ -26,6 +43,7 @@ export const ChangelogTableHeader = ({ setSortDirection, setColumnToSortBy, entityType, + supportsChangelogV2, }: Props) => { const handleSortIconClick = ({ name, direction }) => { setSortDirection(direction); @@ -36,64 +54,71 @@ export const ChangelogTableHeader = ({ ? SORT_TARGETS.ATTRIBUTE : SORT_TARGETS.DATA_ITEM; + const columns: Array = [ + { + name: SORT_TARGETS.DATE, + label: i18n.t('Date'), + sortIconTitle: i18n.t('Sort by date'), + width: '140px', + isSortable: true, + }, + { + name: SORT_TARGETS.USERNAME, + label: i18n.t('User'), + sortIconTitle: i18n.t('Sort by username'), + width: '125px', + isSortable: supportsChangelogV2, + }, + { + name: sortTargetDataItem, + label: i18n.t('Data item'), + sortIconTitle: i18n.t('Sort by data item'), + width: '125px', + isSortable: supportsChangelogV2, + }, + { + label: i18n.t('Change'), + width: '85px', + isSortable: false, + }, + { + label: i18n.t('Value'), + width: '275px', + isSortable: false, + }, + ]; + return ( - - {i18n.t('Date')} - - - - {i18n.t('User')} - - - - {i18n.t('Data item')} - - - - {i18n.t('Change')} - - - - {i18n.t('Value')} - + {columns.map(({ + name, + label, + sortIconTitle, + width, + isSortable, + }) => ( + + {label} + + ))} );