@openmrs/esm-metadataexport-app 4.5.1-pre.959 → 4.6.1-pre.968

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.
@@ -168,6 +168,24 @@ describe('PackagesTable', () => {
168
168
  expect(mockLaunchViewPackageWorkspace).toHaveBeenCalledTimes(2);
169
169
  });
170
170
 
171
+ it('renders the columns in the order name, description, domains, status', () => {
172
+ mockUsePackages.mockReturnValue({
173
+ packages: [builtPackage],
174
+ totalCount: 1,
175
+ currentPage: 1,
176
+ currentPageSize: 10,
177
+ goTo: vi.fn(),
178
+ isLoading: false,
179
+ isValidating: false,
180
+ error: undefined,
181
+ mutate: vi.fn(),
182
+ });
183
+ render(<PackagesTable />);
184
+
185
+ const columnHeaders = screen.getAllByRole('columnheader').map((header) => header.textContent);
186
+ expect(columnHeaders.slice(0, 4)).toEqual(['Package name', 'Description', 'Domains', 'Status']);
187
+ });
188
+
171
189
  // 25 packages across pages of 10 gives three pages, so both Next and the page-size selector are active.
172
190
  const firstPageOfMany = Array.from({ length: 10 }, (_, index) => ({
173
191
  ...unbuiltPackage,
@@ -6,6 +6,7 @@
6
6
  display: flex;
7
7
  flex-direction: column;
8
8
  height: 100%;
9
+ justify-content: space-between;
9
10
  }
10
11
 
11
12
  .body {
@@ -23,28 +24,37 @@
23
24
  gap: layout.$spacing-04;
24
25
  }
25
26
 
26
- .actionRow {
27
+ .sectionHeader {
27
28
  display: flex;
28
- flex-direction: column;
29
- gap: layout.$spacing-04;
29
+ justify-content: space-between;
30
+ align-items: center;
30
31
  }
31
32
 
32
- .triggerButton {
33
- width: 100%;
34
- max-width: none;
35
- justify-content: center;
33
+ .managementActions {
34
+ display: flex;
35
+ gap: layout.$spacing-02;
36
36
  }
37
37
 
38
- .secondaryActions {
38
+ .managementActions .deleteButton:not(:disabled) svg {
39
+ fill: $danger;
40
+ }
41
+
42
+ .desktopButtonSet {
39
43
  display: flex;
40
- flex-direction: row;
41
- gap: layout.$spacing-04;
44
+ flex-shrink: 0;
45
+ }
46
+
47
+ .tabletButtonSet {
48
+ display: flex;
49
+ flex-shrink: 0;
50
+ flex-direction: row-reverse;
42
51
  }
43
52
 
44
- .secondaryButton {
45
- flex: 1 1 0;
46
- max-width: none;
47
- justify-content: center;
53
+ .desktopButtonSet > .button,
54
+ .tabletButtonSet > .button {
55
+ flex: 1;
56
+ max-inline-size: none;
57
+ height: layout.$spacing-10;
48
58
  }
49
59
 
50
60
  .sectionLabel {
@@ -110,8 +120,33 @@
110
120
  margin: 0;
111
121
  }
112
122
 
113
- .emptyBuilds {
123
+ .emptyBuildsContainer {
124
+ display: flex;
125
+ flex-direction: column;
126
+ align-items: center;
127
+ gap: layout.$spacing-03;
128
+ padding: layout.$spacing-07 layout.$spacing-05;
129
+ border: 1px solid $ui-03;
130
+ text-align: center;
131
+ }
132
+
133
+ .emptyBuildsAction {
134
+ margin-top: layout.$spacing-04;
135
+ }
136
+
137
+ .emptyBuildsIcon {
138
+ fill: $text-02;
139
+ }
140
+
141
+ .emptyBuildsTitle {
142
+ @include type.type-style('heading-compact-02');
143
+ color: $ui-05;
144
+ margin: 0;
145
+ }
146
+
147
+ .emptyBuildsDescription {
114
148
  @include type.type-style('body-compact-01');
115
149
  color: $text-02;
116
150
  margin: 0;
151
+ max-inline-size: 20rem;
117
152
  }
@@ -126,7 +126,7 @@ describe('ViewPackageWorkspace', () => {
126
126
  it('shows an empty message when there are no builds', () => {
127
127
  renderWorkspace();
128
128
 
129
- expect(screen.getByText('No builds yet')).toBeInTheDocument();
129
+ expect(screen.getByText('No builds created yet')).toBeInTheDocument();
130
130
  });
131
131
 
132
132
  it('renders each build with its version, status, and download link', () => {
@@ -312,6 +312,52 @@ describe('ViewPackageWorkspace', () => {
312
312
  );
313
313
  });
314
314
 
315
+ it('shows the trigger build action inside the empty builds section when there are no builds', () => {
316
+ renderWorkspace();
317
+
318
+ expect(screen.getByText('No builds created yet')).toBeInTheDocument();
319
+ expect(
320
+ screen.getByText('Build files allow you to export your metadata package for deployment.'),
321
+ ).toBeInTheDocument();
322
+ expect(screen.getAllByRole('button', { name: 'Trigger new build' })).toHaveLength(1);
323
+ expect(screen.queryByRole('button', { name: 'Close' })).not.toBeInTheDocument();
324
+ });
325
+
326
+ it('shows the close and trigger build actions in the footer once builds exist', () => {
327
+ mockBuilds({ builds: [build()] });
328
+ renderWorkspace();
329
+
330
+ expect(screen.queryByText('No builds created yet')).not.toBeInTheDocument();
331
+ expect(screen.getAllByRole('button', { name: 'Trigger new build' })).toHaveLength(1);
332
+ expect(screen.getByRole('button', { name: 'Close' })).toBeInTheDocument();
333
+ });
334
+
335
+ it('closes the workspace when Close is clicked', async () => {
336
+ const user = userEvent.setup();
337
+ mockBuilds({ builds: [build()] });
338
+ renderWorkspace();
339
+
340
+ await user.click(screen.getByRole('button', { name: 'Close' }));
341
+
342
+ expect(mockCloseWorkspace).toHaveBeenCalled();
343
+ });
344
+
345
+ it('does not show the trigger build action while builds are loading', () => {
346
+ mockBuilds({ isLoading: true });
347
+ renderWorkspace();
348
+
349
+ expect(screen.queryByRole('button', { name: 'Trigger new build' })).not.toBeInTheDocument();
350
+ });
351
+
352
+ it('hides the edit, delete, and trigger build actions from users without the manage privilege', () => {
353
+ mockUserHasAccess.mockReturnValue(false);
354
+ renderWorkspace();
355
+
356
+ expect(screen.queryByRole('button', { name: 'Edit' })).not.toBeInTheDocument();
357
+ expect(screen.queryByRole('button', { name: 'Delete' })).not.toBeInTheDocument();
358
+ expect(screen.queryByRole('button', { name: 'Trigger new build' })).not.toBeInTheDocument();
359
+ });
360
+
315
361
  it('launches a modal name that is registered in routes.json', async () => {
316
362
  const user = userEvent.setup();
317
363
  renderWorkspace();
@@ -1,7 +1,7 @@
1
1
  import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
2
2
  import { useTranslation } from 'react-i18next';
3
- import { Download } from '@carbon/react/icons';
4
- import { Button, InlineLoading, Link, Tag } from '@carbon/react';
3
+ import { Download, Edit, Package, TrashCan } from '@carbon/react/icons';
4
+ import { Button, ButtonSet, IconButton, InlineLoading, Link, Tag } from '@carbon/react';
5
5
  import { useSWRConfig } from 'swr';
6
6
  import {
7
7
  ErrorState,
@@ -11,6 +11,7 @@ import {
11
11
  restBaseUrl,
12
12
  showModal,
13
13
  showSnackbar,
14
+ useLayoutType,
14
15
  useSession,
15
16
  userHasAccess,
16
17
  Workspace2,
@@ -40,6 +41,7 @@ const ViewMetadataPackageWorkspace: React.FC<Workspace2DefinitionProps<ViewPacka
40
41
  const { exportPackage } = workspaceProps;
41
42
  const { t } = useTranslation();
42
43
  const session = useSession();
44
+ const isTablet = useLayoutType() === 'tablet';
43
45
  const { mutate: globalMutate } = useSWRConfig();
44
46
  const { builds, isLoading, error, mutate: mutateBuilds } = usePackageBuilds(exportPackage.uuid);
45
47
 
@@ -113,47 +115,47 @@ const ViewMetadataPackageWorkspace: React.FC<Workspace2DefinitionProps<ViewPacka
113
115
  }
114
116
  }, [closeWorkspace, exportPackage.uuid]);
115
117
 
118
+ const hasNoBuilds = !isLoading && !error && builds.length === 0;
119
+
120
+ const triggerBuildLabel = isTriggeringBuild ? (
121
+ <InlineLoading description={t('triggeringBuild', 'Triggering build') + '…'} />
122
+ ) : (
123
+ t('triggerNewBuild', 'Trigger new build')
124
+ );
125
+
116
126
  return (
117
127
  <Workspace2 title={exportPackage.name}>
118
128
  <div className={styles.container}>
119
129
  <div className={styles.body}>
120
- {canManage && (
121
- <section className={styles.actionRow}>
122
- <Button
123
- className={styles.triggerButton}
124
- kind="primary"
125
- onClick={handleTriggerBuild}
126
- disabled={isTriggeringBuild}
127
- >
128
- {isTriggeringBuild ? (
129
- <InlineLoading description={t('triggeringBuild', 'Triggering build') + '…'} />
130
- ) : (
131
- t('triggerNewBuild', 'Trigger new build')
132
- )}
133
- </Button>
134
- <div className={styles.secondaryActions}>
135
- <Button
136
- className={styles.secondaryButton}
137
- kind="secondary"
138
- onClick={editPackage}
139
- disabled={isTriggeringBuild}
140
- >
141
- {t('edit', 'Edit')}
142
- </Button>
143
- <Button
144
- className={styles.secondaryButton}
145
- kind="danger--tertiary"
146
- onClick={launchDeleteModal}
147
- disabled={isTriggeringBuild}
148
- >
149
- {t('delete', 'Delete')}
150
- </Button>
151
- </div>
152
- </section>
153
- )}
154
-
155
130
  <section className={styles.section}>
156
- <span className={styles.sectionLabel}>{t('details', 'Details')}</span>
131
+ <div className={styles.sectionHeader}>
132
+ <span className={styles.sectionLabel}>{t('details', 'Details')}</span>
133
+ {canManage && (
134
+ <div className={styles.managementActions}>
135
+ <IconButton
136
+ kind="ghost"
137
+ size="sm"
138
+ align="bottom"
139
+ label={t('edit', 'Edit')}
140
+ onClick={editPackage}
141
+ disabled={isTriggeringBuild}
142
+ >
143
+ <Edit size={16} />
144
+ </IconButton>
145
+ <IconButton
146
+ className={styles.deleteButton}
147
+ kind="ghost"
148
+ size="sm"
149
+ align="bottom-end"
150
+ label={t('delete', 'Delete')}
151
+ onClick={launchDeleteModal}
152
+ disabled={isTriggeringBuild}
153
+ >
154
+ <TrashCan size={16} />
155
+ </IconButton>
156
+ </div>
157
+ )}
158
+ </div>
157
159
  <dl className={styles.detailList}>
158
160
  <dt className={styles.detailKey}>{t('domains', 'Domains')}</dt>
159
161
  <dd className={styles.detailValue}>{domainsLabel}</dd>
@@ -166,8 +168,25 @@ const ViewMetadataPackageWorkspace: React.FC<Workspace2DefinitionProps<ViewPacka
166
168
  <InlineLoading description={t('loadingBuilds', 'Loading builds…')} />
167
169
  ) : error ? (
168
170
  <ErrorState error={error} headerTitle={t('builds', 'Builds')} />
169
- ) : builds.length === 0 ? (
170
- <p className={styles.emptyBuilds}>{t('noBuildsYet', 'No builds yet')}</p>
171
+ ) : hasNoBuilds ? (
172
+ <div className={styles.emptyBuildsContainer}>
173
+ <Package size={32} className={styles.emptyBuildsIcon} />
174
+ <p className={styles.emptyBuildsTitle}>{t('noBuildsYet', 'No builds created yet')}</p>
175
+ <p className={styles.emptyBuildsDescription}>
176
+ {t('noBuildsDescription', 'Build files allow you to export your metadata package for deployment.')}
177
+ </p>
178
+ {canManage && (
179
+ <Button
180
+ className={styles.emptyBuildsAction}
181
+ kind="primary"
182
+ size="md"
183
+ onClick={handleTriggerBuild}
184
+ disabled={isTriggeringBuild}
185
+ >
186
+ {triggerBuildLabel}
187
+ </Button>
188
+ )}
189
+ </div>
171
190
  ) : (
172
191
  <ul className={styles.buildList}>
173
192
  {builds.map((build) => (
@@ -211,6 +230,17 @@ const ViewMetadataPackageWorkspace: React.FC<Workspace2DefinitionProps<ViewPacka
211
230
  )}
212
231
  </section>
213
232
  </div>
233
+
234
+ {canManage && !isLoading && !hasNoBuilds && (
235
+ <ButtonSet className={isTablet ? styles.tabletButtonSet : styles.desktopButtonSet}>
236
+ <Button className={styles.button} kind="secondary" onClick={() => closeWorkspace()}>
237
+ {t('close', 'Close')}
238
+ </Button>
239
+ <Button className={styles.button} kind="primary" onClick={handleTriggerBuild} disabled={isTriggeringBuild}>
240
+ {triggerBuildLabel}
241
+ </Button>
242
+ </ButtonSet>
243
+ )}
214
244
  </div>
215
245
  </Workspace2>
216
246
  );
@@ -6,6 +6,7 @@
6
6
  "buildTriggerFailed": "Failed to trigger build",
7
7
  "buildVersion": "Build {{version}}",
8
8
  "cancel": "Cancel",
9
+ "close": "Close",
9
10
  "COMPLETED": "Completed",
10
11
  "completedAgo": "Completed {{time}} ago",
11
12
  "createPackage": "Create package",
@@ -31,7 +32,8 @@
31
32
  "newPackage": "New package",
32
33
  "nextPage": "Next page",
33
34
  "noBuilds": "No builds",
34
- "noBuildsYet": "No builds yet",
35
+ "noBuildsDescription": "Build files allow you to export your metadata package for deployment.",
36
+ "noBuildsYet": "No builds created yet",
35
37
  "notStarted": "Not started",
36
38
  "packageCreated": "Package created",
37
39
  "packageCreatedSubtitle": "{{name}} was created successfully",