-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Update viewFile toggle in commit detail page #3623
Changes from all commits
be2a3b9
f12cf4f
f3cf51d
1558e21
bbdda7e
12d7511
497eacd
a2cc578
10578f5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,6 @@ import { useLocation, useParams } from 'react-router-dom' | |
|
||
import { ImpactedFileType, useCommit } from 'services/commit' | ||
import { OrderingDirection, OrderingParameter } from 'services/pull/usePull' | ||
import A from 'ui/A' | ||
import Icon from 'ui/Icon' | ||
import Spinner from 'ui/Spinner' | ||
import TotalsNumber from 'ui/TotalsNumber' | ||
|
@@ -71,7 +70,7 @@ function getFilter(sorting: Array<{ id: string; desc: boolean }>) { | |
return undefined | ||
} | ||
|
||
function getColumns({ commitId }: { commitId: string }) { | ||
function getColumns() { | ||
return [ | ||
columnHelper.accessor('headName', { | ||
id: 'name', | ||
|
@@ -83,42 +82,14 @@ function getColumns({ commitId }: { commitId: string }) { | |
return ( | ||
<div className="flex flex-row items-center break-all"> | ||
{!isDeletedFile ? ( | ||
<span | ||
data-action="clickable" | ||
data-testid="file-diff-expand" | ||
className={cs( | ||
'inline-flex items-center gap-1 font-sans hover:underline focus:ring-2', | ||
{ | ||
'text-ds-blue-default': row.getIsExpanded(), | ||
} | ||
)} | ||
{...{ | ||
onClick: row.getToggleExpandedHandler(), | ||
}} | ||
> | ||
<Icon | ||
size="md" | ||
name={row.getIsExpanded() ? 'chevronDown' : 'chevronRight'} | ||
variant="solid" | ||
/> | ||
</span> | ||
<Icon | ||
size="md" | ||
name={row.getIsExpanded() ? 'chevronDown' : 'chevronRight'} | ||
variant="solid" | ||
className="flex-none" | ||
/> | ||
) : null} | ||
{isDeletedFile ? ( | ||
<>{headName}</> | ||
) : ( | ||
/* @ts-expect-error - A hasn't been typed yet */ | ||
<A | ||
to={{ | ||
pageName: 'commitFileDiff', | ||
options: { | ||
commit: commitId, | ||
tree: headName, | ||
}, | ||
}} | ||
> | ||
{headName} | ||
</A> | ||
)} | ||
<span>{headName}</span> | ||
{row.original?.isCriticalFile ? ( | ||
<span className="ml-2 h-fit flex-none rounded border border-ds-gray-tertiary p-1 text-xs text-ds-gray-senary"> | ||
Critical file | ||
|
@@ -286,7 +257,7 @@ export default function FilesChangedTable() { | |
}, [commit?.compareWithParent]) | ||
|
||
const table = useReactTable({ | ||
columns: getColumns({ commitId: commitSha }), | ||
columns: getColumns(), | ||
data: filesChanged, | ||
state: { | ||
expanded, | ||
|
@@ -297,7 +268,7 @@ export default function FilesChangedTable() { | |
getCoreRowModel: getCoreRowModel(), | ||
getSortedRowModel: getSortedRowModel(), | ||
getExpandedRowModel: getExpandedRowModel(), | ||
getRowCanExpand: () => true, | ||
getRowCanExpand: (row) => row.original?.headCoverage !== null, // deleted files are not expandable | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this check used elsewhere (outside of these tables I mean)? Jw how we know this is the item to key off of when making a determination of if the file is deleted or not There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh good question. I pulled that from an existing usage from this table, but I get what you mean, maybe we should have this be a more inherent property of the file in api than having the UI make that designation here adhoc. And something more obvious than headCoverage being null (which can in theory happen for more reasons, not just due to a deleted file). I'll have to think about that one but in the meantime may ship this work independently There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yep totally fair! I'll keep this in the back of my head too in case I stumble upon a more straight-forward abstraction of this info at some point |
||
}) | ||
|
||
if (isLoading || commit?.state === 'pending') { | ||
|
@@ -321,7 +292,7 @@ export default function FilesChangedTable() { | |
} | ||
|
||
return ( | ||
<div className="filelistui" data-highlight-row="onHover"> | ||
<div className="filelistui"> | ||
<div> | ||
{table.getHeaderGroups().map((headerGroup) => ( | ||
<div key={headerGroup.id} className="filelistui-thead"> | ||
|
@@ -364,33 +335,47 @@ export default function FilesChangedTable() { | |
})} | ||
</div> | ||
))} | ||
{table.getRowModel().rows.map((row, i) => ( | ||
<Fragment key={i}> | ||
<div className="filelistui-row"> | ||
{row.getVisibleCells().map((cell) => { | ||
return ( | ||
<div | ||
key={cell.id} | ||
{...(isNumericValue(cell.column.id) | ||
? { | ||
'data-type': 'numeric', | ||
} | ||
: {})} | ||
className={cs({ | ||
'w-6/12': cell.column.id === 'name', | ||
'w-2/12 justify-end flex': cell.column.id !== 'name', | ||
})} | ||
> | ||
{flexRender(cell.column.columnDef.cell, cell.getContext())} | ||
</div> | ||
) | ||
})} | ||
</div> | ||
<div data-expanded={row.getIsExpanded()}> | ||
{row.getIsExpanded() ? <RenderSubComponent row={row} /> : null} | ||
</div> | ||
</Fragment> | ||
))} | ||
{table.getRowModel().rows.map((row, i) => { | ||
const isDeletedFile = row.original?.headCoverage === null | ||
return ( | ||
<Fragment key={i}> | ||
<div | ||
className={cs('filelistui-row', { | ||
'cursor-pointer': !isDeletedFile, | ||
'cursor-default': isDeletedFile, | ||
})} | ||
data-testid="file-diff-expand" | ||
onClick={() => !isDeletedFile && row.toggleExpanded()} | ||
data-highlight-row={!isDeletedFile ? 'onHover' : undefined} | ||
> | ||
{row.getVisibleCells().map((cell) => { | ||
return ( | ||
<div | ||
key={cell.id} | ||
{...(isNumericValue(cell.column.id) | ||
? { | ||
'data-type': 'numeric', | ||
} | ||
: {})} | ||
className={cs({ | ||
'w-6/12': cell.column.id === 'name', | ||
'w-2/12 justify-end flex': cell.column.id !== 'name', | ||
})} | ||
> | ||
{flexRender( | ||
cell.column.columnDef.cell, | ||
cell.getContext() | ||
)} | ||
</div> | ||
) | ||
})} | ||
</div> | ||
<div data-expanded={row.getIsExpanded()}> | ||
{row.getIsExpanded() ? <RenderSubComponent row={row} /> : null} | ||
</div> | ||
</Fragment> | ||
) | ||
})} | ||
</div> | ||
</div> | ||
) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very nice that we can delete this conditional logic now