eschutho commented on code in PR #20281:
URL: https://github.com/apache/superset/pull/20281#discussion_r904087362


##########
superset-frontend/src/explore/components/controls/DatasourceControl/index.jsx:
##########
@@ -122,23 +125,59 @@ const EDIT_DATASET = 'edit_dataset';
 const QUERY_PREVIEW = 'query_preview';
 const SAVE_AS_DATASET = 'save_as_dataset';
 
+// If the string is longer than this value's number characters we add
+// a tooltip for user can see the full name by hovering over the visually 
truncated string in UI
+const VISIBLE_TITLE_LENGTH = 25;
+
+// Assign icon for each DatasourceType.  If no icon assingment is found in the 
lookup, no icon will render
+export const datasourceIconLookup = {
+  [DatasourceType.Query]: (
+    <Icons.ConsoleSqlOutlined className="datasource-svg" />
+  ),
+  [DatasourceType.Table]: <Icons.DatasetPhysical className="datasource-svg" />,
+};
+
+// Render title for datasource with tooltip only if text is longer than 
VISIBLE_TITLE_LENGTH
+export const renderDatasourceTitle = displayString =>
+  displayString.length > VISIBLE_TITLE_LENGTH ? (
+    // Add a tooltip only for long names that will be visually truncated
+    <Tooltip title={displayString}>
+      <span className="title-select">{displayString}</span>
+    </Tooltip>
+  ) : (
+    <span title={displayString} className="title-select">
+      {displayString}
+    </span>
+  );
+
+// Different data source types use different attributes for the display title
+export const getDatasourceTitle = datasource => {
+  let text = '';
+  const dataSourceType = datasource?.type;
+  if (dataSourceType) {
+    switch (dataSourceType) {
+      case DatasourceType.Query:
+        text = datasource?.sql ?? '';
+        break;
+      default:
+        text = datasource?.name ?? '';

Review Comment:
   similar comment here re: duck typing. You may want to do something like 'if 
it has a name use it, otherwise, use sql if it has it'



-- 
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.

To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org
For additional commands, e-mail: notifications-h...@superset.apache.org

Reply via email to