Skip to content

Commit

Permalink
Fix minor bugs and lint
Browse files Browse the repository at this point in the history
  • Loading branch information
ikhoon committed Aug 28, 2024
1 parent b3955a2 commit bee440c
Show file tree
Hide file tree
Showing 14 changed files with 62 additions and 36 deletions.
6 changes: 4 additions & 2 deletions webapp/src/dogma/common/components/Breadcrumbs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ export const Breadcrumbs = ({
if (omitIndexList.includes(i)) {
return null;
}
let query0 = '';
if (!omitQueryList.includes(i)) {
let query0;
if (omitQueryList.includes(i) || omitQueryList.includes(i - asPathNestedRoutes.length)) {
query0 = '';
} else {
query0 = query ? `?${query}` : '';
}

Expand Down
1 change: 1 addition & 0 deletions webapp/src/dogma/common/components/Deferred.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { Loading } from './Loading';

interface LoadingProps {
isLoading: boolean;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
error: any;
children: () => ReactNode;
}
Expand Down
13 changes: 11 additions & 2 deletions webapp/src/dogma/common/components/editor/FileEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export type FileEditorProps = {
originalContent: string;
path: string;
name: string;
revision: string | number;
};

// Map file extension to language identifier
Expand All @@ -58,7 +59,15 @@ export const extensionToLanguageMap: { [key: string]: string } = {
toml: 'toml',
};

const FileEditor = ({ projectName, repoName, extension, originalContent, path, name }: FileEditorProps) => {
const FileEditor = ({
projectName,
repoName,
extension,
originalContent,
path,
name,
revision,
}: FileEditorProps) => {
const dispatch = useAppDispatch();
const language = extensionToLanguageMap[extension] || extension;
let jsonContent = '';
Expand Down Expand Up @@ -108,7 +117,7 @@ const FileEditor = ({ projectName, repoName, extension, originalContent, path, n
<Button
size={'sm'}
as={Link}
href={`/app/projects/${projectName}/repos/${repoName}/commits/${path}`}
href={`/app/projects/${projectName}/repos/${repoName}/commits/${path}${revision !== 'head' ? `?from=${revision}` : ''}`}
leftIcon={<FaHistory />}
variant="outline"
colorScheme="gray"
Expand Down
2 changes: 2 additions & 0 deletions webapp/src/dogma/common/components/table/DataTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const DataTable = <Data extends object>({ table }: { table: ReactTable<Da
<Tr key={headerGroup.id}>
{headerGroup.headers.map((header) => {
// see https://tanstack.com/table/v8/docs/api/core/column-def#meta to type this correctly
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const meta: any = header.column.columnDef.meta;
return (
<Th
Expand Down Expand Up @@ -41,6 +42,7 @@ export const DataTable = <Data extends object>({ table }: { table: ReactTable<Da
<Tr key={row.id} data-testid="table-row">
{row.getVisibleCells().map((cell) => {
// see https://tanstack.com/table/v8/docs/api/core/column-def#meta to type this correctly
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const meta: any = cell.column.columnDef.meta;
return (
<Td key={cell.id} isNumeric={meta?.isNumeric}>
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/dogma/common/components/table/PaginationBar.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Flex, Input, Text, Select, Spacer, IconButton, Box, HStack, Stack } from '@chakra-ui/react';
import { Flex, IconButton, Input, Select, Spacer, Text } from '@chakra-ui/react';
import { Table as ReactTable } from '@tanstack/react-table';
import { MdNavigateBefore, MdNavigateNext, MdSkipNext, MdSkipPrevious } from 'react-icons/md';

Expand Down
4 changes: 4 additions & 0 deletions webapp/src/dogma/features/api/apiSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ export const apiSlice = createApi({
query: ({ projectName, id }) => `/api/v1/projects/${projectName}/mirrors/${id}`,
providesTags: ['Metadata'],
}),
// eslint-disable-next-line @typescript-eslint/no-explicit-any
addNewMirror: builder.mutation<any, MirrorDto>({
query: (mirror) => ({
url: `/api/v1/projects/${mirror.projectName}/mirrors`,
Expand All @@ -336,6 +337,7 @@ export const apiSlice = createApi({
}),
invalidatesTags: ['Metadata'],
}),
// eslint-disable-next-line @typescript-eslint/no-explicit-any
updateMirror: builder.mutation<any, { projectName: string; id: string; mirror: MirrorDto }>({
query: ({ projectName, id, mirror }) => ({
url: `/api/v1/projects/${projectName}/mirrors/${id}`,
Expand All @@ -352,6 +354,7 @@ export const apiSlice = createApi({
query: ({ projectName, id }) => `/api/v1/projects/${projectName}/credentials/${id}`,
providesTags: ['Metadata'],
}),
// eslint-disable-next-line @typescript-eslint/no-explicit-any
addNewCredential: builder.mutation<any, { projectName: string; credential: CredentialDto }>({
query: ({ projectName, credential }) => ({
url: `/api/v1/projects/${projectName}/credentials`,
Expand All @@ -360,6 +363,7 @@ export const apiSlice = createApi({
}),
invalidatesTags: ['Metadata'],
}),
// eslint-disable-next-line @typescript-eslint/no-explicit-any
updateCredential: builder.mutation<any, { projectName: string; id: string; credential: CredentialDto }>({
query: ({ projectName, id, credential }) => ({
url: `/api/v1/projects/${projectName}/credentials/${id}`,
Expand Down
1 change: 1 addition & 0 deletions webapp/src/dogma/features/file/FileDto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ export interface FileDto {
revision: number;
type: FileType;
url: string;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
content?: string | any;
}
2 changes: 1 addition & 1 deletion webapp/src/dogma/features/history/HistoryList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const HistoryList = ({
header: 'Timestamp',
}),
],
[columnHelper, projectName, repoName, filePath],
[columnHelper, projectName, repoName, filePath, isDirectory],
);

return (
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/dogma/features/services/ErrorMessageParser.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class ErrorMessageParser {
// eslint-disable-line @typescript-eslint/no-explicit-any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
static parse(object: any): string {
if (object.response && object.response.data.message) {
return object.response.data.message;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const CommitViewPage = () => {
data: oldData,
isLoading: isOldLoading,
error: oldError,
}: any = useGetFilesQuery(
} = useGetFilesQuery(
{
projectName,
repoName,
Expand Down Expand Up @@ -114,7 +114,8 @@ const CommitViewPage = () => {
return <FourOhFour title={`Revision ${revision} does not exist..`} />;
}
// 404 Not Found is returned if the file does not exist in the old revision.
const oldError0 = oldError && oldError.status != 404 ? oldError : null;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const oldError0 = oldError && (oldError as any).status != 404 ? oldError : null;

return (
<Deferred
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { ChakraLink } from 'dogma/common/components/ChakraLink';
import { makeTraversalFileLinks, toFilePath } from 'dogma/util/path-util';
import { PaginationState } from '@tanstack/react-table';
import { MdErrorOutline } from 'react-icons/md';
import { FileIcon } from 'dogma/common/components/FileIcon';

const DEFAULT_PAGE_SIZE = 10;

Expand All @@ -34,16 +35,11 @@ const HistoryListPage = () => {
fromRevision = headRevision + from + 1;
}
let baseRevision = parseInt(router.query.base as string) || fromRevision - DEFAULT_PAGE_SIZE + 1;
const pageSize = fromRevision - baseRevision + 1;
if (baseRevision < 1) {
baseRevision = 1;
}

let pageSize = fromRevision - baseRevision + 1;
if (pageSize < DEFAULT_PAGE_SIZE && baseRevision < DEFAULT_PAGE_SIZE) {
// This is the end of the history which may be less than the original page size.
// In this case, we should use the default page size as a best effort.
pageSize = DEFAULT_PAGE_SIZE;
}
const fromPageCount = Math.ceil(fromRevision / pageSize);
let headPageCount;
if (fromRevision > headRevision) {
Expand Down Expand Up @@ -71,9 +67,8 @@ const HistoryListPage = () => {

if (newPageIndex != pageIndex || newPageSize != pageSize) {
const from = fromRevision - (newPageIndex - pageIndex) * newPageSize;
let base = from - newPageSize + 1;
base = Math.max(base, 1);
const query: { [key: string]: any } = { from, base };
const base = from - newPageSize + 1;
const query: { [key: string]: string | number } = { from, base };
if (type) {
query['type'] = type;
}
Expand Down Expand Up @@ -117,16 +112,23 @@ const HistoryListPage = () => {
size={'sm'}
colorScheme={'green'}
as={ChakraLink}
href={`/app/projects/${projectName}/repos/${repoName}/commits/${filePath}?from=${fromRevision - DEFAULT_PAGE_SIZE}${type ? `&type=${type}` : ''}`}
href={`/app/projects/${projectName}/repos/${repoName}/commits/${filePath}?from=${baseRevision - 1}&base=${baseRevision - 100}${type ? `&type=${type}` : ''}`}
>
Go to older commits
</Button>
</VStack>
);

const urlAndSegments = makeTraversalFileLinks(projectName, repoName, 'commits', filePath);

return (
<Deferred isLoading={isLoading || isHistoryLoading} error={error || historyError}>
{() => {
const omitQueryList = [1, 2, 4, 5];
if (type !== 'tree' && router.query.from) {
// Omit the 'type=tree' query parameter when the type is a file.
omitQueryList.push(-2);
}
return (
<Box p="2">
<Breadcrumbs
Expand All @@ -135,26 +137,29 @@ const HistoryListPage = () => {
}
omitIndexList={[0]}
unlinkedList={[3]}
omitQueryList={[1, 2, 4, 5]}
query={type ? `type=${type}` : ''}
omitQueryList={omitQueryList}
query="type=tree"
/>
<Flex minWidth="max-content" alignItems="center" gap="2" mb={6}>
<Heading size="lg">
{filePath ? (
<HStack gap={0}>
<Box color={'teal'} marginRight={2}>
<FcOpenedFolder />
<Box color={'teal'} marginRight={2} marginBottom={-2}>
{type === 'tree' ? <Icon as={FcOpenedFolder} /> : <FileIcon fileName={filePath} />}
</Box>
{makeTraversalFileLinks(projectName, repoName, 'commits', filePath).map(
({ segment, url }) => {
return (
<Box key={url}>
{'/'}
<ChakraLink href={url}>{segment}</ChakraLink>
</Box>
);
},
)}
{urlAndSegments.map(({ segment, url }, index) => {
let query = '';
if (type === 'tree' || index < urlAndSegments.length - 1) {
query = '?type=tree';
}
const targetUrl = url + query;
return (
<Box key={targetUrl}>
{'/'}
<ChakraLink href={targetUrl}>{segment}</ChakraLink>
</Box>
);
})}
<Box fontWeight={'normal'}>&nbsp;commits</Box>
</HStack>
) : (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const ChangesViewPage = () => {
data: oldData,
isLoading: isOldLoading,
error: oldError,
}: any = useGetFilesQuery({
} = useGetFilesQuery({
projectName,
repoName,
revision: baseRevision,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const FileContentPage = () => {
<Flex minWidth="max-content" alignItems="center" gap="2" mb={6}>
<Heading size="lg">
<HStack color="teal">
<Box>
<Box marginBottom={-1}>
<FileIcon fileName={fileName} />
</Box>
<Box>{fileName}</Box>
Expand All @@ -60,6 +60,7 @@ const FileContentPage = () => {
originalContent={data.content}
path={data.path}
name={fileName}
revision={revision}
/>
</Box>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ cat ${project}/${repo}${path}`;
<Button
size={'sm'}
as={ChakraLink}
href={`/app/projects/${projectName}/repos/${repoName}/commits${filePath}?type=tree`}
href={`/app/projects/${projectName}/repos/${repoName}/commits${filePath}?type=tree${revision !== 'head' ? `&from=${revision}` : ''}`}
leftIcon={<FaHistory />}
variant="outline"
colorScheme="gray"
Expand Down

0 comments on commit bee440c

Please sign in to comment.