You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by hu...@apache.org on 2022/08/16 20:35:35 UTC

[superset] 01/01: fix(dashboard): Fix scroll behaviour in DashboardBuilderSidepane (#20969)

This is an automated email from the ASF dual-hosted git repository.

hugh pushed a commit to branch spa-bsd-sql-endpoint
in repository https://gitbox.apache.org/repos/asf/superset.git

commit 746276c13670f5a52a848a3c8e45de58ccb65096
Author: EugeneTorap <ev...@gmail.com>
AuthorDate: Tue Aug 16 20:29:28 2022 +0300

    fix(dashboard): Fix scroll behaviour in DashboardBuilderSidepane (#20969)
---
 .../components/BuilderComponentPane/index.tsx      | 15 +------
 superset/initialization/__init__.py                |  5 +++
 superset/sql/api.py                                | 51 ++++++++++++++++++++++
 superset/views/sql.py                              | 36 +++++++++++++++
 4 files changed, 94 insertions(+), 13 deletions(-)

diff --git a/superset-frontend/src/dashboard/components/BuilderComponentPane/index.tsx b/superset-frontend/src/dashboard/components/BuilderComponentPane/index.tsx
index 4e47e161e4..7a1019a0e2 100644
--- a/superset-frontend/src/dashboard/components/BuilderComponentPane/index.tsx
+++ b/superset-frontend/src/dashboard/components/BuilderComponentPane/index.tsx
@@ -41,8 +41,7 @@ export interface BCPProps {
 
 const SUPERSET_HEADER_HEIGHT = 59;
 const SIDEPANE_ADJUST_OFFSET = 4;
-const SIDEPANE_HEADER_HEIGHT = 64; // including margins
-const SIDEPANE_FILTERBAR_HEIGHT = 56;
+const TOP_PANEL_OFFSET = 210;
 
 const BuilderComponentPaneTabs = styled(Tabs)`
   line-height: inherit;
@@ -52,20 +51,10 @@ const BuilderComponentPaneTabs = styled(Tabs)`
 const DashboardBuilderSidepane = styled.div<{
   topOffset: number;
 }>`
-  height: 100%;
+  height: calc(100% - ${TOP_PANEL_OFFSET}px);
   position: fixed;
   right: 0;
   top: 0;
-
-  .ReactVirtualized__List {
-    padding-bottom: ${({ topOffset }) =>
-      `${
-        SIDEPANE_HEADER_HEIGHT +
-        SIDEPANE_FILTERBAR_HEIGHT +
-        SIDEPANE_ADJUST_OFFSET +
-        topOffset
-      }px`};
-  }
 `;
 
 const BuilderComponentPane: React.FC<BCPProps> = ({
diff --git a/superset/initialization/__init__.py b/superset/initialization/__init__.py
index 2fe5591dac..c5d6405037 100644
--- a/superset/initialization/__init__.py
+++ b/superset/initialization/__init__.py
@@ -145,6 +145,7 @@ class SupersetAppInitializer:  # pylint: disable=too-many-public-methods
         from superset.reports.api import ReportScheduleRestApi
         from superset.reports.logs.api import ReportExecutionLogRestApi
         from superset.security.api import SecurityRestApi
+        from superset.sql.api import SqlRestApi
         from superset.views.access_requests import AccessRequestsModelView
         from superset.views.alerts import AlertView, ReportView
         from superset.views.annotations import (
@@ -176,6 +177,7 @@ class SupersetAppInitializer:  # pylint: disable=too-many-public-methods
         from superset.views.log.api import LogRestApi
         from superset.views.log.views import LogModelView
         from superset.views.redirects import R
+        from superset.views.sql import SqlView
         from superset.views.sql_lab.views import (
             SavedQueryView,
             SavedQueryViewApi,
@@ -215,6 +217,8 @@ class SupersetAppInitializer:  # pylint: disable=too-many-public-methods
         appbuilder.add_api(ReportScheduleRestApi)
         appbuilder.add_api(ReportExecutionLogRestApi)
         appbuilder.add_api(SavedQueryRestApi)
+        appbuilder.add_api(SqlRestApi)
+
         #
         # Setup regular views
         #
@@ -308,6 +312,7 @@ class SupersetAppInitializer:  # pylint: disable=too-many-public-methods
         appbuilder.add_view_no_menu(TabStateView)
         appbuilder.add_view_no_menu(TagView)
         appbuilder.add_view_no_menu(ReportView)
+        appbuilder.add_view_no_menu(SqlView)
 
         #
         # Add links
diff --git a/superset/sql/api.py b/superset/sql/api.py
new file mode 100644
index 0000000000..7653acf492
--- /dev/null
+++ b/superset/sql/api.py
@@ -0,0 +1,51 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+import logging
+
+from flask import g, request, Response
+from flask_appbuilder.api import BaseApi, expose, protect, safe
+
+from superset.charts.commands.exceptions import ChartNotFoundError
+from superset.constants import MODEL_API_RW_METHOD_PERMISSION_MAP, RouteMethod
+from superset.explore.commands.get import GetExploreCommand
+from superset.explore.commands.parameters import CommandParameters
+from superset.explore.exceptions import DatasetAccessDeniedError, WrongEndpointError
+from superset.explore.permalink.exceptions import ExplorePermalinkGetFailedError
+from superset.explore.schemas import ExploreContextSchema
+from superset.extensions import event_logger
+
+logger = logging.getLogger(__name__)
+
+
+class SqlRestApi(BaseApi):
+    method_permission_name = MODEL_API_RW_METHOD_PERMISSION_MAP
+    include_route_methods = {RouteMethod.GET}
+    # allow_browser_login = True
+    class_permission_name = "Superset"
+    resource_name = "sql"
+    # openapi_spec_tag = "Explore"
+    # openapi_spec_component_schemas = (ExploreContextSchema,)
+
+    @expose("/", methods=["GET"])
+    @protect()
+    @safe
+    @event_logger.log_this_with_context(
+        action=lambda self, *args, **kwargs: f"{self.__class__.__name__}.get",
+        log_to_statsd=True,
+    )
+    def get(self) -> Response:
+        return self.response(200, result={"foo": "bar"})
diff --git a/superset/views/sql.py b/superset/views/sql.py
new file mode 100644
index 0000000000..4a148decd0
--- /dev/null
+++ b/superset/views/sql.py
@@ -0,0 +1,36 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+from flask_appbuilder import permission_name
+from flask_appbuilder.api import expose
+from flask_appbuilder.security.decorators import has_access
+
+from superset import event_logger
+from superset.superset_typing import FlaskResponse
+
+from .base import BaseSupersetView
+
+
+class SqlView(BaseSupersetView):
+    route_base = "/sql"
+    class_permission_name = "Superset"
+
+    @expose("/")
+    # @has_access
+    # @permission_name("read")
+    # @event_logger.log_this
+    def root(self) -> FlaskResponse:
+        return super().render_app_template()