Compare commits

..

1 Commits

Author SHA1 Message Date
sunilyadav840
4a227941b9 fixed tableEntity treeComponent and DefaultExperienceUtility file typescript issue 2021-08-24 19:38:19 +05:30
8 changed files with 57 additions and 65 deletions

View File

@@ -36,7 +36,7 @@ export interface TableEntityProps {
onDeleteEntity?: () => void;
onEditEntity?: () => void;
onEntityPropertyChange: (event: React.FormEvent<HTMLElement>, newInput?: string) => void;
onEntityTypeChange: (event: React.FormEvent<HTMLElement>, selectedParam: IDropdownOption) => void;
onEntityTypeChange: (event: React.FormEvent<HTMLElement>, selectedParam: IDropdownOption | undefined) => void;
onEntityValueChange: (event: React.FormEvent<HTMLElement>, newInput?: string) => void;
onSelectDate: (date: Date | null | undefined) => void;
onEntityTimeValueChange: (event: React.FormEvent<HTMLElement>, newInput?: string) => void;

View File

@@ -43,7 +43,7 @@ export interface TreeNode {
isLeavesParentsSeparate?: boolean; // Display parents together first, then leaves
isLoading?: boolean;
isSelected?: () => boolean;
onClick?: (isExpanded: boolean) => void; // Only if a leaf, other click will expand/collapse
onClick?: (isExpanded?: boolean) => void; // Only if a leaf, other click will expand/collapse
onExpanded?: () => void;
onCollapsed?: () => void;
onContextMenuOpen?: () => void;
@@ -73,7 +73,7 @@ interface TreeNodeComponentProps {
}
interface TreeNodeComponentState {
isExpanded: boolean;
isExpanded?: boolean;
isMenuShowing: boolean;
}
export class TreeNodeComponent extends React.Component<TreeNodeComponentProps, TreeNodeComponentState> {
@@ -82,7 +82,7 @@ export class TreeNodeComponent extends React.Component<TreeNodeComponentProps, T
private static readonly transitionDurationMS = 200;
private static readonly callbackDelayMS = 100; // avoid calling at the same time as transition to make it smoother
private contextMenuRef = React.createRef<HTMLDivElement>();
private isExpanded: boolean;
private isExpanded?: boolean;
constructor(props: TreeNodeComponentProps) {
super(props);
@@ -93,7 +93,7 @@ export class TreeNodeComponent extends React.Component<TreeNodeComponentProps, T
};
}
componentDidUpdate(prevProps: TreeNodeComponentProps, prevState: TreeNodeComponentState) {
componentDidUpdate(_prevProps: TreeNodeComponentProps, prevState: TreeNodeComponentState) {
// Only call when expand has actually changed
if (this.state.isExpanded !== prevState.isExpanded) {
if (this.state.isExpanded) {
@@ -103,7 +103,7 @@ export class TreeNodeComponent extends React.Component<TreeNodeComponentProps, T
}
}
if (this.props.node.isExpanded !== this.isExpanded) {
this.isExpanded = this.props.node.isExpanded;
this.isExpanded = this.props.node && this.props.node.isExpanded;
this.setState({
isExpanded: this.props.node.isExpanded,
});
@@ -114,7 +114,7 @@ export class TreeNodeComponent extends React.Component<TreeNodeComponentProps, T
return this.renderNode(this.props.node, this.props.generation);
}
private static getSortedChildren(treeNode: TreeNode): TreeNode[] {
private static getSortedChildren(treeNode: TreeNode): TreeNode[] | undefined {
if (!treeNode || !treeNode.children) {
return undefined;
}
@@ -195,7 +195,7 @@ export class TreeNodeComponent extends React.Component<TreeNodeComponentProps, T
{node.children && (
<AnimateHeight duration={TreeNodeComponent.transitionDurationMS} height={this.state.isExpanded ? "auto" : 0}>
<div className="nodeChildren" data-test={node.label}>
{TreeNodeComponent.getSortedChildren(node).map((childNode: TreeNode) => (
{TreeNodeComponent?.getSortedChildren(node)?.map((childNode: TreeNode) => (
<TreeNodeComponent
key={`${childNode.label}-${generation + 1}-${childNode.timestamp}`}
node={childNode}
@@ -214,15 +214,15 @@ export class TreeNodeComponent extends React.Component<TreeNodeComponentProps, T
* Recursive: is the node or any descendant selected
* @param node
*/
private static isAnyDescendantSelected(node: TreeNode): boolean {
return (
node.children &&
node.children.reduce(
return node.children
? node.children.reduce(
(previous: boolean, child: TreeNode) =>
previous || (child.isSelected && child.isSelected()) || TreeNodeComponent.isAnyDescendantSelected(child),
false
)
);
: false;
}
private static createClickEvent(): MouseEvent {
@@ -230,7 +230,7 @@ export class TreeNodeComponent extends React.Component<TreeNodeComponentProps, T
}
private onRightClick = (): void => {
this.contextMenuRef.current.firstChild.dispatchEvent(TreeNodeComponent.createClickEvent());
this.contextMenuRef?.current?.firstChild?.dispatchEvent(TreeNodeComponent.createClickEvent());
};
private renderContextMenuButton(node: TreeNode): JSX.Element {
@@ -253,18 +253,18 @@ export class TreeNodeComponent extends React.Component<TreeNodeComponentProps, T
coverTarget: true,
isBeakVisible: false,
directionalHint: DirectionalHint.topAutoEdge,
onMenuOpened: (contextualMenu?: IContextualMenuProps) => {
onMenuOpened: (_contextualMenu?: IContextualMenuProps) => {
this.setState({ isMenuShowing: true });
node.onContextMenuOpen && node.onContextMenuOpen();
},
onMenuDismissed: (contextualMenu?: IContextualMenuProps) => this.setState({ isMenuShowing: false }),
onMenuDismissed: (_contextualMenu?: IContextualMenuProps) => this.setState({ isMenuShowing: false }),
contextualMenuItemAs: (props: IContextualMenuItemProps) => (
<div
data-test={`treeComponentMenuItemContainer`}
className="treeComponentMenuItemContainer"
onContextMenu={(e) => e.target.dispatchEvent(TreeNodeComponent.createClickEvent())}
>
{props.item.onRenderIcon()}
{props.item.onRenderIcon && props.item.onRenderIcon()}
<span
className={
"treeComponentMenuItemLabel" + (props.item.className ? ` ${props.item.className}Label` : "")
@@ -274,7 +274,8 @@ export class TreeNodeComponent extends React.Component<TreeNodeComponentProps, T
</span>
</div>
),
items: node.contextMenu.map((menuItem: TreeNodeMenuItem) => ({
items: node.contextMenu
? node.contextMenu.map((menuItem: TreeNodeMenuItem) => ({
key: menuItem.label,
text: menuItem.label,
disabled: menuItem.isDisabled,
@@ -285,8 +286,9 @@ export class TreeNodeComponent extends React.Component<TreeNodeComponentProps, T
label: menuItem.label,
});
},
onRenderIcon: (props: any) => <img src={menuItem.iconSrc} alt="" />,
})),
onRenderIcon: (_props: any) => <img src={menuItem.iconSrc} alt="" />,
}))
: [],
}}
styles={buttonStyles}
/>
@@ -324,7 +326,7 @@ export class TreeNodeComponent extends React.Component<TreeNodeComponentProps, T
this.props.node.onClick && this.props.node.onClick(this.state.isExpanded);
};
private onNodeKeyPress = (event: React.KeyboardEvent<HTMLDivElement>, node: TreeNode): void => {
private onNodeKeyPress = (event: React.KeyboardEvent<HTMLDivElement>, _node: TreeNode): void => {
if (event.charCode === Constants.KeyCodes.Space || event.charCode === Constants.KeyCodes.Enter) {
event.stopPropagation();
this.props.node.onClick && this.props.node.onClick(this.state.isExpanded);

View File

@@ -18,7 +18,7 @@ const EditorContainer = styled.div`
`;
interface MappedStateProps {
mimetype: string | null;
mimetype: string;
text: string;
contentRef: ContentRef;
theme?: "light" | "dark";
@@ -37,7 +37,7 @@ interface TextFileState {
class EditorPlaceholder extends React.PureComponent<MonacoEditorProps> {
render(): JSX.Element {
// TODO: Show a little blocky placeholder
return <div />;
return undefined;
}
}
@@ -83,7 +83,7 @@ interface InitialProps {
}
function makeMapStateToTextFileProps(
_initialState: AppState,
initialState: AppState,
initialProps: InitialProps
): (state: AppState) => MappedStateProps {
const { contentRef } = initialProps;
@@ -106,7 +106,7 @@ function makeMapStateToTextFileProps(
}
const makeMapDispatchToTextFileProps = (
_initialDispatch: Dispatch,
initialDispatch: Dispatch,
initialProps: InitialProps
): ((dispatch: Dispatch) => MappedDispatchProps) => {
const { contentRef } = initialProps;

View File

@@ -99,7 +99,7 @@ export class PureMarkdownCell extends React.Component<ComponentProps & DispatchP
}
export const makeMapStateToProps = (
_initialState: AppState,
initialState: AppState,
ownProps: ComponentProps
): ((state: AppState) => StateProps) => {
const { id, contentRef } = ownProps;
@@ -134,7 +134,7 @@ export const makeMapStateToProps = (
};
const makeMapDispatchToProps = (
_initialDispatch: Dispatch,
initialDispatch: Dispatch,
ownProps: ComponentProps
): ((dispatch: Dispatch) => DispatchProps) => {
const { id, contentRef } = ownProps;

View File

@@ -2,7 +2,9 @@ import * as DataModels from "../Contracts/DataModels";
import { userContext } from "../UserContext";
export class DefaultExperienceUtility {
public static getApiKindFromDefaultExperience(defaultExperience: typeof userContext.apiType): DataModels.ApiKind {
public static getApiKindFromDefaultExperience(
defaultExperience: typeof userContext.apiType | null
): DataModels.ApiKind {
if (!defaultExperience) {
return DataModels.ApiKind.SQL;
}

View File

@@ -32,9 +32,8 @@ export async function fetchDatabaseAccounts(subscriptionId: string, accessToken:
export function useDatabaseAccounts(subscriptionId: string, armToken: string): DatabaseAccount[] | undefined {
const { data } = useSWR(
// eslint-disable-next-line no-null/no-null
() => (armToken && subscriptionId ? ["databaseAccounts", subscriptionId, armToken] : null),
(_: string, subscriptionId: string, armToken: string) => fetchDatabaseAccounts(subscriptionId, armToken)
() => (armToken && subscriptionId ? ["databaseAccounts", subscriptionId, armToken] : undefined),
(_, subscriptionId, armToken) => fetchDatabaseAccounts(subscriptionId, armToken)
);
return data;
}

View File

@@ -34,9 +34,8 @@ export async function fetchSubscriptions(accessToken: string): Promise<Subscript
export function useSubscriptions(armToken: string): Subscription[] | undefined {
const { data } = useSWR(
// eslint-disable-next-line no-null/no-null
() => (armToken ? ["subscriptions", armToken] : null),
(_: string, armToken: string) => fetchSubscriptions(armToken)
() => (armToken ? ["subscriptions", armToken] : undefined),
(_, armToken) => fetchSubscriptions(armToken)
);
return data;
}

View File

@@ -8,9 +8,7 @@
"noUnusedParameters": true
},
"files": [
"./src/hooks/useDatabaseAccounts.tsx",
"./src/hooks/useSubscriptions.tsx",
"./src/Explorer/Notebook/NotebookComponent/contents/file/text-file.tsx",
"./src/Explorer/Controls/TreeComponent/TreeComponent.tsx",
"./src/AuthType.ts",
"./src/Bindings/ReactBindingHandler.ts",
"./src/Common/ArrayHashMap.ts",
@@ -58,6 +56,7 @@
"./src/Explorer/Notebook/NotebookContentItem.ts",
"./src/Explorer/Notebook/NotebookRenderer/AzureTheme.tsx",
"./src/Explorer/Notebook/NotebookRenderer/Prompt.tsx",
"./src/Explorer/Notebook/NotebookRenderer/PromptContent.test.tsx",
"./src/Explorer/Notebook/NotebookRenderer/PromptContent.tsx",
"./src/Explorer/Notebook/NotebookRenderer/StatusBar.tsx",
"./src/Explorer/Notebook/NotebookRenderer/decorators/CellCreator.tsx",
@@ -85,10 +84,13 @@
"./src/Explorer/Tree/AccessibleVerticalList.ts",
"./src/GitHub/GitHubConnector.ts",
"./src/HostedExplorerChildFrame.ts",
"./src/Index.tsx",
"./src/Platform/Hosted/Authorization.ts",
"./src/Platform/Hosted/Components/MeControl.test.tsx",
"./src/Platform/Hosted/Components/MeControl.tsx",
"./src/Platform/Hosted/Components/SignInButton.tsx",
"./src/Platform/Hosted/Components/SwitchAccount.tsx",
"./src/Platform/Hosted/Components/SwitchSubscription.tsx",
"./src/Platform/Hosted/HostedUtils.test.ts",
"./src/Platform/Hosted/HostedUtils.ts",
"./src/Platform/Hosted/extractFeatures.test.ts",
@@ -97,17 +99,6 @@
"./src/SelfServe/Example/SelfServeExample.types.ts",
"./src/SelfServe/SelfServeStyles.tsx",
"./src/SelfServe/SqlX/SqlxTypes.ts",
"./src/Shared/Constants.ts",
"./src/Shared/DefaultExperienceUtility.ts",
"./src/Shared/ExplorerSettings.ts",
"./src/Shared/LocalStorageUtility.ts",
"./src/Shared/PriceEstimateCalculator.ts",
"./src/Shared/SessionStorageUtility.ts",
"./src/Shared/StorageUtility.test.ts",
"./src/Shared/StorageUtility.ts",
"./src/Shared/StringUtility.test.ts",
"./src/Shared/StringUtility.ts",
"./src/Shared/appInsights.ts",
"./src/UserContext.ts",
"./src/Utils/APITypeUtils.ts",
"./src/Utils/AutoPilotUtils.ts",
@@ -132,17 +123,16 @@
"./src/hooks/useFullScreenURLs.tsx",
"./src/hooks/useGraphPhoto.tsx",
"./src/hooks/useNotebookSnapshotStore.ts",
"./src/hooks/usePortalAccessToken.tsx",
"./src/hooks/useNotificationConsole.ts",
"./src/hooks/useObservable.ts",
"./src/hooks/usePortalAccessToken.tsx",
"./src/hooks/useSidePanel.ts",
"./src/i18n.ts",
"./src/quickstart.ts",
"./src/setupTests.ts",
"./src/userContext.test.ts",
"src/Common/EntityValue.tsx",
"./src/Platform/Hosted/Components/SwitchAccount.tsx",
"./src/Platform/Hosted/Components/SwitchSubscription.tsx"
"src/Common/TableEntity.tsx"
],
"include": [
"src/CellOutputViewer/transforms/**/*",
@@ -164,7 +154,7 @@
"src/Localization/**/*",
"src/Platform/Emulator/**/*",
"src/SelfServe/Documentation/**/*",
"src/Shared/Telemetry/**/*",
"src/Shared/**/*",
"src/Terminal/**/*",
"src/Utils/arm/**/*"
]