michael-s-molina commented on code in PR #20399:
URL: https://github.com/apache/superset/pull/20399#discussion_r903621866


##########
superset/explore/commands/get.py:
##########
@@ -0,0 +1,172 @@
+# 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 abc import ABC
+from typing import Any, cast, Dict, Optional
+
+import simplejson as json
+from flask import current_app as app
+from flask_babel import gettext as __, lazy_gettext as _
+from sqlalchemy.exc import SQLAlchemyError
+
+from superset import db, security_manager
+from superset.commands.base import BaseCommand
+from superset.connectors.base.models import BaseDatasource
+from superset.connectors.connector_registry import ConnectorRegistry
+from superset.connectors.sqla.models import SqlaTable
+from superset.datasets.commands.exceptions import DatasetNotFoundError
+from superset.exceptions import SupersetException
+from superset.explore.commands.parameters import CommandParameters
+from superset.explore.exceptions import DatasetAccessDeniedError, 
WrongEndpointError
+from superset.explore.form_data.commands.get import GetFormDataCommand
+from superset.explore.form_data.commands.parameters import (
+    CommandParameters as FormDataCommandParameters,
+)
+from superset.explore.permalink.commands.get import GetExplorePermalinkCommand
+from superset.explore.permalink.exceptions import 
ExplorePermalinkGetFailedError
+from superset.models.sql_lab import Query
+from superset.utils import core as utils
+from superset.views.utils import (
+    get_datasource_info,
+    get_form_data,
+    sanitize_datasource_data,
+)
+
+logger = logging.getLogger(__name__)
+
+
+class GetExploreCommand(BaseCommand, ABC):
+    def __init__(
+        self,
+        params: CommandParameters,
+    ) -> None:
+        self._actor = params.actor
+        self._permalink_key = params.permalink_key
+        self._form_data_key = params.form_data_key
+        self._dataset_id = params.dataset_id
+        self._dataset_type = params.dataset_type
+        self._slice_id = params.slice_id
+
+    # pylint: disable=too-many-locals,too-many-branches,too-many-statements
+    def run(self) -> Optional[Dict[str, Any]]:
+        initial_form_data = {}
+
+        if self._permalink_key is not None:
+            command = GetExplorePermalinkCommand(self._actor, 
self._permalink_key)
+            permalink_value = command.run()
+            if permalink_value:
+                state = permalink_value["state"]
+                initial_form_data = state["formData"]
+                url_params = state.get("urlParams")
+                if url_params:
+                    initial_form_data["url_params"] = dict(url_params)
+            else:
+                raise ExplorePermalinkGetFailedError()
+        elif self._form_data_key:
+            parameters = FormDataCommandParameters(
+                actor=self._actor, key=self._form_data_key
+            )
+            value = GetFormDataCommand(parameters).run()
+            initial_form_data = json.loads(value) if value else {}
+
+        message = None

Review Comment:
   Ok. I'll leave the refactor for a follow-up then. @zhaoyongjie commented 
that we may have parts that are not even being used anymore. After we complete 
the SPA work, we'll have more knowledge of the domain as well, which will give 
us more information for the refactoring.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org
For additional commands, e-mail: notifications-h...@superset.apache.org

Reply via email to