-
Notifications
You must be signed in to change notification settings - Fork 19
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
DESENG-675 Make widget component "reusable" #2579
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
24 changes: 24 additions & 0 deletions
24
met-api/migrations/versions/c2a384ddfe6a_add_widget_location.py
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
"""Add locations to widgets | ||
|
||
Revision ID: c2a384ddfe6a | ||
Revises: 901a6724bca2 | ||
Create Date: 2024-08-21 16:04:25.726651 | ||
|
||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = 'c2a384ddfe6a' | ||
down_revision = '901a6724bca2' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
op.add_column('widget', sa.Column('location', sa.Integer(), nullable=True)) | ||
|
||
|
||
def downgrade(): | ||
op.drop_column('widget', 'location') |
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
83 changes: 83 additions & 0 deletions
83
met-web/src/components/engagement/admin/create/widgets/WidgetPickerButton.tsx
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 | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,83 @@ | ||||||||
import React, { useContext, useEffect } from 'react'; | ||||||||
import { WidgetDrawerContext } from 'components/engagement/form/EngagementWidgets/WidgetDrawerContext'; | ||||||||
import { Grid, Skeleton } from '@mui/material'; | ||||||||
import { If, Else, Then } from 'react-if'; | ||||||||
import { useAppDispatch } from 'hooks'; | ||||||||
import { colors } from 'styles/Theme'; | ||||||||
import { WidgetCardSwitch } from 'components/engagement/form/EngagementWidgets/WidgetCardSwitch'; | ||||||||
import { openNotificationModal } from 'services/notificationModalService/notificationModalSlice'; | ||||||||
import { WidgetLocation } from 'models/widget'; | ||||||||
|
||||||||
export const WidgetPickerButton = ({ location }: { location: WidgetLocation }) => { | ||||||||
const { widgets, deleteWidget, handleWidgetDrawerOpen, isWidgetsLoading, setWidgetLocation } = | ||||||||
useContext(WidgetDrawerContext); | ||||||||
const dispatch = useAppDispatch(); | ||||||||
|
||||||||
useEffect(() => { | ||||||||
setWidgetLocation(location); | ||||||||
return () => setWidgetLocation(0); | ||||||||
}, []); | ||||||||
|
||||||||
const removeWidget = (widgetId: number) => { | ||||||||
dispatch( | ||||||||
openNotificationModal({ | ||||||||
open: true, | ||||||||
data: { | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
style: 'warning', | ||||||||
header: 'Remove Widget', | ||||||||
subText: [ | ||||||||
{ text: 'You will be removing this widget from the engagement.' }, | ||||||||
{ text: 'Do you want to remove this widget?' }, | ||||||||
], | ||||||||
handleConfirm: () => { | ||||||||
deleteWidget(widgetId); | ||||||||
}, | ||||||||
}, | ||||||||
type: 'confirm', | ||||||||
}), | ||||||||
); | ||||||||
}; | ||||||||
|
||||||||
return ( | ||||||||
<Grid container spacing={2} direction="column"> | ||||||||
<If condition={isWidgetsLoading}> | ||||||||
<Then> | ||||||||
<Grid item xs={12}> | ||||||||
<Skeleton width="100%" height="3em" /> | ||||||||
</Grid> | ||||||||
</Then> | ||||||||
<Else> | ||||||||
<Grid item> | ||||||||
{/* Only ever render the first selected widget. This may change in the future. */} | ||||||||
{widgets.length > 0 ? ( | ||||||||
<WidgetCardSwitch | ||||||||
singleSelection={true} | ||||||||
key={`${widgets[0].widget_type_id}`} | ||||||||
widget={widgets[0]} | ||||||||
removeWidget={removeWidget} | ||||||||
/> | ||||||||
) : ( | ||||||||
<button | ||||||||
onClick={() => handleWidgetDrawerOpen(true)} | ||||||||
style={{ | ||||||||
width: '100%', | ||||||||
borderRadius: '8px', | ||||||||
borderColor: colors.surface.blue[90], | ||||||||
borderWidth: '2px', | ||||||||
borderStyle: 'dashed', | ||||||||
backgroundColor: colors.surface.blue[10], | ||||||||
padding: '3rem', | ||||||||
fontSize: '16px', | ||||||||
color: colors.surface.blue[90], | ||||||||
cursor: 'pointer', | ||||||||
}} | ||||||||
> | ||||||||
Optional Content Widgets | ||||||||
</button> | ||||||||
)} | ||||||||
</Grid> | ||||||||
</Else> | ||||||||
</If> | ||||||||
</Grid> | ||||||||
); | ||||||||
}; |
19 changes: 19 additions & 0 deletions
19
met-web/src/components/engagement/admin/create/widgets/index.tsx
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import React from 'react'; | ||
import WidgetDrawer from 'components/engagement/form/EngagementWidgets/WidgetDrawer'; | ||
import { WidgetDrawerProvider } from 'components/engagement/form/EngagementWidgets/WidgetDrawerContext'; | ||
import { WidgetPickerButton } from './WidgetPickerButton'; | ||
import { WidgetLocation } from 'models/widget'; | ||
import { ActionProvider } from 'components/engagement/form/ActionContext'; | ||
|
||
export const WidgetPicker = ({ location }: { location: WidgetLocation }) => { | ||
return ( | ||
<ActionProvider> | ||
<WidgetDrawerProvider> | ||
<WidgetPickerButton location={location} /> | ||
<WidgetDrawer /> | ||
</WidgetDrawerProvider> | ||
</ActionProvider> | ||
); | ||
}; | ||
|
||
export default WidgetPicker; |
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
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
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
Oops, something went wrong.
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.
Does it still make sense to have a sort_index on a widget if its position is determined by its location?
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.
Solid question - I kept it so we could:
That said, once we know the fate of the old picker and widgets going forward, a clean-up ticket would be warranted