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

Restore onDrop JSON file #305

Merged
merged 1 commit into from
Sep 28, 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 packages/vscode-extension/src/app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { debounce, Diagram } from '@data-story/core';
import { DataStory } from '@data-story/ui';
import { VsCodeClient } from './VsCodeClient';
import { VsCodeToast } from './VsCodeToast';
import { onDrop } from './onDrop';

const fileUri = window.initialData.fileUri;

Expand Down Expand Up @@ -67,6 +68,7 @@ export default function App() {
key={'abc'}
initDiagram={diagram}
onChange={handleChange}
onDrop={onDrop}
/>
<VsCodeToast postMessage={window.vscode.postMessage}/>
</div>
Expand Down
32 changes: 32 additions & 0 deletions packages/vscode-extension/src/app/onDrop.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { NodeDescription, str } from '@data-story/core';

export const onDrop = (event: any, addNodeFromDescription: any) => {
event.preventDefault();

const path = event.dataTransfer.getData('text/plain');
const filename = path.split('/').pop();
const extention = filename.split('.').pop();

if (extention !== 'json') {
console.warn('Currently, only JSON files are supported.');
return;
}

const description: NodeDescription = {
name: 'JsonFile',
label: filename,
inputs: [],
outputs: [{
name: 'output',
schema: {}
}],
params: [
str({
name: 'uri',
value: path,
})
],
}

addNodeFromDescription(description);
}
32 changes: 20 additions & 12 deletions packages/vscode-extension/src/messageHandlers/vsCodeNodeProvider.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
import { ServiceProvider, Application, Computer } from '@data-story/core';
import { ServiceProvider, Application, Computer, str } from '@data-story/core';
import fs from 'fs';

const CustomPass: Computer = {
name: 'CustomPass',
label: 'CustomPass',
inputs: [{
name: 'input',
schema: {},
}],
const JsonFile: Computer = {
name: 'JsonFile',
label: 'JsonFile',
inputs: [],
outputs: [{
name: 'output',
schema: {},
}],
params: [],
params: [
str({
name: 'uri',
}),
],

run: async function* ({ output, params }) {
const path = params.uri as string;
const content = fs.readFileSync(path, 'utf8');
const data = JSON.parse(content);

run: async function* ({ input, output }) {
console.log('In the custom passer!')
output.push(data);
}
}

export const vsCodeNodeProvider: ServiceProvider = {
async boot(app: Application) {
app.addComputers([ CustomPass]);
app.addComputers([
JsonFile,
]);
}
}
Loading