2021-10-21 06:31:51 -04:00
|
|
|
import { useCallback, useMemo, useState } from 'react'
|
2021-09-30 07:29:25 -04:00
|
|
|
import useFetchMock from './hooks/use-fetch-mock'
|
|
|
|
import { Button } from 'react-bootstrap'
|
|
|
|
import PdfPreviewPane from '../js/features/pdf-preview/components/pdf-preview-pane'
|
|
|
|
import PdfPreview from '../js/features/pdf-preview/components/pdf-preview'
|
|
|
|
import PdfFileList from '../js/features/pdf-preview/components/pdf-file-list'
|
|
|
|
import { buildFileList } from '../js/features/pdf-preview/util/file-list'
|
|
|
|
import PdfLogsViewer from '../js/features/pdf-preview/components/pdf-logs-viewer'
|
|
|
|
import PdfPreviewError from '../js/features/pdf-preview/components/pdf-preview-error'
|
2021-10-12 04:47:46 -04:00
|
|
|
import PdfPreviewHybridToolbar from '../js/features/pdf-preview/components/pdf-preview-hybrid-toolbar'
|
2022-03-31 07:22:36 -04:00
|
|
|
import { useDetachCompileContext as useCompileContext } from '../js/shared/context/detach-compile-context'
|
2021-10-21 06:31:51 -04:00
|
|
|
import {
|
|
|
|
dispatchDocChanged,
|
|
|
|
mockBuildFile,
|
|
|
|
mockClearCache,
|
|
|
|
mockCompile,
|
|
|
|
mockCompileError,
|
|
|
|
mockCompileValidationIssues,
|
|
|
|
mockEventTracking,
|
|
|
|
outputFiles,
|
|
|
|
} from './fixtures/compile'
|
|
|
|
import { cloneDeep } from 'lodash'
|
2022-05-16 05:38:20 -04:00
|
|
|
import { ScopeDecorator } from './decorators/scope'
|
2023-11-14 04:51:30 -05:00
|
|
|
import { PdfPreviewProvider } from '@/features/pdf-preview/components/pdf-preview-provider'
|
2024-10-10 03:26:18 -04:00
|
|
|
import { bsVersionDecorator } from '../../.storybook/utils/with-bootstrap-switcher'
|
2021-09-30 07:29:25 -04:00
|
|
|
|
|
|
|
export default {
|
2022-03-28 06:23:21 -04:00
|
|
|
title: 'Editor / PDF Preview',
|
2021-09-30 07:29:25 -04:00
|
|
|
component: PdfPreview,
|
|
|
|
subcomponents: {
|
2021-10-12 04:47:46 -04:00
|
|
|
PdfPreviewHybridToolbar,
|
2021-09-30 07:29:25 -04:00
|
|
|
PdfFileList,
|
|
|
|
PdfPreviewError,
|
|
|
|
},
|
2022-05-16 05:38:20 -04:00
|
|
|
decorators: [ScopeDecorator],
|
2024-10-10 03:26:18 -04:00
|
|
|
argTypes: {
|
|
|
|
...bsVersionDecorator.argTypes,
|
|
|
|
},
|
2021-09-30 07:29:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export const Interactive = () => {
|
|
|
|
useFetchMock(fetchMock => {
|
|
|
|
mockCompile(fetchMock)
|
|
|
|
mockBuildFile(fetchMock)
|
|
|
|
mockClearCache(fetchMock)
|
|
|
|
})
|
|
|
|
|
|
|
|
const Inner = () => {
|
2021-10-15 05:39:56 -04:00
|
|
|
const context = useCompileContext()
|
2021-09-30 07:29:25 -04:00
|
|
|
|
|
|
|
const { setHasLintingError } = context
|
|
|
|
|
|
|
|
const toggleLintingError = useCallback(() => {
|
|
|
|
setHasLintingError(value => !value)
|
|
|
|
}, [setHasLintingError])
|
|
|
|
|
|
|
|
const values = useMemo(() => {
|
|
|
|
const entries = Object.entries(context).sort((a, b) => {
|
|
|
|
return a[0].localeCompare(b[0])
|
|
|
|
})
|
|
|
|
|
|
|
|
const values = { boolean: [], other: [] }
|
|
|
|
|
|
|
|
for (const entry of entries) {
|
|
|
|
const type = typeof entry[1]
|
|
|
|
|
|
|
|
if (type === 'boolean') {
|
|
|
|
values.boolean.push(entry)
|
|
|
|
} else if (type !== 'function') {
|
|
|
|
values.other.push(entry)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return values
|
|
|
|
}, [context])
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
style={{
|
|
|
|
padding: 20,
|
|
|
|
background: 'white',
|
|
|
|
float: 'left',
|
|
|
|
zIndex: 10,
|
|
|
|
position: 'absolute',
|
|
|
|
top: 60,
|
|
|
|
bottom: 60,
|
|
|
|
right: 20,
|
|
|
|
left: 400,
|
|
|
|
overflow: 'hidden',
|
|
|
|
boxShadow: '0px 2px 5px #ccc',
|
|
|
|
borderRadius: 3,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<div
|
|
|
|
style={{
|
|
|
|
display: 'flex',
|
|
|
|
fontSize: 14,
|
|
|
|
gap: 20,
|
|
|
|
height: '100%',
|
|
|
|
overflow: 'hidden',
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<div style={{ height: '100%', overflow: 'auto', flexShrink: 0 }}>
|
|
|
|
<table>
|
|
|
|
<tbody>
|
|
|
|
{values.boolean.map(([key, value]) => {
|
|
|
|
return (
|
|
|
|
<tr key={key} style={{ border: '1px solid #ddd' }}>
|
|
|
|
<td style={{ padding: 5 }}>{value ? '🟢' : '🔴'}</td>
|
|
|
|
<th style={{ padding: 5 }}>{key}</th>
|
|
|
|
</tr>
|
|
|
|
)
|
|
|
|
})}
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
|
|
|
|
<div>
|
|
|
|
<div
|
|
|
|
style={{
|
|
|
|
display: 'flex',
|
|
|
|
flexDirection: 'column',
|
|
|
|
gap: 10,
|
|
|
|
margin: '10px 0',
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Button onClick={dispatchDocChanged}>trigger doc change</Button>
|
|
|
|
<Button onClick={toggleLintingError}>
|
|
|
|
toggle linting error
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div style={{ height: '100%', overflow: 'auto' }}>
|
|
|
|
<table
|
|
|
|
style={{
|
|
|
|
width: '100%',
|
|
|
|
overflow: 'hidden',
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<tbody>
|
|
|
|
{values.other.map(([key, value]) => {
|
|
|
|
return (
|
|
|
|
<tr
|
|
|
|
key={key}
|
|
|
|
style={{
|
|
|
|
width: '100%',
|
|
|
|
overflow: 'hidden',
|
|
|
|
border: '1px solid #ddd',
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<th
|
|
|
|
style={{
|
|
|
|
verticalAlign: 'top',
|
|
|
|
padding: 5,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{key}
|
|
|
|
</th>
|
|
|
|
<td
|
|
|
|
style={{
|
|
|
|
overflow: 'auto',
|
|
|
|
padding: 5,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<pre
|
|
|
|
style={{
|
|
|
|
margin: '0 10px',
|
|
|
|
fontSize: 10,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{JSON.stringify(value, null, 2)}
|
|
|
|
</pre>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
)
|
|
|
|
})}
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-05-16 05:38:20 -04:00
|
|
|
return (
|
2021-09-30 07:29:25 -04:00
|
|
|
<div className="pdf-viewer">
|
2021-10-15 05:39:56 -04:00
|
|
|
<PdfPreviewPane />
|
|
|
|
<Inner />
|
2022-05-16 05:38:20 -04:00
|
|
|
</div>
|
2021-09-30 07:29:25 -04:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
const compileStatuses = [
|
|
|
|
'autocompile-backoff',
|
|
|
|
'clear-cache',
|
|
|
|
'clsi-maintenance',
|
|
|
|
'compile-in-progress',
|
|
|
|
'exited',
|
|
|
|
'failure',
|
|
|
|
'generic',
|
|
|
|
'project-too-large',
|
|
|
|
'rate-limited',
|
|
|
|
'success',
|
|
|
|
'terminated',
|
|
|
|
'timedout',
|
|
|
|
'too-recently-compiled',
|
|
|
|
'unavailable',
|
|
|
|
'validation-problems',
|
|
|
|
'foo',
|
|
|
|
]
|
|
|
|
|
|
|
|
export const CompileError = () => {
|
|
|
|
const [status, setStatus] = useState('success')
|
|
|
|
|
|
|
|
useFetchMock(fetchMock => {
|
|
|
|
mockCompileError(fetchMock, status, 0)
|
|
|
|
mockBuildFile(fetchMock)
|
|
|
|
})
|
|
|
|
|
|
|
|
const Inner = () => {
|
2021-10-15 05:39:56 -04:00
|
|
|
const { startCompile } = useCompileContext()
|
2021-09-30 07:29:25 -04:00
|
|
|
|
|
|
|
const handleStatusChange = useCallback(
|
|
|
|
event => {
|
|
|
|
setStatus(event.target.value)
|
|
|
|
window.setTimeout(() => {
|
2021-10-11 09:45:36 -04:00
|
|
|
startCompile()
|
2021-09-30 07:29:25 -04:00
|
|
|
}, 0)
|
|
|
|
},
|
2021-10-11 09:45:36 -04:00
|
|
|
[startCompile]
|
2021-09-30 07:29:25 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
style={{
|
|
|
|
position: 'absolute',
|
|
|
|
bottom: 10,
|
|
|
|
left: 10,
|
|
|
|
background: 'white',
|
|
|
|
padding: 10,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<label>
|
|
|
|
{'status: '}
|
|
|
|
<select value={status} onInput={handleStatusChange}>
|
|
|
|
{compileStatuses.map(status => (
|
|
|
|
<option key={status}>{status}</option>
|
|
|
|
))}
|
|
|
|
</select>
|
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-05-16 05:38:20 -04:00
|
|
|
return (
|
2021-10-15 05:39:56 -04:00
|
|
|
<>
|
2021-09-30 07:29:25 -04:00
|
|
|
<PdfPreviewPane />
|
|
|
|
<Inner />
|
2022-05-16 05:38:20 -04:00
|
|
|
</>
|
2021-09-30 07:29:25 -04:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
const compileErrors = [
|
|
|
|
'autocompile-backoff',
|
|
|
|
'clear-cache',
|
|
|
|
'clsi-maintenance',
|
|
|
|
'compile-in-progress',
|
|
|
|
'exited',
|
|
|
|
'failure',
|
|
|
|
'generic',
|
|
|
|
'project-too-large',
|
|
|
|
'rate-limited',
|
|
|
|
'success',
|
|
|
|
'terminated',
|
|
|
|
'timedout',
|
|
|
|
'too-recently-compiled',
|
|
|
|
'unavailable',
|
|
|
|
'validation-problems',
|
|
|
|
'foo',
|
|
|
|
]
|
|
|
|
|
|
|
|
export const DisplayError = () => {
|
2021-10-21 06:31:51 -04:00
|
|
|
useFetchMock(fetchMock => {
|
|
|
|
mockCompile(fetchMock)
|
|
|
|
})
|
|
|
|
|
2022-05-16 05:38:20 -04:00
|
|
|
return (
|
2021-10-15 05:39:56 -04:00
|
|
|
<>
|
2021-09-30 07:29:25 -04:00
|
|
|
{compileErrors.map(error => (
|
|
|
|
<div
|
|
|
|
key={error}
|
|
|
|
style={{ background: '#5d6879', padding: 10, margin: 5 }}
|
|
|
|
>
|
|
|
|
<div style={{ fontFamily: 'monospace', color: 'white' }}>{error}</div>
|
|
|
|
<PdfPreviewError error={error} />
|
|
|
|
</div>
|
|
|
|
))}
|
2022-05-16 05:38:20 -04:00
|
|
|
</>
|
2021-09-30 07:29:25 -04:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-10-12 04:47:46 -04:00
|
|
|
export const HybridToolbar = () => {
|
|
|
|
useFetchMock(fetchMock => {
|
|
|
|
mockCompile(fetchMock, 500)
|
|
|
|
mockBuildFile(fetchMock)
|
2021-10-21 06:31:51 -04:00
|
|
|
mockEventTracking(fetchMock)
|
2021-10-12 04:47:46 -04:00
|
|
|
})
|
|
|
|
|
2022-05-16 05:38:20 -04:00
|
|
|
return (
|
2021-10-15 05:39:56 -04:00
|
|
|
<div className="pdf">
|
|
|
|
<PdfPreviewHybridToolbar />
|
2022-05-16 05:38:20 -04:00
|
|
|
</div>
|
2021-10-12 04:47:46 -04:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-09-30 07:29:25 -04:00
|
|
|
export const FileList = () => {
|
|
|
|
const fileList = useMemo(() => {
|
2021-10-21 06:31:51 -04:00
|
|
|
return buildFileList(cloneDeep(outputFiles))
|
2021-09-30 07:29:25 -04:00
|
|
|
}, [])
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="dropdown open">
|
|
|
|
<div className="dropdown-menu">
|
|
|
|
<PdfFileList fileList={fileList} />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export const Logs = () => {
|
|
|
|
useFetchMock(fetchMock => {
|
2021-10-15 05:39:56 -04:00
|
|
|
mockCompileError(fetchMock, 400, 0)
|
2021-09-30 07:29:25 -04:00
|
|
|
mockBuildFile(fetchMock)
|
|
|
|
mockClearCache(fetchMock)
|
|
|
|
})
|
|
|
|
|
2022-05-16 05:38:20 -04:00
|
|
|
return (
|
2021-10-15 05:39:56 -04:00
|
|
|
<div className="pdf">
|
2023-11-14 04:51:30 -05:00
|
|
|
<PdfPreviewProvider>
|
|
|
|
<PdfLogsViewer />
|
|
|
|
</PdfPreviewProvider>
|
2022-05-16 05:38:20 -04:00
|
|
|
</div>
|
2021-09-30 07:29:25 -04:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
const validationProblems = {
|
|
|
|
sizeCheck: {
|
|
|
|
resources: [
|
|
|
|
{ path: 'foo/bar', kbSize: 76221 },
|
|
|
|
{ path: 'bar/baz', kbSize: 2342 },
|
|
|
|
],
|
|
|
|
},
|
|
|
|
mainFile: true,
|
|
|
|
conflictedPaths: [
|
|
|
|
{
|
|
|
|
path: 'foo/bar',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: 'foo/baz',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}
|
|
|
|
|
|
|
|
export const ValidationIssues = () => {
|
|
|
|
useFetchMock(fetchMock => {
|
|
|
|
mockCompileValidationIssues(fetchMock, validationProblems, 0)
|
|
|
|
mockBuildFile(fetchMock)
|
|
|
|
})
|
|
|
|
|
2022-05-16 05:38:20 -04:00
|
|
|
return <PdfPreviewPane />
|
2021-09-30 07:29:25 -04:00
|
|
|
}
|