-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add code insights page & components (#122)
* Add code insights page and related components * Fix styles on code insights charts components * Set height on tab carousel and clean up some styles
- Loading branch information
Showing
43 changed files
with
3,375 additions
and
78 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
70 changes: 70 additions & 0 deletions
70
src/components/CodeInsights/CodeInsightsExamples.module.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,70 @@ | ||
.card { | ||
--border-radius: 3px; | ||
--color-bg-1: #ffffff; | ||
--border-color-2: #dbe2f0; | ||
--primary: #1c7ed6; | ||
--body-bg: #fcfcff; | ||
--border-color: #e2e4e8; | ||
--body-color: #343a4d; | ||
--text-muted: #5e6e8c; | ||
--box-shadow: 0 0.25rem 0.5rem #{rgba(#343a4d, 0.07)}; | ||
|
||
flex: 1; | ||
flex-basis: 25rem; | ||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif, | ||
'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji'; | ||
} | ||
|
||
/* Need to override autogenerated styles. | ||
Also see https://github.com/sourcegraph/about/blob/40fe7625efa20c29b1563ae2a320f07b5afc27dd/website/src/components/code-insights/components/line-chart/LineChartContent.module.scss#L56 | ||
*/ | ||
|
||
.searchChart { | ||
height: 200px !important; | ||
} | ||
|
||
.chart { | ||
min-height: 13rem; | ||
flex-grow: 1; | ||
width: 100%; | ||
position: relative; | ||
flex-basis: 13rem; | ||
} | ||
|
||
.chartContent { | ||
position: absolute; | ||
width: 100%; | ||
height: 100%; | ||
top: 0; | ||
left: 0; | ||
} | ||
|
||
.actionLink { | ||
margin-top: -0.25rem; | ||
flex-shrink: 0; | ||
} | ||
|
||
.legend { | ||
display: flex; | ||
flex-direction: column; | ||
gap: 0.5rem; | ||
margin: 1rem 0 0 0; | ||
|
||
&--horizontal { | ||
flex-direction: column; | ||
} | ||
} | ||
|
||
.legendMigrationItem { | ||
min-width: 7.5rem; | ||
font-size: 12px; | ||
} | ||
|
||
.captureGroup { | ||
display: flex; | ||
height: 100%; | ||
} | ||
|
||
.keyword { | ||
color: var(--primary); | ||
} |
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,97 @@ | ||
import React from 'react' | ||
|
||
import { ParentSize } from '@visx/responsive' | ||
import classNames from 'classnames' | ||
|
||
import { CodeInsightsQueryBlock } from './components/CodeInsightsQueryBlock' | ||
import { LegendBlock, LegendItem } from './components/legend/CodeInsightLegend' | ||
import { getLineStroke } from './components/line-chart/constants' | ||
import { LineChart } from './components/line-chart/LineChart' | ||
import { LineChartSeries } from './components/line-chart/types' | ||
import { View } from './components/view/View' | ||
import { CaptureGroupInsightData, CodeInsightExampleType, SearchInsightData } from './types' | ||
|
||
import styles from './CodeInsightsExamples.module.scss' | ||
|
||
export type CodeInsightExampleProps = CodeInsightSearchExampleProps | CodeInsightCaptureExampleProps | ||
|
||
export interface CodeInsightSearchExampleProps { | ||
type: CodeInsightExampleType.Search | ||
data: SearchInsightData | ||
className?: string | ||
} | ||
|
||
export interface CodeInsightCaptureExampleProps { | ||
type: CodeInsightExampleType.Capture | ||
data: CaptureGroupInsightData | ||
className?: string | ||
} | ||
|
||
export const CodeInsightExample: React.FunctionComponent<CodeInsightExampleProps> = props => { | ||
const { type } = props | ||
|
||
if (type === CodeInsightExampleType.Search) { | ||
return <CodeInsightSearchExample {...(props as CodeInsightSearchExampleProps)} /> | ||
} | ||
|
||
return <CodeInsightCaptureExample {...(props as CodeInsightCaptureExampleProps)} /> | ||
} | ||
|
||
const CodeInsightSearchExample: React.FunctionComponent<CodeInsightSearchExampleProps> = props => { | ||
const { className, data } = props | ||
|
||
return ( | ||
<View | ||
title={data.title} | ||
subtitle={<CodeInsightsQueryBlock className="mt-1">{data.repositories}</CodeInsightsQueryBlock>} | ||
className={classNames(className, styles.card)} | ||
> | ||
<div className={styles.chart}> | ||
<ParentSize className={styles.searchChart}> | ||
{({ width, height }) => <LineChart {...data} width={width} height={height} />} | ||
</ParentSize> | ||
</div> | ||
|
||
<LegendBlock className={styles.legend}> | ||
{data.series.map(line => ( | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
<LegendItem key={line.dataKey.toString()} color={getLineStroke<any>(line)}> | ||
<span className={classNames(styles.legendMigrationItem, 'flex-shrink-0 mr-2')}> | ||
{line.name} | ||
</span> | ||
<CodeInsightsQueryBlock>{line.query}</CodeInsightsQueryBlock> | ||
</LegendItem> | ||
))} | ||
</LegendBlock> | ||
</View> | ||
) | ||
} | ||
|
||
const CodeInsightCaptureExample: React.FunctionComponent<CodeInsightCaptureExampleProps> = props => { | ||
const { className, data } = props | ||
|
||
return ( | ||
<View | ||
title={data.title} | ||
subtitle={<CodeInsightsQueryBlock className="mt-1">All repositories</CodeInsightsQueryBlock>} | ||
className={classNames(className, styles.card)} | ||
> | ||
<div className={styles.captureGroup}> | ||
<div className={styles.chart}> | ||
<ParentSize className={styles.chartContent}> | ||
{({ width, height }) => <LineChart {...data} width={width} height={height} />} | ||
</ParentSize> | ||
</div> | ||
|
||
<LegendBlock className={classNames(styles.legend, 'horizontal')}> | ||
{data.series.map(line => ( | ||
<LegendItem key={line.dataKey.toString()} color={getLineStroke<LineChartSeries<string>>(line)}> | ||
{line.name} | ||
</LegendItem> | ||
))} | ||
</LegendBlock> | ||
</div> | ||
<CodeInsightsQueryBlock className="mt-2">{data.query}</CodeInsightsQueryBlock> | ||
</View> | ||
) | ||
} |
11 changes: 11 additions & 0 deletions
11
src/components/CodeInsights/components/CodeInsightsQueryBlock.module.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,11 @@ | ||
.query { | ||
display: inline-block; | ||
width: 100%; | ||
margin: 0; | ||
padding: 0.25rem 0.5rem; | ||
font-size: 11px; | ||
border-radius: 3px; | ||
background-color: #f9fafb; | ||
font-family: sfmono-regular, consolas, menlo, dejavu sans mono, monospace; | ||
word-break: break-word; | ||
} |
9 changes: 9 additions & 0 deletions
9
src/components/CodeInsights/components/CodeInsightsQueryBlock.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,9 @@ | ||
import React from 'react' | ||
|
||
import classNames from 'classnames' | ||
|
||
import styles from './CodeInsightsQueryBlock.module.scss' | ||
|
||
export const CodeInsightsQueryBlock: React.FunctionComponent<React.HTMLAttributes<HTMLSpanElement>> = props => ( | ||
<span {...props} className={classNames(props.className, styles.query)} /> | ||
) |
22 changes: 22 additions & 0 deletions
22
src/components/CodeInsights/components/card/Card.module.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,22 @@ | ||
.card { | ||
--card-bg: var(--color-bg-1); | ||
--card-border-color: var(--border-color-2); | ||
--card-border-radius: var(--border-radius); | ||
|
||
// Added inset box shadow to prevent interactive card jump on hover and focus | ||
--hover-box-shadow: 0 0 0 1px var(--primary) inset; | ||
--card-spacer-y: 0.5rem; | ||
--card-spacer-x: 0.5rem; | ||
|
||
position: relative; | ||
display: flex; | ||
flex-direction: column; | ||
min-width: 0; // See https://github.com/twbs/bootstrap/pull/22740#issuecomment-305868106 | ||
word-wrap: break-word; | ||
background-color: var(--card-bg); | ||
background-clip: border-box; | ||
border-width: 1px; | ||
border-style: solid; | ||
border-color: var(--card-border-color); | ||
border-radius: var(--card-border-radius); | ||
} |
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,16 @@ | ||
import React from 'react' | ||
|
||
import classNames from 'classnames' | ||
|
||
import styles from './Card.module.scss' | ||
|
||
export interface CardProps extends React.HTMLAttributes<HTMLElement> {} | ||
|
||
/** | ||
* Card Element | ||
*/ | ||
export const Card: React.FunctionComponent<CardProps> = ({ children, className, ...attributes }) => ( | ||
<div className={classNames(styles.card, className)} {...attributes}> | ||
{children} | ||
</div> | ||
) |
31 changes: 31 additions & 0 deletions
31
src/components/CodeInsights/components/legend/CodeInsightLegend.module.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,31 @@ | ||
.legendList { | ||
display: flex; | ||
flex-wrap: wrap; | ||
gap: 0.5rem; | ||
|
||
// Reset ul styles (bullets, paddings, margins) | ||
list-style: none; | ||
margin: 0; | ||
padding: 0; | ||
line-height: 1.2; | ||
} | ||
|
||
.legendItem { | ||
display: flex; | ||
align-items: baseline; | ||
font-size: 12px; | ||
|
||
@media only screen and (max-width: 768px) { | ||
max-width: 100%; | ||
flex-wrap: wrap; | ||
} | ||
} | ||
|
||
.legendMark { | ||
align-self: baseline; | ||
width: 0.5rem; | ||
height: 0.5rem; | ||
flex-shrink: 0; | ||
margin-right: 0.25rem; | ||
border-radius: 50%; | ||
} |
Oops, something went wrong.