Skip to content

Commit

Permalink
fix(webui): update remaining references to entry -> bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
byCedric committed Apr 22, 2024
1 parent 5a64522 commit 34cc12e
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 36 deletions.
10 changes: 4 additions & 6 deletions webui/src/app/(atlas)/[bundle].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ export default function BundlePage() {
<BundleGraph bundle={bundle} graph={modules.data!.data} />
) : (
<StateInfo title={filtersEnabled ? 'No data matching filters' : 'No data available'}>
<p>
{filtersEnabled ? 'Try adjusting or clearing the filters' : 'Try another bundle entry'}
</p>
<p>{filtersEnabled ? 'Try adjusting or clearing the filters' : 'Try another bundle'}</p>
</StateInfo>
)}
</Layout>
Expand All @@ -77,16 +75,16 @@ function useModuleGraphData(bundleId: string, filters: ModuleFilters) {
placeholderData: keepPreviousData,
queryKey: [`bundles`, bundleId, 'bundle-graph', filters],
queryFn: ({ queryKey }) => {
const [_key, entry, _graph, filters] = queryKey as [
const [_key, bundle, _graph, filters] = queryKey as [
string,
string,
string,
ModuleFilters | undefined,
];

const url = filters
? `/bundles/${entry}/modules/graph?${moduleFiltersToParams(filters)}`
: `/bundles/${entry}/modules/graph`;
? `/bundles/${bundle}/modules/graph?${moduleFiltersToParams(filters)}`
: `/bundles/${bundle}/modules/graph`;

return fetchApi(url)
.then((res) => (res.ok ? res : Promise.reject(res)))
Expand Down
2 changes: 1 addition & 1 deletion webui/src/app/(atlas)/[bundle]/folders/[path].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export default function FolderPage() {
) : (
!modules.isPending && (
<StateInfo title={filtersEnabled ? 'No data matching filters' : 'No data available'}>
{filtersEnabled ? 'Try adjusting or clearing the filters' : 'Try another bundle entry'}
{filtersEnabled ? 'Try adjusting or clearing the filters' : 'Try another bundle'}
</StateInfo>
)
)}
Expand Down
2 changes: 1 addition & 1 deletion webui/src/app/(atlas)/[bundle]/modules/[path].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default function ModulePage() {
Try restarting Expo Atlas. If this error keeps happening, open a bug report.
</StateInfo>
) : !module.data ? (
<StateInfo title="Module not found.">Try another bundle entry</StateInfo>
<StateInfo title="Module not found.">Try another bundle</StateInfo>
) : (
<div className="mx-8 mb-4">
{!!module.data.importedBy?.length && (
Expand Down
7 changes: 5 additions & 2 deletions webui/src/app/--/bundles/[bundle]/reload+api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ export async function GET(_request: Request, params: Record<'bundle', string>) {
try {
const bundle = await getSource().getBundle(params.bundle);
if (!bundle) {
return Response.json({ error: 'Entry not found' }, { status: 404 });
return Response.json({ error: 'Bundle not found' }, { status: 404 });
}

if (!bundle.serializeOptions?.sourceUrl) {
return Response.json({ error: 'Entry has no `serializeOptions.sourceUrl`' }, { status: 406 });
return Response.json(
{ error: 'Bundle has no `serializeOptions.sourceUrl`' },
{ status: 406 }
);
}

return Response.redirect(bundle.serializeOptions.sourceUrl, 302);
Expand Down
2 changes: 1 addition & 1 deletion webui/src/components/BundleSelectForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function BundleSelectForm() {
const { bundle, bundles } = useBundle();

return (
<Select.Root value={bundle.id} onValueChange={(entry) => router.setParams({ entry })}>
<Select.Root value={bundle.id} onValueChange={(bundle) => router.setParams({ bundle })}>
<Select.Trigger asChild>
<Button variant="quaternary" size="sm">
<Tag variant={bundle.platform} size="xs" className="mr-2" />
Expand Down
36 changes: 18 additions & 18 deletions webui/src/providers/bundle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ export const bundleContext = createContext<BundleContext>({

export const useBundle = () => {
const { bundles } = useContext(bundleContext);
const { entry: bundleId } = useLocalSearchParams<{ entry?: string }>();
const { bundle: bundleId } = useLocalSearchParams<{ bundle?: string }>();
const bundle = useMemo(
() => bundles.find((entry) => entry.id === bundleId) || bundles[0],
() => bundles.find((bundle) => bundle.id === bundleId) || bundles[0],
[bundles, bundleId]
);

Expand Down Expand Up @@ -83,7 +83,7 @@ function useBundleData() {
});
}

/** A logic-component to show a toast notification when the entry is outdated. */
/** A logic-component to show a toast notification when the bundle is outdated. */
export function BundleDeltaToast({
bundle,
modulePath,
Expand All @@ -95,9 +95,9 @@ export function BundleDeltaToast({
const toaster = useToast();

const deltaResponse = useBundleDeltaData(bundle.id);
const entryDelta = deltaResponse.data?.delta;
const bundleDelta = deltaResponse.data?.delta;

const refetchEntryData = useCallback(
const refetchBundleData = useCallback(
() =>
fetchApi(`/bundles/${bundle.id}/reload`)
.then((res) => (!res.ok ? Promise.reject(res) : res.text()))
Expand All @@ -106,47 +106,47 @@ export function BundleDeltaToast({
);

useEffect(() => {
if (!entryDelta) return;
if (!bundleDelta) return;

if (modulePath) {
if (entryDelta.deletedPaths.includes(modulePath)) {
if (bundleDelta.deletedPaths.includes(modulePath)) {
toaster.toast(toastModuleDeleted(bundle.id));
} else if (entryDelta.modifiedPaths.includes(modulePath)) {
refetchEntryData().then(() => toaster.toast(toastModuleModified(bundle.id)));
} else if (bundleDelta.modifiedPaths.includes(modulePath)) {
refetchBundleData().then(() => toaster.toast(toastModuleModified(bundle.id)));
}
return;
}

toaster.toast(toastBundleUpdate(bundle.id, refetchEntryData));
}, [bundle.id, entryDelta, refetchEntryData, modulePath]);
toaster.toast(toastBundleUpdate(bundle.id, refetchBundleData));
}, [bundle.id, bundleDelta, refetchBundleData, modulePath]);

return null;
}

function toastModuleModified(entryId: string): ToasterToast {
function toastModuleModified(bundleId: string): ToasterToast {
return {
id: `bundle-delta-${entryId}`,
id: `bundle-delta-${bundleId}`,
title: 'Module modified',
description: 'This module is updated to reflect the latest changes.',
};
}

function toastModuleDeleted(entryId: string): ToasterToast {
function toastModuleDeleted(bundleId: string): ToasterToast {
return {
id: `bundle-delta-${entryId}`,
id: `bundle-delta-${bundleId}`,
title: 'Module deleted',
description: 'This file is deleted since latest build, and is no longer available.',
};
}

function toastBundleUpdate(entryId: string, refetchEntryData: () => any): ToasterToast {
function toastBundleUpdate(bundleId: string, refetchBundleData: () => any): ToasterToast {
return {
id: `bundle-delta-${entryId}`,
id: `bundle-delta-${bundleId}`,
title: 'Bundle outdated',
description: 'The code was changed since last build.',
action: (
<ToastAction altText="Reload bundle">
<Button variant="secondary" size="xs" onClick={refetchEntryData}>
<Button variant="secondary" size="xs" onClick={refetchBundleData}>
Reload bundle
</Button>
</ToastAction>
Expand Down
12 changes: 6 additions & 6 deletions webui/src/utils/bundle.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { PartialAtlasBundle } from '~core/data/types';

/**
* Translate an absolute path to a relative path, based on the entry's project root.
* Translate an absolute path to a relative path, based on the bundle's project root.
* This is a simple replace operation.
*/
export function relativeBundlePath(
entry: Pick<PartialAtlasBundle, 'projectRoot' | 'sharedRoot'>,
bundle: Pick<PartialAtlasBundle, 'projectRoot' | 'sharedRoot'>,
path: string
) {
return path.replace(rootBundlePath(entry) + '/', '');
return path.replace(rootBundlePath(bundle) + '/', '');
}

/**
* Get the "shared root" of all paths within the entry.
* Get the "shared root" of all paths within the bundle.
* This is calculated by comparing `projectRoot` and `watchFolders`.
*/
export function rootBundlePath(entry: Pick<PartialAtlasBundle, 'projectRoot' | 'sharedRoot'>) {
return entry.sharedRoot || entry.projectRoot;
export function rootBundlePath(bundle: Pick<PartialAtlasBundle, 'projectRoot' | 'sharedRoot'>) {
return bundle.sharedRoot || bundle.projectRoot;
}
2 changes: 1 addition & 1 deletion webui/src/utils/treemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export function createModuleTree(modules: AtlasModule[]): TreemapNode {
value: 100, // 100%
moduleSize: totalSize,
moduleFiles: modules.length,
// NOTE(cedric): technically, this should be the entry's project root,
// NOTE(cedric): technically, this should be the bundle's shared root,
// but that kind of clutters the treemap's tooltip a bit
modulePath: '',
modulePackage: undefined,
Expand Down

0 comments on commit 34cc12e

Please sign in to comment.