villebro commented on a change in pull request #7770: Autocomplete in the table 
browser in SQL lab is broken - Fix part 2
URL: 
https://github.com/apache/incubator-superset/pull/7770#discussion_r298796779
 
 

 ##########
 File path: superset/assets/src/components/TableSelector.jsx
 ##########
 @@ -99,15 +99,22 @@ export default class TableSelector extends 
React.PureComponent {
     });
   }
   getTableNamesBySubStr(input) {
-    const { tableName } = this.state;
     if (!this.props.dbId || !input) {
-      const options = this.addOptionIfMissing([], tableName);
+      const options = [];
       return Promise.resolve({ options });
     }
     return SupersetClient.get({
       endpoint: encodeURI(`/superset/tables/${this.props.dbId}/` +
         
`${encodeURIComponent(this.props.schema)}/${encodeURIComponent(input)}`),
-    }).then(({ json }) => ({ options: this.addOptionIfMissing(json.options, 
tableName) }));
+    }).then(({ json }) => {
+      const options = json.options.map(o => ({
+        value: o.value.table,
+        schema: o.value.schema,
+        label: o.label,
+        title: o.label,
 
 Review comment:
   To avoid confusion down the line I think it might be a good idea to align 
what is returned by the backend with this new structure. Something along these 
lines (didn't test so might contain typos):
   ```diff
   diff --git a/superset/assets/spec/javascripts/sqllab/fixtures.js 
b/superset/assets/spec/javascripts/sqllab/fixtures.js
   index 99e740c3..2b737fef 100644
   --- a/superset/assets/spec/javascripts/sqllab/fixtures.js
   +++ b/superset/assets/spec/javascripts/sqllab/fixtures.js
   @@ -343,16 +343,22 @@ export const databases = {
    export const tables = {
      options: [
        {
   -      value: { schema: 'main', table: 'birth_names' },
   +      value: 'birth_names',
   +      schema: 'main',
          label: 'birth_names',
   +      title: 'birth_names',
        },
        {
   -      value: { schema: 'main', table: 'energy_usage' },
   +      value: 'energy_usage',
   +      schema: 'main',
          label: 'energy_usage',
   +      title: 'energy_usage',
        },
        {
   -      value: { schema: 'main', table: 'wb_health_population' },
   +      value: 'wb_health_population',
   +      schema: 'main',
          label: 'wb_health_population',
   +      title: 'wb_health_population',
        },
      ],
    };
   diff --git a/superset/assets/src/components/TableSelector.jsx 
b/superset/assets/src/components/TableSelector.jsx
   index 4c9ef7a9..dc5d075c 100644
   --- a/superset/assets/src/components/TableSelector.jsx
   +++ b/superset/assets/src/components/TableSelector.jsx
   @@ -108,10 +108,10 @@ export default class TableSelector extends 
React.PureComponent {
            
`${encodeURIComponent(this.props.schema)}/${encodeURIComponent(input)}`),
        }).then(({ json }) => {
          const options = json.options.map(o => ({
   -        value: o.value.table,
   -        schema: o.value.schema,
   +        value: o.value,
   +        schema: o.schema,
            label: o.label,
   -        title: o.label,
   +        title: o.title,
          }));
          return ({ options });
        });
   @@ -138,10 +138,10 @@ export default class TableSelector extends 
React.PureComponent {
           return SupersetClient.get({ endpoint })
            .then(({ json }) => {
              const options = json.options.map(o => ({
   -            value: o.value.table,
   -            schema: o.value.schema,
   +            value: o.value,
   +            schema: o.schema,
                label: o.label,
   -            title: o.label,
   +            title: o.title,
              }));
              this.setState(() => ({
                filterOptions: createFilterOptions({ options }),
   diff --git a/superset/views/core.py b/superset/views/core.py
   index 06727f7a..8355ec39 100755
   --- a/superset/views/core.py
   +++ b/superset/views/core.py
   @@ -1627,14 +1627,16 @@ class Superset(BaseSupersetView):
                max_tables = max_items * len(tables) // total_items
                max_views = max_items * len(views) // total_items
    
   -        def get_datasource_value(ds_name: utils.DatasourceName) -> 
Dict[str, str]:
   -            return {'schema': ds_name.schema, 'table': ds_name.table}
   -
   -        table_options = [{'value': get_datasource_value(tn),
   -                          'label': get_datasource_label(tn)}
   +        table_options = [{'value': tn.table,
   +                          'schema': tn.schema,
   +                          'label': get_datasource_label(tn),
   +                          'title': get_datasource_label(tn)}
                             for tn in tables[:max_tables]]
   -        table_options.extend([{'value': get_datasource_value(vn),
   -                               'label': f'[view] 
{get_datasource_label(vn)}'}
   +        table_options.extend([{'value': vn.table,
   +                               'schema': vn.schema,
   +                               'label': f'[view] 
{get_datasource_label(vn)}',
   +                               'title': f'[view] 
{get_datasource_label(vn)}',
   +                               }
                                  for vn in views[:max_views]])
            payload = {
                'tableLength': len(tables) + len(views),
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to