Skip to content

Commit 67e2744

Browse files
Fix after review
1 parent de2afa8 commit 67e2744

File tree

2 files changed

+53
-47
lines changed

2 files changed

+53
-47
lines changed

packages/devextreme/js/__internal/scheduler/appointment_popup/m_customize_form_items.ts

Lines changed: 28 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@ import type {
33
FormItemComponent,
44
GroupItem,
55
Item as FormItem,
6-
TabbedItem,
76
} from '@js/ui/form';
87

98
type ConfigItem = string | FormItem;
109

1110
const isGroupItem = (item: FormItem): item is GroupItem => 'items' in item && !('tabs' in item);
12-
const isTabbedItem = (item: FormItem): item is TabbedItem => 'tabs' in item;
1311

1412
const createFormItemFromConfig = (configItem: ConfigItem): FormItem => (
1513
typeof configItem === 'string'
@@ -19,14 +17,9 @@ const createFormItemFromConfig = (configItem: ConfigItem): FormItem => (
1917
name: configItem,
2018
dataField: configItem,
2119
}
22-
: { ...configItem }
20+
: configItem
2321
);
2422

25-
const getChildren = (item: FormItem): FormItem[] => [
26-
...isGroupItem(item) ? item.items ?? [] : [],
27-
...isTabbedItem(item) ? item.tabs?.flatMap((tab) => tab.items ?? []) ?? [] : [],
28-
];
29-
3023
const buildFormItemsMap = (
3124
items: FormItem[],
3225
map: Map<string, FormItem> = new Map(),
@@ -35,7 +28,7 @@ const buildFormItemsMap = (
3528
if (item.name) {
3629
accumulator.set(item.name, { ...item });
3730
}
38-
return buildFormItemsMap(getChildren(item), accumulator);
31+
return buildFormItemsMap(isGroupItem(item) ? item.items ?? [] : [], accumulator);
3932
},
4033
map,
4134
);
@@ -51,29 +44,14 @@ const removeItemFromGroups = (
5144
});
5245
};
5346

54-
const getItemName = (configure: ConfigItem): string | undefined => (
55-
typeof configure === 'string' ? configure : configure.name
47+
const getItemName = (customItem: ConfigItem): string | undefined => (
48+
typeof customItem === 'string' ? customItem : customItem.name
5649
);
5750

58-
const shouldMergeWithExisting = (configure: ConfigItem): configure is FormItem => typeof configure === 'object';
59-
60-
const hasChildItems = (configure: ConfigItem): configure is GroupItem => typeof configure === 'object'
61-
&& isGroupItem(configure) && Boolean(configure.items);
62-
63-
const baseResolveItem = (map: Map<string, FormItem>) => (configure: ConfigItem): FormItem => {
64-
const itemName = getItemName(configure);
65-
const existingItem = itemName ? map.get(itemName) : undefined;
66-
67-
if (!existingItem || !itemName) {
68-
return createFormItemFromConfig(configure);
69-
}
70-
71-
removeItemFromGroups(itemName, map);
51+
const shouldMergeWithExisting = (customItems: ConfigItem): customItems is FormItem => typeof customItems === 'object';
7252

73-
return shouldMergeWithExisting(configure)
74-
? extend(true, {}, existingItem, configure) as FormItem
75-
: existingItem;
76-
};
53+
const hasChildItems = (customItems: ConfigItem): customItems is GroupItem => typeof customItems === 'object'
54+
&& isGroupItem(customItems) && Boolean(customItems.items);
7755

7856
const customizeFormItems = (
7957
items: FormItem[],
@@ -83,14 +61,29 @@ const customizeFormItems = (
8361
return items;
8462
}
8563

86-
const map = buildFormItemsMap(items);
87-
const resolveItem = baseResolveItem(map);
64+
const defaultItemsMap = buildFormItemsMap(items);
65+
66+
const resolveItem = (customItems: ConfigItem): FormItem => {
67+
const itemName = getItemName(customItems);
68+
const defaultItem = itemName ? defaultItemsMap.get(itemName) : undefined;
69+
70+
if (defaultItem && itemName) {
71+
removeItemFromGroups(itemName, defaultItemsMap);
72+
73+
return shouldMergeWithExisting(customItems)
74+
? extend(true, {}, defaultItem, customItems) as FormItem
75+
: defaultItem;
76+
}
77+
78+
return createFormItemFromConfig(customItems);
79+
};
8880

89-
const customize = (config: ConfigItem[]): FormItem[] => config.map((configure): FormItem => {
90-
const formItem = resolveItem(configure);
81+
const customize = (userItems: ConfigItem[]):
82+
FormItem[] => userItems.map((customItems): FormItem => {
83+
const formItem = resolveItem(customItems);
9184

92-
if (isGroupItem(formItem) && hasChildItems(configure) && configure.items) {
93-
return { ...formItem, items: customize(configure.items) };
85+
if (isGroupItem(formItem) && hasChildItems(customItems) && customItems.items) {
86+
return { ...formItem, items: customize(customItems.items) };
9487
}
9588

9689
return formItem;

packages/devextreme/js/__internal/scheduler/appointment_popup/m_form.ts

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,25 @@ const DATE_GROUP_NAME = 'dateGroup';
105105
const START_DATE_GROUP_NAME = 'startDateGroup';
106106
const END_DATE_GROUP_NAME = 'endDateGroup';
107107
const RESOURCES_GROUP_NAME = 'resourcesGroup';
108+
const SUBJECT_GROUP_NAME = 'subjectGroup';
109+
const REPEAT_GROUP_NAME = 'repeatGroup';
110+
const DESCRIPTION_GROUP_NAME = 'descriptionGroup';
108111

109112
const START_DATE_EDITOR_NAME = 'startDate';
110113
const START_TIME_EDITOR_NAME = 'startTime';
111114
const END_DATE_EDITOR_NAME = 'endDate';
112115
const END_TIME_EDITOR_NAME = 'endTime';
113116
const REPEAT_EDITOR_NAME = 'repeat';
117+
const ALL_DAY_EDITOR_NAME = 'allDay';
118+
const SUBJECT_EDITOR_NAME = 'subject';
119+
const DESCRIPTION_EDITOR_NAME = 'description';
120+
const START_DATE_TIMEZONE_EDITOR_NAME = 'startDateTimeZone';
121+
const END_DATE_TIMEZONE_EDITOR_NAME = 'endDateTimeZone';
122+
123+
const SUBJECT_ICON_NAME = 'subjectIcon';
124+
const DATE_ICON_NAME = 'dateIcon';
125+
const REPEAT_ICON_NAME = 'repeatIcon';
126+
const DESCRIPTION_ICON_NAME = 'descriptionIcon';
114127

115128
export class AppointmentForm {
116129
private readonly scheduler: any;
@@ -286,7 +299,7 @@ export class AppointmentForm {
286299
const { textExpr } = this.scheduler.getDataAccessors().expr;
287300

288301
return {
289-
name: 'subjectGroup',
302+
name: SUBJECT_GROUP_NAME,
290303
itemType: 'group',
291304
cssClass: `${CLASSES.subjectGroup} ${CLASSES.groupWithIcon}`,
292305
colCount: 2,
@@ -295,13 +308,13 @@ export class AppointmentForm {
295308
},
296309
items: [
297310
{
298-
name: 'subjectIcon',
311+
name: SUBJECT_ICON_NAME,
299312
colSpan: 1,
300313
cssClass: CLASSES.formIcon,
301314
template: createFormIconTemplate('isnotblank'),
302315
},
303316
{
304-
name: 'subject',
317+
name: SUBJECT_EDITOR_NAME,
305318
colSpan: 1,
306319
itemType: 'simple',
307320
cssClass: CLASSES.textEditor,
@@ -326,7 +339,7 @@ export class AppointmentForm {
326339
},
327340
items: [
328341
{
329-
name: 'dateIcon',
342+
name: DATE_ICON_NAME,
330343
colSpan: 1,
331344
cssClass: CLASSES.formIcon,
332345
template: createFormIconTemplate('clock'),
@@ -348,7 +361,7 @@ export class AppointmentForm {
348361
const { allDayExpr, startDateExpr, endDateExpr } = this.scheduler.getDataAccessors().expr;
349362

350363
return {
351-
name: 'allDay',
364+
name: ALL_DAY_EDITOR_NAME,
352365
itemType: 'simple',
353366
dataField: allDayExpr,
354367
cssClass: CLASSES.allDaySwitch,
@@ -407,7 +420,7 @@ export class AppointmentForm {
407420
cssClass: CLASSES.startTimeEditor,
408421
},
409422
{
410-
name: 'startDateTimeZone',
423+
name: START_DATE_TIMEZONE_EDITOR_NAME,
411424
dataField: startDateTimeZoneExpr,
412425
cssClass: CLASSES.startDateTimeZoneEditor,
413426
editorOptions: {
@@ -442,7 +455,7 @@ export class AppointmentForm {
442455
cssClass: CLASSES.endTimeEditor,
443456
},
444457
{
445-
name: 'endDateTimeZone',
458+
name: END_DATE_TIMEZONE_EDITOR_NAME,
446459
dataField: endDateTimeZoneExpr,
447460
cssClass: CLASSES.endDateTimeZoneEditor,
448461
},
@@ -580,7 +593,7 @@ export class AppointmentForm {
580593

581594
private createRepeatGroup(): GroupItem {
582595
return {
583-
name: 'repeatGroup',
596+
name: REPEAT_GROUP_NAME,
584597
itemType: 'group',
585598
colCount: 2,
586599
colCountByScreen: {
@@ -589,7 +602,7 @@ export class AppointmentForm {
589602
cssClass: `${CLASSES.repeatGroup} ${CLASSES.groupWithIcon}`,
590603
items: [
591604
{
592-
name: 'repeatIcon',
605+
name: REPEAT_ICON_NAME,
593606
colSpan: 1,
594607
cssClass: CLASSES.formIcon,
595608
template: createFormIconTemplate('repeat'),
@@ -626,7 +639,7 @@ export class AppointmentForm {
626639

627640
private createDescriptionGroup(): GroupItem {
628641
return {
629-
name: 'descriptionGroup',
642+
name: DESCRIPTION_GROUP_NAME,
630643
itemType: 'group',
631644
colCount: 2,
632645
colCountByScreen: {
@@ -635,13 +648,13 @@ export class AppointmentForm {
635648
cssClass: `${CLASSES.descriptionGroup} ${CLASSES.groupWithIcon}`,
636649
items: [
637650
{
638-
name: 'descriptionIcon',
651+
name: DESCRIPTION_ICON_NAME,
639652
colSpan: 1,
640653
cssClass: CLASSES.formIcon,
641654
template: createFormIconTemplate('description'),
642655
},
643656
{
644-
name: 'description',
657+
name: DESCRIPTION_EDITOR_NAME,
645658
colSpan: 1,
646659
itemType: 'simple',
647660
cssClass: CLASSES.descriptionEditor,

0 commit comments

Comments
 (0)