Skip to content

Commit

Permalink
feat: Allow collapsing of individual diff sections in diff view argop…
Browse files Browse the repository at this point in the history
  • Loading branch information
ciiay authored Aug 13, 2021
1 parent 311926b commit d842e83
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@
font-size: 10pt;
&__title {
font-weight: bold;
.diff__collapse {
position: absolute;
right: 0;
cursor: pointer;
margin-left: auto;
margin-right: 1.5rem;
color: #495763;
font-size: 20px;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import {Checkbox, DataLoader} from 'argo-ui';
import * as jsYaml from 'js-yaml';
import * as React from 'react';
import {Diff, Hunk, parseDiff} from 'react-diff-view';
import {parseDiff} from 'react-diff-view';
import 'react-diff-view/style/index.css';
import {diffLines, formatLines} from 'unidiff';
import * as models from '../../../shared/models';
import {services} from '../../../shared/services';
import {IndividualDiffSection} from './individual-diff-section';

require('./application-resources-diff.scss');

Expand Down Expand Up @@ -74,12 +75,7 @@ ${formatLines(diffLines(i.a, i.b), {context, aname: `a/${name}}`, bname: `b/${i.
{files
.sort((a: any, b: any) => a.newPath.localeCompare(b.newPath))
.map((file: any) => (
<div key={file.newPath} className={whiteBox + ' application-component-diff__diff'}>
{showPath && <p className='application-resources-diff__diff__title'>{file.newPath}</p>}
<Diff viewType={viewType} diffType={file.type} hunks={file.hunks}>
{(hunks: any) => hunks.map((hunk: any) => <Hunk key={hunk.content} hunk={hunk} />)}
</Diff>
</div>
<IndividualDiffSection key={file.newPath} file={file} showPath={showPath} whiteBox={whiteBox} viewType={viewType} />
))}
</div>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import * as React from 'react';
import {useState} from 'react';
import {Diff, Hunk} from 'react-diff-view';
import 'react-diff-view/style/index.css';

require('./application-resources-diff.scss');

export interface IndividualDiffSectionProps {
file: any;
showPath: boolean;
whiteBox: string;
viewType: string;
}

export const IndividualDiffSection = (props: IndividualDiffSectionProps) => {
const {file, showPath, whiteBox, viewType} = props;
const [collapsed, setCollapsed] = useState(false);
return (
<div className={`${whiteBox} application-component-diff__diff`}>
{showPath && (
<p className='application-resources-diff__diff__title'>
{file.newPath}
<i className={`fa fa-caret-${collapsed ? 'down' : 'up'} diff__collapse`} onClick={() => setCollapsed(!collapsed)} />
</p>
)}
{!collapsed && (
<Diff viewType={viewType} diffType={file.type} hunks={file.hunks}>
{(hunks: any) => hunks.map((hunk: any) => <Hunk key={hunk.content} hunk={hunk} />)}
</Diff>
)}
</div>
);
};

0 comments on commit d842e83

Please sign in to comment.