Skip to content

fix(plasma-web,plasma-b2c): Add useResizeObserver and fix behavior with resize in TextArea #1186

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

neretin-trike
Copy link
Contributor

@neretin-trike neretin-trike commented Apr 11, 2022

📦 Published PR as canary version: Canary Versions

✨ Test out this PR locally via:

npm install @sberdevices/demo-canvas-app@0.72.0-canary.1186.5efcc7d7f9e2526d222828be46b19844e1f11d8e.0
npm install @sberdevices/plasma-b2c@1.57.0-canary.1186.5efcc7d7f9e2526d222828be46b19844e1f11d8e.0
npm install @sberdevices/plasma-core@1.56.0-canary.1186.5efcc7d7f9e2526d222828be46b19844e1f11d8e.0
npm install @sberdevices/plasma-icons@1.75.0-canary.1186.5efcc7d7f9e2526d222828be46b19844e1f11d8e.0
npm install @sberdevices/plasma-temple@1.57.0-canary.1186.5efcc7d7f9e2526d222828be46b19844e1f11d8e.0
npm install @sberdevices/plasma-ui@1.95.0-canary.1186.5efcc7d7f9e2526d222828be46b19844e1f11d8e.0
npm install @sberdevices/plasma-web@1.92.0-canary.1186.5efcc7d7f9e2526d222828be46b19844e1f11d8e.0
npm install @sberdevices/plasma-sb-utils@0.55.0-canary.1186.5efcc7d7f9e2526d222828be46b19844e1f11d8e.0
npm install @sberdevices/showcase@0.115.0-canary.1186.5efcc7d7f9e2526d222828be46b19844e1f11d8e.0
npm install @sberdevices/plasma-ui-docs@0.64.0-canary.1186.5efcc7d7f9e2526d222828be46b19844e1f11d8e.0
npm install @sberdevices/plasma-web-docs@0.50.0-canary.1186.5efcc7d7f9e2526d222828be46b19844e1f11d8e.0
npm install @sberdevices/plasma-website@0.47.0-canary.1186.5efcc7d7f9e2526d222828be46b19844e1f11d8e.0
# or 
yarn add @sberdevices/demo-canvas-app@0.72.0-canary.1186.5efcc7d7f9e2526d222828be46b19844e1f11d8e.0
yarn add @sberdevices/plasma-b2c@1.57.0-canary.1186.5efcc7d7f9e2526d222828be46b19844e1f11d8e.0
yarn add @sberdevices/plasma-core@1.56.0-canary.1186.5efcc7d7f9e2526d222828be46b19844e1f11d8e.0
yarn add @sberdevices/plasma-icons@1.75.0-canary.1186.5efcc7d7f9e2526d222828be46b19844e1f11d8e.0
yarn add @sberdevices/plasma-temple@1.57.0-canary.1186.5efcc7d7f9e2526d222828be46b19844e1f11d8e.0
yarn add @sberdevices/plasma-ui@1.95.0-canary.1186.5efcc7d7f9e2526d222828be46b19844e1f11d8e.0
yarn add @sberdevices/plasma-web@1.92.0-canary.1186.5efcc7d7f9e2526d222828be46b19844e1f11d8e.0
yarn add @sberdevices/plasma-sb-utils@0.55.0-canary.1186.5efcc7d7f9e2526d222828be46b19844e1f11d8e.0
yarn add @sberdevices/showcase@0.115.0-canary.1186.5efcc7d7f9e2526d222828be46b19844e1f11d8e.0
yarn add @sberdevices/plasma-ui-docs@0.64.0-canary.1186.5efcc7d7f9e2526d222828be46b19844e1f11d8e.0
yarn add @sberdevices/plasma-web-docs@0.50.0-canary.1186.5efcc7d7f9e2526d222828be46b19844e1f11d8e.0
yarn add @sberdevices/plasma-website@0.47.0-canary.1186.5efcc7d7f9e2526d222828be46b19844e1f11d8e.0

@SberDevices-Eva
Copy link
Collaborator

Demo canvas app deployed!

http://plasma.sberdevices.ru/demo-canvas-app-pr-1186/

@SberDevices-Eva
Copy link
Collaborator

@codecov
Copy link

codecov bot commented Apr 11, 2022

Codecov Report

Merging #1186 (e0216ef) into master (b00a2de) will decrease coverage by 0.12%.
The diff coverage is 68.75%.

@@            Coverage Diff             @@
##           master    #1186      +/-   ##
==========================================
- Coverage   89.04%   88.92%   -0.13%     
==========================================
  Files         451      451              
  Lines        6189     6228      +39     
  Branches     1790     1797       +7     
==========================================
+ Hits         5511     5538      +27     
- Misses        677      689      +12     
  Partials        1        1              
Flag Coverage Δ
plasma-b2c 95.89% <100.00%> (+0.05%) ⬆️
plasma-core 94.39% <100.00%> (+0.02%) ⬆️
plasma-temple 82.08% <53.12%> (-0.28%) ⬇️
plasma-ui 94.55% <ø> (ø)
plasma-web 92.92% <100.00%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...temple/src/components/PlasmaApp/AppStateContext.ts 66.66% <ø> (ø)
packages/plasma-temple/src/store/reducer.ts 76.92% <0.00%> (-10.04%) ⬇️
...asma-temple/src/components/PlasmaApp/PlasmaApp.tsx 84.50% <40.00%> (-12.05%) ⬇️
packages/plasma-temple/src/store/actions.ts 66.66% <50.00%> (-2.57%) ⬇️
.../plasma-temple/src/hooks/useInitializeAssistant.ts 89.65% <80.00%> (-6.00%) ⬇️
...es/plasma-b2c/src/components/TextArea/TextArea.tsx 100.00% <100.00%> (ø)
...ackages/plasma-temple/src/components/Page/Page.tsx 70.73% <100.00%> (+0.73%) ⬆️
...es/plasma-web/src/components/TextArea/TextArea.tsx 100.00% <100.00%> (ø)
packages/plasma-temple/src/hooks/useCharacter.ts 100.00% <0.00%> (+100.00%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6c88c67...e0216ef. Read the comment docs.

@neretin-trike neretin-trike force-pushed the neretinaa/fix-textarea-resize branch from 25105cc to f6d7c80 Compare April 12, 2022 06:49
@SberDevices-Eva
Copy link
Collaborator

Demo canvas app deployed!

http://plasma.sberdevices.ru/demo-canvas-app-pr-1186/

@SberDevices-Eva
Copy link
Collaborator

@neretin-trike neretin-trike force-pushed the neretinaa/fix-textarea-resize branch from f6d7c80 to e0216ef Compare April 12, 2022 08:00
@neretin-trike neretin-trike added B2B/E Plasma Web B2C Plasma B2C Core labels Apr 12, 2022
@SberDevices-Eva
Copy link
Collaborator

Demo canvas app deployed!

http://plasma.sberdevices.ru/demo-canvas-app-pr-1186/

@SberDevices-Eva
Copy link
Collaborator


return () => {
/* istanbul ignore if: убираем проверку на рефы из покрытия */
if (!ref?.current) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

а этот ифак зачем? у тебя же не дойдет сюда если рефа нет

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ага, я тоже так думал, но почему-то ts ругается

Comment on lines +43 to +53
const [width, setWidth] = useState(0);
const ref = useMemo(() => (outerRef && 'current' in outerRef ? outerRef : createRef<HTMLTextAreaElement>()), [
outerRef,
]);

useResizeObserver(ref, (currentElement) => {
const { width: elementWidth } = currentElement.getBoundingClientRect();

setWidth(elementWidth);
});

Copy link
Contributor

@LamaEats LamaEats Apr 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

не хочется это в отдельный хуй отнести? один и тот же код два раза встречается

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

кажется, что пока нет в этом необходимости, т.к. конкретно эти случаи очень специфичны и появляются в двух компонентах.
По-хорошему бы там вообще эти компоненты как-то в Core перетащить вместе с логикой, потому что они сильно похожи, но это уже задача на рефакторинг

) {
const [width, setWidth] = useState(0);
const ref = useMemo(() => (outerRef && 'current' in outerRef ? outerRef : createRef<HTMLTextAreaElement>()), [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

не сломается, если сюда функцию передадут в outerRef?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

не должно, как раз проверкой на 'current' in outerRef я чекаю, штоб это было именно ref объектом

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
B2B/E Plasma Web B2C Plasma B2C Core
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants