Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support upload and display jsonl file #21

Merged
merged 5 commits into from
Feb 1, 2024
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
2 changes: 2 additions & 0 deletions .vscode/cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
"fdspawn",
"getipython",
"grpcio",
"highlightjs",
"hljs",
"ifaddresses",
"iloc",
"INET",
Expand Down
4 changes: 2 additions & 2 deletions packages/secretnote-ui/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "build"
"outDir": "build",
},
"include": ["./src/**/*", "./src/.openapi-stubs/**/*"],
"references": [{ "path": "./tsconfig.node.json" }]
"references": [{ "path": "./tsconfig.node.json" }],
}
1 change: 1 addition & 0 deletions packages/secretnote/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"classnames": "^2.3.2",
"d3-dsv": "^3.0.1",
"endent": "^2.1.0",
"highlight.js": "^11.9.0",
"lodash-es": "^4.17.21",
"lucide-react": "^0.284.0",
"monaco-editor": "^0.45.0",
Expand Down
46 changes: 46 additions & 0 deletions packages/secretnote/src/modules/file/jsonl-preview-contrib.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { singleton } from '@difizen/mana-app';
import hljs from 'highlight.js';
import { useEffect } from 'react';

import { FilePreviewContribution } from './protocol';
import 'highlight.js/styles/xcode.css'; // 选择主题 https://highlightjs.org/demo

const JsonlView = (props: { data: string }) => {
useEffect(() => {
hljs.highlightAll();
}, []);

// 创建行号
const lineNumber = props.data
.trim()
.split('\n')
.map((_, index) => `${index + 1}\n`)
.join('');

return (
<pre style={{ width: '100%', height: '100%', overflow: 'scroll', margin: 0 }}>
<span
style={{
float: 'left',
textAlign: 'right',
marginRight: 12,
color: '#bfbfbf',
userSelect: 'none',
}}
>
{lineNumber}
</span>
<code className="language-json" style={{ padding: '0 1em' }}>
{props.data}
</code>
</pre>
);
};

@singleton({ contrib: [FilePreviewContribution] })
export class JsonlPreview implements FilePreviewContribution {
type = 'jsonl';
render = (data: string) => {
return <JsonlView data={data} />;
};
}
2 changes: 2 additions & 0 deletions packages/secretnote/src/modules/file/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { SecretNoteServerModule } from '@/modules/server';

import { CsvPreview } from './csv-preview-contrib';
import { ExtraView } from './extra-view';
import { JsonlPreview } from './jsonl-preview-contrib';
import { LogPreview } from './log-preview-contrib';
import { FilePreviewView } from './preview-view';
import { FilePreviewContribution } from './protocol';
Expand Down Expand Up @@ -35,6 +36,7 @@ export const FilePreviewModule = ManaModule.create()
FilePreviewView,
CsvPreview,
LogPreview,
JsonlPreview,
createViewPreference({
slot: PreviewLayoutArea.main,
view: FilePreviewView,
Expand Down
2 changes: 1 addition & 1 deletion packages/secretnote/src/modules/file/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { downloadFileByUrl as download } from '@/utils';
import { SecretNoteServerManager } from '../server';

export const BASE_PATH = '/';
export const FILE_EXTS = ['.csv', '.log', '.txt'];
export const FILE_EXTS = ['.csv', '.log', '.txt', '.jsonl'];
@singleton()
export class FileService {
protected readonly contentsManager: ContentsManager;
Expand Down
4 changes: 2 additions & 2 deletions packages/secretnote/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"compilerOptions": {
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"importHelpers": false
}
"importHelpers": false,
},
}
Loading
Loading