Refactor Components

This commit is contained in:
Steve Faulkner
2021-01-02 20:47:54 -06:00
parent 09ac1d1552
commit 2147b10361
8 changed files with 1099 additions and 15 deletions

1082
src/HostedExplorer.ts Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -5,17 +5,17 @@ import { render } from "react-dom";
import ChevronRight from "../images/chevron-right.svg"; import ChevronRight from "../images/chevron-right.svg";
import "../less/hostedexplorer.less"; import "../less/hostedexplorer.less";
import { AuthType } from "./AuthType"; import { AuthType } from "./AuthType";
import { ConnectExplorer } from "./ConnectExplorer"; import { ConnectExplorer } from "./Platform/Hosted/Components/ConnectExplorer";
import { DatabaseAccount } from "./Contracts/DataModels"; import { DatabaseAccount } from "./Contracts/DataModels";
import { DirectoryPickerPanel } from "./DirectoryPickerPanel"; import { DirectoryPickerPanel } from "./Platform/Hosted/Components/DirectoryPickerPanel";
import { AccountSwitchComponent } from "./Explorer/Controls/AccountSwitch/AccountSwitchComponent"; import { AccountSwitcher } from "./Platform/Hosted/Components/AccountSwitcher";
import "./Explorer/Menus/NavBar/MeControlComponent.less"; import "./Explorer/Menus/NavBar/MeControlComponent.less";
import { FeedbackCommandButton } from "./FeedbackCommandButton"; import { FeedbackCommandButton } from "./FeedbackCommandButton";
import { usePortalAccessToken } from "./hooks/usePortalAccessToken"; import { usePortalAccessToken } from "./hooks/usePortalAccessToken";
import { MeControl } from "./MeControl"; import { MeControl } from "./Platform/Hosted/Components/MeControl";
import "./Platform/Hosted/ConnectScreen.less"; import "./Platform/Hosted/ConnectScreen.less";
import "./Shared/appInsights"; import "./Shared/appInsights";
import { SignInButton } from "./SignInButton"; import { SignInButton } from "./Platform/Hosted/Components/SignInButton";
import { useAADAuth } from "./hooks/useAADAuth"; import { useAADAuth } from "./hooks/useAADAuth";
initializeIcons(); initializeIcons();
@@ -76,7 +76,7 @@ const App: React.FunctionComponent = () => {
)} )}
{isLoggedIn && ( {isLoggedIn && (
<span className="accountSwitchComponentContainer"> <span className="accountSwitchComponentContainer">
<AccountSwitchComponent armToken={armToken} setDatabaseAccount={setDatabaseAccount} /> <AccountSwitcher armToken={armToken} setDatabaseAccount={setDatabaseAccount} />
</span> </span>
)} )}
{!isLoggedIn && encryptedTokenMetadata?.accountName && ( {!isLoggedIn && encryptedTokenMetadata?.accountName && (

View File

@@ -41,10 +41,12 @@ const buttonStyles: IButtonStyles = {
const cachedSubscriptionId = localStorage.getItem("cachedSubscriptionId"); const cachedSubscriptionId = localStorage.getItem("cachedSubscriptionId");
const cachedDatabaseAccountName = localStorage.getItem("cachedDatabaseAccountName"); const cachedDatabaseAccountName = localStorage.getItem("cachedDatabaseAccountName");
export const AccountSwitchComponent: React.FunctionComponent<{ interface Props {
armToken: string; armToken: string;
setDatabaseAccount: (account: DatabaseAccount) => void; setDatabaseAccount: (account: DatabaseAccount) => void;
}> = ({ armToken, setDatabaseAccount }) => { }
export const AccountSwitcher: React.FunctionComponent<Props> = ({ armToken, setDatabaseAccount }: Props) => {
const subscriptions = useSubscriptions(armToken); const subscriptions = useSubscriptions(armToken);
const [selectedSubscriptionId, setSelectedSubscriptionId] = React.useState<string>(cachedSubscriptionId); const [selectedSubscriptionId, setSelectedSubscriptionId] = React.useState<string>(cachedSubscriptionId);
const accounts = useDatabaseAccounts(selectedSubscriptionId, armToken); const accounts = useDatabaseAccounts(selectedSubscriptionId, armToken);
@@ -52,7 +54,7 @@ export const AccountSwitchComponent: React.FunctionComponent<{
React.useEffect(() => { React.useEffect(() => {
if (accounts && selectedAccountName) { if (accounts && selectedAccountName) {
const account = accounts.find(account => account.name == selectedAccountName); const account = accounts.find(account => account.name === selectedAccountName);
// Only set a new account if one is found // Only set a new account if one is found
if (account) { if (account) {
setDatabaseAccount(account); setDatabaseAccount(account);

View File

@@ -1,8 +1,8 @@
import * as React from "react"; import * as React from "react";
import { useBoolean } from "@uifabric/react-hooks"; import { useBoolean } from "@uifabric/react-hooks";
import { HttpHeaders } from "./Common/Constants"; import { HttpHeaders } from "../../../Common/Constants";
import { GenerateTokenResponse } from "./Contracts/DataModels"; import { GenerateTokenResponse } from "../../../Contracts/DataModels";
import { configContext } from "./ConfigContext"; import { configContext } from "../../../ConfigContext";
interface Props { interface Props {
login: () => void; login: () => void;

View File

@@ -1,6 +1,6 @@
import { Panel, PanelType, ChoiceGroup } from "office-ui-fabric-react"; import { Panel, PanelType, ChoiceGroup } from "office-ui-fabric-react";
import * as React from "react"; import * as React from "react";
import { useDirectories } from "./hooks/useDirectories"; import { useDirectories } from "../../../hooks/useDirectories";
interface Props { interface Props {
isOpen: boolean; isOpen: boolean;

View File

@@ -1,5 +1,5 @@
import * as React from "react"; import * as React from "react";
import { CommandButtonComponent } from "./Explorer/Controls/CommandButton/CommandButtonComponent"; import { CommandButtonComponent } from "../../../Explorer/Controls/CommandButton/CommandButtonComponent";
import FeedbackIcon from "../images/Feedback.svg"; import FeedbackIcon from "../images/Feedback.svg";
export const FeedbackCommandButton: React.FunctionComponent = () => { export const FeedbackCommandButton: React.FunctionComponent = () => {

View File

@@ -8,7 +8,7 @@ import {
} from "office-ui-fabric-react"; } from "office-ui-fabric-react";
import * as React from "react"; import * as React from "react";
import { Account } from "msal"; import { Account } from "msal";
import { useGraphPhoto } from "./hooks/useGraphPhoto"; import { useGraphPhoto } from "../../../hooks/useGraphPhoto";
interface Props { interface Props {
graphToken: string; graphToken: string;