-
-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dashboard): Add feature to remove action events (#688)
* feat: Add feature to remove action events * fix: Fix database revision
- Loading branch information
Showing
13 changed files
with
196 additions
and
20 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
openadapt/alembic/versions/a29b537fabe6_add_disabled_field_to_action_event.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,31 @@ | ||
"""add_disabled_field_to_action_event | ||
Revision ID: a29b537fabe6 | ||
Revises: 98c8851a5321 | ||
Create Date: 2024-05-28 11:28:50.353928 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "a29b537fabe6" | ||
down_revision = "98c8851a5321" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
with op.batch_alter_table("action_event", schema=None) as batch_op: | ||
batch_op.add_column(sa.Column("disabled", sa.Boolean(), nullable=True)) | ||
|
||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
with op.batch_alter_table("action_event", schema=None) as batch_op: | ||
batch_op.drop_column("disabled") | ||
|
||
# ### end Alembic commands ### |
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,42 @@ | ||
"""API endpoints for recordings.""" | ||
|
||
from fastapi import APIRouter | ||
from loguru import logger | ||
|
||
from openadapt.db import crud | ||
|
||
|
||
class ActionEventsAPI: | ||
"""API endpoints for action events.""" | ||
|
||
def __init__(self) -> None: | ||
"""Initialize the ActionEventsAPI class.""" | ||
self.app = APIRouter() | ||
|
||
def attach_routes(self) -> APIRouter: | ||
"""Attach routes to the FastAPI app.""" | ||
self.app.add_api_route("/{event_id}", self.disable_event, methods=["DELETE"]) | ||
return self.app | ||
|
||
@staticmethod | ||
def disable_event(event_id: int) -> dict[str, str]: | ||
"""Disable an action event. | ||
Args: | ||
event_id (int): The ID of the event to disable. | ||
Returns: | ||
dict: The response message and status code. | ||
""" | ||
if not crud.acquire_db_lock(): | ||
return {"message": "Database is locked", "status": "error"} | ||
session = crud.get_new_session(read_and_write=True) | ||
try: | ||
crud.disable_action_event(session, event_id) | ||
except Exception as e: | ||
logger.error(f"Error deleting event: {e}") | ||
session.rollback() | ||
crud.release_db_lock() | ||
return {"message": "Error deleting event", "status": "error"} | ||
crud.release_db_lock() | ||
return {"message": "Event deleted", "status": "success"} |
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
52 changes: 52 additions & 0 deletions
52
openadapt/app/dashboard/components/ActionEvent/RemoveActionEvent.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,52 @@ | ||
import { ActionEvent } from '@/types/action-event'; | ||
import { Button, Text } from '@mantine/core'; | ||
import { modals } from '@mantine/modals'; | ||
import { notifications } from '@mantine/notifications'; | ||
import React from 'react' | ||
|
||
type Props = { | ||
event: ActionEvent; | ||
} | ||
|
||
export const RemoveActionEvent = ({ | ||
event | ||
}: Props) => { | ||
const openModal = (e: React.MouseEvent<HTMLButtonElement>) => { | ||
e.stopPropagation(); | ||
modals.openConfirmModal({ | ||
title: 'Please confirm your action', | ||
children: ( | ||
<Text size="sm"> | ||
Are you sure you want to delete this action event? This action cannot be undone. | ||
</Text> | ||
), | ||
labels: { confirm: 'Confirm', cancel: 'Cancel' }, | ||
onCancel: () => {}, | ||
onConfirm: deleteActionEvent, | ||
confirmProps: { color: 'red' }, | ||
}); | ||
} | ||
|
||
const deleteActionEvent = () => { | ||
fetch(`/api/action-events/${event.id}`, { | ||
method: 'DELETE', | ||
}).then(res => res.json()).then(data => { | ||
const { message, status } = data; | ||
if (status === 'success') { | ||
window.location.reload(); | ||
} else { | ||
notifications.show({ | ||
title: 'Error', | ||
message, | ||
color: 'red', | ||
}) | ||
} | ||
}); | ||
} | ||
if (event.isComputed || !event.isOriginal) return null; | ||
return ( | ||
<Button variant='filled' color='red' onClick={openModal}> | ||
Remove action event | ||
</Button> | ||
) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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