From eb61f6fd055f8aa0cf7cf3db4d09d258eacaa60a Mon Sep 17 00:00:00 2001 From: Cedric van Putten Date: Tue, 23 Apr 2024 18:40:26 +0200 Subject: [PATCH] feature(webui): style `imported by` section on module pages --- .../app/(atlas)/[bundle]/modules/[path].tsx | 32 ++++------ webui/src/components/ModuleImportedBy.tsx | 61 +++++++++++++++++++ webui/src/ui/Code.tsx | 4 +- webui/src/ui/Panel.tsx | 2 +- webui/src/utils/shiki.ts | 6 +- 5 files changed, 80 insertions(+), 25 deletions(-) create mode 100644 webui/src/components/ModuleImportedBy.tsx diff --git a/webui/src/app/(atlas)/[bundle]/modules/[path].tsx b/webui/src/app/(atlas)/[bundle]/modules/[path].tsx index 966e6b0..c7c3845 100644 --- a/webui/src/app/(atlas)/[bundle]/modules/[path].tsx +++ b/webui/src/app/(atlas)/[bundle]/modules/[path].tsx @@ -1,9 +1,10 @@ import { useQuery } from '@tanstack/react-query'; -import { Link, useLocalSearchParams } from 'expo-router'; +import { useLocalSearchParams } from 'expo-router'; import { BreadcrumbLinks } from '~/components/BreadcrumbLinks'; import { BundleSelectForm } from '~/components/BundleSelectForm'; import { ModuleCode } from '~/components/ModuleCode'; +import { ModuleImportedBy } from '~/components/ModuleImportedBy'; import { PropertySummary } from '~/components/PropertySummary'; import { StateInfo } from '~/components/StateInfo'; import { BundleDeltaToast, useBundle } from '~/providers/bundle'; @@ -11,7 +12,6 @@ import { Layout, LayoutHeader, LayoutNavigation, LayoutTitle } from '~/ui/Layout import { Skeleton } from '~/ui/Skeleton'; import { Tag } from '~/ui/Tag'; import { fetchApi } from '~/utils/api'; -import { relativeBundlePath } from '~/utils/bundle'; import { formatFileSize } from '~/utils/formatString'; import { type AtlasModule } from '~core/data/types'; @@ -48,28 +48,17 @@ export default function ModulePage() { ) : !module.data ? ( Try another bundle ) : ( -
+
{!!module.data.importedBy?.length && ( -
-

Imported from:

-
    - {module.data.importedBy.map((path) => ( -
  • - - {relativeBundlePath(bundle, path)} - -
  • - ))} -
+
+

Imported by

+
)} - +
+

Module content

+ +
)} @@ -103,6 +92,7 @@ function ModulePageSkeleton() {
+
); diff --git a/webui/src/components/ModuleImportedBy.tsx b/webui/src/components/ModuleImportedBy.tsx new file mode 100644 index 0000000..74450ec --- /dev/null +++ b/webui/src/components/ModuleImportedBy.tsx @@ -0,0 +1,61 @@ +import { Link } from 'expo-router'; +// @ts-expect-error +import PackageIcon from 'lucide-react/dist/esm/icons/box'; +// @ts-expect-error +import FileIcon from 'lucide-react/dist/esm/icons/file'; +import { PropsWithChildren } from 'react'; + +import { relativeBundlePath } from '~/utils/bundle'; +import type { AtlasModule, AtlasModuleRef, PartialAtlasBundle } from '~core/data/types'; + +type ModuleImportedByProps = { + bundle: PartialAtlasBundle; + module: AtlasModule; +}; + +export function ModuleImportedBy(props: ModuleImportedByProps) { + return ( + <> + {props.module.importedBy.map((moduleRef) => ( +
+ +
+ ))} + + ); +} + +type ModuleImportLinkProps = PropsWithChildren<{ + bundle: PartialAtlasBundle; + reference: AtlasModuleRef; +}>; + +function ModuleImportLink(props: ModuleImportLinkProps) { + const relativePath = relativeBundlePath(props.bundle, props.reference.path); + const Icon = props.reference.package ? PackageIcon : FileIcon; + + return ( + + + + + {relativePath} + + + + + ); +} diff --git a/webui/src/ui/Code.tsx b/webui/src/ui/Code.tsx index 7bbfdbd..54b776b 100644 --- a/webui/src/ui/Code.tsx +++ b/webui/src/ui/Code.tsx @@ -5,7 +5,7 @@ import { Button } from './Button'; export function CodeHeader(props: PropsWithChildren) { return ( -
+
{props.children}
); @@ -19,7 +19,7 @@ export function CodeAction({ className, ...props }: ComponentProps ); diff --git a/webui/src/ui/Panel.tsx b/webui/src/ui/Panel.tsx index 2f90dfb..84ac31a 100644 --- a/webui/src/ui/Panel.tsx +++ b/webui/src/ui/Panel.tsx @@ -10,7 +10,7 @@ export function PanelGroup(props: PropsWithChildren) { export function Panel(props: PropsWithChildren) { return ( -
+
{props.children}
); diff --git a/webui/src/utils/shiki.ts b/webui/src/utils/shiki.ts index 4acd58d..6a27f8c 100644 --- a/webui/src/utils/shiki.ts +++ b/webui/src/utils/shiki.ts @@ -78,6 +78,7 @@ export function getLanguageFromPath(path: string): HighlightLanguage { export type HighlightOptions = { code: string; language: HighlightLanguage; + lineNumberStart?: number; }; /** @@ -89,6 +90,9 @@ export function getHighlightedHtml(highlighter: Highlighter | null, options: Hig lang: options.language, theme: 'expo-theme', transformers: [AtlasTransformer], + meta: { + lineNumberStart: options.lineNumberStart || 0, + }, }); } @@ -123,6 +127,6 @@ const AtlasTransformer: ShikiTransformer = { }, line(hast, line) { - hast.properties['data-atlas-line'] = line; + hast.properties['data-atlas-line'] = line + (this.options.meta?.lineNumberStart || 0); }, };