mirror of
https://github.com/apache/superset.git
synced 2024-09-16 02:29:39 -04:00
feat: add main datetime column to dataset editor (#17739)
* feat: add main dttm col to dataset editor * Add tests
This commit is contained in:
parent
215ee08a47
commit
63d9693f21
@ -167,6 +167,7 @@ export default {
|
|||||||
column_types: [0, 1, 2],
|
column_types: [0, 1, 2],
|
||||||
id,
|
id,
|
||||||
granularity_sqla: [['ds', 'ds']],
|
granularity_sqla: [['ds', 'ds']],
|
||||||
|
main_dttm_col: 'ds',
|
||||||
name: 'birth_names',
|
name: 'birth_names',
|
||||||
owners: [{ first_name: 'joe', last_name: 'man', id: 1 }],
|
owners: [{ first_name: 'joe', last_name: 'man', id: 1 }],
|
||||||
database: {
|
database: {
|
||||||
|
@ -156,7 +156,9 @@ CollectionTabTitle.propTypes = {
|
|||||||
|
|
||||||
function ColumnCollectionTable({
|
function ColumnCollectionTable({
|
||||||
columns,
|
columns,
|
||||||
onChange,
|
datasource,
|
||||||
|
onColumnsChange,
|
||||||
|
onDatasourceChange,
|
||||||
editableColumnName,
|
editableColumnName,
|
||||||
showExpression,
|
showExpression,
|
||||||
allowAddItem,
|
allowAddItem,
|
||||||
@ -166,8 +168,22 @@ function ColumnCollectionTable({
|
|||||||
return (
|
return (
|
||||||
<CollectionTable
|
<CollectionTable
|
||||||
collection={columns}
|
collection={columns}
|
||||||
tableColumns={['column_name', 'type', 'is_dttm', 'filterable', 'groupby']}
|
tableColumns={[
|
||||||
sortColumns={['column_name', 'type', 'is_dttm', 'filterable', 'groupby']}
|
'column_name',
|
||||||
|
'type',
|
||||||
|
'is_dttm',
|
||||||
|
'main_dttm_col',
|
||||||
|
'filterable',
|
||||||
|
'groupby',
|
||||||
|
]}
|
||||||
|
sortColumns={[
|
||||||
|
'column_name',
|
||||||
|
'type',
|
||||||
|
'is_dttm',
|
||||||
|
'main_dttm_col',
|
||||||
|
'filterable',
|
||||||
|
'groupby',
|
||||||
|
]}
|
||||||
allowDeletes
|
allowDeletes
|
||||||
allowAddItem={allowAddItem}
|
allowAddItem={allowAddItem}
|
||||||
itemGenerator={itemGenerator}
|
itemGenerator={itemGenerator}
|
||||||
@ -284,9 +300,10 @@ function ColumnCollectionTable({
|
|||||||
type: t('Data type'),
|
type: t('Data type'),
|
||||||
groupby: t('Is dimension'),
|
groupby: t('Is dimension'),
|
||||||
is_dttm: t('Is temporal'),
|
is_dttm: t('Is temporal'),
|
||||||
|
main_dttm_col: t('Default datetime'),
|
||||||
filterable: t('Is filterable'),
|
filterable: t('Is filterable'),
|
||||||
}}
|
}}
|
||||||
onChange={onChange}
|
onChange={onColumnsChange}
|
||||||
itemRenderers={{
|
itemRenderers={{
|
||||||
column_name: (v, onItemChange, _, record) =>
|
column_name: (v, onItemChange, _, record) =>
|
||||||
editableColumnName ? (
|
editableColumnName ? (
|
||||||
@ -310,6 +327,25 @@ function ColumnCollectionTable({
|
|||||||
{v}
|
{v}
|
||||||
</StyledLabelWrapper>
|
</StyledLabelWrapper>
|
||||||
),
|
),
|
||||||
|
main_dttm_col: (value, _onItemChange, _label, record) => {
|
||||||
|
const checked = datasource.main_dttm_col === record.column_name;
|
||||||
|
const disabled = !columns.find(
|
||||||
|
column => column.column_name === record.column_name,
|
||||||
|
).is_dttm;
|
||||||
|
return (
|
||||||
|
<Radio
|
||||||
|
data-test={`radio-default-dttm-${record.column_name}`}
|
||||||
|
checked={checked}
|
||||||
|
disabled={disabled}
|
||||||
|
onChange={() =>
|
||||||
|
onDatasourceChange({
|
||||||
|
...datasource,
|
||||||
|
main_dttm_col: record.column_name,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
},
|
||||||
type: d => (d ? <Label>{d}</Label> : null),
|
type: d => (d ? <Label>{d}</Label> : null),
|
||||||
is_dttm: checkboxGenerator,
|
is_dttm: checkboxGenerator,
|
||||||
filterable: checkboxGenerator,
|
filterable: checkboxGenerator,
|
||||||
@ -320,7 +356,9 @@ function ColumnCollectionTable({
|
|||||||
}
|
}
|
||||||
ColumnCollectionTable.propTypes = {
|
ColumnCollectionTable.propTypes = {
|
||||||
columns: PropTypes.array.isRequired,
|
columns: PropTypes.array.isRequired,
|
||||||
onChange: PropTypes.func.isRequired,
|
datasource: PropTypes.object.isRequired,
|
||||||
|
onColumnsChange: PropTypes.func.isRequired,
|
||||||
|
onDatasourceChange: PropTypes.func.isRequired,
|
||||||
editableColumnName: PropTypes.bool,
|
editableColumnName: PropTypes.bool,
|
||||||
showExpression: PropTypes.bool,
|
showExpression: PropTypes.bool,
|
||||||
allowAddItem: PropTypes.bool,
|
allowAddItem: PropTypes.bool,
|
||||||
@ -1227,9 +1265,11 @@ class DatasourceEditor extends React.PureComponent {
|
|||||||
<ColumnCollectionTable
|
<ColumnCollectionTable
|
||||||
className="columns-table"
|
className="columns-table"
|
||||||
columns={this.state.databaseColumns}
|
columns={this.state.databaseColumns}
|
||||||
onChange={databaseColumns =>
|
datasource={datasource}
|
||||||
|
onColumnsChange={databaseColumns =>
|
||||||
this.setColumns({ databaseColumns })
|
this.setColumns({ databaseColumns })
|
||||||
}
|
}
|
||||||
|
onDatasourceChange={this.onDatasourceChange}
|
||||||
/>
|
/>
|
||||||
{this.state.metadataLoading && <Loading />}
|
{this.state.metadataLoading && <Loading />}
|
||||||
</div>
|
</div>
|
||||||
@ -1245,9 +1285,11 @@ class DatasourceEditor extends React.PureComponent {
|
|||||||
>
|
>
|
||||||
<ColumnCollectionTable
|
<ColumnCollectionTable
|
||||||
columns={this.state.calculatedColumns}
|
columns={this.state.calculatedColumns}
|
||||||
onChange={calculatedColumns =>
|
onColumnsChange={calculatedColumns =>
|
||||||
this.setColumns({ calculatedColumns })
|
this.setColumns({ calculatedColumns })
|
||||||
}
|
}
|
||||||
|
onDatasourceChange={this.onDatasourceChange}
|
||||||
|
datasource={datasource}
|
||||||
editableColumnName
|
editableColumnName
|
||||||
showExpression
|
showExpression
|
||||||
allowAddItem
|
allowAddItem
|
||||||
|
@ -230,4 +230,30 @@ describe('DatasourceEditor RTL', () => {
|
|||||||
userEvent.type(certificationDetails, 'I am typing something new');
|
userEvent.type(certificationDetails, 'I am typing something new');
|
||||||
expect(certificationDetails.value).toEqual('I am typing something new');
|
expect(certificationDetails.value).toEqual('I am typing something new');
|
||||||
});
|
});
|
||||||
|
it('shows the default datetime column', async () => {
|
||||||
|
render(<DatasourceEditor {...props} />, { useRedux: true });
|
||||||
|
const metricButton = screen.getByTestId('collection-tab-Columns');
|
||||||
|
userEvent.click(metricButton);
|
||||||
|
|
||||||
|
const dsDefaultDatetimeRadio = screen.getByTestId('radio-default-dttm-ds');
|
||||||
|
expect(dsDefaultDatetimeRadio).toBeChecked();
|
||||||
|
|
||||||
|
const genderDefaultDatetimeRadio = screen.getByTestId(
|
||||||
|
'radio-default-dttm-gender',
|
||||||
|
);
|
||||||
|
expect(genderDefaultDatetimeRadio).not.toBeChecked();
|
||||||
|
});
|
||||||
|
it('allows choosing only temporal columns as the default datetime', async () => {
|
||||||
|
render(<DatasourceEditor {...props} />, { useRedux: true });
|
||||||
|
const metricButton = screen.getByTestId('collection-tab-Columns');
|
||||||
|
userEvent.click(metricButton);
|
||||||
|
|
||||||
|
const dsDefaultDatetimeRadio = screen.getByTestId('radio-default-dttm-ds');
|
||||||
|
expect(dsDefaultDatetimeRadio).toBeEnabled();
|
||||||
|
|
||||||
|
const genderDefaultDatetimeRadio = screen.getByTestId(
|
||||||
|
'radio-default-dttm-gender',
|
||||||
|
);
|
||||||
|
expect(genderDefaultDatetimeRadio).toBeDisabled();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
# specific language governing permissions and limitations
|
# specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
table_name: cleaned_sales_data
|
table_name: cleaned_sales_data
|
||||||
main_dttm_col: OrderDate
|
main_dttm_col: order_date
|
||||||
description: null
|
description: null
|
||||||
default_endpoint: null
|
default_endpoint: null
|
||||||
offset: 0
|
offset: 0
|
||||||
|
Loading…
Reference in New Issue
Block a user