mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-12-20 17:30:46 +00:00
feat: add conditionalClass utility and refactor className assignments for improved readability.
This commit is contained in:
@@ -30,6 +30,7 @@ import { KeyboardAction, KeyboardActionGroup, KeyboardActionHandler, useKeyboard
|
|||||||
import { isFabric, isFabricMirrored, isFabricNative } from "Platform/Fabric/FabricUtil";
|
import { isFabric, isFabricMirrored, isFabricNative } from "Platform/Fabric/FabricUtil";
|
||||||
import { userContext } from "UserContext";
|
import { userContext } from "UserContext";
|
||||||
import { getCollectionName, getDatabaseName } from "Utils/APITypeUtils";
|
import { getCollectionName, getDatabaseName } from "Utils/APITypeUtils";
|
||||||
|
import { conditionalClass } from "Utils/StyleUtils";
|
||||||
import { Allotment, AllotmentHandle } from "allotment";
|
import { Allotment, AllotmentHandle } from "allotment";
|
||||||
import { useSidePanel } from "hooks/useSidePanel";
|
import { useSidePanel } from "hooks/useSidePanel";
|
||||||
import useZoomLevel from "hooks/useZoomLevel";
|
import useZoomLevel from "hooks/useZoomLevel";
|
||||||
@@ -347,13 +348,16 @@ export const SidebarContainer: React.FC<SidebarProps> = ({ explorer }) => {
|
|||||||
ref={allotment}
|
ref={allotment}
|
||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
onDragEnd={onDragEnd}
|
onDragEnd={onDragEnd}
|
||||||
className={`resourceTreeAndTabs ${styles.accessibleContent} ${isZoomed ? styles.accessibleContentZoom : ""}`}
|
className={`resourceTreeAndTabs ${styles.accessibleContent} ${conditionalClass(
|
||||||
|
isZoomed,
|
||||||
|
styles.accessibleContentZoom,
|
||||||
|
)}`}
|
||||||
>
|
>
|
||||||
{/* Collections Tree - Start */}
|
{/* Collections Tree - Start */}
|
||||||
{hasSidebar && (
|
{hasSidebar && (
|
||||||
// When collapsed, we force the pane to 24 pixels wide and make it non-resizable.
|
// When collapsed, we force the pane to 24 pixels wide and make it non-resizable.
|
||||||
<Allotment.Pane
|
<Allotment.Pane
|
||||||
className={`${styles.minHeightResponsive} ${isZoomed ? styles.minHeightZoom : ""}`}
|
className={`${styles.minHeightResponsive} ${conditionalClass(isZoomed, styles.minHeightZoom)}`}
|
||||||
minSize={24}
|
minSize={24}
|
||||||
preferredSize={250}
|
preferredSize={250}
|
||||||
>
|
>
|
||||||
@@ -413,7 +417,7 @@ export const SidebarContainer: React.FC<SidebarProps> = ({ explorer }) => {
|
|||||||
</Allotment.Pane>
|
</Allotment.Pane>
|
||||||
)}
|
)}
|
||||||
<Allotment.Pane
|
<Allotment.Pane
|
||||||
className={`${styles.minHeightResponsive} ${isZoomed ? styles.minHeightZoom : ""}`}
|
className={`${styles.minHeightResponsive} ${conditionalClass(isZoomed, styles.minHeightZoom)}`}
|
||||||
minSize={200}
|
minSize={200}
|
||||||
>
|
>
|
||||||
<Tabs explorer={explorer} />
|
<Tabs explorer={explorer} />
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import { QueryResults } from "../../../Contracts/ViewModels";
|
|||||||
import { ErrorList } from "./ErrorList";
|
import { ErrorList } from "./ErrorList";
|
||||||
import { ResultsView } from "./ResultsView";
|
import { ResultsView } from "./ResultsView";
|
||||||
import useZoomLevel from "hooks/useZoomLevel";
|
import useZoomLevel from "hooks/useZoomLevel";
|
||||||
|
import { conditionalClass } from "Utils/StyleUtils";
|
||||||
|
|
||||||
export interface ResultsViewProps {
|
export interface ResultsViewProps {
|
||||||
isMongoDB: boolean;
|
isMongoDB: boolean;
|
||||||
@@ -30,7 +31,7 @@ const ExecuteQueryCallToAction: React.FC = () => {
|
|||||||
<div>
|
<div>
|
||||||
<p>
|
<p>
|
||||||
<img
|
<img
|
||||||
className={`${styles.responsiveImg} ${isZoomed ? styles.zoomedImageSize : ""}`}
|
className={`${styles.responsiveImg} ${conditionalClass(isZoomed, styles.zoomedImageSize)}`}
|
||||||
src={RunQuery}
|
src={RunQuery}
|
||||||
aria-hidden="true"
|
aria-hidden="true"
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -21,3 +21,11 @@ export function copyStyles(sourceDoc: Document, targetDoc: Document): void {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Conditionally returns a class name based on a boolean condition.
|
||||||
|
* If the condition is true, returns the `trueValue` class; otherwise, returns `falseValue` (or an empty string if not provided).
|
||||||
|
*/
|
||||||
|
export function conditionalClass(condition: boolean, trueValue: string, falseValue?: string): string {
|
||||||
|
return condition ? trueValue : falseValue || "";
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user