Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ui): Adding manifest prefix config #19141

Merged
merged 11 commits into from
Mar 17, 2022
4 changes: 2 additions & 2 deletions superset-frontend/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ const plugins = [
entryFiles[entry] = {
css: chunks
.filter(x => x.endsWith('.css'))
.map(x => path.join(output.publicPath, x)),
.map(x => `${output.publicPath}${x}`),
js: chunks
.filter(x => x.endsWith('.js'))
.map(x => path.join(output.publicPath, x)),
.map(x => `${output.publicPath}${x}`),
};
});

Expand Down
2 changes: 1 addition & 1 deletion superset/common/query_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
QueryObjectValidationError,
)
from superset.sql_parse import validate_filter_clause
from superset.typing import Column, Metric, OrderBy
from superset.superset_typing import Column, Metric, OrderBy
from superset.utils import pandas_postprocessing
from superset.utils.core import (
DTTM_ALIAS,
Expand Down
6 changes: 5 additions & 1 deletion superset/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
from superset.constants import CHANGE_ME_SECRET_KEY
from superset.jinja_context import BaseTemplateProcessor
from superset.stats_logger import DummyStatsLogger
from superset.typing import CacheConfig
from superset.superset_typing import CacheConfig
from superset.utils.core import is_test, parse_boolean_string
from superset.utils.encrypt import SQLAlchemyUtilsAdapter
from superset.utils.log import DBEventLogger
Expand Down Expand Up @@ -1249,6 +1249,10 @@ def SQL_QUERY_MUTATOR( # pylint: disable=invalid-name,unused-argument
# SQLALCHEMY_DATABASE_URI by default if set to `None`
SQLALCHEMY_EXAMPLES_URI = None

# Optional prefix to be added to all static asset paths when rendering the UI.
# This is useful for hosting assets in an external CDN, for example
STATIC_ASSETS_PREFIX = ""

# Some sqlalchemy connection strings can open Superset to security risks.
# Typically these should not be allowed.
PREVENT_UNSAFE_DB_CONNECTIONS = True
Expand Down
2 changes: 1 addition & 1 deletion superset/connectors/base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from superset.datasets.commands.exceptions import DatasetNotFoundError
from superset.models.helpers import AuditMixinNullable, ImportExportMixin, QueryResult
from superset.models.slice import Slice
from superset.typing import FilterValue, FilterValues, QueryObjectDict
from superset.superset_typing import FilterValue, FilterValues, QueryObjectDict
from superset.utils import core as utils
from superset.utils.core import GenericDataType

Expand Down
2 changes: 1 addition & 1 deletion superset/connectors/druid/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
from superset.extensions import encrypted_field_factory
from superset.models.core import Database
from superset.models.helpers import AuditMixinNullable, ImportExportMixin, QueryResult
from superset.typing import (
from superset.superset_typing import (
AdhocMetric,
AdhocMetricColumn,
FilterValues,
Expand Down
2 changes: 1 addition & 1 deletion superset/connectors/druid/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from superset.connectors.connector_registry import ConnectorRegistry
from superset.connectors.druid import models
from superset.constants import RouteMethod
from superset.typing import FlaskResponse
from superset.superset_typing import FlaskResponse
from superset.utils import core as utils
from superset.views.base import (
BaseSupersetView,
Expand Down
8 changes: 7 additions & 1 deletion superset/connectors/sqla/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,14 @@
QueryResult,
)
from superset.sql_parse import ParsedQuery
from superset.superset_typing import (
AdhocColumn,
AdhocMetric,
Metric,
OrderBy,
QueryObjectDict,
)
from superset.tables.models import Table as NewTable
from superset.typing import AdhocColumn, AdhocMetric, Metric, OrderBy, QueryObjectDict
from superset.utils import core as utils
from superset.utils.core import (
GenericDataType,
Expand Down
2 changes: 1 addition & 1 deletion superset/connectors/sqla/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
from superset.connectors.base.views import DatasourceModelView
from superset.connectors.sqla import models
from superset.constants import MODEL_VIEW_RW_METHOD_PERMISSION_MAP, RouteMethod
from superset.typing import FlaskResponse
from superset.superset_typing import FlaskResponse
from superset.utils import core as utils
from superset.views.base import (
check_ownership,
Expand Down
2 changes: 1 addition & 1 deletion superset/databases/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
from superset.errors import ErrorLevel, SupersetError, SupersetErrorType
from superset.extensions import security_manager
from superset.models.core import Database
from superset.typing import FlaskResponse
from superset.superset_typing import FlaskResponse
from superset.utils.core import error_msg_from_exception
from superset.views.base_api import (
BaseSupersetModelRestApi,
Expand Down
36 changes: 20 additions & 16 deletions superset/extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,26 @@ def init_app(self, app: Flask) -> None:
self.app = app
# Preload the cache
self.parse_manifest_json()

@app.context_processor
def get_manifest() -> Dict[str, Callable[[str], List[str]]]:
loaded_chunks = set()

def get_files(bundle: str, asset_type: str = "js") -> List[str]:
files = self.get_manifest_files(bundle, asset_type)
filtered_files = [f for f in files if f not in loaded_chunks]
for f in filtered_files:
loaded_chunks.add(f)
return filtered_files

return dict(
js_manifest=lambda bundle: get_files(bundle, "js"),
css_manifest=lambda bundle: get_files(bundle, "css"),
)
self.register_processor(app)

def register_processor(self, app: Flask) -> None:
app.template_context_processors[None].append(self.get_manifest)

def get_manifest(self) -> Dict[str, Callable[[str], List[str]]]:
loaded_chunks = set()

def get_files(bundle: str, asset_type: str = "js") -> List[str]:
files = self.get_manifest_files(bundle, asset_type)
filtered_files = [f for f in files if f not in loaded_chunks]
for f in filtered_files:
loaded_chunks.add(f)
Comment on lines +77 to +78
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to do this (specially if CI is green) but this can be simplified:

Suggested change
for f in filtered_files:
loaded_chunks.add(f)
loaded_chunks.update(filtered_files)

return filtered_files

return dict(
js_manifest=lambda bundle: get_files(bundle, "js"),
css_manifest=lambda bundle: get_files(bundle, "css"),
assets_prefix=self.app.config["STATIC_ASSETS_PREFIX"] if self.app else "",
)

def parse_manifest_json(self) -> None:
try:
Expand Down
2 changes: 1 addition & 1 deletion superset/initialization/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
talisman,
)
from superset.security import SupersetSecurityManager
from superset.typing import FlaskResponse
from superset.superset_typing import FlaskResponse
from superset.utils.core import pessimistic_connection_handling
from superset.utils.log import DBEventLogger, get_event_logger_from_cfg_value

Expand Down
2 changes: 1 addition & 1 deletion superset/result_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import pyarrow as pa

from superset.db_engine_specs import BaseEngineSpec
from superset.typing import DbapiDescription, DbapiResult
from superset.superset_typing import DbapiDescription, DbapiResult
from superset.utils import core as utils

logger = logging.getLogger(__name__)
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion superset/templates/superset/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

{% block head_css %}
{{ super() }}
<link rel="icon" type="image/png" href="/static/assets/images/favicon.png">
<link rel="icon" type="image/png" href="{{ assets_prefix }}/static/assets/images/favicon.png">
{{ css_bundle("theme") }}
{% endblock %}

Expand Down
8 changes: 4 additions & 4 deletions superset/templates/superset/basic.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@
rel="{{favicon.rel if favicon.rel else "icon"}}"
type="{{favicon.type if favicon.type else "image/png"}}"
{% if favicon.sizes %}sizes={{favicon.sizes}}{% endif %}
href="{{favicon.href}}"
href="{{ assets_prefix }}{{favicon.href}}"
>
{% endfor %}
<link rel="stylesheet" type="text/css" href="/static/appbuilder/css/flags/flags16.css" />
<link rel="stylesheet" type="text/css" href="/static/appbuilder/css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="{{ assets_prefix }}/static/appbuilder/css/flags/flags16.css" />
<link rel="stylesheet" type="text/css" href="{{ assets_prefix }}/static/appbuilder/css/font-awesome.min.css">

{{ css_bundle("theme") }}

Expand Down Expand Up @@ -73,7 +73,7 @@

{% block body %}
<div id="app" data-bootstrap="{{ bootstrap_data }}">
<img src="/static/assets/images/loading.gif" style="width: 50px; position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%)">
<img src="{{ assets_prefix }}/static/assets/images/loading.gif" style="width: 50px; position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%)">
</div>
{% endblock %}

Expand Down
2 changes: 1 addition & 1 deletion superset/templates/superset/theme.html
Original file line number Diff line number Diff line change
Expand Up @@ -1342,5 +1342,5 @@ <h4 class="modal-title">Source Code</h4>
{{ super() }}
<script src="https://code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="/static/assets/stylesheets/less/cosmo/cosmoTheme.js"></script>
<script src="{{ assets_prefix }}/static/assets/stylesheets/less/cosmo/cosmoTheme.js"></script>
{% endblock %}
2 changes: 1 addition & 1 deletion superset/utils/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
SupersetException,
SupersetTimeoutException,
)
from superset.typing import (
from superset.superset_typing import (
AdhocColumn,
AdhocMetric,
AdhocMetricColumn,
Expand Down
2 changes: 1 addition & 1 deletion superset/views/alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
from superset import is_feature_enabled
from superset.constants import RouteMethod
from superset.models.alerts import Alert, AlertLog, SQLObservation
from superset.superset_typing import FlaskResponse
from superset.tasks.alerts.validator import check_validator
from superset.typing import FlaskResponse
from superset.utils import core as utils
from superset.utils.core import get_email_address_str, markdown

Expand Down
2 changes: 1 addition & 1 deletion superset/views/annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from superset import is_feature_enabled
from superset.constants import MODEL_VIEW_RW_METHOD_PERMISSION_MAP, RouteMethod
from superset.models.annotations import Annotation, AnnotationLayer
from superset.typing import FlaskResponse
from superset.superset_typing import FlaskResponse
from superset.views.base import SupersetModelView


Expand Down
2 changes: 1 addition & 1 deletion superset/views/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
)
from superset.legacy import update_time_range
from superset.models.slice import Slice
from superset.typing import FlaskResponse
from superset.superset_typing import FlaskResponse
from superset.utils import core as utils
from superset.utils.date_parser import get_since_until
from superset.views.base import api, BaseSupersetView, handle_api_exception
Expand Down
2 changes: 1 addition & 1 deletion superset/views/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@
)
from superset.models.helpers import ImportExportMixin
from superset.models.reports import ReportRecipientType
from superset.superset_typing import FlaskResponse
from superset.translations.utils import get_language_pack
from superset.typing import FlaskResponse
from superset.utils import core as utils

from .utils import bootstrap_user_data
Expand Down
2 changes: 1 addition & 1 deletion superset/views/base_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
from superset.schemas import error_payload_content
from superset.sql_lab import Query as SqllabQuery
from superset.stats_logger import BaseStatsLogger
from superset.typing import FlaskResponse
from superset.superset_typing import FlaskResponse
from superset.utils.core import time_function

logger = logging.getLogger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion superset/views/chart/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from superset import is_feature_enabled
from superset.constants import MODEL_VIEW_RW_METHOD_PERMISSION_MAP, RouteMethod
from superset.models.slice import Slice
from superset.typing import FlaskResponse
from superset.superset_typing import FlaskResponse
from superset.utils import core as utils
from superset.views.base import (
check_ownership,
Expand Down
2 changes: 1 addition & 1 deletion superset/views/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@
from superset.sqllab.sqllab_execution_context import SqlJsonExecutionContext
from superset.sqllab.utils import apply_display_max_row_configuration_if_require
from superset.sqllab.validators import CanAccessQueryValidatorImpl
from superset.superset_typing import FlaskResponse
from superset.tasks.async_queries import load_explore_json_into_cache
from superset.typing import FlaskResponse
from superset.utils import core as utils, csv
from superset.utils.async_query_manager import AsyncQueryTokenException
from superset.utils.cache import etag_cache
Expand Down
2 changes: 1 addition & 1 deletion superset/views/css_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from superset import is_feature_enabled
from superset.constants import MODEL_VIEW_RW_METHOD_PERMISSION_MAP, RouteMethod
from superset.models import core as models
from superset.typing import FlaskResponse
from superset.superset_typing import FlaskResponse
from superset.views.base import DeleteMixin, SupersetModelView


Expand Down
2 changes: 1 addition & 1 deletion superset/views/dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from superset import db, event_logger, is_feature_enabled, security_manager
from superset.constants import MODEL_VIEW_RW_METHOD_PERMISSION_MAP, RouteMethod
from superset.models.dashboard import Dashboard as DashboardModel
from superset.typing import FlaskResponse
from superset.superset_typing import FlaskResponse
from superset.utils import core as utils
from superset.views.base import (
BaseSupersetView,
Expand Down
2 changes: 1 addition & 1 deletion superset/views/database/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
from superset.exceptions import CertificateException
from superset.extensions import event_logger
from superset.sql_parse import Table
from superset.typing import FlaskResponse
from superset.superset_typing import FlaskResponse
from superset.utils import core as utils
from superset.views.base import DeleteMixin, SupersetModelView, YamlExportMixin

Expand Down
2 changes: 1 addition & 1 deletion superset/views/datasource/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
from superset.exceptions import SupersetException, SupersetSecurityException
from superset.extensions import security_manager
from superset.models.core import Database
from superset.typing import FlaskResponse
from superset.superset_typing import FlaskResponse
from superset.views.base import (
api,
BaseSupersetView,
Expand Down
2 changes: 1 addition & 1 deletion superset/views/health.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# specific language governing permissions and limitations
# under the License.
from superset import app, talisman
from superset.typing import FlaskResponse
from superset.superset_typing import FlaskResponse


@talisman(force_https=False)
Expand Down
2 changes: 1 addition & 1 deletion superset/views/key_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

from superset import db, event_logger, is_feature_enabled
from superset.models import core as models
from superset.typing import FlaskResponse
from superset.superset_typing import FlaskResponse
from superset.utils import core as utils
from superset.views.base import BaseSupersetView, json_error_response

Expand Down
2 changes: 1 addition & 1 deletion superset/views/redirects.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

from superset import db, event_logger
from superset.models import core as models
from superset.typing import FlaskResponse
from superset.superset_typing import FlaskResponse
from superset.views.base import BaseSupersetView

logger = logging.getLogger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion superset/views/schedules.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
SliceEmailSchedule,
)
from superset.models.slice import Slice
from superset.superset_typing import FlaskResponse
from superset.tasks.schedules import schedule_email_report
from superset.typing import FlaskResponse
from superset.utils.core import get_email_address_list, json_iso_dttm_ser
from superset.views.core import json_success

Expand Down
2 changes: 1 addition & 1 deletion superset/views/sql_lab.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from superset import db, is_feature_enabled
from superset.constants import MODEL_VIEW_RW_METHOD_PERMISSION_MAP, RouteMethod
from superset.models.sql_lab import Query, SavedQuery, TableSchema, TabState
from superset.typing import FlaskResponse
from superset.superset_typing import FlaskResponse
from superset.utils import core as utils

from .base import BaseSupersetView, DeleteMixin, json_success, SupersetModelView
Expand Down
2 changes: 1 addition & 1 deletion superset/views/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from superset.models.slice import Slice
from superset.models.sql_lab import SavedQuery
from superset.models.tags import ObjectTypes, Tag, TaggedObject, TagTypes
from superset.typing import FlaskResponse
from superset.superset_typing import FlaskResponse

from .base import BaseSupersetView, json_success

Expand Down
2 changes: 1 addition & 1 deletion superset/views/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
from superset.models.dashboard import Dashboard
from superset.models.slice import Slice
from superset.models.sql_lab import Query
from superset.typing import FormData
from superset.superset_typing import FormData
from superset.utils.decorators import stats_timing
from superset.viz import BaseViz

Expand Down
8 changes: 7 additions & 1 deletion superset/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,13 @@
from superset.extensions import cache_manager, security_manager
from superset.models.helpers import QueryResult
from superset.sql_parse import validate_filter_clause
from superset.typing import Column, Metric, QueryObjectDict, VizData, VizPayload
from superset.superset_typing import (
Column,
Metric,
QueryObjectDict,
VizData,
VizPayload,
)
from superset.utils import core as utils, csv
from superset.utils.cache import set_and_log_cache
from superset.utils.core import (
Expand Down
Loading