-
Notifications
You must be signed in to change notification settings - Fork 245
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ui: Add user guide link for table sampling feature (#1460)
* ui: Add user guide link for table sampling feature
- Loading branch information
Showing
7 changed files
with
166 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,3 +35,4 @@ table_sampling: | |
sample_rates: | ||
- 0.1 | ||
default_sample_rate: 0 # 0 means no sampling | ||
sample_user_guide_link: '' |
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
5 changes: 5 additions & 0 deletions
5
querybook/webapp/components/DataDocTableSamplingInfo/DataDocTableSamplingInfo.scss
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,5 @@ | ||
.DataDocTableSamplingInfo { | ||
.link-text-highlight { | ||
color: var(--color-accent-dark); | ||
} | ||
} |
87 changes: 87 additions & 0 deletions
87
querybook/webapp/components/DataDocTableSamplingInfo/DataDocTableSamplingInfo.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,87 @@ | ||
import React from 'react'; | ||
|
||
import { QueryComparison } from 'components/TranspileQueryModal/QueryComparison'; | ||
import PublicConfig from 'config/querybook_public_config.yaml'; | ||
import { ISamplingTables } from 'const/datadoc'; | ||
import { useResource } from 'hooks/useResource'; | ||
import { formatError } from 'lib/utils/error'; | ||
import { QueryTransformResource } from 'resource/queryTransform'; | ||
import { Link } from 'ui/Link/Link'; | ||
import { Loading } from 'ui/Loading/Loading'; | ||
import { ErrorMessage } from 'ui/Message/ErrorMessage'; | ||
import { Modal } from 'ui/Modal/Modal'; | ||
|
||
import './DataDocTableSamplingInfo.scss'; | ||
|
||
interface IProps { | ||
query: string; | ||
language: string; | ||
samplingTables: ISamplingTables; | ||
onHide: () => void; | ||
} | ||
|
||
export const DataDocTableSamplingInfo: React.FC<IProps> = ({ | ||
query, | ||
language, | ||
samplingTables, | ||
onHide, | ||
}) => { | ||
const sampleUserGuideLink = | ||
PublicConfig.table_sampling?.sample_user_guide_link ?? ''; | ||
|
||
const { | ||
data: sampledQuery, | ||
isLoading, | ||
isError, | ||
error, | ||
} = useResource( | ||
React.useCallback( | ||
() => | ||
QueryTransformResource.getSampledQuery( | ||
query, | ||
language, | ||
samplingTables | ||
), | ||
[language, query, samplingTables] | ||
) | ||
); | ||
|
||
let contentDOM = null; | ||
|
||
if (isLoading) { | ||
contentDOM = <Loading />; | ||
} else if (isError) { | ||
contentDOM = ( | ||
<ErrorMessage title={'Failed to sample query.'}> | ||
{formatError(error)} | ||
</ErrorMessage> | ||
); | ||
} else { | ||
contentDOM = ( | ||
<Modal onHide={onHide}> | ||
<div className="DataDocTableSamplingInfo"> | ||
By enabling table sampling, it will use a sample version of | ||
the table or apply table sample to the original table. | ||
{sampleUserGuideLink ? ( | ||
<span> | ||
{' '} | ||
Please see more about it{' '} | ||
<Link to={sampleUserGuideLink} newTab> | ||
<span className="link-text-highlight"> | ||
here | ||
</span> | ||
</Link> | ||
</span> | ||
) : null} | ||
</div> | ||
<QueryComparison | ||
fromQuery={query} | ||
toQuery={sampledQuery} | ||
fromQueryTitle={'Original Query'} | ||
toQueryTitle={'Transformed Query'} | ||
/> | ||
</Modal> | ||
); | ||
} | ||
return contentDOM; | ||
}; |
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