-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DESENG-675 Make widget component "reusable" (#2579)
* DESENG-675 Make widget component "reusable" * DESENG-675 Update changelog, contributing, met-web tests * DESENG-675 Merge import statements, add warning style to widget deletion
- Loading branch information
Showing
32 changed files
with
203 additions
and
5 deletions.
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: { | ||
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.