Skip to content

Commit c375c44

Browse files
fix(user-profile): fixed selected-boxes updating in react (#387)
* fix(user-profile): fixed selected-boxes updating in react * fix(tests): fixed etalons * fix(tests): fixed etalons * chore(etalons): reverted some etalons * chore(tests): updated calendar etalon * chore(tests): updated calendar etalon * chore(tests): updated calendar etalon * chore(tests): updated calendar scheduler etalon * chore(tests): updated tests * chore(tests): updated mask * fix(ProfileCard): fixed react inputs * fix(profileCard): fixed text binding in vue * chore(test): added tests for check inputs focuses on User Profile * chore(tests): updated etalons * chore(tests): removed thumbnamils * fix(ProfilCard): fixed rerender items list in react * chore(tests): update masks * chore(tests): update masks * chore(tests): update etalons * chore(test): added test for selectors * chore(tests): added etalons * chore(tests): fixed etalons * chore(tests): fixed test * chore(test): updated etalons * fix(tests): removed masks * fix(tests): added masks --------- Co-authored-by: sergey-kras <krasnoluckiy280799@icloud.com>
1 parent 8c4814b commit c375c44

File tree

43 files changed

+120
-48
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+120
-48
lines changed

packages/react/src/components/library/profile-card/ProfileCard.tsx

Lines changed: 44 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import './ProfileCard.scss';
2-
import React, { useRef } from 'react';
2+
import React, { useRef, useMemo } from 'react';
33
import { Form, FormRef, Item, Label, ValidationRule as ValidationRuleComponent, FormTypes } from 'devextreme-react/form';
44
import { StatusSelectBox } from '../status-select-box/StatusSelectBox';
55
import { PicturedItemSelectBox } from '../pictured-item-select-box/PicturedItemSelectBox';
@@ -25,6 +25,11 @@ interface ProfileCardProps {
2525
wrapperCssClass?: string;
2626
}
2727

28+
const commonEditorOptions = {
29+
stylingMode: 'filled',
30+
valueChangeEvent: 'input',
31+
};
32+
2833
export const ProfileCard = ({
2934
items = [],
3035
colCount = 2,
@@ -44,12 +49,48 @@ export const ProfileCard = ({
4449
}
4550

4651
if (fieldName) {
47-
cardData[fieldName] = value;
52+
cardData = { ...cardData, [fieldName]: value };
4853
}
4954

5055
onDataChanged(cardData);
5156
};
5257
const onFormFieldChange = (e: FormTypes.FieldDataChangedEvent) => onFieldChange(e.dataField)(e.value);
58+
const itemsWithCommonOptions = useMemo(() => items.map((item) => {
59+
item.editorOptions = { ...commonEditorOptions, ...item.editorOptions };
60+
return item;
61+
}), [items]);
62+
63+
const renderItems = useMemo(() => itemsWithCommonOptions.map((item, index) => (
64+
<Item key={index}
65+
dataField={item.dataField}
66+
editorType={item.editorType}
67+
editorOptions={item.editorOptions}
68+
colSpan={item.colSpan}>
69+
{item.label && <Label text={item.label} />}
70+
{item.validators?.map((rule, index) =>
71+
<ValidationRuleComponent
72+
key={index}
73+
type={rule.type}
74+
/>)
75+
}
76+
{item.dataField === 'status' &&
77+
<StatusSelectBox
78+
labelMode='hidden'
79+
stylingMode='filled'
80+
value={cardData[item.dataField]}
81+
onValueChange={onFieldChange(item.dataField)}
82+
/>
83+
}
84+
{item.dataField === 'supervisor' &&
85+
<PicturedItemSelectBox
86+
label={item.label}
87+
value={cardData[item.dataField]}
88+
items={item.itemsList}
89+
onValueChange={onFieldChange(item.dataField)}
90+
/>
91+
}
92+
</Item>
93+
)), [items, onFieldChange, cardData]);
5394

5495
return (
5596
<div className={wrapperCssClass}>
@@ -69,41 +110,7 @@ export const ProfileCard = ({
69110
labelMode='outside'
70111
onFieldDataChanged={onFormFieldChange}
71112
>
72-
{items.map((item, index) => (
73-
<Item key={index}
74-
dataField={item.dataField}
75-
editorType={item.editorType}
76-
editorOptions={{
77-
stylingMode: 'filled',
78-
valueChangeEvent: 'input',
79-
...item.editorOptions
80-
}}
81-
colSpan={item.colSpan}>
82-
{item.label && <Label text={item.label} />}
83-
{item.validators?.map((rule, index) =>
84-
<ValidationRuleComponent
85-
key={index}
86-
type={rule.type}
87-
/>)
88-
}
89-
{item.dataField === 'status' &&
90-
<StatusSelectBox
91-
labelMode='hidden'
92-
stylingMode='filled'
93-
value={cardData[item.dataField]}
94-
onValueChange={onFieldChange(item.dataField)}
95-
/>
96-
}
97-
{item.dataField === 'supervisor' &&
98-
<PicturedItemSelectBox
99-
label={item.label}
100-
value={cardData[item.dataField]}
101-
items={item.itemsList}
102-
onValueChange={onFieldChange(item.dataField)}
103-
/>
104-
}
105-
</Item>
106-
))}
113+
{renderItems}
107114
</Form>
108115
</div>
109116
</div>

packages/react/src/pages/user-profile/user-profile.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ type UserProfileContentProps = {
4141
contactItems: ProfileCardItem[];
4242
addressItems: ProfileCardItem[];
4343
profileData: Record<string, string>;
44-
handleDataChanged: () => void;
44+
handleDataChanged: (cardData: Record<string, string>) => void;
4545
handleChangePasswordClick: () => void;
4646
handleContentScrolled: (boolean) => void;
4747
};
@@ -173,9 +173,10 @@ export const UserProfile = () => {
173173
const [addressItems, setAddressItems] = useState<ProfileCardItem[]>([]);
174174
const [isContentScrolled, setIsContentScrolled] = useState(false);
175175

176-
const dataChanged = useCallback(() => {
176+
const dataChanged = useCallback((data) => {
177+
setProfileData({ ...profileData, ...data });
177178
setIsDataChanged(true);
178-
}, []);
179+
}, [profileData]);
179180

180181
const changePassword = useCallback(() => {
181182
setIsChangedPasswordPopupOpened(true);
16.8 KB
16.7 KB
16.7 KB
16.5 KB
17.8 KB
1.26 KB
17.7 KB
15.7 KB

0 commit comments

Comments
 (0)