-
Notifications
You must be signed in to change notification settings - Fork 149
[front] - refacto: connectors modals #9765
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
Conversation
Automatic code review is enabled for this repository. I will perform a review of this PR. |
…nectorDataUpdatedModal - Transition to using Sheet component to handle the data sync progress interface instead of Modal - Prevent interactions outside Sheet when data sync is in progress to maintain focus on the process - Improve structure and readability of the component by grouping related elements within SheetContainer and SheetContent components
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.
I've reviewed the connector modals refactoring PR. While the overall structure is good, there are a few important issues that need to be addressed:
- There are several bugs in the Sheet component's onOpenChange handlers that could affect modal behavior
- A performance optimization opportunity with useMemo for frequently used calculations
Please address these issues before merging. The bugs in particular could affect user experience.
const canUpdatePermissions = PERMISSIONS_EDITABLE_CONNECTOR_TYPES.has( | ||
connector.type | ||
); | ||
const isDataAvailable = !!connector && !!dataSource; |
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.
Consider extracting the isDataAvailable
check into a useMemo hook since it's used in multiple places and depends on connector and dataSource props that could change:
const isDataAvailable = !!connector && !!dataSource; | |
const isDataAvailable = useMemo(() => !!connector && !!dataSource, [connector, dataSource]); |
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.
( i won't do that - useMemo will be more expensive than redoing the test on every render )
)} | ||
</div> | ||
{OptionsComponent && plan && ( | ||
<Sheet open={modalToShow === "selection"} onOpenChange={onClose}> |
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.
The Sheet's onOpenChange prop is receiving onClose directly, but onClose expects a boolean parameter while onOpenChange provides a boolean. You should wrap it to match the expected signature:
<Sheet open={modalToShow === "selection"} onOpenChange={onClose}> | |
<Sheet open={modalToShow === "selection"} onOpenChange={(open) => onClose(!open)}> |
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.
boolean parameters have not the same semantic, but should probably be : (open) => if (!open) { onClose(false) }
(does it happen that we have onOpenChange called with true) ?
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.
onOpenChange
is actually only called when closing the dialog
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.
it would still be bad to call onClose(true)
(which means close and save) when opening the modal if onOpenChange is ever called with true. so better to be clear on it
, including the Limited Use requirements. | ||
</div> | ||
</div> | ||
<Sheet open={isOpen} onOpenChange={onClose}> |
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.
Similar to the previous comment, the Sheet's onOpenChange prop should be wrapped to match onClose's expected signature:
<Sheet open={isOpen} onOpenChange={onClose}> | |
<Sheet open={isOpen} onOpenChange={(open) => onClose()}> |
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.
maybe (open) => if (!open) { onClose() }
?
<div>Data sync in progress...</div> | ||
</div> | ||
</div> | ||
<Sheet open={isOpen}> |
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.
The Sheet component should have an onOpenChange handler to match the parent's onClose behavior:
<Sheet open={isOpen}> | |
<Sheet open={isOpen} onOpenChange={(open) => !open && onClose()}> |
- Increment the version of @dust-tt/sparkle to incorporate the latest features and fixes - Ensure compatibility with the updated version of the sparkle package in the project dependencies
…irmation - Switch out the Modal component for the new Sheet component layout in CreateConnectionConfirmationModal - Adjust the components and structure inside the modal to fit the Sheet design such as adding SheetContent and SheetHeader components
…ns modal - Replace the use of Modal with Sheet for improved user experience and consistency - Introduce SheetHeader and SheetContent to structure the content within the Sheet - Ensure actions like saving and deletion are still facilitated through updated UI components within SheetContent
- Bump @dust-tt/sparkle version from 0.2.352 to 0.2.355 to include latest features and fixes - Update @dust-tt/client version from 1.0.16 to 1.0.18 to align with current dependencies and improvements
…nvocation - Simplify how ConnectorPermissionsModal is rendered by removing conditional checks - Adjust connector and dataSource to accept null values, allowing for more generic usage [front/components] - fix: add missing padding in ConnectorPermissionsModal - Add horizontal padding to the main container in ConnectorPermissionsModal for better layout consistency [front/components/spaces] - refactor: remove redundant connector check before modal - Remove unnecessary check for connector existence before rendering ConnectorPermissionsModal in SpaceResourcesList [front/lib/swr] - refactor: enhance useConnectorPermissions hook flexibility - Modify useConnectorPermissions hook to handle a null dataSource gracefully - Construct API URL conditionally based on existence of dataSource in useConnectorPermissions hook - Clean up the URL construction process for fetching data source permissions
…component - Deleted RequestOrAddDataFromDataSourceModal component and associated code due to redundancy or migration to new system.
…bust - Handle null values for connector and dataSource props to prevent crashes - Add checks for data availability before rendering components and executing save procedure - Import SheetTitle from "@dust-tt/sparkle" and use it in the SheetHeader to ensure consistency across modals
…t using SheetContainer - Wrap options and content tree in new SheetContainer component for improved structure - Simplify button and header layout within modal for enhanced visual coherence - Remove redundant div elements to streamline modal markup
2d67c44
to
31a78f4
Compare
- Use type-only import for NotificationType to improve code clarity and reduce potential for runtime import issues
…ogic - Removed the state and dialog for showing data connection synchronization from ConnectorPermissionsModal - Adjusted logic handling after data update to close modal without showing the data connection dialog [front/components] - style: update ContentMessage to amber variant in ConnectorDataUpdatedModal - Changed ContentMessage color from 'slate' to 'amber' to presumably enhance visibility or indication status
…omponent - Remove owner prop and Page wrapper to simplify the modal structure - Rework content layout and presentation for clarity - Adjust modal title and instructions for syncing data sources and using space access
const canUpdatePermissions = PERMISSIONS_EDITABLE_CONNECTOR_TYPES.has( | ||
connector.type | ||
); | ||
const isDataAvailable = !!connector && !!dataSource; |
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.
( i won't do that - useMemo will be more expensive than redoing the test on every render )
, including the Limited Use requirements. | ||
</div> | ||
</div> | ||
<Sheet open={isOpen} onOpenChange={onClose}> |
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.
maybe (open) => if (!open) { onClose() }
?
)} | ||
</div> | ||
{OptionsComponent && plan && ( | ||
<Sheet open={modalToShow === "selection"} onOpenChange={onClose}> |
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.
boolean parameters have not the same semantic, but should probably be : (open) => if (!open) { onClose(false) }
(does it happen that we have onOpenChange called with true) ?
front/lib/swr/connectors.ts
Outdated
if (includeParents) { | ||
url += "&includeParents=true"; | ||
let url = ""; | ||
if (dataSource) { |
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.
Shouldn't we set disabled if dataSource is null ? what would happen by calling useSWRWithDefaults with empty url ?
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.
Yeah you're right, I was setting the disable parameter on the function call, but let's move the logic within the hook 👍🏼
/> | ||
</> | ||
)} | ||
<ConnectorPermissionsModal |
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 it really needed to render this if there's no connector/datasource ? it complexifies the code a lot and it seems ConnectorPermissionsModal can't do a lot if we don't have data to display ?
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.
You right, let's not render it here. Good catch thx 🙏🏼
- Ensure ConnectorPermissionsModal is not disabled based on data availability, only on update permission [front/components] - refactor: conditionally render ConnectorPermissionsModal only if dataSource and connector exist - Modify SpaceResourcesList to render ConnectorPermissionsModal only with valid dataSource and connector [front/lib] - fix: correct disable condition in useConnectorPermissions hook - Address an issue in useConnectorPermissions hook by disabling it if dataSource is not present along with existing disabled conditions
…rops and logic - Remove nullability from `connector` and `dataSource` props, assuming they must always be provided - Simplify `canUpdatePermissions` logic by removing redundant data availability checks - Eliminate redundant conditional checks for rendering modals and OptionsComponent within ConnectorPermissionsModal [front/components/spaces] - fix: ensure connector exists before using it in SpaceDataSourceViewContentList - Add a safety check to confirm the presence of `connector` before attempting to use it in the SpaceDataSourceViewContentList component
- Modify `onOpenChange` prop in `Sheet` components to only call `onClose` when closing - Ensure modals 'ConnectorPermissionsModal' and 'CreateConnectionConfirmationModal' only execute onClose when the `Sheet` is being closed
defa747
to
2251c19
Compare
- Remove conditional dataSource check as dataSource is now always provided - Streamline the url assignment process by eliminating unnecessary conditionals
Description
This PR migrates "connector-related" modals to use the new
Sheet
component instead ofModal
. Other than layout changes and adapting the existing code to fit theSheet
API the main difference is that we need to keep theSheet
mounted to observe the closing animation.Note: deleted the
front/components/data_source/RequestOrAddDataFromDataSourceModal.tsx
file as it appeared unused.Risk
Breaking UX
Deploy Plan
front-edge
front