|
| 1 | +/*--------------------------------------------------------------------------------------------- |
| 2 | + * Copyright (c) Microsoft Corporation. All rights reserved. |
| 3 | + * Licensed under the MIT License. See License.txt in the project root for license information. |
| 4 | + *--------------------------------------------------------------------------------------------*/ |
| 5 | + |
| 6 | +import * as sc from "../../../sharedInterfaces/schemaCompare"; |
| 7 | +import * as mssql from "vscode-mssql"; |
| 8 | + |
| 9 | +import { createContext } from "react"; |
| 10 | +import { useVscodeWebview } from "../../common/vscodeWebviewProvider"; |
| 11 | + |
| 12 | +const schemaCompareContext = createContext<sc.SchemaCompareContextProps>( |
| 13 | + {} as sc.SchemaCompareContextProps, |
| 14 | +); |
| 15 | + |
| 16 | +interface SchemaCompareStateProviderProps { |
| 17 | + children: React.ReactNode; |
| 18 | +} |
| 19 | + |
| 20 | +const SchemaCompareStateProvider: React.FC<SchemaCompareStateProviderProps> = ({ |
| 21 | + children, |
| 22 | +}) => { |
| 23 | + const webViewState = useVscodeWebview< |
| 24 | + sc.SchemaCompareWebViewState, |
| 25 | + sc.SchemaCompareReducers |
| 26 | + >(); |
| 27 | + const schemaCompareState = webViewState?.state; |
| 28 | + |
| 29 | + return ( |
| 30 | + <schemaCompareContext.Provider |
| 31 | + value={{ |
| 32 | + state: schemaCompareState, |
| 33 | + themeKind: webViewState?.themeKind, |
| 34 | + compare: function ( |
| 35 | + sourceEndpointInfo: mssql.SchemaCompareEndpointInfo, |
| 36 | + targetEndpointInfo: mssql.SchemaCompareEndpointInfo, |
| 37 | + taskExecutionMode: mssql.TaskExecutionMode, |
| 38 | + deploymentOptions: mssql.DeploymentOptions, |
| 39 | + ): void { |
| 40 | + webViewState?.extensionRpc.action("compare", { |
| 41 | + sourceEndpointInfo: sourceEndpointInfo, |
| 42 | + targetEndpointInfo: targetEndpointInfo, |
| 43 | + taskExecutionMode: taskExecutionMode, |
| 44 | + deploymentOptions: deploymentOptions, |
| 45 | + }); |
| 46 | + }, |
| 47 | + generateScript: function ( |
| 48 | + targetServerName: string, |
| 49 | + targetDatabaseName: string, |
| 50 | + taskExecutionMode: mssql.TaskExecutionMode, |
| 51 | + ): void { |
| 52 | + webViewState?.extensionRpc.action("generateScript", { |
| 53 | + targetServerName: targetServerName, |
| 54 | + targetDatabaseName: targetDatabaseName, |
| 55 | + taskExecutionMode: taskExecutionMode, |
| 56 | + }); |
| 57 | + }, |
| 58 | + publishDatabaseChanges: function ( |
| 59 | + targetServerName: string, |
| 60 | + targetDatabaseName: string, |
| 61 | + taskExecutionMode: mssql.TaskExecutionMode, |
| 62 | + ): void { |
| 63 | + webViewState?.extensionRpc.action( |
| 64 | + "publishDatabaseChanges", |
| 65 | + { |
| 66 | + targetServerName: targetServerName, |
| 67 | + targetDatabaseName: targetDatabaseName, |
| 68 | + taskExecutionMode: taskExecutionMode, |
| 69 | + }, |
| 70 | + ); |
| 71 | + }, |
| 72 | + publishProjectChanges: function ( |
| 73 | + targetProjectPath: string, |
| 74 | + targetFolderStructure: mssql.ExtractTarget, |
| 75 | + taskExecutionMode: mssql.TaskExecutionMode, |
| 76 | + ): void { |
| 77 | + webViewState?.extensionRpc.action("publishProjectChanges", { |
| 78 | + targetProjectPath: targetProjectPath, |
| 79 | + targetFolderStructure: targetFolderStructure, |
| 80 | + taskExecutionMode: taskExecutionMode, |
| 81 | + }); |
| 82 | + }, |
| 83 | + getDefaultOptions: function (): void { |
| 84 | + webViewState?.extensionRpc.action("getDefaultOptions", {}); |
| 85 | + }, |
| 86 | + includeExcludeNode: function ( |
| 87 | + diffEntry: mssql.DiffEntry, |
| 88 | + includeRequest: boolean, |
| 89 | + taskExecutionMode: mssql.TaskExecutionMode, |
| 90 | + ): void { |
| 91 | + webViewState?.extensionRpc.action("includeExcludeNode", { |
| 92 | + diffEntry: diffEntry, |
| 93 | + includeRequest: includeRequest, |
| 94 | + taskExecutionMode: taskExecutionMode, |
| 95 | + }); |
| 96 | + }, |
| 97 | + openScmp: function (filePath: string): void { |
| 98 | + webViewState?.extensionRpc.action("openScmp", { |
| 99 | + filePath: filePath, |
| 100 | + }); |
| 101 | + }, |
| 102 | + saveScmp: function ( |
| 103 | + sourceEndpointInfo: mssql.SchemaCompareEndpointInfo, |
| 104 | + targetEndpointInfo: mssql.SchemaCompareEndpointInfo, |
| 105 | + taskExecutionMode: mssql.TaskExecutionMode, |
| 106 | + deploymentOptions: mssql.DeploymentOptions, |
| 107 | + scmpFilePath: string, |
| 108 | + excludedSourceObjects: mssql.SchemaCompareObjectId[], |
| 109 | + excludedTargetObjects: mssql.SchemaCompareObjectId[], |
| 110 | + ): void { |
| 111 | + webViewState?.extensionRpc.action("saveScmp", { |
| 112 | + sourceEndpointInfo: sourceEndpointInfo, |
| 113 | + targetEndpointInfo: targetEndpointInfo, |
| 114 | + taskExecutionMode: taskExecutionMode, |
| 115 | + deploymentOptions: deploymentOptions, |
| 116 | + scmpFilePath: scmpFilePath, |
| 117 | + excludedSourceObjects: excludedSourceObjects, |
| 118 | + excludedTargetObjects: excludedTargetObjects, |
| 119 | + }); |
| 120 | + }, |
| 121 | + cancel: function (): void { |
| 122 | + webViewState?.extensionRpc.action("cancel", {}); |
| 123 | + }, |
| 124 | + }} |
| 125 | + > |
| 126 | + {children} |
| 127 | + </schemaCompareContext.Provider> |
| 128 | + ); |
| 129 | +}; |
| 130 | + |
| 131 | +export { SchemaCompareStateProvider }; |
0 commit comments