From 7db22e8c05c263c2ef192fb24c40e2170f7d2e76 Mon Sep 17 00:00:00 2001 From: cardosofede Date: Tue, 4 Jun 2024 20:08:55 +0200 Subject: [PATCH] (feat) add delete controllers feature and simplify box --- frontend/components/launch_strategy_v2.py | 63 ++++++++++++++--------- 1 file changed, 38 insertions(+), 25 deletions(-) diff --git a/frontend/components/launch_strategy_v2.py b/frontend/components/launch_strategy_v2.py index 810957a..2d265e5 100644 --- a/frontend/components/launch_strategy_v2.py +++ b/frontend/components/launch_strategy_v2.py @@ -11,7 +11,7 @@ from .dashboard import Dashboard class LaunchStrategyV2(Dashboard.Item): DEFAULT_ROWS = [] 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_type', "headerName": 'Controller Type', "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 " "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): with mui.Paper(key=self._key, sx={"display": "flex", "flexDirection": "column", "borderRadius": 3, "overflow": "hidden"}, elevation=1): 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(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): mui.TextField(label="Instance Name", variant="outlined", onChange=lazy(self._set_bot_name), sx={"width": "100%"}) @@ -111,12 +108,13 @@ class LaunchStrategyV2(Dashboard.Item): for image in available_images: mui.MenuItem(image, value=image) with mui.Grid(item=True, xs=4): - with mui.Button(onClick=self.launch_new_bot, - variant="outlined", - color="success", - sx={"width": "100%", "height": "100%"}): - mui.icon.AddCircleOutline() - mui.Typography("Create") + 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) all_controllers_config = self._backend_api_client.get_all_controllers_config() data = [] for config in all_controllers_config: @@ -140,15 +138,29 @@ class LaunchStrategyV2(Dashboard.Item): "time_limit": time_limit}) with mui.Grid(item=True, xs=12): - mui.Alert("Select the controller configs to deploy", severity="info") with mui.Paper(key=self._key, sx={"display": "flex", "flexDirection": "column", "borderRadius": 3, "overflow": "hidden", "height": 1000}, - elevation=1): + elevation=2): with self.title_bar(padding="10px 15px 10px 15px", dark_switcher=False): - mui.icon.ViewCompact() - mui.Typography("Controllers Config") - with mui.Box(sx={"flex": 1, "minHeight": 3}): + with mui.Grid(container=True, spacing=2): + with mui.Grid(item=True, xs=8): + 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( columns=self.DEFAULT_COLUMNS, rows=data, @@ -156,5 +168,6 @@ class LaunchStrategyV2(Dashboard.Item): rowsPerPageOptions=[15], checkboxSelection=True, disableSelectionOnClick=True, + disableColumnResize=False, onSelectionModelChange=self._handle_row_selection, )