diff --git a/src/Explorer/Tabs/QueryTablesTab/QueryTableEntityClause.tsx b/src/Explorer/Tabs/QueryTablesTab/QueryTableEntityClause.tsx index 144229f96..d485d2abc 100644 --- a/src/Explorer/Tabs/QueryTablesTab/QueryTableEntityClause.tsx +++ b/src/Explorer/Tabs/QueryTablesTab/QueryTableEntityClause.tsx @@ -13,6 +13,7 @@ import { import React, { FunctionComponent } from "react"; import AddIcon from "../../../../images/Add.svg"; import CancelIcon from "../../../../images/cancel.svg"; +import { userContext } from "../../../UserContext"; import { IOption } from "./QueryTableTabUtils"; const dropdownStyles: Partial = { dropdown: { width: 100 } }; @@ -73,6 +74,15 @@ export const QueryTableEntityClause: FunctionComponent { + if (userContext.apiType === "Cassandra") { + return true; + } else if (selectedField === "PartitionKey" || selectedField === "RowKey" || selectedField === "Timestamp") { + return true; + } + return false; + }; + return ( <> @@ -115,7 +125,7 @@ export const QueryTableEntityClause: FunctionComponent 0) { Object.keys(this.state.selection.getSelection()[0]).map((key, index) => { - if (key === "Timestamp") { - timeStamp = Object.values(this.state.selection.getSelection()[0])[index]; + if (key === documentKey) { + itemValue = Object.values(this.state.selection.getSelection()[0])[index]; console.log( "🚀 ~ file: QueryTablesTabComponent.tsx ~ line 445 ~ QueryTablesTabComponent ~ timeStamp", - timeStamp + itemValue ); } }); - selectedItems = this.state.entities.filter((item) => item["Timestamp"]._ === timeStamp); + selectedItems = this.state.entities.filter((item) => item[documentKey]._ === itemValue); console.log( "🚀 ~ file: QueryTablesTabComponent.tsx ~ line 293 ~ QueryTablesTabComponent ~ selectedItems", selectedItems @@ -434,9 +436,11 @@ class QueryTablesTabComponent extends Component { this.allQueryTableRows.push({ @@ -479,22 +483,75 @@ class QueryTablesTabComponent extends Component { - const { tableEntityListViewModel } = this.state; + const { tableEntityListViewModel, selectedQueryText } = this.state; tableEntityListViewModel.renderNextPageAndupdateCache(); + let headers: string[] = []; + let documents: any = {}; + if (userContext.apiType === "Cassandra") { + const query = `SELECT * FROM ${getQuotedCqlIdentifier( + this.props.queryTablesTab.collection.databaseId + )}.${getQuotedCqlIdentifier(this.props.queryTablesTab.collection.id())}`; + 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; + documents = await this.getDocuments(collection, selectedQueryText); + headers = this.getFormattedHeaders(documents.Results); + this.setupIntialEntities(documents.Results, headers, isInitialLoad); + } - // setTimeout(() => { - // console.log( - // "🚀 ~ file: QueryTablesTabComponent.tsx ~ line 296 ~ QueryTablesTabComponent ~ componentDidMount ~ componentDidMount", - // this.state.tableEntityListViewModel.items() + // 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(); + // } + // } // ); - // const { queryTableRows } = this.state; - console.log( - "🚀 ~ file: QueryTablesTabComponent.tsx ~ line 496 ~ QueryTablesTabComponent ~ //setTimeout ~ this.state.selectedQueryText", - this.state.selectedQueryText - ); - const { collection } = this.props; - const documents = await this.getDocuments(collection, this.state.selectedQueryText); - const headers = this.getFormattedHeaders(documents.Results); + + //If + } + + private setupIntialEntities = ( + entities: Entities.ITableEntity[], + headers: string[], + isInitialLoad: boolean + ): void => { this.columns = []; headers.map((header) => { this.columns.push({ @@ -527,7 +584,9 @@ class QueryTablesTabComponent extends Component { if (isInitialLoad) { this.loadFilterExample(); - // this.setDefaultItemSelection(); + this.setDefaultItemSelection(); } } ); - } + }; private onColumnClick = (ev: React.MouseEvent, column: IColumn): void => { const { columns, items } = this.state; @@ -998,14 +1057,23 @@ class QueryTablesTabComponent extends Component