From e3c3a8b1b792a8ba69d480540e318ad4666c3818 Mon Sep 17 00:00:00 2001 From: bogercraig <124094535+bogercraig@users.noreply.github.com> Date: Thu, 3 Apr 2025 17:19:28 -0700 Subject: [PATCH] Hide Keys and Connection Strings in Connect Tab (#2095) * Hide connection strings and keys by default. Move URI above pivot since common across tabs. Matches frontend. Need to add scrolling of keys when window is small. Possibly reduce URI width. * Add vertical scrolling when window size reduces. * Adding missing semicolon at end of connection strings. --- src/Explorer/Tabs/ConnectTab.tsx | 143 ++++++++++++++++++++++--------- 1 file changed, 103 insertions(+), 40 deletions(-) diff --git a/src/Explorer/Tabs/ConnectTab.tsx b/src/Explorer/Tabs/ConnectTab.tsx index 3c334fbc1..62f190996 100644 --- a/src/Explorer/Tabs/ConnectTab.tsx +++ b/src/Explorer/Tabs/ConnectTab.tsx @@ -16,10 +16,20 @@ export const ConnectTab: React.FC = (): JSX.Element => { const [primaryReadonlyMasterKey, setPrimaryReadonlyMasterKey] = useState(""); const [secondaryReadonlyMasterKey, setSecondaryReadonlyMasterKey] = useState(""); const uri: string = userContext.databaseAccount.properties?.documentEndpoint; - const primaryConnectionStr = `AccountEndpoint=${uri};AccountKey=${primaryMasterKey}`; - const secondaryConnectionStr = `AccountEndpoint=${uri};AccountKey=${secondaryMasterKey}`; - const primaryReadonlyConnectionStr = `AccountEndpoint=${uri};AccountKey=${primaryReadonlyMasterKey}`; - const secondaryReadonlyConnectionStr = `AccountEndpoint=${uri};AccountKey=${secondaryReadonlyMasterKey}`; + const primaryConnectionStr = `AccountEndpoint=${uri};AccountKey=${primaryMasterKey};`; + const secondaryConnectionStr = `AccountEndpoint=${uri};AccountKey=${secondaryMasterKey};`; + const primaryReadonlyConnectionStr = `AccountEndpoint=${uri};AccountKey=${primaryReadonlyMasterKey};`; + const secondaryReadonlyConnectionStr = `AccountEndpoint=${uri};AccountKey=${secondaryReadonlyMasterKey};`; + const maskedValue: string = + "*********************************************************************************************************************************"; + const [showPrimaryMasterKey, setShowPrimaryMasterKey] = useState(false); + const [showSecondaryMasterKey, setShowSecondaryMasterKey] = useState(false); + const [showPrimaryReadonlyMasterKey, setShowPrimaryReadonlyMasterKey] = useState(false); + const [showSecondaryReadonlyMasterKey, setShowSecondaryReadonlyMasterKey] = useState(false); + const [showPrimaryConnectionStr, setShowPrimaryConnectionStr] = useState(false); + const [showSecondaryConnectionStr, setShowSecondaryConnectionStr] = useState(false); + const [showPrimaryReadonlyConnectionStr, setShowPrimaryReadonlyConnectionStr] = useState(false); + const [showSecondaryReadonlyConnectionStr, setShowSecondaryReadonlyConnectionStr] = useState(false); useEffect(() => { fetchKeys(); @@ -62,55 +72,97 @@ export const ConnectTab: React.FC = (): JSX.Element => { root: { width: "100%" }, field: { backgroundColor: "rgb(230, 230, 230)" }, fieldGroup: { borderColor: "rgb(138, 136, 134)" }, + suffix: { + backgroundColor: "rgb(230, 230, 230)", + margin: 0, + padding: 0, + }, }; + const renderCopyButton = (selector: string) => ( + onCopyBtnClicked(selector)} + styles={{ + root: { + height: "100%", + backgroundColor: "rgb(230, 230, 230)", + border: "none", + }, + rootHovered: { + backgroundColor: "rgb(220, 220, 220)", + }, + rootPressed: { + backgroundColor: "rgb(210, 210, 210)", + }, + }} + /> + ); + return (
+ + renderCopyButton("#uriTextfield")} + /> +
+
+ {userContext.hasWriteAccess && ( - - - - onCopyBtnClicked("#uriTextfield")} /> - - + renderCopyButton("#primaryKeyTextfield"), + })} + /> + setShowPrimaryMasterKey(!showPrimaryMasterKey)} /> - onCopyBtnClicked("#primaryKeyTextfield")} /> - renderCopyButton("#secondaryKeyTextfield"), + })} /> onCopyBtnClicked("#secondaryKeyTextfield")} + iconProps={{ iconName: showSecondaryMasterKey ? "Hide3" : "View" }} + onClick={() => setShowSecondaryMasterKey(!showSecondaryMasterKey)} /> - renderCopyButton("#primaryConStrTextfield"), + })} /> onCopyBtnClicked("#primaryConStrTextfield")} + iconProps={{ iconName: showPrimaryConnectionStr ? "Hide3" : "View" }} + onClick={() => setShowPrimaryConnectionStr(!showPrimaryConnectionStr)} /> @@ -118,34 +170,36 @@ export const ConnectTab: React.FC = (): JSX.Element => { label="SECONDARY CONNECTION STRING" id="secondaryConStrTextfield" readOnly - value={secondaryConnectionStr} + value={showSecondaryConnectionStr ? secondaryConnectionStr : maskedValue} styles={textfieldStyles} + {...(showSecondaryConnectionStr && { + onRenderSuffix: () => renderCopyButton("#secondaryConStrTextfield"), + })} /> onCopyBtnClicked("#secondaryConStrTextfield")} + iconProps={{ iconName: showSecondaryConnectionStr ? "Hide3" : "View" }} + onClick={() => setShowSecondaryConnectionStr(!showSecondaryConnectionStr)} /> )} - - - - onCopyBtnClicked("#uriReadOnlyTextfield")} /> - + renderCopyButton("#primaryReadonlyKeyTextfield"), + })} /> onCopyBtnClicked("#primaryReadonlyKeyTextfield")} + iconProps={{ iconName: showPrimaryReadonlyMasterKey ? "Hide3" : "View" }} + onClick={() => setShowPrimaryReadonlyMasterKey(!showPrimaryReadonlyMasterKey)} /> @@ -153,12 +207,15 @@ export const ConnectTab: React.FC = (): JSX.Element => { label="SECONDARY READ-ONLY KEY" id="secondaryReadonlyKeyTextfield" readOnly - value={secondaryReadonlyMasterKey} + value={showSecondaryReadonlyMasterKey ? secondaryReadonlyMasterKey : maskedValue} styles={textfieldStyles} + {...(showSecondaryReadonlyMasterKey && { + onRenderSuffix: () => renderCopyButton("#secondaryReadonlyKeyTextfield"), + })} /> onCopyBtnClicked("#secondaryReadonlyKeyTextfield")} + iconProps={{ iconName: showSecondaryReadonlyMasterKey ? "Hide3" : "View" }} + onClick={() => setShowSecondaryReadonlyMasterKey(!showSecondaryReadonlyMasterKey)} /> @@ -166,25 +223,31 @@ export const ConnectTab: React.FC = (): JSX.Element => { label="PRIMARY READ-ONLY CONNECTION STRING" id="primaryReadonlyConStrTextfield" readOnly - value={primaryReadonlyConnectionStr} + value={showPrimaryReadonlyConnectionStr ? primaryReadonlyConnectionStr : maskedValue} styles={textfieldStyles} + {...(showPrimaryReadonlyConnectionStr && { + onRenderSuffix: () => renderCopyButton("#primaryReadonlyConStrTextfield"), + })} /> onCopyBtnClicked("#primaryReadonlyConStrTextfield")} + iconProps={{ iconName: showPrimaryReadonlyConnectionStr ? "Hide3" : "View" }} + onClick={() => setShowPrimaryReadonlyConnectionStr(!showPrimaryReadonlyConnectionStr)} /> renderCopyButton("#secondaryReadonlyConStrTextfield"), + })} /> onCopyBtnClicked("#secondaryReadonlyConStrTextfield")} + iconProps={{ iconName: showSecondaryReadonlyConnectionStr ? "Hide3" : "View" }} + onClick={() => setShowSecondaryReadonlyConnectionStr(!showSecondaryReadonlyConnectionStr)} />