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: add certifiedby & certification details fields to the edit dataset columns fields #16454

Merged
merged 22 commits into from
Sep 22, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
00a17ed
add migration
pkdotson Aug 25, 2021
75fdca9
add backend and frontend for certified
pkdotson Aug 25, 2021
75ad447
update migration with batch
pkdotson Aug 27, 2021
03ac0c7
fix integration test and update Updating.md
pkdotson Aug 31, 2021
a0290ba
Merge branch 'master' of https://github.com/preset-io/superset into a…
pkdotson Aug 31, 2021
ba2059e
Update superset-frontend/src/datasource/DatasourceEditor.jsx
pkdotson Sep 9, 2021
b70d320
Update superset-frontend/src/datasource/DatasourceEditor.jsx
pkdotson Sep 9, 2021
22e8ce2
Update superset-frontend/src/datasource/DatasourceEditor.jsx
pkdotson Sep 9, 2021
393dac2
Merge branch 'master' of https://github.com/preset-io/superset into a…
pkdotson Sep 9, 2021
5c292e0
change method name
pkdotson Sep 9, 2021
dde96cf
add tooltip info
pkdotson Sep 13, 2021
b455c96
add mixin
pkdotson Sep 14, 2021
9119334
Merge branch 'master' of https://github.com/preset-io/superset into a…
pkdotson Sep 14, 2021
2d8264b
merge heads
pkdotson Sep 15, 2021
b9aecae
Merge branch 'master' into add-certified-columns
pkdotson Sep 15, 2021
aa1d81b
address comments
pkdotson Sep 20, 2021
96ef64c
fix select label styles
pkdotson Sep 20, 2021
c994637
Merge branch 'add-certified-columns' of https://github.com/preset-io/…
pkdotson Sep 20, 2021
29aa9bc
add extra field
pkdotson Sep 20, 2021
a3d71bd
fix test?
pkdotson Sep 20, 2021
a689c25
Merge branch 'master' of https://github.com/preset-io/superset into a…
pkdotson Sep 20, 2021
92b2552
add extra field to put schema
pkdotson Sep 21, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 47 additions & 4 deletions superset-frontend/src/datasource/DatasourceEditor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ const ColumnButtonWrapper = styled.div`
${({ theme }) => `margin-bottom: ${theme.gridUnit * 2}px`}
`;

const StyledLabelWrapper = styled.div`
display: flex;
align-items: center;
span {
margin-right: ${({ theme }) => theme.gridUnit}px;
}
`;

const checkboxGenerator = (d, onChange) => (
<CheckboxControl value={d} onChange={onChange} />
);
Expand Down Expand Up @@ -235,6 +243,26 @@ function ColumnCollectionTable({
/>
}
/>
<Field
fieldKey="certified_by"
label={t('Certified By')}
control={
<TextControl
controlId="certified"
placeholder={t('Certified By')}
/>
}
/>
<Field
fieldKey="certification_details"
label={t('Certification Details')}
control={
<TextControl
controlId="certificationDetails"
placeholder={t('Certification Details')}
/>
}
/>
</Fieldset>
</FormContainer>
}
Expand All @@ -247,11 +275,27 @@ function ColumnCollectionTable({
}}
onChange={onChange}
itemRenderers={{
column_name: (v, onItemChange) =>
column_name: (v, onItemChange, _, record) =>
editableColumnName ? (
<EditableTitle canEdit title={v} onSaveTitle={onItemChange} />
<StyledLabelWrapper>
{record.is_certified && (
<CertifiedIcon
certifiedBy={record.certified_by}
details={record.certification_details}
/>
)}
<EditableTitle canEdit title={v} onSaveTitle={onItemChange} />
</StyledLabelWrapper>
) : (
v
<StyledLabelWrapper>
{record.is_certified && (
<CertifiedIcon
certifiedBy={record.certified_by}
details={record.certification_details}
/>
)}
{v}
</StyledLabelWrapper>
),
type: d => (d ? <Label>{d}</Label> : null),
is_dttm: checkboxGenerator,
Expand Down Expand Up @@ -1084,7 +1128,6 @@ class DatasourceEditor extends React.PureComponent {
const { datasource, activeTabKey } = this.state;
const { metrics } = datasource;
const sortedMetrics = metrics?.length ? this.sortMetrics(metrics) : [];

return (
<DatasourceContainer>
{this.renderErrors()}
Expand Down
18 changes: 12 additions & 6 deletions superset-frontend/src/datasource/DatasourceModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,17 @@ interface DatasourceModalProps {
show: boolean;
}

function buildMetricExtraJsonObject(metric: Record<string, unknown>) {
function buildExtraJsonObjects(item: Record<string, unknown>) {
const certification =
metric?.certified_by || metric?.certification_details
item?.certified_by || item?.certification_details
? {
certified_by: metric?.certified_by,
details: metric?.certification_details,
certified_by: item?.certified_by,
details: item?.certification_details,
}
: undefined;
return JSON.stringify({
certification,
warning_markdown: metric?.warning_markdown,
warning_markdown: item?.warning_markdown,
});
}

Expand Down Expand Up @@ -109,7 +109,13 @@ const DatasourceModal: FunctionComponent<DatasourceModalProps> = ({
metrics: currentDatasource?.metrics?.map(
(metric: Record<string, unknown>) => ({
...metric,
extra: buildMetricExtraJsonObject(metric),
extra: buildExtraJsonObjects(metric),
}),
),
columns: currentDatasource?.columns?.map(
(column: Record<string, unknown>) => ({
...column,
extra: buildExtraJsonObjects(column),
}),
),
type: currentDatasource.type || currentDatasource.datasource_type,
Expand Down
35 changes: 34 additions & 1 deletion superset/connectors/sqla/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ class TableColumn(Model, BaseColumn):
is_dttm = Column(Boolean, default=False)
expression = Column(Text)
python_date_format = Column(String(255))
extra = Column(Text)

export_fields = [
"table_id",
Expand All @@ -200,6 +201,7 @@ class TableColumn(Model, BaseColumn):
"expression",
"description",
"python_date_format",
"extra",
]

update_from_object_fields = [s for s in export_fields if s not in ("table_id",)]
Expand Down Expand Up @@ -267,6 +269,28 @@ def get_sqla_col(self, label: Optional[str] = None) -> Column:
def datasource(self) -> RelationshipProperty:
return self.table

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

@property
def is_certified(self) -> bool:
return bool(self.get_extra_dict().get("certification"))

@property
def certified_by(self) -> Optional[str]:
return self.get_extra_dict().get("certification", {}).get("certified_by")

@property
def certification_details(self) -> Optional[str]:
return self.get_extra_dict().get("certification", {}).get("details")

@property
def warning_markdown(self) -> Optional[str]:
return self.get_extra_dict().get("warning_markdown")

def get_time_filter(
self,
start_dttm: DateTime,
Expand Down Expand Up @@ -374,8 +398,17 @@ def data(self) -> Dict[str, Any]:
"type",
"type_generic",
"python_date_format",
"is_certified",
"certified_by",
"certification_details",
"warning_markdown",
)
return {s: getattr(self, s) for s in attrs if hasattr(self, s)}

attr_dict = {s: getattr(self, s) for s in attrs if hasattr(self, s)}

attr_dict.update(super().data)

return attr_dict


class SqlMetric(Model, BaseMetric):
Expand Down
9 changes: 9 additions & 0 deletions superset/connectors/sqla/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class TableColumnInlineView(CompactCRUDMixin, SupersetModelView):
"expression",
"is_dttm",
"python_date_format",
"extra",
]
add_columns = edit_columns
list_columns = [
Expand Down Expand Up @@ -129,6 +130,14 @@ class TableColumnInlineView(CompactCRUDMixin, SupersetModelView):
),
True,
),
"extra": utils.markdown(
"Extra data to specify column metadata. Currently supports "
'certification data of the format: `{ "certification": "certified_by": '
'"Taylor Swift", "details": "This column is the source of truth." '
"} }`. This should be modified from the edit datasource model in "
"Explore to ensure correct formatting.",
True,
),
}
label_columns = {
"column_name": _("Column"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# 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.
"""add_extra_column_to_columns_model

Revision ID: 181091c0ef16
Revises: 07071313dd52
Create Date: 2021-08-24 23:27:30.403308

"""

# revision identifiers, used by Alembic.
revision = "181091c0ef16"
down_revision = "07071313dd52"

import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects import postgresql


def upgrade():
op.add_column("table_columns", sa.Column("extra", sa.Text(), nullable=True))


def downgrade():
op.drop_column("table_columns", "extra")