mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-12-19 08:51:24 +00:00
load cassandra query documents
This commit is contained in:
@@ -13,6 +13,7 @@ import {
|
|||||||
import React, { FunctionComponent } from "react";
|
import React, { FunctionComponent } from "react";
|
||||||
import AddIcon from "../../../../images/Add.svg";
|
import AddIcon from "../../../../images/Add.svg";
|
||||||
import CancelIcon from "../../../../images/cancel.svg";
|
import CancelIcon from "../../../../images/cancel.svg";
|
||||||
|
import { userContext } from "../../../UserContext";
|
||||||
import { IOption } from "./QueryTableTabUtils";
|
import { IOption } from "./QueryTableTabUtils";
|
||||||
const dropdownStyles: Partial<IDropdownStyles> = { dropdown: { width: 100 } };
|
const dropdownStyles: Partial<IDropdownStyles> = { dropdown: { width: 100 } };
|
||||||
|
|
||||||
@@ -73,6 +74,15 @@ export const QueryTableEntityClause: FunctionComponent<IQueryTableEntityClausePr
|
|||||||
|
|
||||||
const sectionStackTokens: IStackTokens = { childrenGap: 12 };
|
const sectionStackTokens: IStackTokens = { childrenGap: 12 };
|
||||||
|
|
||||||
|
const validateEntityTypeOption = (): boolean => {
|
||||||
|
if (userContext.apiType === "Cassandra") {
|
||||||
|
return true;
|
||||||
|
} else if (selectedField === "PartitionKey" || selectedField === "RowKey" || selectedField === "Timestamp") {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Stack horizontal tokens={sectionStackTokens}>
|
<Stack horizontal tokens={sectionStackTokens}>
|
||||||
@@ -115,7 +125,7 @@ export const QueryTableEntityClause: FunctionComponent<IQueryTableEntityClausePr
|
|||||||
}
|
}
|
||||||
options={entityTypeOptions}
|
options={entityTypeOptions}
|
||||||
id="entityOptionId"
|
id="entityOptionId"
|
||||||
disabled={selectedField !== "t3PN"}
|
disabled={validateEntityTypeOption()}
|
||||||
styles={dropdownStyles}
|
styles={dropdownStyles}
|
||||||
/>
|
/>
|
||||||
<Dropdown
|
<Dropdown
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ import Explorer from "../../Explorer";
|
|||||||
import { useCommandBar } from "../../Menus/CommandBar/CommandBarComponentAdapter";
|
import { useCommandBar } from "../../Menus/CommandBar/CommandBarComponentAdapter";
|
||||||
import { AddTableEntityPanel } from "../../Panes/Tables/AddTableEntityPanel";
|
import { AddTableEntityPanel } from "../../Panes/Tables/AddTableEntityPanel";
|
||||||
import { EditTableEntityPanel } from "../../Panes/Tables/EditTableEntityPanel";
|
import { EditTableEntityPanel } from "../../Panes/Tables/EditTableEntityPanel";
|
||||||
|
import { getQuotedCqlIdentifier } from "../../Tables/CqlUtilities";
|
||||||
import * as DataTableUtilities from "../../Tables/DataTable/DataTableUtilities";
|
import * as DataTableUtilities from "../../Tables/DataTable/DataTableUtilities";
|
||||||
import TableCommands from "../../Tables/DataTable/TableCommands";
|
import TableCommands from "../../Tables/DataTable/TableCommands";
|
||||||
import TableEntityListViewModel from "../../Tables/DataTable/TableEntityListViewModel";
|
import TableEntityListViewModel from "../../Tables/DataTable/TableEntityListViewModel";
|
||||||
@@ -210,7 +211,7 @@ class QueryTablesTabComponent extends Component<IQueryTablesTabComponentProps, I
|
|||||||
isQueryTableEntityChecked: false,
|
isQueryTableEntityChecked: false,
|
||||||
selectedOperator: "=",
|
selectedOperator: "=",
|
||||||
id: "1",
|
id: "1",
|
||||||
selectedField: "PartitionKey",
|
selectedField: userContext.apiType === "Cassandra" ? "email" : "PartitionKey",
|
||||||
selectedOperation: "",
|
selectedOperation: "",
|
||||||
entityValue: "",
|
entityValue: "",
|
||||||
selectedEntityType: "String",
|
selectedEntityType: "String",
|
||||||
@@ -482,9 +483,11 @@ class QueryTablesTabComponent extends Component<IQueryTablesTabComponentProps, I
|
|||||||
queryTableRows: queryTableRowsClone,
|
queryTableRows: queryTableRowsClone,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (userContext.apiType !== "Cassandra") {
|
||||||
this.state.queryViewModel
|
this.state.queryViewModel
|
||||||
.queryBuilderViewModel()
|
.queryBuilderViewModel()
|
||||||
.setExample(entities.length && entities[0].PartitionKey._, entities.length && entities[0].RowKey._);
|
.setExample(entities.length && entities[0].PartitionKey._, entities.length && entities[0].RowKey._);
|
||||||
|
}
|
||||||
|
|
||||||
this.state.queryViewModel.queryBuilderViewModel().queryClauses.children.map((clause, index) => {
|
this.state.queryViewModel.queryBuilderViewModel().queryClauses.children.map((clause, index) => {
|
||||||
this.allQueryTableRows.push({
|
this.allQueryTableRows.push({
|
||||||
@@ -529,16 +532,73 @@ class QueryTablesTabComponent extends Component<IQueryTablesTabComponentProps, I
|
|||||||
public async loadEntities(isInitialLoad: boolean): Promise<void> {
|
public async loadEntities(isInitialLoad: boolean): Promise<void> {
|
||||||
const { tableEntityListViewModel } = this.state;
|
const { tableEntityListViewModel } = this.state;
|
||||||
tableEntityListViewModel.renderNextPageAndupdateCache();
|
tableEntityListViewModel.renderNextPageAndupdateCache();
|
||||||
|
let headers: string[] = [];
|
||||||
// setTimeout(() => {
|
let documents: any = {};
|
||||||
// console.log(
|
if (userContext.apiType === "Cassandra") {
|
||||||
// "🚀 ~ file: QueryTablesTabComponent.tsx ~ line 296 ~ QueryTablesTabComponent ~ componentDidMount ~ componentDidMount",
|
const query = `SELECT * FROM ${getQuotedCqlIdentifier(
|
||||||
// this.state.tableEntityListViewModel.items()
|
this.props.queryTablesTab.collection.databaseId
|
||||||
// );
|
)}.${getQuotedCqlIdentifier(this.props.queryTablesTab.collection.id())}`;
|
||||||
// const { queryTableRows } = this.state;
|
documents = await this.props.queryTablesTab.container.tableDataClient.queryDocuments(
|
||||||
|
this.props.queryTablesTab.collection,
|
||||||
|
query,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
headers = this.getFormattedHeaders(documents.Results);
|
||||||
|
this.setupIntialEntities(documents.Results, headers, isInitialLoad);
|
||||||
|
} else {
|
||||||
const { collection } = this.props;
|
const { collection } = this.props;
|
||||||
const documents = await this.getDocuments(collection, "Select * from c");
|
documents = await this.getDocuments(collection, "Select * from c");
|
||||||
const headers = this.getFormattedHeaders(documents.Results);
|
headers = this.getFormattedHeaders(documents.Results);
|
||||||
|
this.setupIntialEntities(documents.Results, headers, isInitialLoad);
|
||||||
|
}
|
||||||
|
|
||||||
|
// this.columns = [];
|
||||||
|
// headers.map((header) => {
|
||||||
|
// this.columns.push({
|
||||||
|
// key: header,
|
||||||
|
// name: header,
|
||||||
|
// minWidth: 100,
|
||||||
|
// maxWidth: 200,
|
||||||
|
// data: "string",
|
||||||
|
// fieldName: header,
|
||||||
|
// isResizable: true,
|
||||||
|
// isSorted: true,
|
||||||
|
// isSortedDescending: false,
|
||||||
|
// sortAscendingAriaLabel: "Sorted A to Z",
|
||||||
|
// sortDescendingAriaLabel: "Sorted Z to A",
|
||||||
|
// });
|
||||||
|
// });
|
||||||
|
|
||||||
|
// const documentItems = this.generateDetailsList(documents.Results);
|
||||||
|
// // const queryTableRowsClone = [...queryTableRows];
|
||||||
|
// // queryTableRowsClone[0].fieldOptions = getformattedOptions(headers);
|
||||||
|
// this.setState(
|
||||||
|
// {
|
||||||
|
// columns: this.columns,
|
||||||
|
// headers,
|
||||||
|
// operators: this.state.queryViewModel.queryBuilderViewModel().operators(),
|
||||||
|
// isLoading: false,
|
||||||
|
// items: documentItems,
|
||||||
|
// entities: documents.Results,
|
||||||
|
// originalItems: documentItems,
|
||||||
|
// queryText: this.state.queryViewModel.queryText(),
|
||||||
|
// },
|
||||||
|
// () => {
|
||||||
|
// if (isInitialLoad) {
|
||||||
|
// this.loadFilterExample();
|
||||||
|
// // this.setDefaultItemSelection();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// );
|
||||||
|
|
||||||
|
//If
|
||||||
|
}
|
||||||
|
|
||||||
|
private setupIntialEntities = (
|
||||||
|
entities: Entities.ITableEntity[],
|
||||||
|
headers: string[],
|
||||||
|
isInitialLoad: boolean
|
||||||
|
): void => {
|
||||||
this.columns = [];
|
this.columns = [];
|
||||||
headers.map((header) => {
|
headers.map((header) => {
|
||||||
this.columns.push({
|
this.columns.push({
|
||||||
@@ -556,7 +616,7 @@ class QueryTablesTabComponent extends Component<IQueryTablesTabComponentProps, I
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
const documentItems = this.generateDetailsList(documents.Results);
|
const documentItems = this.generateDetailsList(entities);
|
||||||
// const queryTableRowsClone = [...queryTableRows];
|
// const queryTableRowsClone = [...queryTableRows];
|
||||||
// queryTableRowsClone[0].fieldOptions = getformattedOptions(headers);
|
// queryTableRowsClone[0].fieldOptions = getformattedOptions(headers);
|
||||||
this.setState(
|
this.setState(
|
||||||
@@ -566,7 +626,7 @@ class QueryTablesTabComponent extends Component<IQueryTablesTabComponentProps, I
|
|||||||
operators: this.state.queryViewModel.queryBuilderViewModel().operators(),
|
operators: this.state.queryViewModel.queryBuilderViewModel().operators(),
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
items: documentItems,
|
items: documentItems,
|
||||||
entities: documents.Results,
|
entities: entities,
|
||||||
originalItems: documentItems,
|
originalItems: documentItems,
|
||||||
queryText: this.state.queryViewModel.queryText(),
|
queryText: this.state.queryViewModel.queryText(),
|
||||||
},
|
},
|
||||||
@@ -577,9 +637,7 @@ class QueryTablesTabComponent extends Component<IQueryTablesTabComponentProps, I
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
};
|
||||||
//If
|
|
||||||
}
|
|
||||||
|
|
||||||
private getFormattedHeaders = (entities: Entities.ITableEntity[]): string[] => {
|
private getFormattedHeaders = (entities: Entities.ITableEntity[]): string[] => {
|
||||||
const selectedHeadersUnion: string[] = DataTableUtilities.getPropertyIntersectionFromTableEntities(
|
const selectedHeadersUnion: string[] = DataTableUtilities.getPropertyIntersectionFromTableEntities(
|
||||||
@@ -980,6 +1038,7 @@ class QueryTablesTabComponent extends Component<IQueryTablesTabComponentProps, I
|
|||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
cloneQueryTableRows[index][selectedOptionType] = selectedOption.text;
|
cloneQueryTableRows[index][selectedOptionType] = selectedOption.text;
|
||||||
|
if (userContext.apiType !== "Cassandra") {
|
||||||
if (selectedOptionType !== "selectedOperation" && selectedOptionType !== "selectedOperator") {
|
if (selectedOptionType !== "selectedOperation" && selectedOptionType !== "selectedOperator") {
|
||||||
cloneQueryTableRows[index].selectedEntityType = "String";
|
cloneQueryTableRows[index].selectedEntityType = "String";
|
||||||
const { text } = selectedOption;
|
const { text } = selectedOption;
|
||||||
@@ -990,6 +1049,14 @@ class QueryTablesTabComponent extends Component<IQueryTablesTabComponentProps, I
|
|||||||
cloneQueryTableRows[index].isTimeStampSelected = false;
|
cloneQueryTableRows[index].isTimeStampSelected = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
const { text } = selectedOption;
|
||||||
|
if (text === "userid") {
|
||||||
|
cloneQueryTableRows[index].selectedEntityType = "Int";
|
||||||
|
} else {
|
||||||
|
cloneQueryTableRows[index].selectedEntityType = "Text";
|
||||||
|
}
|
||||||
|
}
|
||||||
this.setState({ queryTableRows: cloneQueryTableRows });
|
this.setState({ queryTableRows: cloneQueryTableRows });
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1023,12 +1090,12 @@ class QueryTablesTabComponent extends Component<IQueryTablesTabComponentProps, I
|
|||||||
operatorOptions: getformattedOptions(queryViewModel.queryBuilderViewModel().operators()),
|
operatorOptions: getformattedOptions(queryViewModel.queryBuilderViewModel().operators()),
|
||||||
// id: cloneQueryTableRows.length + 1,
|
// id: cloneQueryTableRows.length + 1,
|
||||||
id: newClause._id,
|
id: newClause._id,
|
||||||
selectedField: "PartitionKey",
|
selectedField: userContext.apiType === "Cassandra" ? "email" : "PartitionKey",
|
||||||
fieldOptions: getformattedOptions(headers),
|
fieldOptions: getformattedOptions(headers),
|
||||||
|
|
||||||
entityTypeOptions: getformattedOptions(queryViewModel.queryBuilderViewModel().edmTypes()),
|
entityTypeOptions: getformattedOptions(queryViewModel.queryBuilderViewModel().edmTypes()),
|
||||||
|
|
||||||
selectedEntityType: "String",
|
selectedEntityType: userContext.apiType === "Cassandra" ? "Text" : "String",
|
||||||
operationOptions: getformattedOptions(queryViewModel.queryBuilderViewModel().clauseRules()),
|
operationOptions: getformattedOptions(queryViewModel.queryBuilderViewModel().clauseRules()),
|
||||||
// operationOptions: queryTableRows[0].operationOptions,
|
// operationOptions: queryTableRows[0].operationOptions,
|
||||||
selectedOperation: "And",
|
selectedOperation: "And",
|
||||||
|
|||||||
Reference in New Issue
Block a user