-
Notifications
You must be signed in to change notification settings - Fork 241
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add column hover tooltip and column value auto completion (#1526)
* feat: add column hover tooltip and column value auto completion * comments * address comments
- Loading branch information
Showing
16 changed files
with
634 additions
and
430 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
querybook/webapp/components/CodeMirrorTooltip/TableColumnTooltip.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { ContentState } from 'draft-js'; | ||
import React from 'react'; | ||
|
||
import { TableTag } from 'components/DataTableTags/DataTableTags'; | ||
import { IDataColumn } from 'const/metastore'; | ||
import { useResource } from 'hooks/useResource'; | ||
import { TableColumnResource } from 'resource/table'; | ||
import { Tag, TagGroup } from 'ui/Tag/Tag'; | ||
|
||
interface IProps { | ||
column: IDataColumn; | ||
} | ||
|
||
export const TableColumnTooltip: React.FunctionComponent<IProps> = ({ | ||
column, | ||
}) => { | ||
const { data: tags } = useResource( | ||
React.useCallback( | ||
() => TableColumnResource.getTags(column.id), | ||
[column.id] | ||
) | ||
); | ||
|
||
const tagsDOM = (tags || []).map((tag) => ( | ||
<TableTag tag={tag} readonly={true} key={tag.id} mini={true} /> | ||
)); | ||
|
||
const description = | ||
typeof column.description === 'string' | ||
? column.description | ||
: (column.description as ContentState).getPlainText(); | ||
|
||
const statsDOM = (column.stats || []).map((stat, i) => { | ||
const formattedValue = Array.isArray(stat.value) | ||
? stat.value.join(', ') | ||
: stat.value; | ||
return ( | ||
<TagGroup key={stat.key}> | ||
<Tag mini>{stat.key}</Tag> | ||
<Tag highlighted mini> | ||
{formattedValue} | ||
</Tag> | ||
</TagGroup> | ||
); | ||
}); | ||
|
||
const contentDOM = ( | ||
<> | ||
<div className="tooltip-header flex-row"> | ||
<div>{column.name}</div> | ||
</div> | ||
{column.type && ( | ||
<div className="mt4 flex-row"> | ||
<div className="tooltip-title">Type:</div> | ||
<div className="tooltip-content">{column.type}</div> | ||
</div> | ||
)} | ||
{tagsDOM.length > 0 && ( | ||
<div className="DataTableTags flex-row">{tagsDOM}</div> | ||
)} | ||
{column.comment && ( | ||
<div className="mt4"> | ||
<div className="tooltip-title">Definition</div> | ||
<div className="tooltip-content">{column.comment}</div> | ||
</div> | ||
)} | ||
{description && ( | ||
<div className="mt4"> | ||
<div className="tooltip-title">Description</div> | ||
<div className="tooltip-content">{description}</div> | ||
</div> | ||
)} | ||
{statsDOM.length && ( | ||
<div className="mt4"> | ||
<div className="tooltip-title">Stats</div> | ||
<div className="tooltip-content">{statsDOM}</div> | ||
</div> | ||
)} | ||
</> | ||
); | ||
|
||
return <div className="rich-text-content">{contentDOM}</div>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.