(feat) add delete controllers feature and simplify box

This commit is contained in:
cardosofede
2024-06-04 20:08:55 +02:00
parent 9dfa3e3c78
commit 7db22e8c05

View File

@@ -11,7 +11,7 @@ from .dashboard import Dashboard
class LaunchStrategyV2(Dashboard.Item): class LaunchStrategyV2(Dashboard.Item):
DEFAULT_ROWS = [] DEFAULT_ROWS = []
DEFAULT_COLUMNS = [ DEFAULT_COLUMNS = [
{"field": 'id', "headerName": 'ID', "width": 230}, {"field": 'id', "headerName": 'ID', "minWidth": 230, "editable": False, },
{"field": 'controller_name', "headerName": 'Controller Name', "width": 150, "editable": False, }, {"field": 'controller_name', "headerName": 'Controller Name', "width": 150, "editable": False, },
{"field": 'controller_type', "headerName": 'Controller Type', "width": 150, "editable": False, }, {"field": 'controller_type', "headerName": 'Controller Type', "width": 150, "editable": False, },
{"field": 'connector_name', "headerName": 'Connector', "width": 150, "editable": False, }, {"field": 'connector_name', "headerName": 'Connector', "width": 150, "editable": False, },
@@ -79,26 +79,23 @@ class LaunchStrategyV2(Dashboard.Item):
st.warning("You need to define the bot name and select the controllers configs " st.warning("You need to define the bot name and select the controllers configs "
"that you want to deploy.") "that you want to deploy.")
def delete_selected_configs(self):
if self._controller_config_selected:
for config in self._controller_config_selected:
response = self._backend_api_client.delete_controller_config(config)
st.success(response)
self._controller_configs_available = self._backend_api_client.get_all_controllers_config()
else:
st.warning("You need to select the controllers configs that you want to delete.")
def __call__(self): def __call__(self):
with mui.Paper(key=self._key, with mui.Paper(key=self._key,
sx={"display": "flex", "flexDirection": "column", "borderRadius": 3, "overflow": "hidden"}, sx={"display": "flex", "flexDirection": "column", "borderRadius": 3, "overflow": "hidden"},
elevation=1): elevation=1):
with self.title_bar(padding="10px 15px 10px 15px", dark_switcher=False): with self.title_bar(padding="10px 15px 10px 15px", dark_switcher=False):
mui.Typography("🚀 Select the controller configs to launch", variant="h5") mui.Typography("🎛️ Bot Configuration", variant="h5")
with mui.Grid(container=True, spacing=2, sx={"padding": "10px 15px 10px 15px"}): with mui.Grid(container=True, spacing=2, sx={"padding": "10px 15px 10px 15px"}):
with mui.Grid(item=True, xs=8):
mui.Alert(
"The new instance will contain the credentials configured in the following base instance:",
severity="info")
with mui.Grid(item=True, xs=4):
available_credentials = self._backend_api_client.get_accounts()
with mui.FormControl(variant="standard", sx={"width": "100%"}):
mui.FormHelperText("Credentials")
with mui.Select(label="Credentials", defaultValue="master_account",
variant="standard", onChange=lazy(self._set_credentials)):
for master_config in available_credentials:
mui.MenuItem(master_config, value=master_config)
with mui.Grid(item=True, xs=4): with mui.Grid(item=True, xs=4):
mui.TextField(label="Instance Name", variant="outlined", onChange=lazy(self._set_bot_name), mui.TextField(label="Instance Name", variant="outlined", onChange=lazy(self._set_bot_name),
sx={"width": "100%"}) sx={"width": "100%"})
@@ -111,12 +108,13 @@ class LaunchStrategyV2(Dashboard.Item):
for image in available_images: for image in available_images:
mui.MenuItem(image, value=image) mui.MenuItem(image, value=image)
with mui.Grid(item=True, xs=4): with mui.Grid(item=True, xs=4):
with mui.Button(onClick=self.launch_new_bot, available_credentials = self._backend_api_client.get_accounts()
variant="outlined", with mui.FormControl(variant="standard", sx={"width": "100%"}):
color="success", mui.FormHelperText("Credentials")
sx={"width": "100%", "height": "100%"}): with mui.Select(label="Credentials", defaultValue="master_account",
mui.icon.AddCircleOutline() variant="standard", onChange=lazy(self._set_credentials)):
mui.Typography("Create") for master_config in available_credentials:
mui.MenuItem(master_config, value=master_config)
all_controllers_config = self._backend_api_client.get_all_controllers_config() all_controllers_config = self._backend_api_client.get_all_controllers_config()
data = [] data = []
for config in all_controllers_config: for config in all_controllers_config:
@@ -140,15 +138,29 @@ class LaunchStrategyV2(Dashboard.Item):
"time_limit": time_limit}) "time_limit": time_limit})
with mui.Grid(item=True, xs=12): with mui.Grid(item=True, xs=12):
mui.Alert("Select the controller configs to deploy", severity="info")
with mui.Paper(key=self._key, with mui.Paper(key=self._key,
sx={"display": "flex", "flexDirection": "column", "borderRadius": 3, sx={"display": "flex", "flexDirection": "column", "borderRadius": 3,
"overflow": "hidden", "height": 1000}, "overflow": "hidden", "height": 1000},
elevation=1): elevation=2):
with self.title_bar(padding="10px 15px 10px 15px", dark_switcher=False): with self.title_bar(padding="10px 15px 10px 15px", dark_switcher=False):
mui.icon.ViewCompact() with mui.Grid(container=True, spacing=2):
mui.Typography("Controllers Config") with mui.Grid(item=True, xs=8):
with mui.Box(sx={"flex": 1, "minHeight": 3}): mui.Typography("🗄️ Available Configurations", variant="h6")
with mui.Grid(item=True, xs=2):
with mui.Button(onClick=self.delete_selected_configs,
variant="outlined",
color="error",
sx={"width": "100%", "height": "100%"}):
mui.icon.Delete()
mui.Typography("Delete")
with mui.Grid(item=True, xs=2):
with mui.Button(onClick=self.launch_new_bot,
variant="outlined",
color="success",
sx={"width": "100%", "height": "100%"}):
mui.icon.AddCircleOutline()
mui.Typography("Launch Bot")
with mui.Box(sx={"flex": 1, "minHeight": 3, "width": "100%"}):
mui.DataGrid( mui.DataGrid(
columns=self.DEFAULT_COLUMNS, columns=self.DEFAULT_COLUMNS,
rows=data, rows=data,
@@ -156,5 +168,6 @@ class LaunchStrategyV2(Dashboard.Item):
rowsPerPageOptions=[15], rowsPerPageOptions=[15],
checkboxSelection=True, checkboxSelection=True,
disableSelectionOnClick=True, disableSelectionOnClick=True,
disableColumnResize=False,
onSelectionModelChange=self._handle_row_selection, onSelectionModelChange=self._handle_row_selection,
) )