-
Notifications
You must be signed in to change notification settings - Fork 305
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
fix(metadata-sidebar): Fix metadata sidebar ai capabilities #3681
Merged
mergify
merged 5 commits into
box:master
from
jankowiakdawid:fix-metadata-sidebar-ai-capabilities
Oct 7, 2024
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b2d0c00
fix(metadata-sidebar): Check if AI Suggestion are enabled feature
jankowiakdawid 7cc24cb
fix(metadata-sidebar): Fix storybook test
jankowiakdawid 5bf0228
fix(metadata-sidebar): Spread mockFeatures instead of duplication
jankowiakdawid f7fd803
feat(metadata-sidebar): Select only one button as only one is used
jankowiakdawid 9dbe6b7
feat(metadata-sidebar): Add FeatureProvider to test-utils
jankowiakdawid File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,30 @@ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import { render, type RenderOptions } from '@testing-library/react'; | ||
|
||
// Data Providers | ||
import { TooltipProvider } from '@box/blueprint-web'; | ||
import { IntlProvider } from 'react-intl'; | ||
import { AutofillContextProvider } from '@box/metadata-editor'; | ||
import { FeatureProvider } from '../elements/common/feature-checking'; | ||
|
||
jest.unmock('react-intl'); | ||
|
||
const Wrapper = ({ children }) => ( | ||
<AutofillContextProvider isAiSuggestionsFeatureEnabled={false} fetchSuggestions={() => Promise.resolve([])}> | ||
<TooltipProvider> | ||
<IntlProvider locale="en">{children}</IntlProvider> | ||
</TooltipProvider> | ||
const Wrapper = ({ children, features = {}, isAiSuggestionsFeatureEnabled = false, fetchSuggestions = () => Promise.resolve([]) }) => ( | ||
<AutofillContextProvider isAiSuggestionsFeatureEnabled={isAiSuggestionsFeatureEnabled} fetchSuggestions={fetchSuggestions}> | ||
<FeatureProvider features={features}> | ||
<TooltipProvider> | ||
<IntlProvider locale="en">{children}</IntlProvider> | ||
</TooltipProvider> | ||
</FeatureProvider> | ||
</AutofillContextProvider> | ||
); | ||
|
||
const renderConnected = (element, options = {}) => render(element, { wrapper: Wrapper, ...options }); | ||
type RenderConnectedOptions = Omit<RenderOptions, 'wrapper'> & { | ||
wrapperProps?: Record<string, unknown>; | ||
}; | ||
|
||
const renderConnected = (element, options: RenderConnectedOptions = {}) => | ||
render(element, { wrapper: props => <Wrapper {...props} {...options.wrapperProps} />, ...options }); | ||
|
||
export * from '@testing-library/react'; | ||
export { renderConnected as render }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is
isFeatureEnabled
doing whatuseFeatureEnabled
is doing? do we need both?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No I don't think so.
useFeatureEnabled
is checking thefeatures
array. In our case we can check if metadata redesign is enabled, or if metadata aiSuggestions are enabled.isFeatureEnabled
is a prop that comes from host application inmetadataSidebarProps
box-ui-elements/src/elements/content-sidebar/SidebarPanels.js
Line 61 in 549188a
it's defined here
box-ui-elements/src/elements/content-sidebar/MetadataSidebar.js
Lines 43 to 47 in 549188a
maybe @bfoxx1906 or @jstoffan have more insight if it should be used 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Took a look, useFeatureEnabled isn't used anywhere else in BUIE. However, Seems like a use case for components that don't have the features array passed down, so it probably is needed here. Have we tested useFeatureEnabled works as expected here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes,
useFeatureEnabled
works as expected. It's covered with a storybook story test (also in this PR). It was recommended by @jstoffan some time ago.Now after re-reading this I understand initial confusion. As I mentioned
isFeatereEnalbed
is a prop indicating if user has Metadata Sidebar enabled for them.