From bee440cc2788172ec09a49b5a886597c581b3749 Mon Sep 17 00:00:00 2001 From: Ikhun Um Date: Wed, 28 Aug 2024 11:57:40 +0900 Subject: [PATCH] Fix minor bugs and lint --- .../dogma/common/components/Breadcrumbs.tsx | 6 ++- .../src/dogma/common/components/Deferred.tsx | 1 + .../common/components/editor/FileEditor.tsx | 13 ++++- .../common/components/table/DataTable.tsx | 2 + .../common/components/table/PaginationBar.tsx | 2 +- webapp/src/dogma/features/api/apiSlice.ts | 4 ++ webapp/src/dogma/features/file/FileDto.ts | 1 + .../dogma/features/history/HistoryList.tsx | 2 +- .../features/services/ErrorMessageParser.ts | 2 +- .../commit/[revision]/[[...path]]/index.tsx | 5 +- .../[repoName]/commits/[[...path]]/index.tsx | 53 ++++++++++--------- .../[revision]/base/[baseRevision]/index.tsx | 2 +- .../files/[revision]/[[...path]]/index.tsx | 3 +- .../tree/[revision]/[[...path]]/index.tsx | 2 +- 14 files changed, 62 insertions(+), 36 deletions(-) diff --git a/webapp/src/dogma/common/components/Breadcrumbs.tsx b/webapp/src/dogma/common/components/Breadcrumbs.tsx index 9750db3137..13f8af2a51 100644 --- a/webapp/src/dogma/common/components/Breadcrumbs.tsx +++ b/webapp/src/dogma/common/components/Breadcrumbs.tsx @@ -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}` : ''; } diff --git a/webapp/src/dogma/common/components/Deferred.tsx b/webapp/src/dogma/common/components/Deferred.tsx index 61d62d0500..06ddb9dcf5 100644 --- a/webapp/src/dogma/common/components/Deferred.tsx +++ b/webapp/src/dogma/common/components/Deferred.tsx @@ -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; } diff --git a/webapp/src/dogma/common/components/editor/FileEditor.tsx b/webapp/src/dogma/common/components/editor/FileEditor.tsx index a168faaa2c..b8d215cc8f 100644 --- a/webapp/src/dogma/common/components/editor/FileEditor.tsx +++ b/webapp/src/dogma/common/components/editor/FileEditor.tsx @@ -37,6 +37,7 @@ export type FileEditorProps = { originalContent: string; path: string; name: string; + revision: string | number; }; // Map file extension to language identifier @@ -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 = ''; @@ -108,7 +117,7 @@ const FileEditor = ({ projectName, repoName, extension, originalContent, path, n ); + const urlAndSegments = makeTraversalFileLinks(projectName, repoName, 'commits', filePath); + return ( {() => { + 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 ( { } omitIndexList={[0]} unlinkedList={[3]} - omitQueryList={[1, 2, 4, 5]} - query={type ? `type=${type}` : ''} + omitQueryList={omitQueryList} + query="type=tree" /> {filePath ? ( - - + + {type === 'tree' ? : } - {makeTraversalFileLinks(projectName, repoName, 'commits', filePath).map( - ({ segment, url }) => { - return ( - - {'/'} - {segment} - - ); - }, - )} + {urlAndSegments.map(({ segment, url }, index) => { + let query = ''; + if (type === 'tree' || index < urlAndSegments.length - 1) { + query = '?type=tree'; + } + const targetUrl = url + query; + return ( + + {'/'} + {segment} + + ); + })}  commits ) : ( diff --git a/webapp/src/pages/app/projects/[projectName]/repos/[repoName]/compare/[revision]/base/[baseRevision]/index.tsx b/webapp/src/pages/app/projects/[projectName]/repos/[repoName]/compare/[revision]/base/[baseRevision]/index.tsx index c0f73cc498..37ec2fb017 100644 --- a/webapp/src/pages/app/projects/[projectName]/repos/[repoName]/compare/[revision]/base/[baseRevision]/index.tsx +++ b/webapp/src/pages/app/projects/[projectName]/repos/[repoName]/compare/[revision]/base/[baseRevision]/index.tsx @@ -65,7 +65,7 @@ const ChangesViewPage = () => { data: oldData, isLoading: isOldLoading, error: oldError, - }: any = useGetFilesQuery({ + } = useGetFilesQuery({ projectName, repoName, revision: baseRevision, diff --git a/webapp/src/pages/app/projects/[projectName]/repos/[repoName]/files/[revision]/[[...path]]/index.tsx b/webapp/src/pages/app/projects/[projectName]/repos/[repoName]/files/[revision]/[[...path]]/index.tsx index 4fd72b173b..1adbb62b40 100644 --- a/webapp/src/pages/app/projects/[projectName]/repos/[repoName]/files/[revision]/[[...path]]/index.tsx +++ b/webapp/src/pages/app/projects/[projectName]/repos/[repoName]/files/[revision]/[[...path]]/index.tsx @@ -41,7 +41,7 @@ const FileContentPage = () => { - + {fileName} @@ -60,6 +60,7 @@ const FileContentPage = () => { originalContent={data.content} path={data.path} name={fileName} + revision={revision} /> ); diff --git a/webapp/src/pages/app/projects/[projectName]/repos/[repoName]/tree/[revision]/[[...path]]/index.tsx b/webapp/src/pages/app/projects/[projectName]/repos/[repoName]/tree/[revision]/[[...path]]/index.tsx index bc0ce655f9..d49cafd0dd 100644 --- a/webapp/src/pages/app/projects/[projectName]/repos/[repoName]/tree/[revision]/[[...path]]/index.tsx +++ b/webapp/src/pages/app/projects/[projectName]/repos/[repoName]/tree/[revision]/[[...path]]/index.tsx @@ -140,7 +140,7 @@ cat ${project}/${repo}${path}`;