Skip to content

Commit

Permalink
using a regex instead of split
Browse files Browse the repository at this point in the history
  • Loading branch information
jamagalhaes committed Jan 21, 2025
1 parent 208aaec commit c618a7d
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions canvas_sdk/handlers/action_button.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
from abc import abstractmethod
from enum import StrEnum

Expand All @@ -6,6 +7,8 @@
from canvas_sdk.events import EventType
from canvas_sdk.handlers.base import BaseHandler

SHOW_BUTTON_REGEX = re.compile(r"^SHOW_(.+?)_BUTTON$")


class ActionButton(BaseHandler):
"""Base class for action buttons."""
Expand Down Expand Up @@ -60,8 +63,10 @@ def compute(self) -> list[Effect]:
if not self.BUTTON_LOCATION:
return []

if self.event.name.startswith("SHOW"):
location = "_".join(self.event.name.split("_")[1:-1])
show_button_event_match = SHOW_BUTTON_REGEX.fullmatch(self.event.name)

if show_button_event_match:
location = show_button_event_match.group(1)
if self.ButtonLocation[location] == self.BUTTON_LOCATION and self.visible():
return [ShowButtonEffect(key=self.BUTTON_KEY, title=self.BUTTON_TITLE).apply()]
elif self.context["key"] == self.BUTTON_KEY:
Expand Down

0 comments on commit c618a7d

Please sign in to comment.