[Query Copilot] Update sample data resource tree item stylings (#1530)

* Update sample data resource tree item stylings

* Clean up sample data tree

---------

Co-authored-by: Victor Meng <vimeng@microsoft.com>
This commit is contained in:
v-darkora 2023-07-13 09:17:29 +02:00 committed by GitHub
parent e9f3c64239
commit fb6c0caca6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 67 additions and 72 deletions

View File

@ -28,4 +28,4 @@
.clickDisabled { .clickDisabled {
pointer-events: none; pointer-events: none;
} }
} }

View File

@ -25,6 +25,7 @@ export class AccordionComponent extends React.Component<AccordionComponentProps>
export interface AccordionItemComponentProps { export interface AccordionItemComponentProps {
title: string; title: string;
isExpanded?: boolean; isExpanded?: boolean;
containerStyles?: React.CSSProperties;
styles?: React.CSSProperties; styles?: React.CSSProperties;
} }
@ -54,9 +55,9 @@ export class AccordionItemComponent extends React.Component<AccordionItemCompone
} }
public render(): JSX.Element { public render(): JSX.Element {
const { styles } = this.props; const { containerStyles, styles } = this.props;
return ( return (
<div className="accordionItemContainer"> <div className="accordionItemContainer" style={{ ...containerStyles }}>
<div className="accordionItemHeader" onClick={this.onHeaderClick} onKeyPress={this.onHeaderKeyPress}> <div className="accordionItemHeader" onClick={this.onHeaderClick} onKeyPress={this.onHeaderKeyPress}>
{this.renderCollapseExpandIcon()} {this.renderCollapseExpandIcon()}
{this.props.title} {this.props.title}

View File

@ -790,14 +790,10 @@ export const ResourceTree: React.FC<ResourceTreeProps> = ({ container }: Resourc
{!isNotebookEnabled && isSampleDataEnabled && ( {!isNotebookEnabled && isSampleDataEnabled && (
<> <>
<AccordionComponent> <AccordionComponent>
<AccordionItemComponent <AccordionItemComponent title={"MY DATA"} isExpanded={!gitHubNotebooksContentRoot}>
title={"MY DATA"}
isExpanded={!gitHubNotebooksContentRoot}
styles={{ maxHeight: 230 }}
>
<TreeComponent className="dataResourceTree" rootNode={dataRootNode} /> <TreeComponent className="dataResourceTree" rootNode={dataRootNode} />
</AccordionItemComponent> </AccordionItemComponent>
<AccordionItemComponent title={"SAMPLE DATA"}> <AccordionItemComponent title={"SAMPLE DATA"} containerStyles={{ display: "table" }}>
<SampleDataTree sampleDataResourceTokenCollection={sampleDataResourceTokenCollection} /> <SampleDataTree sampleDataResourceTokenCollection={sampleDataResourceTokenCollection} />
</AccordionItemComponent> </AccordionItemComponent>
</AccordionComponent> </AccordionComponent>
@ -808,14 +804,10 @@ export const ResourceTree: React.FC<ResourceTreeProps> = ({ container }: Resourc
{isNotebookEnabled && isSampleDataEnabled && ( {isNotebookEnabled && isSampleDataEnabled && (
<> <>
<AccordionComponent> <AccordionComponent>
<AccordionItemComponent <AccordionItemComponent title={"MY DATA"} isExpanded={!gitHubNotebooksContentRoot}>
title={"MY DATA"}
isExpanded={!gitHubNotebooksContentRoot}
styles={{ maxHeight: 130 }}
>
<TreeComponent className="dataResourceTree" rootNode={dataRootNode} /> <TreeComponent className="dataResourceTree" rootNode={dataRootNode} />
</AccordionItemComponent> </AccordionItemComponent>
<AccordionItemComponent title={"SAMPLE DATA"}> <AccordionItemComponent title={"SAMPLE DATA"} containerStyles={{ display: "table" }}>
<SampleDataTree sampleDataResourceTokenCollection={sampleDataResourceTokenCollection} /> <SampleDataTree sampleDataResourceTokenCollection={sampleDataResourceTokenCollection} />
</AccordionItemComponent> </AccordionItemComponent>
<AccordionItemComponent title={"NOTEBOOKS"}> <AccordionItemComponent title={"NOTEBOOKS"}>

View File

@ -2,7 +2,7 @@ import { useCommandBar } from "Explorer/Menus/CommandBar/CommandBarComponentAdap
import TabsBase from "Explorer/Tabs/TabsBase"; import TabsBase from "Explorer/Tabs/TabsBase";
import { useSelectedNode } from "Explorer/useSelectedNode"; import { useSelectedNode } from "Explorer/useSelectedNode";
import { useTabs } from "hooks/useTabs"; import { useTabs } from "hooks/useTabs";
import React, { useEffect, useState } from "react"; import React from "react";
import CosmosDBIcon from "../../../images/Azure-Cosmos-DB.svg"; import CosmosDBIcon from "../../../images/Azure-Cosmos-DB.svg";
import CollectionIcon from "../../../images/tree-collection.svg"; import CollectionIcon from "../../../images/tree-collection.svg";
import * as ViewModels from "../../Contracts/ViewModels"; import * as ViewModels from "../../Contracts/ViewModels";
@ -14,62 +14,64 @@ export const SampleDataTree = ({
}: { }: {
sampleDataResourceTokenCollection: ViewModels.CollectionBase; sampleDataResourceTokenCollection: ViewModels.CollectionBase;
}): JSX.Element => { }): JSX.Element => {
const [root, setRoot] = useState<TreeNode | undefined>(undefined); const buildSampleDataTree = (): TreeNode => {
const updatedSampleTree: TreeNode = {
useEffect(() => { label: sampleDataResourceTokenCollection.databaseId,
if (sampleDataResourceTokenCollection) { isExpanded: true,
const updatedSampleTree: TreeNode = { iconSrc: CosmosDBIcon,
label: sampleDataResourceTokenCollection.databaseId, className: "databaseHeader",
isExpanded: false, children: [
iconSrc: CosmosDBIcon, {
className: "databaseHeader", label: sampleDataResourceTokenCollection.id(),
children: [ iconSrc: CollectionIcon,
{ isExpanded: false,
label: sampleDataResourceTokenCollection.id(), className: "collectionHeader",
iconSrc: CollectionIcon, contextMenu: ResourceTreeContextMenuButtonFactory.createSampleCollectionContextMenuButton(),
isExpanded: false, onClick: () => {
className: "dataResourceTree", useSelectedNode.getState().setSelectedNode(sampleDataResourceTokenCollection);
contextMenu: ResourceTreeContextMenuButtonFactory.createSampleCollectionContextMenuButton(), useCommandBar.getState().setContextButtons([]);
onClick: () => { useTabs
// Rewritten version of expandCollapseCollection .getState()
useSelectedNode.getState().setSelectedNode(sampleDataResourceTokenCollection); .refreshActiveTab(
useCommandBar.getState().setContextButtons([]); (tab: TabsBase) =>
useTabs tab.collection?.id() === sampleDataResourceTokenCollection.id() &&
.getState() tab.collection.databaseId === sampleDataResourceTokenCollection.databaseId
.refreshActiveTab( );
(tab: TabsBase) =>
tab.collection?.id() === sampleDataResourceTokenCollection.id() &&
tab.collection.databaseId === sampleDataResourceTokenCollection.databaseId
);
},
isSelected: () =>
useSelectedNode
.getState()
.isDataNodeSelected(
sampleDataResourceTokenCollection.databaseId,
sampleDataResourceTokenCollection.id()
),
onContextMenuOpen: () => useSelectedNode.getState().setSelectedNode(sampleDataResourceTokenCollection),
children: [
{
label: "Items",
onClick: () => sampleDataResourceTokenCollection.onDocumentDBDocumentsClick(),
isSelected: () =>
useSelectedNode
.getState()
.isDataNodeSelected(
sampleDataResourceTokenCollection.databaseId,
sampleDataResourceTokenCollection.id(),
[ViewModels.CollectionTabKind.Documents]
),
},
],
}, },
], isSelected: () =>
}; useSelectedNode
setRoot(updatedSampleTree); .getState()
} .isDataNodeSelected(sampleDataResourceTokenCollection.databaseId, sampleDataResourceTokenCollection.id()),
}, [sampleDataResourceTokenCollection]); onContextMenuOpen: () => useSelectedNode.getState().setSelectedNode(sampleDataResourceTokenCollection),
children: [
{
label: "Items",
onClick: () => sampleDataResourceTokenCollection.onDocumentDBDocumentsClick(),
isSelected: () =>
useSelectedNode
.getState()
.isDataNodeSelected(
sampleDataResourceTokenCollection.databaseId,
sampleDataResourceTokenCollection.id(),
[ViewModels.CollectionTabKind.Documents]
),
},
],
},
],
};
return <TreeComponent className="dataResourceTree" rootNode={root || { label: "Sample data not initialized." }} />; return {
label: undefined,
isExpanded: true,
children: [updatedSampleTree],
};
};
return (
<TreeComponent
className="dataResourceTree"
rootNode={sampleDataResourceTokenCollection ? buildSampleDataTree() : { label: "Sample data not initialized." }}
/>
);
}; };