import { Checkbox, ChoiceGroup, IChoiceGroupOption, SpinButton } from "office-ui-fabric-react"; import React, { FunctionComponent, MouseEvent, useState } from "react"; import * as Constants from "../../../Common/Constants"; import { Tooltip } from "../../../Common/Tooltip"; import { configContext } from "../../../ConfigContext"; import { LocalStorageUtility, StorageKey } from "../../../Shared/StorageUtility"; import * as StringUtility from "../../../Shared/StringUtility"; import { userContext } from "../../../UserContext"; import { logConsoleInfo } from "../../../Utils/NotificationConsoleUtils"; import Explorer from "../../Explorer"; import { GenericRightPaneComponent, GenericRightPaneProps } from "../GenericRightPaneComponent"; export interface SettingsPaneProps { explorer: Explorer; closePanel: () => void; } export const SettingsPane: FunctionComponent = ({ explorer: container, closePanel, }: SettingsPaneProps) => { const [formErrors, setFormErrors] = useState(""); const [isExecuting, setIsExecuting] = useState(false); const [pageOption, setPageOption] = useState( LocalStorageUtility.getEntryNumber(StorageKey.ActualItemPerPage) === Constants.Queries.unlimitedItemsPerPage ? Constants.Queries.UnlimitedPageOption : Constants.Queries.CustomPageOption ); const [customItemPerPage, setCustomItemPerPage] = useState( LocalStorageUtility.getEntryNumber(StorageKey.CustomItemPerPage) || 0 ); const [crossPartitionQueryEnabled, setCrossPartitionQueryEnabled] = useState( LocalStorageUtility.hasItem(StorageKey.IsCrossPartitionQueryEnabled) ? LocalStorageUtility.getEntryString(StorageKey.IsCrossPartitionQueryEnabled) === "true" : true ); const [graphAutoVizDisabled, setGraphAutoVizDisabled] = useState( LocalStorageUtility.hasItem(StorageKey.IsGraphAutoVizDisabled) ? LocalStorageUtility.getEntryString(StorageKey.IsGraphAutoVizDisabled) : "false" ); const [maxDegreeOfParallelism, setMaxDegreeOfParallelism] = useState( LocalStorageUtility.hasItem(StorageKey.MaxDegreeOfParellism) ? LocalStorageUtility.getEntryNumber(StorageKey.MaxDegreeOfParellism) : Constants.Queries.DefaultMaxDegreeOfParallelism ); const explorerVersion = configContext.gitSha; const shouldShowQueryPageOptions = userContext.apiType === "SQL"; const shouldShowGraphAutoVizOption = userContext.apiType === "Gremlin"; const shouldShowCrossPartitionOption = userContext.apiType !== "Gremlin"; const shouldShowParallelismOption = userContext.apiType !== "Gremlin"; const handlerOnSubmit = (e: MouseEvent) => { setFormErrors(""); setIsExecuting(true); LocalStorageUtility.setEntryNumber( StorageKey.ActualItemPerPage, isCustomPageOptionSelected() ? customItemPerPage : Constants.Queries.unlimitedItemsPerPage ); LocalStorageUtility.setEntryNumber(StorageKey.CustomItemPerPage, customItemPerPage); LocalStorageUtility.setEntryString(StorageKey.IsCrossPartitionQueryEnabled, crossPartitionQueryEnabled.toString()); LocalStorageUtility.setEntryNumber(StorageKey.MaxDegreeOfParellism, maxDegreeOfParallelism); if (shouldShowGraphAutoVizOption) { LocalStorageUtility.setEntryBoolean( StorageKey.IsGraphAutoVizDisabled, StringUtility.toBoolean(graphAutoVizDisabled) ); } setIsExecuting(false); logConsoleInfo( `Updated items per page setting to ${LocalStorageUtility.getEntryNumber(StorageKey.ActualItemPerPage)}` ); logConsoleInfo(`${crossPartitionQueryEnabled ? "Enabled" : "Disabled"} cross-partition query feed option`); logConsoleInfo( `Updated the max degree of parallelism query feed option to ${LocalStorageUtility.getEntryNumber( StorageKey.MaxDegreeOfParellism )}` ); if (shouldShowGraphAutoVizOption) { logConsoleInfo( `Graph result will be displayed as ${ LocalStorageUtility.getEntryBoolean(StorageKey.IsGraphAutoVizDisabled) ? "JSON" : "Graph" }` ); } logConsoleInfo( `Updated query setting to ${LocalStorageUtility.getEntryString(StorageKey.SetPartitionKeyUndefined)}` ); closePanel(); e.preventDefault(); }; const isCustomPageOptionSelected = () => { return pageOption === Constants.Queries.CustomPageOption; }; const handleOnGremlinChange = (ev: React.FormEvent, option: IChoiceGroupOption): void => { setGraphAutoVizDisabled(option.key); }; const genericPaneProps: GenericRightPaneProps = { container, formError: formErrors, formErrorDetail: "", id: "settingspane", isExecuting, title: "Setting", submitButtonText: "Apply", onClose: () => closePanel(), onSubmit: () => handlerOnSubmit(undefined), }; const pageOptionList: IChoiceGroupOption[] = [ { key: Constants.Queries.CustomPageOption, text: "Custom" }, { key: Constants.Queries.UnlimitedPageOption, text: "Unlimited" }, ]; const graphAutoOptionList: IChoiceGroupOption[] = [ { key: "false", text: "Graph" }, { key: "true", text: "JSON" }, ]; const handleOnPageOptionChange = (ev: React.FormEvent, option: IChoiceGroupOption): void => { setPageOption(option.key); }; return (
{shouldShowQueryPageOptions && (
Page options Choose Custom to specify a fixed amount of query results to show, or choose Unlimited to show as many query results per page.
{isCustomPageOptionSelected() && (
Query results per page Enter the number of query results that should be shown per page.
{ setCustomItemPerPage(parseInt(newValue) + 1 || customItemPerPage); }} onDecrement={(newValue) => setCustomItemPerPage(parseInt(newValue) - 1 || customItemPerPage)} onValidate={(newValue) => setCustomItemPerPage(parseInt(newValue) || customItemPerPage)} min={1} step={1} className="textfontclr" incrementButtonAriaLabel="Increase value by 1" decrementButtonAriaLabel="Decrease value by 1" />
)}
)} {shouldShowCrossPartitionOption && (
Enable cross-partition query Send more than one request while executing a query. More than one request is necessary if the query is not scoped to single partition key value.
setCrossPartitionQueryEnabled(!crossPartitionQueryEnabled)} />
)} {shouldShowParallelismOption && (
Max degree of parallelism Gets or sets the number of concurrent operations run client side during parallel query execution. A positive property value limits the number of concurrent operations to the set value. If it is set to less than 0, the system automatically decides the number of concurrent operations to run.
setMaxDegreeOfParallelism(parseInt(newValue) + 1 || maxDegreeOfParallelism)} onDecrement={(newValue) => setMaxDegreeOfParallelism(parseInt(newValue) - 1 || maxDegreeOfParallelism)} onValidate={(newValue) => setMaxDegreeOfParallelism(parseInt(newValue) || maxDegreeOfParallelism)} ariaLabel="Max degree of parallelism" />
)} {shouldShowGraphAutoVizOption && (
Display Gremlin query results as:  Select Graph to automatically visualize the query results as a Graph or JSON to display the results as JSON.
)}
Explorer Version
{explorerVersion}
); };