Skip to content

Commit

Permalink
fix: visibility of Blocks visualiser when error (#1145)
Browse files Browse the repository at this point in the history
* fixed visibility of Blocks visualiser

* added changeset

* sonarcloud issues fixed
  • Loading branch information
catosaurusrex2003 authored Oct 10, 2024
1 parent a3f6fe0 commit 0336253
Show file tree
Hide file tree
Showing 3 changed files with 11,451 additions and 13,436 deletions.
5 changes: 5 additions & 0 deletions .changeset/cold-garlics-attack.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@asyncapi/studio": patch
---

fixed the rendering of block visualiser when document has errors
25 changes: 18 additions & 7 deletions apps/studio/src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { SettingsModal, ConfirmNewFileModal } from './Modals';

import { usePanelsState, panelsState, useDocumentsState } from '@/state';

import type { FunctionComponent, ReactNode } from 'react';
import { useEffect, useState, type FunctionComponent, type ReactNode } from 'react';
import type { PanelsState } from '@/state/panels.state';
import { driverObj } from '@/helpers/driver';

Expand Down Expand Up @@ -54,12 +54,12 @@ interface SidebarProps {}

export const Sidebar: FunctionComponent<SidebarProps> = () => {
const { show, secondaryPanelType } = usePanelsState();
const document = useDocumentsState(state => state.documents['asyncapi']?.document) || null;
const isV3 = document?.version().startsWith('3.');

if (show.activityBar === false) {
return null;
}
const [document, hasErrors] = useDocumentsState((state) => [
state.documents['asyncapi']?.document,
state.documents['asyncapi']?.diagnostics?.errors.length > 0,
]) || [null, false];

const [isV3, setIsV3] = useState(document?.version().startsWith('3.'));

let navigation: NavItem[] = [
// navigation
Expand Down Expand Up @@ -125,6 +125,17 @@ export const Sidebar: FunctionComponent<SidebarProps> = () => {
const getCurrentTourStep = localStorage.getItem('currentTourStep');
driverObj.drive(parseInt(getCurrentTourStep ?? '0', 10));
};

useEffect(() => {
// if the document has no errors then only update the setIsV3 variable
if (!hasErrors) {
setIsV3(document?.version().startsWith('3.'));
}
}, [document]);

if (show.activityBar === false) {
return null;
}

return (
<div className="flex flex-col bg-gray-800 shadow-lg border-r border-gray-700 justify-between" id="sidebar">
Expand Down
Loading

0 comments on commit 0336253

Please sign in to comment.