mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2026-01-09 04:25:57 +00:00
Rename index.tsx to {class name}.tsx (#689)
* Rename index.tsx to {class name}.tsx
* Update tests
Co-authored-by: Steve Faulkner <southpolesteve@gmail.com>
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
import { mount } from "enzyme";
|
||||
import * as ko from "knockout";
|
||||
import React from "react";
|
||||
import { QueriesClient } from "../../../Common/QueriesClient";
|
||||
import { Query } from "../../../Contracts/DataModels";
|
||||
import Explorer from "../../Explorer";
|
||||
import { BrowseQueriesPane } from "./BrowseQueriesPane";
|
||||
|
||||
describe("Browse queries panel", () => {
|
||||
const fakeExplorer = {} as Explorer;
|
||||
fakeExplorer.canSaveQueries = ko.computed<boolean>(() => true);
|
||||
const fakeClientQuery = {} as QueriesClient;
|
||||
const fakeQueryData = [] as Query[];
|
||||
fakeClientQuery.getQueries = async () => fakeQueryData;
|
||||
fakeExplorer.queriesClient = fakeClientQuery;
|
||||
const props = {
|
||||
explorer: fakeExplorer,
|
||||
closePanel: (): void => undefined,
|
||||
};
|
||||
|
||||
it("Should render Default properly", () => {
|
||||
const wrapper = mount(<BrowseQueriesPane {...props} />);
|
||||
expect(wrapper).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it("Should show empty view when query is empty []", () => {
|
||||
const wrapper = mount(<BrowseQueriesPane {...props} />);
|
||||
expect(wrapper.exists("#emptyQueryBanner")).toBe(true);
|
||||
});
|
||||
});
|
||||
63
src/Explorer/Panes/BrowseQueriesPane/BrowseQueriesPane.tsx
Normal file
63
src/Explorer/Panes/BrowseQueriesPane/BrowseQueriesPane.tsx
Normal file
@@ -0,0 +1,63 @@
|
||||
import React, { FunctionComponent } from "react";
|
||||
import { Areas } from "../../../Common/Constants";
|
||||
import { logError } from "../../../Common/Logger";
|
||||
import { Query } from "../../../Contracts/DataModels";
|
||||
import { Collection } from "../../../Contracts/ViewModels";
|
||||
import { Action, ActionModifiers } from "../../../Shared/Telemetry/TelemetryConstants";
|
||||
import { trace } from "../../../Shared/Telemetry/TelemetryProcessor";
|
||||
import { userContext } from "../../../UserContext";
|
||||
import {
|
||||
QueriesGridComponent,
|
||||
QueriesGridComponentProps,
|
||||
} from "../../Controls/QueriesGridReactComponent/QueriesGridComponent";
|
||||
import Explorer from "../../Explorer";
|
||||
import QueryTab from "../../Tabs/QueryTab";
|
||||
|
||||
interface BrowseQueriesPaneProps {
|
||||
explorer: Explorer;
|
||||
closePanel: () => void;
|
||||
}
|
||||
|
||||
export const BrowseQueriesPane: FunctionComponent<BrowseQueriesPaneProps> = ({
|
||||
explorer,
|
||||
closePanel,
|
||||
}: BrowseQueriesPaneProps): JSX.Element => {
|
||||
const loadSavedQuery = (savedQuery: Query): void => {
|
||||
const selectedCollection: Collection = explorer && explorer.findSelectedCollection();
|
||||
if (!selectedCollection) {
|
||||
// should never get into this state because this pane is only accessible through the query tab
|
||||
logError("No collection was selected", "BrowseQueriesPane.loadSavedQuery");
|
||||
return;
|
||||
} else if (userContext.apiType === "Mongo") {
|
||||
selectedCollection.onNewMongoQueryClick(selectedCollection, undefined);
|
||||
} else {
|
||||
selectedCollection.onNewQueryClick(selectedCollection, undefined);
|
||||
}
|
||||
const queryTab = explorer.tabsManager.activeTab() as QueryTab;
|
||||
queryTab.tabTitle(savedQuery.queryName);
|
||||
queryTab.tabPath(`${selectedCollection.databaseId}>${selectedCollection.id()}>${savedQuery.queryName}`);
|
||||
queryTab.initialEditorContent(savedQuery.query);
|
||||
queryTab.sqlQueryEditorContent(savedQuery.query);
|
||||
trace(Action.LoadSavedQuery, ActionModifiers.Mark, {
|
||||
dataExplorerArea: Areas.ContextualPane,
|
||||
queryName: savedQuery.queryName,
|
||||
paneTitle: "Open Saved Queries",
|
||||
});
|
||||
closePanel();
|
||||
};
|
||||
|
||||
const props: QueriesGridComponentProps = {
|
||||
queriesClient: explorer.queriesClient,
|
||||
onQuerySelect: loadSavedQuery,
|
||||
containerVisible: true,
|
||||
saveQueryEnabled: explorer.canSaveQueries(),
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="panelFormWrapper">
|
||||
<div className="panelMainContent">
|
||||
<QueriesGridComponent {...props} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,58 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`Browse queries panel Should render Default properly 1`] = `
|
||||
<BrowseQueriesPane
|
||||
closePanel={[Function]}
|
||||
explorer={
|
||||
Object {
|
||||
"canSaveQueries": [Function],
|
||||
"queriesClient": Object {
|
||||
"getQueries": [Function],
|
||||
},
|
||||
}
|
||||
}
|
||||
>
|
||||
<div
|
||||
className="panelFormWrapper"
|
||||
>
|
||||
<div
|
||||
className="panelMainContent"
|
||||
>
|
||||
<QueriesGridComponent
|
||||
containerVisible={true}
|
||||
onQuerySelect={[Function]}
|
||||
queriesClient={
|
||||
Object {
|
||||
"getQueries": [Function],
|
||||
}
|
||||
}
|
||||
saveQueryEnabled={true}
|
||||
>
|
||||
<div
|
||||
id="emptyQueryBanner"
|
||||
>
|
||||
<div>
|
||||
You have not saved any queries yet.
|
||||
<br />
|
||||
|
||||
<br />
|
||||
To write a new query, open a new query tab and enter the desired query. Once ready to save, click on Save Query and follow the prompt in order to save the query.
|
||||
</div>
|
||||
<img
|
||||
alt="Save query helper banner"
|
||||
src=""
|
||||
style={
|
||||
Object {
|
||||
"border": "1px solid undefined",
|
||||
"height": "150px",
|
||||
"marginTop": "20px",
|
||||
"width": "310px",
|
||||
}
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
</QueriesGridComponent>
|
||||
</div>
|
||||
</div>
|
||||
</BrowseQueriesPane>
|
||||
`;
|
||||
Reference in New Issue
Block a user