Skip to content

Commit

Permalink
EOS - Data flow analysis steps that restrict snippet size and make th…
Browse files Browse the repository at this point in the history
…e entire width clickable (#34)
  • Loading branch information
Or-Geva authored Aug 7, 2023
1 parent 79d0212 commit 332e6ce
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/components/Page/Eos/ContextualAnalysis.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('ContextualAnalysis component', () => {
const { getByText } = render(<ContextualAnalysis analysisSteps={analysisSteps} />)
expect(getByText('DATA FLOW ANALYSIS')).toBeInTheDocument()
analysisSteps.forEach(step => {
const analysisStepElement = getByText(`${step.fileName} ${step.startRow}:`)
const analysisStepElement = getByText(`${step.fileName}${step.startRow}:`)
expect(analysisStepElement).toBeInTheDocument()
})
})
Expand Down
5 changes: 5 additions & 0 deletions src/components/UI/List/AnalysisStepsListElement.module.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.container {
display: flex;
width: 100%;
justify-content: space-between;
color: #a0a0a0;
font-weight: 400;
Expand All @@ -20,6 +21,10 @@
align-items: center;
}

.snippet {
color: rgba(255, 255, 255, 0.8);
}

.number {
background: #454545;
border-radius: 20px;
Expand Down
4 changes: 2 additions & 2 deletions src/components/UI/List/AnalysisStepsListElement.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ describe('AnalysisStepsListElement component', () => {
expect(buttons).toHaveLength(defaultProps.items.length)

// Assert that the button content is rendered correctly
expect(getByText('Example File 1:')).toBeInTheDocument()
expect(getByText('Test File 10:')).toBeInTheDocument()
expect(getByText('Example File1:')).toBeInTheDocument()
expect(getByText('Test File10:')).toBeInTheDocument()
})

test('calls jumpToCode when button is clicked', () => {
Expand Down
17 changes: 13 additions & 4 deletions src/components/UI/List/AnalysisStepsListElement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { IAnalysisStep } from '../../../model/analysisStep'
import css from './AnalysisStepsListElement.module.css'
import { useContext } from 'react'
import { eventManagerContext } from '../../../store/eventContext'
import Markdown from '../Markdown/Markdown'

export interface Props {
items: IAnalysisStep[]
Expand All @@ -16,6 +15,14 @@ export default function AnalysisStepsListElement(props: Props): JSX.Element {
ctx.jumpToCode(item)
}

const hideOverflowText = (text: string, max: number): string => {
if (text.length > max) {
return `${text.substring(0, max)}...`
}

return text
}

return (
<>
{props.items.map((item, i) => (
Expand All @@ -29,10 +36,12 @@ export default function AnalysisStepsListElement(props: Props): JSX.Element {
<div className={css.file} id={i.toString()}>
<div className={css.number}>{i + 1}</div>
<div className={css.row}>
{' '}
{item.fileName} {item.startRow}:{' '}
{item.fileName && hideOverflowText(item.fileName, 30)}
{item.startRow}:
</div>
<div className={css.snippet}>
{item.snippet && <div>{hideOverflowText(item.snippet, 100)}</div>}
</div>
{item.snippet && <Markdown text={item.snippet} />}
</div>
</button>
))}
Expand Down

0 comments on commit 332e6ce

Please sign in to comment.