Skip to content

Commit

Permalink
add certified
Browse files Browse the repository at this point in the history
  • Loading branch information
hughhhh authored May 19, 2022
1 parent 4dee6c0 commit 166b352
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 21 deletions.
13 changes: 13 additions & 0 deletions superset-frontend/src/views/CRUD/data/dataset/DatasetList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ const DatasetList: FunctionComponent<DatasetListProps> = ({
accessor: 'kind_icon',
disableSortBy: true,
size: 'xs',
id: 'id',
},
{
Cell: ({
Expand Down Expand Up @@ -506,6 +507,18 @@ const DatasetList: FunctionComponent<DatasetListProps> = ({
{ label: 'Physical', value: true },
],
},
{
Header: t('Certified'),
id: 'id',
urlDisplay: 'certified',
input: 'select',
operator: 'dataset_is_certified',
unfilteredLabel: t('Any'),
selects: [
{ label: t('Yes'), value: true },
{ label: t('No'), value: false },
],
},
{
Header: t('Search'),
id: 'table_name',
Expand Down
24 changes: 3 additions & 21 deletions superset/datasets/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
from flask_appbuilder.models.sqla.interface import SQLAInterface
from flask_babel import ngettext
from marshmallow import ValidationError
from sqlalchemy import not_

from superset import event_logger, is_feature_enabled
from superset.commands.importers.exceptions import NoValidFilesFoundError
Expand All @@ -53,7 +52,7 @@
from superset.datasets.commands.refresh import RefreshDatasetCommand
from superset.datasets.commands.update import UpdateDatasetCommand
from superset.datasets.dao import DatasetDAO
from superset.datasets.filters import DatasetIsNullOrEmptyFilter
from superset.datasets.filters import DatasetCertifiedFilter, DatasetIsNullOrEmptyFilter
from superset.datasets.schemas import (
DatasetPostSchema,
DatasetPutSchema,
Expand All @@ -74,24 +73,6 @@

logger = logging.getLogger(__name__)

from flask_babel import lazy_gettext as _
from sqlalchemy.orm.query import Query

from superset.views.base import BaseFilter


class DatasetCertifiedFilter(BaseFilter):
name = _("Is certified")
arg_name = "dataset_is_certified"

def apply(self, query: Query, value: Any) -> Query:
breakpoint()
if value is True:
return query.filter(SqlaTable.extra.ilike("%certification%"))
if value is False:
return query.exclude(SqlaTable.extra.ilike("%certification%"))
return query


class DatasetRestApi(BaseSupersetModelRestApi):
datamodel = SQLAInterface(SqlaTable)
Expand Down Expand Up @@ -216,8 +197,9 @@ class DatasetRestApi(BaseSupersetModelRestApi):
}
search_filters = {
"sql": [DatasetIsNullOrEmptyFilter],
"sql": [DatasetCertifiedFilter],
"id": [DatasetCertifiedFilter],
}
search_columns = ["id", "sql"]
filter_rel_fields = {"database": [["id", DatabaseFilter, lambda: []]]}
allowed_rel_fields = {"database", "owners"}
allowed_distinct_fields = {"schema"}
Expand Down
19 changes: 19 additions & 0 deletions superset/datasets/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
from typing import Any

from flask_babel import lazy_gettext as _
from sqlalchemy import not_, or_
from sqlalchemy.orm.query import Query
Expand All @@ -33,3 +35,20 @@ def apply(self, query: Query, value: bool) -> Query:
filter_clause = not_(filter_clause)

return query.filter(filter_clause)


class DatasetCertifiedFilter(BaseFilter): # pylint: disable=too-few-public-methods
name = _("Is certified")
arg_name = "dataset_is_certified"

def apply(self, query: Query, value: Any) -> Query:
if value is True:
return query.filter(SqlaTable.extra.ilike("%certification%"))
if value is False:
return query.filter(
or_(
SqlaTable.extra.notlike("%certification%"),
SqlaTable.extra.is_(None),
)
)
return query

0 comments on commit 166b352

Please sign in to comment.