Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 4 additions & 4 deletions src/pages/views/components/SingleView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ const SingleView: React.FC<SingleViewProps> = ({ id }) => {
// Render the main view through ViewSection to reuse its spacing/scroll styling;
// rendering the raw View here caused padding/overflow glitches alongside sections.
const primaryViewSection = {
title: "",
title: title || name,
viewRef: {
namespace: namespace || "",
name: name
Expand All @@ -185,7 +185,7 @@ const SingleView: React.FC<SingleViewProps> = ({ id }) => {
)
}
>
<div className="flex h-full w-full flex-1 flex-col overflow-y-auto p-6 pb-0">
<div className="flex h-full w-full flex-1 flex-col overflow-y-auto px-6">
{/* Render aggregated variables once at the top */}
{aggregatedVariables && aggregatedVariables.length > 0 && (
<GlobalFiltersForm
Expand All @@ -201,7 +201,7 @@ const SingleView: React.FC<SingleViewProps> = ({ id }) => {
<hr className="my-4 border-gray-200" />
)}

<div>
<div className="mt-2">
<ViewSection
key={`${namespace || "default"}:${name}`}
section={primaryViewSection}
Expand All @@ -214,7 +214,7 @@ const SingleView: React.FC<SingleViewProps> = ({ id }) => {
{viewResult.sections.map((section) => (
<div
key={`${section.viewRef.namespace}:${section.viewRef.name}`}
className="mt-6 pt-6"
className="mt-4"
>
<ViewSection section={section} hideVariables />
</div>
Expand Down
110 changes: 79 additions & 31 deletions src/pages/views/components/ViewSection.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from "react";
import React, { useState } from "react";
import { useQuery } from "@tanstack/react-query";
import { IoChevronDownOutline } from "react-icons/io5";
import { getViewDataByNamespace } from "../../../api/services/views";
import View from "../../audit-report/components/View/View";
import { Icon } from "../../../ui/Icons/Icon";
Expand All @@ -16,6 +17,7 @@ const ViewSection: React.FC<ViewSectionProps> = ({
section,
hideVariables
}) => {
const [isExpanded, setIsExpanded] = useState(true);
const { namespace, name } = section.viewRef;

// Use prefixed search params for view variables
Expand All @@ -37,50 +39,96 @@ const ViewSection: React.FC<ViewSectionProps> = ({
staleTime: 5 * 60 * 1000
});

if (isLoading) {
return (
<div className="animate-pulse">
<div className="mb-4 h-4 w-32 rounded bg-gray-200"></div>
<div className="h-64 rounded bg-gray-100"></div>
</div>
);
}
const handleHeaderKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {
if (event.key === "Enter" || event.key === " ") {
event.preventDefault();
setIsExpanded(!isExpanded);
}
};

if (error || !sectionViewResult) {
Comment thread
adityathebe marked this conversation as resolved.
Outdated
const errorContentId = `section-${namespace}-${name}-error`;
return (
<>
<div className="mb-4 flex items-center">
<div
role="button"
tabIndex={0}
aria-expanded={isExpanded}
aria-controls={errorContentId}
className="mb-2 flex cursor-pointer items-center gap-2 rounded px-2 py-1"
onClick={() => setIsExpanded(!isExpanded)}
Comment thread
adityathebe marked this conversation as resolved.
onKeyDown={handleHeaderKeyDown}
>
<IoChevronDownOutline
className={`h-4 w-4 flex-shrink-0 transform text-gray-600 transition-transform ${!isExpanded ? "-rotate-90" : ""}`}
/>
{section.icon && (
<Icon name={section.icon} className="mr-2 h-5 w-5" />
<Icon
name={section.icon}
className="h-5 w-5 flex-shrink-0 text-gray-600"
/>
)}
<h2 className="text-lg font-semibold">{section.title}</h2>
</div>
<div className="text-red-500">
{error instanceof Error ? error.message : "Failed to load section"}
<h3 className="text-lg font-semibold text-gray-600">
{section.title}
</h3>
</div>
{isExpanded && (
<div id={errorContentId} className="text-red-500">
{error instanceof Error ? error.message : "Failed to load section"}
</div>
)}
</>
);
}

const contentId = `section-${namespace}-${name}`;

return (
<>
<div className="mb-4 flex items-center">
{section.icon && <Icon name={section.icon} className="mr-2 h-5 w-5" />}
<h2 className="text-lg font-semibold">{section.title}</h2>
<div
role="button"
tabIndex={0}
aria-expanded={isExpanded}
aria-controls={contentId}
className="mb-2 flex cursor-pointer items-center gap-2 rounded px-2 py-1"
onClick={() => setIsExpanded(!isExpanded)}
onKeyDown={handleHeaderKeyDown}
>
<IoChevronDownOutline
className={`h-4 w-4 flex-shrink-0 transform text-gray-600 transition-transform ${!isExpanded ? "-rotate-90" : ""}`}
/>
{section.icon && (
<Icon
name={section.icon}
className="h-5 w-5 flex-shrink-0 text-gray-600"
/>
)}
<h3 className="text-lg font-semibold text-gray-600">{section.title}</h3>
</div>
<View
title=""
namespace={namespace}
name={name}
columns={sectionViewResult?.columns}
columnOptions={sectionViewResult?.columnOptions}
panels={sectionViewResult?.panels}
variables={sectionViewResult?.variables}
card={sectionViewResult?.card}
requestFingerprint={sectionViewResult.requestFingerprint}
currentVariables={currentViewVariables}
hideVariables={hideVariables}
/>
{isExpanded && (
<div id={contentId}>
{isLoading ? (
<div className="animate-pulse">
<div className="mb-4 h-4 w-32 rounded bg-gray-200"></div>
<div className="h-64 rounded bg-gray-100"></div>
</div>
) : (
<View
title=""
namespace={namespace}
name={name}
columns={sectionViewResult?.columns}
columnOptions={sectionViewResult?.columnOptions}
panels={sectionViewResult?.panels}
variables={sectionViewResult?.variables}
card={sectionViewResult?.card}
requestFingerprint={sectionViewResult.requestFingerprint}
currentVariables={currentViewVariables}
hideVariables={hideVariables}
/>
)}
</div>
)}
</>
);
};
Expand Down
Loading