Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add patch style for oui fixed components #203

Merged
merged 10 commits into from
Jun 7, 2024

Conversation

raintygao
Copy link
Collaborator

@raintygao raintygao commented Jun 6, 2024

Description

There are some UI components from library whose position is fixed and are not compatible with each other and also not compatible with sidecar container. Meanwhile, there is currently no way to provide config for these components at runtime.
This PR adds a hook to patch a style for all these already known components to make them compatible with sidecar.
Will consider to support config provider in OUI and refer this PR later.

ScreenShot

image
image
image

Before: the left or right property of flyout is always to be 0. The content width of bottomBar is always be 100%.

image
image
image

This still needs a PR in OSD to update sidecar z-index. opensearch-project/OpenSearch-Dashboards#6964
After: the left or right property of flyout will be updated accordingly. The bottomBar will be added paddingRight or paddingLeft style accordingly.

Check List

  • New functionality includes testing.
    • All tests pass, including unit test, integration test.
  • New functionality has user manual doc added.
  • Commits are signed per the DCO using --signoff.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

updateHeadStyle(config, textRef.current);
});
return () => {
subscription.unsubscribe();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shall we remove appended style after unmount?

Signed-off-by: tygao <[email protected]>
Signed-off-by: tygao <[email protected]>
Signed-off-by: tygao <[email protected]>
Signed-off-by: tygao <[email protected]>
@ruanyl
Copy link
Member

ruanyl commented Jun 7, 2024

@raintygao Can you also add a screenshot in the description to better show what is the problem?

Copy link

codecov bot commented Jun 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.22%. Comparing base (3991de2) to head (40ea8ed).
Report is 7 commits behind head on main.

Current head 40ea8ed differs from pull request most recent head 62496a9

Please upload reports for the commit 62496a9 to get more accurate results.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #203      +/-   ##
==========================================
+ Coverage   90.02%   90.22%   +0.20%     
==========================================
  Files          54       58       +4     
  Lines        1433     1545     +112     
  Branches      347      373      +26     
==========================================
+ Hits         1290     1394     +104     
- Misses        141      149       +8     
  Partials        2        2              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@raintygao
Copy link
Collaborator Author

@raintygao Can you also add a screenshot in the description to better show what is the problem?

Sure. Updated.

@@ -52,6 +53,7 @@ export const HeaderChatButton = (props: HeaderChatButtonProps) => {
const core = useCore();
const flyoutFullScreen = sidecarDockedMode === SIDECAR_DOCKED_MODE.TAKEOVER;
const flyoutMountPoint = useRef(null);
usePatchFixedStyle();
Copy link
Member

@SuZhou-Joe SuZhou-Joe Jun 7, 2024

Choose a reason for hiding this comment

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

I am thinking, the patched style should apply only when the chatbot is visible right? In current implementation, it will always patch the style to global even if the Chatbot is not mounted, which I think is not clean enough.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Patchstyle contains the logic that when chatbot is closed or docked takeover. When in these cases, we will update a empty style to remove patch style.

Copy link
Member

Choose a reason for hiding this comment

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

I see, so the sidecarConfig$ will emit a null value once the Chatbot is not visible?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sidecar config will emit a new value with isHidden property is true.Then we will update inserted style with ""

@raintygao
Copy link
Collaborator Author

A PR in OSD that is related.cc @ruanyl @SuZhou-Joe opensearch-project/OpenSearch-Dashboards#6964

Comment on lines +85 to +87
requestAnimationFrame(() => {
text.textContent = css;
});
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
requestAnimationFrame(() => {
text.textContent = css;
});
requestAnimationFrame(() => {
if (config?.isHidden) { text.textContent = ''; return ; }
text.textContent = css;
});

Nit: I'd suggest explicitly making the textContent as empty.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think here takeover dockedMode also takes the same effect as isHidden, should we also explicitly append?

@raintygao raintygao added the backport 2.x Trigger the backport flow to 2.x label Jun 7, 2024
@raintygao raintygao merged commit 702f77e into opensearch-project:main Jun 7, 2024
11 checks passed
opensearch-trigger-bot bot pushed a commit that referenced this pull request Jun 7, 2024
* add patch style for oui fixed components

Signed-off-by: tygao <[email protected]>

* add remove child

Signed-off-by: tygao <[email protected]>

* doc: update changelog

Signed-off-by: tygao <[email protected]>

* update test mock

Signed-off-by: tygao <[email protected]>

* add test for hook

Signed-off-by: tygao <[email protected]>

* remove useRef

Signed-off-by: tygao <[email protected]>

* use mock requestAnimationFrame to replace delay

Signed-off-by: tygao <[email protected]>

* add test case for hook unmount

Signed-off-by: tygao <[email protected]>

* update code structure

Signed-off-by: tygao <[email protected]>

---------

Signed-off-by: tygao <[email protected]>
(cherry picked from commit 702f77e)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

# Conflicts:
#	CHANGELOG.md
raintygao pushed a commit that referenced this pull request Jun 7, 2024
* add patch style for oui fixed components

Signed-off-by: tygao <[email protected]>

* add remove child

Signed-off-by: tygao <[email protected]>

* doc: update changelog

Signed-off-by: tygao <[email protected]>

* update test mock

Signed-off-by: tygao <[email protected]>

* add test for hook

Signed-off-by: tygao <[email protected]>

* remove useRef

Signed-off-by: tygao <[email protected]>

* use mock requestAnimationFrame to replace delay

Signed-off-by: tygao <[email protected]>

* add test case for hook unmount

Signed-off-by: tygao <[email protected]>

* update code structure

Signed-off-by: tygao <[email protected]>

---------

Signed-off-by: tygao <[email protected]>
(cherry picked from commit 702f77e)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

# Conflicts:
#	CHANGELOG.md

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 2.x Trigger the backport flow to 2.x v2.15.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants