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: add single dependency graph view for a specific resource relations #1161

Open
wants to merge 15 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 10 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,4 +1,4 @@
import { useEffect, useState } from 'react';
import { useCallback, useEffect, useState } from 'react';
import { useRouter } from 'next/router';

import { InventoryFilterData } from '@components/inventory/hooks/useInventory/types/useInventoryTypes';
Expand All @@ -9,6 +9,10 @@ export type ReactFlowData = {
edges: any[];
};

export type DependencyGraphProps = {
data: ReactFlowData;
};

// converting the json object into data that reactflow needs
// TODO - based on selected library
function GetData(res: any) {
Expand Down Expand Up @@ -66,7 +70,7 @@ function GetData(res: any) {
return d;
}

function useDependencyGraph() {
function useDependencyGraph(resourceId?: string) {
const [loading, setLoading] = useState(true);
const [data, setData] = useState<ReactFlowData>();
const [error, setError] = useState(false);
Expand All @@ -75,26 +79,55 @@ function useDependencyGraph() {
useState<InventoryFilterData[]>();

const router = useRouter();
const fetchRelationsByResourceId = useCallback(
(id: string) => {
settingsService
.getResourceById(`?resourceId=${id}`)
.then(res => {
if (res === Error) {
setLoading(false);
setError(true);
} else {
setLoading(false);
shavidze marked this conversation as resolved.
Show resolved Hide resolved
setData(GetData([].concat(res)));
}
})
.finally(() => {
setLoading(false);
});
},
[resourceId]
);

const fetchAllRelations = useCallback(() => {
settingsService
.getRelations(filters)
.then(res => {
if (res === Error) {
setLoading(false);
setError(true);
} else {
setLoading(false);
setData(GetData([].concat(res)));
}
})
.finally(() => {
setLoading(false);
});
}, [filters]);

function fetch() {
const fetch = useCallback(() => {
if (!loading) {
setLoading(true);
}

if (error) {
setError(false);
}

settingsService.getRelations(filters).then(res => {
if (res === Error) {
setLoading(false);
setError(true);
} else {
setLoading(false);
setData(GetData(res));
}
});
}
if (resourceId) {
fetchRelationsByResourceId(resourceId);
} else fetchAllRelations();
}, [filters, resourceId]);

function deleteFilter(idx: number) {
const updatedFilters: InventoryFilterData[] = [...filters!];
Expand Down
Loading