Skip to content

Commit

Permalink
feat: add certification info to table selector
Browse files Browse the repository at this point in the history
  • Loading branch information
erik_ritter committed Nov 24, 2020
1 parent db73869 commit a9891d0
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,12 @@ const schemaOptions = {
};
const selectedSchema = { label: 'main', title: 'main', value: 'main' };
const selectedTable = {
extra: null,
label: 'birth_names',
schema: 'main',
title: 'birth_names',
value: 'birth_names',
type: undefined,
value: 'birth_names',
};

async function mountAndWait(props = mockedProps) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ import TooltipWrapper from 'src/components/TooltipWrapper';
interface CertifiedIconWithTooltipProps {
certifiedBy?: string;
details?: string;
size?: number;
}

function CertifiedIconWithTooltip({
certifiedBy,
details,
size = 24,
}: CertifiedIconWithTooltipProps) {
return (
<TooltipWrapper
Expand All @@ -40,7 +42,12 @@ function CertifiedIconWithTooltip({
</>
}
>
<Icon color={supersetTheme.colors.primary.base} name="certified" />
<Icon
color={supersetTheme.colors.primary.base}
height={size}
width={size}
name="certified"
/>
</TooltipWrapper>
);
}
Expand Down
27 changes: 20 additions & 7 deletions superset-frontend/src/components/TableSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import FormLabel from 'src/components/FormLabel';

import DatabaseSelector from './DatabaseSelector';
import RefreshLabel from './RefreshLabel';
import CertifiedIconWithTooltip from './CertifiedIconWithTooltip';

const FieldTitle = styled.p`
color: ${({ theme }) => theme.colors.secondary.light2};
Expand Down Expand Up @@ -65,7 +66,14 @@ const TableSelectorWrapper = styled.div`
`;

const TableLabel = styled.span`
align-items: center;
display: flex;
white-space: nowrap;
> svg,
> small {
margin-right: ${({ theme }) => theme.gridUnit}px;
}
`;

interface TableSelectorProps {
Expand Down Expand Up @@ -146,6 +154,7 @@ const TableSelector: FunctionComponent<TableSelectorProps> = ({
label: o.label,
title: o.title,
type: o.type,
extra: o?.extra,
}));
setTableLoading(false);
setTableOptions(options);
Expand Down Expand Up @@ -244,13 +253,16 @@ const TableSelector: FunctionComponent<TableSelectorProps> = ({
function renderTableOption(option: any) {
return (
<TableLabel title={option.label}>
<span className="m-r-5">
<small className="text-muted">
<i
className={`fa fa-${option.type === 'view' ? 'eye' : 'table'}`}
/>
</small>
</span>
{option.extra?.certification && (
<CertifiedIconWithTooltip
certifiedBy={option.extra.certification.certified_by}
details={option.extra.certification.details}
size={20}
/>
)}
<small className="text-muted">
<i className={`fa fa-${option.type === 'view' ? 'eye' : 'table'}`} />
</small>
{option.label}
</TableLabel>
);
Expand Down Expand Up @@ -308,6 +320,7 @@ const TableSelector: FunctionComponent<TableSelectorProps> = ({
// @ts-ignore
value={currentTableName}
optionRenderer={renderTableOption}
valueRenderer={renderTableOption}
/>
);
} else if (formMode) {
Expand Down
7 changes: 7 additions & 0 deletions superset/connectors/sqla/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,13 @@ def data(self) -> Dict[str, Any]:
data_["is_sqllab_view"] = self.is_sqllab_view
return data_

@property
def extra_dict(self) -> Dict[str, Any]:
try:
return json.loads(self.extra)
except (TypeError, json.JSONDecodeError):
return {}

def values_for_column(self, column_name: str, limit: int = 10000) -> List[Any]:
"""Runs query against sqla to retrieve some
sample values for the given column.
Expand Down
5 changes: 5 additions & 0 deletions superset/views/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -981,13 +981,18 @@ def get_datasource_label(ds_name: utils.DatasourceName) -> str:
max_tables = max_items * len(tables) // total_items
max_views = max_items * len(views) // total_items

dataset_tables = {table.name: table for table in database.tables}

table_options = [
{
"value": tn.table,
"schema": tn.schema,
"label": get_datasource_label(tn),
"title": get_datasource_label(tn),
"type": "table",
"extra": dataset_tables[f"{tn.schema}.{tn.table}"].extra_dict
if (f"{tn.schema}.{tn.table}" in dataset_tables)
else None,
}
for tn in tables[:max_tables]
]
Expand Down
7 changes: 4 additions & 3 deletions tests/core_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,19 +155,20 @@ def test_get_superset_tables_substr(self):
response = json.loads(rv.data.decode("utf-8"))
self.assertEqual(rv.status_code, 200)

expeted_response = {
expected_response = {
"options": [
{
"label": "ab_role",
"schema": schema_name,
"title": "ab_role",
"type": "table",
"value": "ab_role",
"extra": None,
}
],
"tableLength": 1,
}
self.assertEqual(response, expeted_response)
self.assertEqual(response, expected_response)

def test_get_superset_tables_not_found(self):
self.login(username="admin")
Expand Down Expand Up @@ -862,7 +863,7 @@ def test_select_star(self):

def test_get_select_star_not_allowed(self):
"""
Database API: Test get select star not allowed
Database API: Test get select star not allowed
"""
self.login(username="gamma")
example_db = utils.get_example_database()
Expand Down

0 comments on commit a9891d0

Please sign in to comment.