From 7f675b884f2efbc771314224c288a8a673ce817c Mon Sep 17 00:00:00 2001 From: Alan Ren Date: Fri, 2 Sep 2022 12:50:30 -0700 Subject: [PATCH] require confirmation when risks present (#1668) --- Packages.props | 2 +- .../Localization/sr.cs | 11 ++++++++++ .../Localization/sr.resx | 4 ++++ .../Localization/sr.strings | 1 + .../Localization/sr.xlf | 5 +++++ .../Requests/GeneratePreviewReportRequest.cs | 22 ++++++++++++++----- .../TableDesigner/TableDesignerService.cs | 4 +++- 7 files changed, 41 insertions(+), 8 deletions(-) diff --git a/Packages.props b/Packages.props index df80e832..ff6579a3 100644 --- a/Packages.props +++ b/Packages.props @@ -22,7 +22,7 @@ - + diff --git a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.cs b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.cs index 3d79884b..70450df7 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.cs @@ -9429,6 +9429,14 @@ namespace Microsoft.SqlTools.ServiceLayer } } + public static string TableDesignerConfirmationText + { + get + { + return Keys.GetString(Keys.TableDesignerConfirmationText); + } + } + public static string GetUserDefinedObjectsFromModelFailed { get @@ -13596,6 +13604,9 @@ namespace Microsoft.SqlTools.ServiceLayer public const string ComputedColumnNeedToBePersistedInForeignKeyRuleDescription = "ComputedColumnNeedToBePersistedInForeignKeyRuleDescription"; + public const string TableDesignerConfirmationText = "TableDesignerConfirmationText"; + + public const string SqlProjectModelNotFound = "SqlProjectModelNotFound"; diff --git a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.resx b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.resx index ff660017..dbf6716d 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.resx +++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.resx @@ -5206,6 +5206,10 @@ The Query Processor estimates that implementing the following index could improv . Parameters: 0 - columnName (string), 1 - foreignKeyName (string) + + I have read the summary and understand the potential risks. + + Could not find SQL model from project: {0}. . diff --git a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.strings b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.strings index e179664b..a2932e61 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.strings +++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.strings @@ -2382,6 +2382,7 @@ ColumnCanOnlyAppearOnceInIndexIncludedColumnsRuleDescription(string columnName, ColumnCannotDuplicateWitIndexKeyColumnsRuleDescription(string columnName, string indexName, int rowNumber) = Included column with name '{0}' has already been part of the index '{1}' and it cannot be included. Row number: {2}. ComputedColumnNeedToBePersistedAndNotNullInPrimaryKeyRuleDescription(string columnName) = The computed column with name '{0}' has to be persisted and not nullable to be part of a primary key. ComputedColumnNeedToBePersistedInForeignKeyRuleDescription(string columnName, string foreignKeyName) = The computed column with name '{0}' has to be persisted to be part of the foreign key '{1}'. +TableDesignerConfirmationText = I have read the summary and understand the potential risks. ############################################################################ # TSql Model diff --git a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.xlf b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.xlf index f3235e5a..89dee44f 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.xlf +++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.xlf @@ -6360,6 +6360,11 @@ The Query Processor estimates that implementing the following index could improv . Parameters: 0 - columnName (string), 1 - foreignKeyName (string) + + I have read the summary and understand the potential risks. + I have read the summary and understand the potential risks. + + \ No newline at end of file diff --git a/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Contracts/Requests/GeneratePreviewReportRequest.cs b/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Contracts/Requests/GeneratePreviewReportRequest.cs index 8788f7f1..f5ac58ea 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Contracts/Requests/GeneratePreviewReportRequest.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Contracts/Requests/GeneratePreviewReportRequest.cs @@ -12,29 +12,39 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner.Contracts /// The service request to generate preview report describing the changes. /// - public class GeneratePreviewReportResult + public class GeneratePreviewReportResult { /// /// The report generated for publish preview /// - public string Report; + public string? Report { get; set; } /// /// format (mimetype) of the string /// - public string MimeType; + public string? MimeType { get; set; } + + /// + /// Whether user confirmation is required. + /// + public bool RequireConfirmation { get; set; } + + /// + /// The confirmation text. + /// + public string? ConfirmationText { get; set; } /// /// Metadata about the table /// - public Dictionary Metadata { get; set; } + public Dictionary? Metadata { get; set; } /// /// The table schema validation error /// - public string SchemaValidationError { get; set; } + public string? SchemaValidationError { get; set; } } - + /// /// The service request to generate preview report describing the changes. /// diff --git a/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/TableDesignerService.cs b/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/TableDesignerService.cs index f1925714..9a641e76 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/TableDesignerService.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/TableDesignerService.cs @@ -196,9 +196,11 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner { var table = this.GetTableDesigner(tableInfo); var report = table.GenerateReport(); - generatePreviewReportResult.Report = report; + generatePreviewReportResult.Report = report.Report; generatePreviewReportResult.MimeType = "text/markdown"; generatePreviewReportResult.Metadata = this.GetMetadata(tableInfo); + generatePreviewReportResult.RequireConfirmation = report.RequireTableRecreation || report.PossibleDataLoss || report.HasWarnings; + generatePreviewReportResult.ConfirmationText = generatePreviewReportResult.RequireConfirmation ? SR.TableDesignerConfirmationText : null; await requestContext.SendResult(generatePreviewReportResult); } catch (DesignerValidationException e)