Skip to content

Commit

Permalink
env changes
Browse files Browse the repository at this point in the history
  • Loading branch information
prakriti-solankey authored Dec 17, 2024
1 parent 07b3a9b commit d94481a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 17 deletions.
10 changes: 6 additions & 4 deletions frontend/src/components/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ const DropdownComponent: React.FC<ReusableDropdownProps> = ({
const isLargeDesktop = useMediaQuery(`(min-width:1440px )`);
const handleChange = (selectedOption: OptionType | null | void) => {
onSelect(selectedOption);
const existingModel = localStorage.getItem('selectedModel');
if (existingModel != selectedOption?.value) {
localStorage.setItem('selectedModel', selectedOption?.value ?? '');
if (view === 'ContentView') {
const existingModel = localStorage.getItem('selectedModel');
if (existingModel != selectedOption?.value) {
localStorage.setItem('selectedModel', selectedOption?.value ?? '');
}
}
};
const allOptions = useMemo(() => options, [options]);
Expand Down Expand Up @@ -52,7 +54,7 @@ const DropdownComponent: React.FC<ReusableDropdownProps> = ({
<span>{label}</span>
),
value,
isDisabled: !isModelSupported,
isDisabled: view === 'ContentView' ? !isModelSupported : isDisabled
};
}),
placeholder: placeholder || 'Select an option',
Expand Down
41 changes: 28 additions & 13 deletions frontend/src/components/Graph/GraphViewModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,17 @@ const GraphViewModal: React.FunctionComponent<GraphViewModalProps> = ({
const graphApi = async (mode?: string) => {
try {
const result = await fetchData();
if (result && result.data.data.nodes.length > 0) {
const neoNodes = result.data.data.nodes;
// Check for valid result data
if (result?.data?.status === 'Success' && result.data.data.nodes.length > 0) {
const { nodes: neoNodes, relationships: neoRels } = result.data.data;
// Create a set of valid node IDs
const nodeIds = new Set(neoNodes.map((node: any) => node.element_id));
const neoRels = result.data.data.relationships
.map((f: Relationship) => f)
.filter((rel: any) => nodeIds.has(rel.end_node_element_id) && nodeIds.has(rel.start_node_element_id));
const { finalNodes, finalRels, schemeVal } = processGraphData(neoNodes, neoRels);

// Filter relationships to include only those with valid node IDs
const filteredRels = neoRels.filter(
(rel: any) => nodeIds.has(rel.start_node_element_id) && nodeIds.has(rel.end_node_element_id)
);
// Process graph data
const { finalNodes, finalRels, schemeVal } = processGraphData(neoNodes, filteredRels);
if (mode === 'refreshMode') {
initGraph(graphType, finalNodes, finalRels, schemeVal);
} else {
Expand All @@ -151,21 +154,33 @@ const GraphViewModal: React.FunctionComponent<GraphViewModalProps> = ({
setNewScheme(schemeVal);
setLoading(false);
}
// Update state
setAllNodes(finalNodes);
setAllRelationships(finalRels);
setScheme(schemeVal);
setDisableRefresh(false);
} else {
setLoading(false);
setStatus('danger');
setStatusMessage(`No Nodes and Relations for the ${inspectedName} file`);
handleEmptyResult(result);
}
} catch (error: any) {
setLoading(false);
setStatus('danger');
setStatusMessage(error.message);
handleError(error);
}
};
// Helper function to handle empty result cases
const handleEmptyResult = (result: any) => {
setLoading(false);
setStatus('danger');
const message = viewPoint === 'tableView'
? `No Nodes and Relations for the ${inspectedName} file`
: result?.data?.message || 'An error occurred';
setStatusMessage(message);
};
// Helper function to handle errors
const handleError = (error: any) => {
setLoading(false);
setStatus('danger');
setStatusMessage(error.message || 'An unexpected error occurred');
};

useEffect(() => {
if (open) {
Expand Down

0 comments on commit d94481a

Please sign in to comment.