@openmrs/esm-metadataexport-app 4.6.2-pre.1030 → 4.6.2-pre.1032

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -36,10 +36,11 @@ interface SelectDomainItemsModalProps {
36
36
  initiallySelectedItems: Array<MetadataItem>;
37
37
  // Uuids of initially selected items the caller has no details for; those items are uuid placeholders.
38
38
  unresolvedItemUuids?: Array<string>;
39
+ initialTab?: TabName;
39
40
  onApply: (selectedItems: Array<MetadataItem>) => void;
40
41
  }
41
42
 
42
- type TabName = 'all' | 'selected';
43
+ export type TabName = 'all' | 'selected';
43
44
 
44
45
  const pageSizeOptions = [8, 20, 50];
45
46
 
@@ -51,13 +52,14 @@ const SelectDomainItemsModal: React.FC<SelectDomainItemsModalProps> = ({
51
52
  packageFormTitle,
52
53
  initiallySelectedItems,
53
54
  unresolvedItemUuids = noUnresolvedItemUuids,
55
+ initialTab = 'all',
54
56
  onApply,
55
57
  }) => {
56
58
  const { t } = useTranslation();
57
59
  const domainLabel = formatDomainLabel(domain);
58
60
  const lowercaseDomainLabel = domainLabel.toLowerCase();
59
61
 
60
- const [activeTabName, setActiveTabName] = useState<TabName>('all');
62
+ const [activeTabName, setActiveTabName] = useState<TabName>(initialTab);
61
63
  const [searchTerm, setSearchTerm] = useState('');
62
64
  const [includeRetired, setIncludeRetired] = useState(false);
63
65
  const [pageSize, setPageSize] = useState(pageSizeOptions[0]);
@@ -142,8 +144,8 @@ const SelectDomainItemsModal: React.FC<SelectDomainItemsModalProps> = ({
142
144
 
143
145
  const applyButtonLabel =
144
146
  selectedItemCount > 0
145
- ? t('addSelectedItems', 'Add {{count}} selected', { count: selectedItemCount })
146
- : t('exportAllDomainItems', 'Export all {{domain}}', { domain: lowercaseDomainLabel });
147
+ ? t('includeSelectedItems', 'Include {{count}} selected', { count: selectedItemCount })
148
+ : t('includeAllDomainItems', 'Include all {{domain}}', { domain: lowercaseDomainLabel });
147
149
 
148
150
  const renderTabContent = () => {
149
151
  if (isAllTabActive && searchError) {
@@ -161,6 +163,8 @@ const SelectDomainItemsModal: React.FC<SelectDomainItemsModalProps> = ({
161
163
  if (isAllTabActive ? isAllTabLoading : isSelectedTabLoading) {
162
164
  return (
163
165
  <DataTableSkeleton
166
+ // Same row height as the items table, so the skeleton is no taller than the table it stands in for.
167
+ className="cds--data-table--md"
164
168
  role="progressbar"
165
169
  columnCount={1}
166
170
  rowCount={pageSize}
@@ -185,6 +189,7 @@ const SelectDomainItemsModal: React.FC<SelectDomainItemsModalProps> = ({
185
189
  }
186
190
  />
187
191
  <Pagination
192
+ className={styles.pagination}
188
193
  forwardText={t('nextPage', 'Next page')}
189
194
  backwardText={t('previousPage', 'Previous page')}
190
195
  page={activeTab.page}
@@ -237,12 +242,14 @@ const SelectDomainItemsModal: React.FC<SelectDomainItemsModalProps> = ({
237
242
  size="sm"
238
243
  hideLabel
239
244
  labelText={t('includeRetired', 'Include retired')}
245
+ // Retired items that are selected always show on the Selected tab, so the toggle only applies to All.
246
+ disabled={!isAllTabActive}
240
247
  toggled={includeRetired}
241
248
  onToggle={setIncludeRetired}
242
249
  />
243
250
  </div>
244
251
 
245
- {renderTabContent()}
252
+ <div className={styles.tabContent}>{renderTabContent()}</div>
246
253
 
247
254
  <div className={styles.selectionSummary}>
248
255
  <span>
@@ -103,6 +103,18 @@ describe('ViewPackageWorkspace', () => {
103
103
  expect(screen.getByText('Concepts, Encounter types')).toBeInTheDocument();
104
104
  });
105
105
 
106
+ it('says how many items a domain is narrowed to', () => {
107
+ renderWorkspace({
108
+ ...exportPackage,
109
+ entries: [
110
+ { domain: 'ROLES', itemUuids: ['role-1', 'role-2'] },
111
+ { domain: 'ENCOUNTER_TYPES', itemUuids: [] },
112
+ ],
113
+ });
114
+
115
+ expect(screen.getByText('Roles (2 items), Encounter types')).toBeInTheDocument();
116
+ });
117
+
106
118
  it('shows "All domains" when the package has no entries', () => {
107
119
  renderWorkspace({ ...exportPackage, entries: [] });
108
120
 
@@ -18,7 +18,7 @@ import {
18
18
  Workspace2,
19
19
  type Workspace2DefinitionProps,
20
20
  } from '@openmrs/esm-framework';
21
- import { formatDomainLabel } from '../../domain-lookups/domain-lookups.resource';
21
+ import { formatPackageDomains } from '../../domain-lookups/domain-lookups.resource';
22
22
  import { isPackagesCacheKey, triggerBuild, usePackageBuilds } from '../../packages/packages.resource';
23
23
  import type { ExportBuildStatus, ExportPackage } from '../../types';
24
24
  import styles from './view-metadata-package.workspace.scss';
@@ -99,15 +99,7 @@ const ViewMetadataPackageWorkspace: React.FC<Workspace2DefinitionProps<ViewPacka
99
99
  });
100
100
  }, [exportPackage, closeWorkspace]);
101
101
 
102
- const domainsLabel = useMemo(() => {
103
- // An empty entries list means the package includes every registered domain.
104
- const includesEveryDomain = exportPackage.entries.length === 0;
105
- if (includesEveryDomain) {
106
- return t('allDomains', 'All domains');
107
- }
108
-
109
- return exportPackage.entries.map((entry) => formatDomainLabel(entry.domain)).join(', ');
110
- }, [exportPackage.entries, t]);
102
+ const domainsLabel = useMemo(() => formatPackageDomains(exportPackage.entries, t), [exportPackage.entries, t]);
111
103
 
112
104
  // Replace this workspace with the edit form so it doesn't reappear with stale package details
113
105
  const editPackage = useCallback(async () => {
@@ -1,6 +1,7 @@
1
1
  import useSWR from 'swr';
2
+ import type { TFunction } from 'i18next';
2
3
  import { type FetchResponse, openmrsFetch, restBaseUrl } from '@openmrs/esm-framework';
3
- import { type MetadataDomain } from '../types';
4
+ import { type ExportPackageEntry, type MetadataDomain } from '../types';
4
5
 
5
6
  export function useDomains() {
6
7
  const apiUrl = `${restBaseUrl}/metadataexport/domains`;
@@ -31,3 +32,25 @@ export function formatDomainLabel(domain: MetadataDomain): string {
31
32
  const text = domain.replace(/_/g, ' ').trim().toLowerCase();
32
33
  return text.charAt(0).toUpperCase() + text.slice(1);
33
34
  }
35
+
36
+ /**
37
+ * Lists a package's domains for display, such as `Roles (12 items), Encounter types`. A domain narrowed to
38
+ * chosen items says how many, so it doesn't read as the whole domain. An empty list means every domain.
39
+ * The extractor doesn't scan this file, so its translation keys are marked in packages-table.component.tsx.
40
+ */
41
+ export function formatPackageDomains(entries: Array<ExportPackageEntry>, t: TFunction): string {
42
+ if (!entries.length) {
43
+ return t('allDomains', 'All domains');
44
+ }
45
+
46
+ return entries
47
+ .map((entry) =>
48
+ entry.itemUuids?.length
49
+ ? t('domainWithItemCount', '{{domain}} ({{count}} items)', {
50
+ domain: formatDomainLabel(entry.domain),
51
+ count: entry.itemUuids.length,
52
+ })
53
+ : formatDomainLabel(entry.domain),
54
+ )
55
+ .join(', ');
56
+ }
@@ -1,6 +1,4 @@
1
1
  {
2
- "addSelectedItems_one": "Add {{count}} selected",
3
- "addSelectedItems_other": "Add {{count}} selected",
4
2
  "all": "All",
5
3
  "allCount_one": "All ({{count}})",
6
4
  "allCount_other": "All ({{count}})",
@@ -12,6 +10,7 @@
12
10
  "buildTriggerFailed": "Failed to trigger build",
13
11
  "buildVersion": "Build {{version}}",
14
12
  "cancel": "Cancel",
13
+ "chooseDomainItems": "Choose items for {{domain}}",
15
14
  "chooseItems": "Choose items",
16
15
  "clearSelection": "Clear selection",
17
16
  "close": "Close",
@@ -27,15 +26,20 @@
27
26
  "descriptionPlaceholder": "Briefly describe what this package contains",
28
27
  "details": "Details",
29
28
  "domains": "Domains",
29
+ "domainWithItemCount_one": "{{domain}} ({{count}} item)",
30
+ "domainWithItemCount_other": "{{domain}} ({{count}} items)",
30
31
  "download": "Download",
31
32
  "edit": "Edit",
33
+ "editDomainItems": "Edit items for {{domain}}",
32
34
  "editPackage": "Edit package",
33
35
  "errorLoadingDomains": "Error loading domains",
34
36
  "errorLoadingItems": "Error loading {{domain}}",
35
37
  "errorLoadingPackage": "Error loading package",
36
- "exportAllDomainItems": "Export all {{domain}}",
37
38
  "FAILED": "Failed",
39
+ "includeAllDomainItems": "Include all {{domain}}",
38
40
  "includeRetired": "Include retired",
41
+ "includeSelectedItems_one": "Include {{count}} selected",
42
+ "includeSelectedItems_other": "Include {{count}} selected",
39
43
  "itemsSelected_one": "{{count}} selected",
40
44
  "itemsSelected_other": "{{count}} selected",
41
45
  "itemsSelectedOfTotal_one": "{{count}} of {{total}}",