Skip to content
Snippets Groups Projects
Commit 509503fb authored by Leonardo Christino's avatar Leonardo Christino
Browse files

feat(schema): add layouting to schema panel

parent 800325a3
No related branches found
No related tags found
1 merge request!74Chore/update backend
...@@ -2,8 +2,11 @@ import { createSlice, PayloadAction } from '@reduxjs/toolkit'; ...@@ -2,8 +2,11 @@ import { createSlice, PayloadAction } from '@reduxjs/toolkit';
import type { RootState } from './store'; import type { RootState } from './store';
export interface GraphQueryResultFromBackendPayload { export interface GraphQueryResultFromBackendPayload {
payload: GraphQueryResultFromBackend; queryID: string;
type: string; result: {
payload: GraphQueryResultFromBackend;
type: string;
};
} }
export interface GraphQueryResultFromBackend { export interface GraphQueryResultFromBackend {
...@@ -63,7 +66,7 @@ export const graphQueryResultSlice = createSlice({ ...@@ -63,7 +66,7 @@ export const graphQueryResultSlice = createSlice({
initialState, initialState,
reducers: { reducers: {
assignNewGraphQueryResult: (state, action: PayloadAction<GraphQueryResultFromBackendPayload>) => { assignNewGraphQueryResult: (state, action: PayloadAction<GraphQueryResultFromBackendPayload>) => {
const payload = action.payload.payload; const payload = action.payload.result.payload;
// Only keep one node and one edge per id. This is also done in the backend, but we do it here as well to be sure. // Only keep one node and one edge per id. This is also done in the backend, but we do it here as well to be sure.
const nodeIDs = new Set(payload.nodes.map((node) => node.id)); const nodeIDs = new Set(payload.nodes.map((node) => node.id));
......
...@@ -8,11 +8,11 @@ import { SchemaFromBackend, SchemaGraph, SchemaGraphology } from '../../schema'; ...@@ -8,11 +8,11 @@ import { SchemaFromBackend, SchemaGraph, SchemaGraphology } from '../../schema';
export type SchemaSettings = { export type SchemaSettings = {
connectionType: 'connection' | 'bezier' | 'straight' | 'step'; connectionType: 'connection' | 'bezier' | 'straight' | 'step';
layoutName: AllLayoutAlgorithms;
}; };
type schemaSliceI = { type schemaSliceI = {
graph: SchemaGraph; graph: SchemaGraph;
layoutName: AllLayoutAlgorithms;
settings: SchemaSettings; settings: SchemaSettings;
}; };
...@@ -20,9 +20,9 @@ type schemaSliceI = { ...@@ -20,9 +20,9 @@ type schemaSliceI = {
export const initialState: schemaSliceI = { export const initialState: schemaSliceI = {
graph: new SchemaGraphology().export(), graph: new SchemaGraphology().export(),
// layoutName: 'Cytoscape_fcose', // layoutName: 'Cytoscape_fcose',
layoutName: Layouts.KLAY,
settings: { settings: {
connectionType: 'connection', connectionType: 'connection',
layoutName: Layouts.KLAY,
}, },
}; };
export const schemaSlice = createSlice({ export const schemaSlice = createSlice({
...@@ -35,11 +35,6 @@ export const schemaSlice = createSlice({ ...@@ -35,11 +35,6 @@ export const schemaSlice = createSlice({
state.graph = action.payload; state.graph = action.payload;
}, },
setSchemaLayout: (state, action: PayloadAction<string>) => {
console.log('setSchemaLayout', action);
state.layoutName = action.payload as AllLayoutAlgorithms;
},
readInSchemaFromBackend: (state, action: PayloadAction<SchemaFromBackend>) => { readInSchemaFromBackend: (state, action: PayloadAction<SchemaFromBackend>) => {
state.graph = SchemaUtils.schemaBackend2Graphology(action.payload).export(); state.graph = SchemaUtils.schemaBackend2Graphology(action.payload).export();
// console.log('Updated schema from backend'); // console.log('Updated schema from backend');
......
...@@ -76,12 +76,11 @@ export const Schema = (props: Props) => { ...@@ -76,12 +76,11 @@ export const Schema = (props: Props) => {
// In case the schema is updated // In case the schema is updated
const schemaGraph = useSchemaGraph(); const schemaGraph = useSchemaGraph();
const schemaGraphology = useMemo(() => toSchemaGraphology(schemaGraph), [schemaGraph]); const schemaGraphology = useMemo(() => toSchemaGraphology(schemaGraph), [schemaGraph]);
const schemaLayout = useSchemaLayout();
const layout = useRef<AlgorithmToLayoutProvider<AllLayoutAlgorithms>>(); const layout = useRef<AlgorithmToLayoutProvider<AllLayoutAlgorithms>>();
function updateLayout() { function updateLayout() {
const layoutFactory = new LayoutFactory(); const layoutFactory = new LayoutFactory();
layout.current = layoutFactory.createLayout(schemaLayout as AllLayoutAlgorithms); // TODO: more layouts here layout.current = layoutFactory.createLayout(settings.layoutName);
} }
useEffect(() => { useEffect(() => {
...@@ -126,7 +125,7 @@ export const Schema = (props: Props) => { ...@@ -126,7 +125,7 @@ export const Schema = (props: Props) => {
// schemaGraphology.order, // schemaGraphology.order,
// schemaFlow // schemaFlow
// ); // );
}, [schemaGraph, schemaLayout, settings]); }, [schemaGraph, settings]);
// console.log(nodes, edges); // console.log(nodes, edges);
......
...@@ -5,6 +5,7 @@ import CloseIcon from '@mui/icons-material/Close'; ...@@ -5,6 +5,7 @@ import CloseIcon from '@mui/icons-material/Close';
import { useAppDispatch, useSchemaSettings } from '../../data-access'; import { useAppDispatch, useSchemaSettings } from '../../data-access';
import { SchemaSettings, setSchemaSettings } from '../../data-access/store/schemaSlice'; import { SchemaSettings, setSchemaSettings } from '../../data-access/store/schemaSlice';
import { FormActions, FormBody, FormCard, FormControl, FormHBar, FormTitle, FormDiv } from '../../components/forms'; import { FormActions, FormBody, FormCard, FormControl, FormHBar, FormTitle, FormDiv } from '../../components/forms';
import { Layouts } from '../../graph-layout';
export const SchemaDialog = React.forwardRef<HTMLDivElement, DialogProps>((props, ref) => { export const SchemaDialog = React.forwardRef<HTMLDivElement, DialogProps>((props, ref) => {
const settings = useSchemaSettings(); const settings = useSchemaSettings();
...@@ -25,7 +26,7 @@ export const SchemaDialog = React.forwardRef<HTMLDivElement, DialogProps>((props ...@@ -25,7 +26,7 @@ export const SchemaDialog = React.forwardRef<HTMLDivElement, DialogProps>((props
<> <>
{props.open && ( {props.open && (
<FormDiv ref={ref}> <FormDiv ref={ref}>
<FormCard> <FormCard className="w-fit">
<FormBody <FormBody
onSubmit={(e) => { onSubmit={(e) => {
e.preventDefault(); e.preventDefault();
...@@ -89,6 +90,25 @@ export const SchemaDialog = React.forwardRef<HTMLDivElement, DialogProps>((props ...@@ -89,6 +90,25 @@ export const SchemaDialog = React.forwardRef<HTMLDivElement, DialogProps>((props
</select> </select>
</FormControl> </FormControl>
<FormHBar /> <FormHBar />
<FormControl>
<label className="label">
<span className="label-text">Layout Type</span>
</label>
<select
className="select select-primary select-sm "
value={state.layoutName}
onChange={(e) => {
setState({ ...state, layoutName: e.target.value as any });
}}
>
{Object.entries(Layouts).map(([k, v]) => (
<option className="option" value={v} key={v}>
{k}
</option>
))}
</select>
</FormControl>
<FormHBar />
<FormActions onClose={props.onClose} /> <FormActions onClose={props.onClose} />
</FormBody> </FormBody>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment