Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
245 changes: 140 additions & 105 deletions packages/components/src/components/Loader/executions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { CodeViewer, DiffViewer } from '../base';
import { Card } from '../Card';
import { CodeOpener } from '../Opener';
import { Title } from '../Title';
import { ServerAPIProvider } from '../Manifest';
import styles from './Analysis/style.module.scss';

interface LoaderExecutionsProps {
Expand All @@ -37,7 +38,7 @@ const LoaderPropsItem = ({
resource,
cwd,
}: {
loader: SDK.LoaderTransformData & {
loader: Omit<SDK.LoaderTransformData, 'input' | 'result'> & {
costs: number;
};
resource: SDK.ResourceData;
Expand Down Expand Up @@ -108,6 +109,123 @@ const LoaderPropsItem = ({
);
};

// Component to render Loader Details content with lazy-loaded code
const LoaderDetailsContent = ({
loader,
resource,
isLight,
codeData,
}: {
loader: Omit<SDK.LoaderTransformData, 'input' | 'result'> & { costs: number };
resource: SDK.ResourceData;
isLight: boolean;
codeData: SDK.ServerAPI.InferResponseType<SDK.ServerAPI.API.GetLoaderFileInputAndOutput>;
}): JSX.Element => {
const hasError = loader.errors && loader.errors.length;
const before = codeData?.input || '';
const loaderResult = codeData?.output || '';

return (
<div style={{ height: '100%' }}>
{hasError ? (
<Col span={24} style={{ height: '53%', minHeight: 400 }}>
<div
style={{
padding: Size.BasePadding,
borderTop: `1px solid ${isLight ? '#f0f0f0' : 'rgba(253, 253, 253, 0.12)'}`,
borderBottom: `1px solid ${isLight ? '#f0f0f0' : 'rgba(253, 253, 253, 0.12)'}`,
}}
>
<Title
text={`the error stack of [${loader.loader}] ${loader.isPitch ? 'pitch' : ''}`}
/>
</div>
<div style={{ height: '90%' }}>
<CodeViewer code={loader.errors[0].message} lang="javascript" />
</div>
</Col>
) : (
<Col span={24} style={{ height: '53%', minHeight: 400 }}>
<div
style={{
display: 'flex',
alignItems: 'center',
padding: Size.BasePadding,
borderBottom: `1px solid ${isLight ? '#f0f0f0' : 'rgba(253, 253, 253, 0.12)'}`,
}}
>
<Title
text={
<>
{`the result of [${loader.loader}] ${loader.isPitch ? 'pitch' : ''}`}
{!loader.isPitch && (
<span style={{ fontWeight: 400 }}>
(
<InputIcon
style={{
verticalAlign: 'middle',
margin: '0 2px',
}}
/>
Input ⟷
<OutputIcon
style={{
verticalAlign: 'middle',
position: 'relative',
top: -2,
}}
/>
Output)
</span>
)}
</>
}
/>
<div style={{ flex: 1 }} />
</div>
{loader.isPitch ? (
loaderResult ? (
<div style={{ height: '90%' }}>
<CodeViewer
isEmbed
code={loaderResult}
filePath={resource.path}
/>
</div>
) : (
<Empty
description={
'No loader result. If you use the Brief Mode, there will not have loader results.'
}
/>
)
) : (
<div style={{ minHeight: '700px' }}>
<div style={{ height: '40rem', overflow: 'hidden' }}>
{!loaderResult && !before ? (
<Empty
description={
'No loader result. If you use the Brief Mode, there will not have loader results.'
}
/>
) : (
<DiffViewer
isEmbed
original={before}
modified={loaderResult || ''}
originalFilePath={resource.path}
modifiedFilePath={resource.path}
/>
)}
</div>
</div>
)}
</Col>
)}
</div>
);
};

export const LoaderExecutions = ({
data,
cwd,
Expand All @@ -118,9 +236,7 @@ export const LoaderExecutions = ({
const { theme } = useTheme();
const isLight = theme === 'light';
const loader = loaders[currentIndex];
const before = loader.input || '';
const leftSpan = 5;
const hasError = loader.errors && loader.errors.length;
const [activeKey, setActiveKey] = useState('loaderDetails');
const onChange = useCallback((key: string) => {
setActiveKey(key);
Expand Down Expand Up @@ -217,108 +333,27 @@ export const LoaderExecutions = ({
{
label: 'Loader Details',
key: 'loaderDetails',
children: (
<div style={{ height: '100%' }}>
{hasError ? (
<Col span={24} style={{ height: '53%', minHeight: 400 }}>
<div
style={{
padding: Size.BasePadding,
borderTop: `1px solid ${isLight ? '#f0f0f0' : 'rgba(253, 253, 253, 0.12)'}`,
borderBottom: `1px solid ${isLight ? '#f0f0f0' : 'rgba(253, 253, 253, 0.12)'}`,
}}
>
<Title
text={`the error stack of [${loader.loader}] ${loader.isPitch ? 'pitch' : ''}`}
/>
</div>
<div style={{ height: '90%' }}>
<CodeViewer
code={loader.errors[0].message}
lang="javascript"
/>
</div>
</Col>
) : (
<Col span={24} style={{ height: '53%', minHeight: 400 }}>
<div
style={{
display: 'flex',
alignItems: 'center',
padding: Size.BasePadding,
borderBottom: `1px solid ${isLight ? '#f0f0f0' : 'rgba(253, 253, 253, 0.12)'}`,
}}
>
<Title
text={
<>
{`the result of [${loader.loader}] ${loader.isPitch ? 'pitch' : ''}`}
{!loader.isPitch && (
<span style={{ fontWeight: 400 }}>
(
<InputIcon
style={{
verticalAlign: 'middle',
margin: '0 2px',
}}
/>
Input ⟷
<OutputIcon
style={{
verticalAlign: 'middle',
position: 'relative',
top: -2,
}}
/>
Output)
</span>
)}
</>
}
/>
<div style={{ flex: 1 }} />
</div>
{loader.isPitch ? (
loader.result ? (
<div style={{ height: '90%' }}>
<CodeViewer
isEmbed
code={loader.result}
filePath={resource.path}
/>
</div>
) : (
<Empty
description={
'No loader result. If you use the Brief Mode, there will not have loader results.'
}
/>
)
) : (
<div style={{ minHeight: '700px' }}>
<div style={{ height: '40rem', overflow: 'hidden' }}>
{!loader.result && !before ? (
<Empty
description={
'No loader result. If you use the Brief Mode, there will not have loader results.'
}
/>
) : (
<DiffViewer
isEmbed
original={before}
modified={loader.result || ''}
originalFilePath={resource.path}
modifiedFilePath={resource.path}
/>
)}
</div>
</div>
)}
</Col>
)}
</div>
),
children:
activeKey === 'loaderDetails' ? (
<ServerAPIProvider
api={SDK.ServerAPI.API.GetLoaderFileInputAndOutput}
body={{
file: resource.path,
loader: loader.loader,
loaderIndex: loader.loaderIndex,
}}
showSkeleton={false}
>
{(codeData) => (
<LoaderDetailsContent
loader={loader}
resource={resource}
isLight={isLight}
codeData={codeData}
/>
)}
</ServerAPIProvider>
) : null,
},
]}
onChange={onChange}
Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/sdk/server/apis/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export interface LoaderAPIResponse {
>;
[API.GetLoaderFileDetails]: {
resource: ResourceData;
loaders: (LoaderTransformData & {
loaders: (Omit<LoaderTransformData, 'input' | 'result'> & {
costs: number;
})[];
};
Expand Down
10 changes: 6 additions & 4 deletions packages/utils/src/common/data/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,12 @@ export class APIDataLoader {

case SDK.ServerAPI.API.GetLoaderFileInputAndOutput:
return this.loader.loadData('loader').then((res) => {
return Loader.getLoaderFileFirstInput(
(
body as SDK.ServerAPI.InferRequestBodyType<SDK.ServerAPI.API.GetLoaderFileFirstInput>
).file,
const params =
body as SDK.ServerAPI.InferRequestBodyType<SDK.ServerAPI.API.GetLoaderFileInputAndOutput>;
return Loader.getLoaderFileInputAndOutput(
params.file,
params.loader,
params.loaderIndex,
res || [],
) as R;
});
Expand Down
16 changes: 8 additions & 8 deletions packages/utils/src/common/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,11 @@ export function getLoaderFileDetails(
return {
...data,
loaders: data.loaders.map((el) => {
// Strip large input/result fields to reduce data volume
// These can be fetched on-demand via GetLoaderFileInputAndOutput API
const { input, result, ...loaderWithoutCode } = el;
return {
...el,
...loaderWithoutCode,
loader: getLoadrName(el.loader),
costs: getLoaderCosts(el, list),
};
Expand Down Expand Up @@ -341,20 +344,17 @@ export function getLoaderFileInputAndOutput(
const item = loaders[i];

if (item.resource.path === file) {
// biome-ignore lint/correctness/noUnreachable: may not need change
for (let j = 0; j < item.loaders.length; j++) {
const l = item.loaders[j];
if (l.loader === loader && l.loaderIndex === loaderIndex) {
if (
getLoadrName(l.loader) === loader &&
l.loaderIndex === loaderIndex
) {
return {
input: l.input || '',
output: l.result || '',
};
}

return {
input: '',
output: '',
};
}
}
}
Expand Down
Loading