Skip to content

Commit 15f663e

Browse files
refactor(enums): harmonize enum names (#5970)
BREAKING CHANGE: the `MessageBoxActions` enum has been renamed to `MessageBoxAction` BREAKING CHANGE: the `MessageBoxTypes` enum has been renamed to `MessageBoxType` BREAKING CHANGE: the `Themes` enum has been renamed to `Theme`
1 parent f41d32b commit 15f663e

File tree

13 files changed

+104
-79
lines changed

13 files changed

+104
-79
lines changed

docs/MigrationGuide.mdx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,4 +295,12 @@ function MyComponent() {
295295
}
296296
```
297297

298+
## Enum Changes
299+
300+
For a better alignment with the UI5 Web Components, the following enums have been renamed:
301+
302+
- `MessageBoxActions` has been renamed to `MessageBoxAction`
303+
- `MessageBoxTypes` has been renamed to `MessageBoxType`
304+
- `Themes` has been renamed to `Theme`
305+
298306
<Footer />

packages/cli/src/scripts/codemod/transforms/v2/codemodConfig.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,11 @@
593593
"WizardContentLayout": "@ui5/webcomponents-fiori/dist/types/WizardContentLayout.js",
594594
"WrappingType": "@ui5/webcomponents/dist/types/WrappingType.js"
595595
},
596+
"renamedEnums": {
597+
"MessageBoxActions": "MessageBoxAction",
598+
"MessageBoxTypes": "MessageBoxType",
599+
"Themes": "Theme"
600+
},
596601
"enumProperties": {
597602
"BusyIndicatorSize": {
598603
"Small": "S",

packages/cli/src/scripts/codemod/transforms/v2/main.cts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,21 @@ export default function transform(file: FileInfo, api: API, options?: Options):
396396
}
397397
});
398398

399+
Object.entries<string>(config.renamedEnums).forEach(([enumName, newName]) => {
400+
const currentImportSpecifier = root.find(j.ImportSpecifier, { local: { name: enumName } });
401+
if (currentImportSpecifier.paths().length) {
402+
const importedFrom = currentImportSpecifier.get().parentPath.parentPath.value.source.value;
403+
404+
if (importedFrom === '@ui5/webcomponents-react') {
405+
currentImportSpecifier.replaceWith(j.importSpecifier(j.identifier(newName), j.identifier(newName)));
406+
407+
const currentIdentifier = root.find(j.Identifier, { name: enumName });
408+
currentIdentifier.replaceWith(j.identifier(newName));
409+
isDirty = true;
410+
}
411+
}
412+
});
413+
399414
Object.entries<Record<string, string>>(config.enumProperties).forEach(([changedEnum, changedValues]) => {
400415
Object.entries(changedValues ?? {}).forEach(([oldValue, newValue]) => {
401416
const enumValueToReplace = root

packages/main/src/components/FilterBar/FilterDialog.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import { createPortal } from 'react-dom';
1212
import {
1313
FlexBoxDirection,
1414
FlexBoxJustifyContent,
15-
MessageBoxActions,
16-
MessageBoxTypes,
15+
MessageBoxAction,
16+
MessageBoxType,
1717
ToolbarStyle
1818
} from '../../enums/index.js';
1919
import {
@@ -614,8 +614,8 @@ export const FilterDialog = (props: FilterDialogPropTypes) => {
614614
createPortal(
615615
<MessageBox
616616
open
617-
type={MessageBoxTypes.Warning}
618-
actions={[MessageBoxActions.OK, MessageBoxActions.Cancel]}
617+
type={MessageBoxType.Warning}
618+
actions={[MessageBoxAction.OK, MessageBoxAction.Cancel]}
619619
onClose={handleMessageBoxClose}
620620
data-component-name="FilterBarDialogResetMessageBox"
621621
>

packages/main/src/components/MessageBox/MessageBox.cy.tsx

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import addIcon from '@ui5/webcomponents-icons/dist/add.js';
2-
import { Button, Icon, MessageBoxActions, MessageBoxTypes } from '../..';
2+
import { Button, Icon, MessageBoxAction, MessageBoxType } from '../..';
33
import { MessageBox } from './index.js';
44

55
describe('MessageBox', () => {
66
[
7-
[MessageBoxTypes.Confirm, MessageBoxActions.OK],
8-
[MessageBoxTypes.Success, MessageBoxActions.OK],
9-
[MessageBoxTypes.Warning, MessageBoxActions.OK],
10-
[MessageBoxTypes.Error, MessageBoxActions.Close],
11-
[MessageBoxTypes.Information, MessageBoxActions.OK]
12-
].forEach(([type, buttonText]: [MessageBoxTypes, MessageBoxActions]) => {
7+
[MessageBoxType.Confirm, MessageBoxAction.OK],
8+
[MessageBoxType.Success, MessageBoxAction.OK],
9+
[MessageBoxType.Warning, MessageBoxAction.OK],
10+
[MessageBoxType.Error, MessageBoxAction.Close],
11+
[MessageBoxType.Information, MessageBoxAction.OK]
12+
].forEach(([type, buttonText]: [MessageBoxType, MessageBoxAction]) => {
1313
it(type, () => {
1414
const callback = cy.spy();
1515
cy.mount(
@@ -37,12 +37,12 @@ describe('MessageBox', () => {
3737
open
3838
onClose={close}
3939
actions={[
40-
MessageBoxActions.Cancel,
40+
MessageBoxAction.Cancel,
4141
<Button onClick={click} key="0">
4242
Custom
4343
</Button>,
4444
'Custom Text Action',
45-
MessageBoxActions.OK
45+
MessageBoxAction.OK
4646
]}
4747
>
4848
My Message Box Content
@@ -70,7 +70,7 @@ describe('MessageBox', () => {
7070
it('Confirm - Cancel', () => {
7171
const callback = cy.spy().as('onMessageBoxClose');
7272
cy.mount(
73-
<MessageBox type={MessageBoxTypes.Confirm} open onClose={callback}>
73+
<MessageBox type={MessageBoxType.Confirm} open onClose={callback}>
7474
Confirm
7575
</MessageBox>
7676
);
@@ -82,7 +82,7 @@ describe('MessageBox', () => {
8282
'have.been.calledWith',
8383
Cypress.sinon.match({
8484
detail: {
85-
action: MessageBoxActions.Cancel
85+
action: MessageBoxAction.Cancel
8686
}
8787
})
8888
);
@@ -91,7 +91,7 @@ describe('MessageBox', () => {
9191
it('Show', () => {
9292
const callback = cy.spy().as('onMessageBoxClose');
9393
cy.mount(
94-
<MessageBox open onClose={callback} titleText="Custom" actions={[MessageBoxActions.Yes, MessageBoxActions.No]}>
94+
<MessageBox open onClose={callback} titleText="Custom" actions={[MessageBoxAction.Yes, MessageBoxAction.No]}>
9595
Custom
9696
</MessageBox>
9797
);
@@ -103,7 +103,7 @@ describe('MessageBox', () => {
103103
'have.been.calledWith',
104104
Cypress.sinon.match({
105105
detail: {
106-
action: MessageBoxActions.Yes
106+
action: MessageBoxAction.Yes
107107
}
108108
})
109109
);
@@ -115,7 +115,7 @@ describe('MessageBox', () => {
115115
'have.been.calledWith',
116116
Cypress.sinon.match({
117117
detail: {
118-
action: MessageBoxActions.No
118+
action: MessageBoxAction.No
119119
}
120120
})
121121
);
@@ -125,7 +125,7 @@ describe('MessageBox', () => {
125125
const callback = cy.spy().as('onMessageBoxClose');
126126
cy.mount(
127127
<MessageBox
128-
type={MessageBoxTypes.Success}
128+
type={MessageBoxType.Success}
129129
open
130130
onClose={callback}
131131
titleText="Custom Success"
@@ -142,7 +142,7 @@ describe('MessageBox', () => {
142142
'have.been.calledWith',
143143
Cypress.sinon.match({
144144
detail: {
145-
action: MessageBoxActions.OK
145+
action: MessageBoxAction.OK
146146
}
147147
})
148148
);
@@ -164,22 +164,22 @@ describe('MessageBox', () => {
164164
cy.mount(
165165
<MessageBox
166166
open
167-
type={MessageBoxTypes.Confirm}
168-
actions={[MessageBoxActions.OK, 'My Custom Action']}
167+
type={MessageBoxType.Confirm}
168+
actions={[MessageBoxAction.OK, 'My Custom Action']}
169169
onClose={callback}
170170
>
171171
My Message Box Content
172172
</MessageBox>
173173
);
174174

175-
cy.findByText(MessageBoxActions.OK).should('be.visible').click();
175+
cy.findByText(MessageBoxAction.OK).should('be.visible').click();
176176
cy.get('@onMessageBoxClose')
177177
.should('have.been.calledOnce')
178178
.should(
179179
'have.been.calledWith',
180180
Cypress.sinon.match({
181181
detail: {
182-
action: MessageBoxActions.OK
182+
action: MessageBoxAction.OK
183183
}
184184
})
185185
);
@@ -209,7 +209,7 @@ describe('MessageBox', () => {
209209

210210
it('initial focus', () => {
211211
cy.mount(
212-
<MessageBox open type={MessageBoxTypes.Confirm} initialFocus={MessageBoxActions.Cancel} data-testid="Dialog">
212+
<MessageBox open type={MessageBoxType.Confirm} initialFocus={MessageBoxAction.Cancel} data-testid="Dialog">
213213
Content
214214
</MessageBox>
215215
);

packages/main/src/components/MessageBox/MessageBox.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ const MessageBoxComponent = () => {
5353
setOpen(true);
5454
};
5555
const handleClose = (event) => {
56-
if (event.detail.action === MessageBoxActions.OK) {
56+
if (event.detail.action === MessageBoxAction.OK) {
5757
// do something on "Ok" button click
5858
} else if (event.detail.action === 'Custom Action') {
5959
// do something on "Custom Action" click
@@ -68,7 +68,7 @@ const MessageBoxComponent = () => {
6868
<MessageBox
6969
open={open}
7070
onClose={handleClose}
71-
actions={[MessageBoxActions.OK, 'Custom Action', MessageBoxActions.Cancel, MessageBoxActions.Abort]}
71+
actions={[MessageBoxAction.OK, 'Custom Action', MessageBoxAction.Cancel, MessageBoxAction.Abort]}
7272
>
7373
Content
7474
</MessageBox>

packages/main/src/components/MessageBox/MessageBox.stories.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { isChromatic } from '@sb/utils';
22
import type { Meta, StoryObj } from '@storybook/react';
33
import { forwardRef, useEffect, useState } from 'react';
44
import { createPortal } from 'react-dom';
5-
import { MessageBoxActions } from '../../enums/MessageBoxActions';
6-
import { MessageBoxTypes } from '../../enums/MessageBoxTypes';
5+
import { MessageBoxAction } from '../../enums/MessageBoxAction';
6+
import { MessageBoxType } from '../../enums/MessageBoxType';
77
import type { DialogDomRef } from '../../webComponents';
88
import { Button } from '../../webComponents/Button/index';
99
import type { MessageBoxPropTypes } from './index.js';
@@ -31,7 +31,7 @@ const meta = {
3131
},
3232
args: {
3333
open: false,
34-
type: MessageBoxTypes.Confirm,
34+
type: MessageBoxType.Confirm,
3535
children: 'Press "Escape" to close the MessageBox.'
3636
},
3737
parameters: {
@@ -68,9 +68,9 @@ export const Default: Story = {
6868
export const WithCustomActions: Story = {
6969
args: {
7070
actions: [
71-
MessageBoxActions.OK,
71+
MessageBoxAction.OK,
7272
'Custom Action',
73-
MessageBoxActions.Cancel,
73+
MessageBoxAction.Cancel,
7474
<Button key="0" id="custom-action">
7575
Custom Button
7676
</Button>

0 commit comments

Comments
 (0)