mirror of
https://github.com/apache/superset.git
synced 2024-09-18 11:39:49 -04:00
move metric parsing to state instantiation (#15069)
This commit is contained in:
parent
821519fcfa
commit
0c470feaef
@ -233,4 +233,21 @@ describe('DatasourceEditor RTL', () => {
|
|||||||
);
|
);
|
||||||
expect(warningMarkdown.value).toEqual('someone');
|
expect(warningMarkdown.value).toEqual('someone');
|
||||||
});
|
});
|
||||||
|
it('properly updates the metric information', async () => {
|
||||||
|
render(<DatasourceEditor {...props} />, {
|
||||||
|
useRedux: true,
|
||||||
|
});
|
||||||
|
const metricButton = screen.getByTestId('collection-tab-Metrics');
|
||||||
|
userEvent.click(metricButton);
|
||||||
|
const expandToggle = await screen.findAllByLabelText(/toggle expand/i);
|
||||||
|
userEvent.click(expandToggle[1]);
|
||||||
|
const certifiedBy = await screen.findByPlaceholderText(/certified by/i);
|
||||||
|
userEvent.type(certifiedBy, 'I am typing a new name');
|
||||||
|
const certificationDetails = await screen.findByPlaceholderText(
|
||||||
|
/certification details/i,
|
||||||
|
);
|
||||||
|
expect(certifiedBy.value).toEqual('I am typing a new name');
|
||||||
|
userEvent.type(certificationDetails, 'I am typing something new');
|
||||||
|
expect(certificationDetails.value).toEqual('I am typing something new');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -307,7 +307,21 @@ class DatasourceEditor extends React.PureComponent {
|
|||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
datasource: props.datasource,
|
datasource: {
|
||||||
|
...props.datasource,
|
||||||
|
metrics: props.datasource.metrics?.map(metric => {
|
||||||
|
const {
|
||||||
|
certification: { details, certified_by: certifiedBy } = {},
|
||||||
|
warning_markdown: warningMarkdown,
|
||||||
|
} = JSON.parse(metric.extra || '{}') || {};
|
||||||
|
return {
|
||||||
|
...metric,
|
||||||
|
certification_details: details || '',
|
||||||
|
warning_markdown: warningMarkdown || '',
|
||||||
|
certified_by: certifiedBy,
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
},
|
||||||
errors: [],
|
errors: [],
|
||||||
isDruid:
|
isDruid:
|
||||||
props.datasource.type === 'druid' ||
|
props.datasource.type === 'druid' ||
|
||||||
@ -936,18 +950,7 @@ class DatasourceEditor extends React.PureComponent {
|
|||||||
</Fieldset>
|
</Fieldset>
|
||||||
</FormContainer>
|
</FormContainer>
|
||||||
}
|
}
|
||||||
collection={this.state.datasource.metrics?.map(metric => {
|
collection={this.state.datasource.metrics}
|
||||||
const {
|
|
||||||
certification: { details, certified_by: certifiedBy } = {},
|
|
||||||
warning_markdown: warningMarkdown,
|
|
||||||
} = JSON.parse(metric.extra || '{}') || {};
|
|
||||||
return {
|
|
||||||
...metric,
|
|
||||||
certification_details: details || '',
|
|
||||||
warning_markdown: warningMarkdown || '',
|
|
||||||
certified_by: certifiedBy,
|
|
||||||
};
|
|
||||||
})}
|
|
||||||
allowAddItem
|
allowAddItem
|
||||||
onChange={this.onDatasourcePropChange.bind(this, 'metrics')}
|
onChange={this.onDatasourcePropChange.bind(this, 'metrics')}
|
||||||
itemGenerator={() => ({
|
itemGenerator={() => ({
|
||||||
|
Loading…
Reference in New Issue
Block a user