FilesView: .keep file should not be clickable and no actions available (#113687)

* FilesView: .keep file should not be clickable and no actions available
This commit is contained in:
Yunwen Zheng
2025-11-12 09:06:41 -05:00
committed by GitHub
parent 735b776edc
commit 3e2dccb544
2 changed files with 30 additions and 0 deletions
@@ -146,4 +146,21 @@ describe('FilesView', () => {
expect(screen.getByRole('link', { name: 'View' })).toBeInTheDocument();
expect(screen.queryByRole('link', { name: 'History' })).not.toBeInTheDocument();
});
it('renders plain text and hides actions for .keep files', () => {
mockRepositoryFilesQuery({
isSuccess: true,
status: 'fulfilled',
data: {
items: [{ path: 'dashboards/.keep', hash: 'abc', size: '0' }],
},
});
renderComponent();
expect(screen.getByText('dashboards/.keep')).toBeInTheDocument();
expect(screen.queryByRole('link', { name: 'dashboards/.keep' })).not.toBeInTheDocument();
expect(screen.queryByRole('link', { name: 'View' })).not.toBeInTheDocument();
expect(screen.queryByRole('link', { name: 'History' })).not.toBeInTheDocument();
});
});
@@ -31,6 +31,10 @@ export function FilesView({ repo }: FilesViewProps) {
sortType: 'string',
cell: ({ row: { original } }: FileCell<'path'>) => {
const { path } = original;
const isDotKeepFile = getIsDotKeepFile(path);
if (isDotKeepFile) {
return path;
}
return <a href={`${PROVISIONING_URL}/${name}/file/${path}`}>{path}</a>;
},
},
@@ -44,6 +48,10 @@ export function FilesView({ repo }: FilesViewProps) {
header: '',
cell: ({ row: { original } }: FileCell<'path'>) => {
const { path } = original;
const isDotKeepFile = getIsDotKeepFile(path);
if (isDotKeepFile) {
return null;
}
return (
<Stack>
{(path.endsWith('.json') || path.endsWith('.yaml') || path.endsWith('.yml')) && (
@@ -84,3 +92,8 @@ export function FilesView({ repo }: FilesViewProps) {
</Stack>
);
}
function getIsDotKeepFile(path: string): boolean {
// e.g. 'dashboards/.keep' → true, 'dashboards/example.keep.json' → false
return path.split('/').pop() === '.keep';
}