Skip to content

Commit

Permalink
The action buttons in CI should make sense
Browse files Browse the repository at this point in the history
  • Loading branch information
ElijahAhianyo committed Jan 24, 2025
1 parent f3ac988 commit fca6bf4
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 25 deletions.
26 changes: 25 additions & 1 deletion ci_template/cijob/backend/table_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,20 @@ class Item(rx.Base):
timestamp: str
duration: str

def __eq__(self, other):
if not isinstance(other, Item):
return NotImplemented
return (
self.pipeline == other.pipeline and
self.status == other.status and
self.workflow == other.workflow and
self.timestamp == other.timestamp and
self.duration == other.duration
)

def __hash__(self):
return hash((self.pipeline, self.status, self.workflow, self.timestamp, self.duration))


class TableState(rx.State):
"""The state class."""
Expand Down Expand Up @@ -97,9 +111,19 @@ def load_entries(self):
with Path("data.csv").open(encoding="utf-8") as file:
reader = csv.DictReader(file)
self.items = [Item(**row) for row in reader]
self.initial_items = self.items
self.initial_items = self.items.copy()
self.total_items = len(self.items)

def toggle_sort(self):
self.sort_reverse = not self.sort_reverse
self.load_entries()

def delete_item(self, item: Item):
self.items.remove(item)
self.initial_items.remove(item)
self.total_items = len(self.items)
self.first_page()
return rx.toast.success(f"{item.pipeline} deleted successfully")



66 changes: 42 additions & 24 deletions ci_template/cijob/views/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


def _create_dialog(
item: Item, icon_name: str, color_scheme: str, dialog_title: str
item: Item, icon_name: str, color_scheme: str, dialog_title: str, action: str
) -> rx.Component:
return rx.dialog.root(
rx.dialog.trigger(
Expand All @@ -14,41 +14,59 @@ def _create_dialog(
)
),
rx.dialog.content(
rx.vstack(
rx.dialog.title(dialog_title),
rx.dialog.description(
rx.match(
action,
("delete",
rx.vstack(
rx.dialog.title(dialog_title),
rx.dialog.description(
rx.center(
rx.text("Are you sure you want to delete this item?")
),
rx.hstack(
rx.button("Delete", size="2", color_scheme="tomato",
on_click=TableState.delete_item(item)),
rx.dialog.close(
rx.button("cancel", size="2", color_scheme=color_scheme),
),
),
),
)
),
rx.fragment(
rx.vstack(
rx.text(item.pipeline),
rx.text(item.workflow),
status_badge(item.status),
rx.text(item.timestamp),
rx.text(item.duration),
)
),
rx.dialog.close(
rx.button("Close Dialog", size="2", color_scheme=color_scheme),
),
rx.dialog.title(dialog_title),
rx.dialog.description(
rx.vstack(
rx.text(item.pipeline),
rx.text(item.workflow),
status_badge(item.status),
rx.text(item.timestamp),
rx.text(item.duration),
)
),
rx.dialog.close(
rx.button("Close Dialog", size="2", color_scheme=color_scheme),
),
),
)
),

),
)


def _delete_dialog(item: Item) -> rx.Component:
return _create_dialog(item, "trash-2", "tomato", "Delete Dialog")

return _create_dialog(item, "trash-2", "tomato", "Delete Dialog", "delete")

def _approve_dialog(item: Item) -> rx.Component:
return _create_dialog(item, "check", "grass", "Approve Dialog")


def _edit_dialog(item: Item) -> rx.Component:
return _create_dialog(item, "square-pen", "blue", "Edit Dialog")
def _view_dialog(item: Item) -> rx.Component:
return _create_dialog(item, "eye", "grass", "View Dialog", "approve")


def _dialog_group(item: Item) -> rx.Component:
return rx.hstack(
_approve_dialog(item),
_edit_dialog(item),
_view_dialog(item),
_delete_dialog(item),
align="center",
spacing="2",
Expand Down Expand Up @@ -149,7 +167,7 @@ def _pagination_view() -> rx.Component:
align="center",
width="100%",
justify="end",
),
)
)


Expand Down

0 comments on commit fca6bf4

Please sign in to comment.