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

#47 URL parsing params implementation #6

Merged
merged 1 commit into from
Jul 8, 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
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Typography, Card, CardContent, CardActionArea, Grid, Container, Box, AppBar, Toolbar, Button } from '@mui/material';
import { useGlobalContext } from "../contexts/GlobalContext.tsx";
import footerImage from '../assets/summary-neurons.png';
import {parseURLParams} from "../helpers/parseURLHelper.ts";

function AppLauncher() {

Expand All @@ -20,7 +21,10 @@ function AppLauncher() {
};

const handlePasteUrlClick = () => {
console.log('Paste URL option clicked');
const exampleURL = 'http://localhost:8080/mode=default&ws_name=workspace1&ids=ADAL,AIBR,RIML&ws_name=workspace3&ids=RIFL,REMV&ws_name=test&ids=ADAL';

const parsedParams = parseURLParams(exampleURL);
console.log(parsedParams)
};

return (
Expand Down
39 changes: 39 additions & 0 deletions applications/visualizer/frontend/src/helpers/parseURLHelper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
interface WorkspaceParams {
mode: string;
workspaces: {
name: string;
ids: string[];
}[];
}

export function parseURLParams(url: string): WorkspaceParams {
const params = new URLSearchParams(url);
let mode = '';
const workspaces: { name: string; ids: string[] }[] = [];

let currentWorkspace: { name: string; ids: string[] } | null = null;

params.forEach((value, key) => {
if (key.includes('mode')) {
mode = value;
} else if (key.startsWith('ws_name')) {
if (currentWorkspace) {
workspaces.push(currentWorkspace);
}
currentWorkspace = {
name: value,
ids: []
};
} else if (key.startsWith('ids')) {
if (currentWorkspace) {
currentWorkspace.ids = value.split(',');
}
}
});

if (currentWorkspace) {
workspaces.push(currentWorkspace);
}

return { mode: mode, workspaces: workspaces };
}