Skip to content

Commit

Permalink
fix: styling across products (#317)
Browse files Browse the repository at this point in the history
* fix: styling across products

* fix: handle failure in html generation

* fix: container background color

* fix: ignore SNYK-DOTNET-SYSTEMTEXTJSON-8168848

* fix: add theme css class

* fix: oss code background color
  • Loading branch information
ShawkyZ authored Oct 24, 2024
1 parent 62cbd5b commit a8e4856
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 159 deletions.
44 changes: 31 additions & 13 deletions .snyk
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities.
version: v1.25.0
# ignores vulnerabilities until expiry date; change duration by modifying expiry date
version: v1.25.1
exclude:
global:
#Exclude test directory for snyk code scan
- Snyk.Code.Library.Tests
- Snyk.Common.Tests
- Snyk.VisualStudio.Extension.Tests
global:
- Snyk.Code.Library.Tests
- Snyk.Common.Tests
- Snyk.VisualStudio.Extension.Tests
# ignores vulnerabilities until expiry date; change duration by modifying expiry date
ignore:
SNYK-DOTNET-NEWTONSOFTJSON-2774678:
- '*':
Expand All @@ -15,32 +14,51 @@ ignore:
created: 2022-06-02T11:45:31.420Z
SNYK-DOTNET-SYSTEMNETHTTP-60045:
- '*':
reason: Runtime vulnerability see - https://docs.snyk.io/scan-applications/supported-languages-and-frameworks/.net#tackling-vulnerabilities-from-runtime-dependencies
reason: >-
Runtime vulnerability see -
https://docs.snyk.io/scan-applications/supported-languages-and-frameworks/.net#tackling-vulnerabilities-from-runtime-dependencies
expires: 2024-09-21T00:00:00.000Z
created: 2023-09-21T11:45:31.420Z
SNYK-DOTNET-SYSTEMNETHTTP-60046:
- '*':
reason: Runtime vulnerability see - https://docs.snyk.io/scan-applications/supported-languages-and-frameworks/.net#tackling-vulnerabilities-from-runtime-dependencies
reason: >-
Runtime vulnerability see -
https://docs.snyk.io/scan-applications/supported-languages-and-frameworks/.net#tackling-vulnerabilities-from-runtime-dependencies
expires: 2024-09-21T00:00:00.000Z
created: 2023-09-21T11:45:31.420Z
SNYK-DOTNET-SYSTEMNETHTTP-72439:
- '*':
reason: Runtime vulnerability see - https://docs.snyk.io/scan-applications/supported-languages-and-frameworks/.net#tackling-vulnerabilities-from-runtime-dependencies
reason: >-
Runtime vulnerability see -
https://docs.snyk.io/scan-applications/supported-languages-and-frameworks/.net#tackling-vulnerabilities-from-runtime-dependencies
expires: 2024-09-21T00:00:00.000Z
created: 2023-09-21T11:45:31.420Z
SNYK-DOTNET-SYSTEMTEXTREGULAREXPRESSIONS-174708:
- '*':
reason: Runtime vulnerability see - https://docs.snyk.io/scan-applications/supported-languages-and-frameworks/.net#tackling-vulnerabilities-from-runtime-dependencies
reason: >-
Runtime vulnerability see -
https://docs.snyk.io/scan-applications/supported-languages-and-frameworks/.net#tackling-vulnerabilities-from-runtime-dependencies
expires: 2024-09-21T00:00:00.000Z
created: 2023-09-21T11:45:31.420Z
SNYK-DOTNET-SYSTEMNETHTTP-60047:
- '*':
reason: Runtime vulnerability see - https://docs.snyk.io/scan-applications/supported-languages-and-frameworks/.net#tackling-vulnerabilities-from-runtime-dependencies
reason: >-
Runtime vulnerability see -
https://docs.snyk.io/scan-applications/supported-languages-and-frameworks/.net#tackling-vulnerabilities-from-runtime-dependencies
expires: 2024-09-21T00:00:00.000Z
created: 2023-09-21T11:45:31.420Z
SNYK-DOTNET-SYSTEMNETHTTP-60048:
- '*':
reason: Runtime vulnerability see - https://docs.snyk.io/scan-applications/supported-languages-and-frameworks/.net#tackling-vulnerabilities-from-runtime-dependencies
reason: >-
Runtime vulnerability see -
https://docs.snyk.io/scan-applications/supported-languages-and-frameworks/.net#tackling-vulnerabilities-from-runtime-dependencies
expires: 2024-09-21T00:00:00.000Z
created: 2023-09-21T11:45:31.420Z
SNYK-DOTNET-SYSTEMTEXTJSON-8168848:
- '*':
reason: >-
Runtime vulnerability see -
https://docs.snyk.io/scan-applications/supported-languages-and-frameworks/.net#tackling-vulnerabilities-from-runtime-dependencies
expires: 2025-11-22T13:14:00.380Z
created: 2024-10-23T13:14:00.384Z
patch: {}
16 changes: 15 additions & 1 deletion Snyk.VisualStudio.Extension.2022/Theme/ThemeInfo.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
namespace Snyk.VisualStudio.Extension.Theme
using System.Windows;
using Microsoft.VisualStudio.PlatformUI;

namespace Snyk.VisualStudio.Extension.Theme
{
using System.IO;
using System.Runtime.InteropServices;
Expand Down Expand Up @@ -80,5 +83,16 @@ private static extern int GetCurrentThemeName(
int cchMaxColorChars,
StringBuilder pszSizeBuff,
int cchMaxSizeChars);
public static bool IsDarkTheme()
{
var backgroundColor = VSColorTheme.GetThemedColor(EnvironmentColors.ToolWindowBackgroundColorKey);
var luminance = (0.299 * backgroundColor.R + 0.587 * backgroundColor.G + 0.114 * backgroundColor.B) / 255;
return luminance < 0.5;
}

public static bool IsHighContrast()
{
return SystemParameters.HighContrast;
}
}
}
4 changes: 1 addition & 3 deletions Snyk.VisualStudio.Extension.2022/UI/Html/BaseHtmlProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ public virtual string GetCss()
return @"
html, body {
height: 100%;
font-size: 0.9rem;
display: flex;
flex-direction: column;
margin: 0;
Expand All @@ -22,7 +21,6 @@ public virtual string GetCss()
background-color: var(--background-color);
color: var(--text-color);
font-weight: 400;
font-size: 0.875rem;
}
section {
Expand Down Expand Up @@ -90,7 +88,7 @@ public virtual string ReplaceCssVariables(string html)
html = html.Replace("var(--border-color)", VSColorTheme.GetThemedColor(EnvironmentColors.AccessKeyToolTipColorKey).ToHex());
html = html.Replace("var(--link-color)", VSColorTheme.GetThemedColor(EnvironmentColors.PanelHyperlinkBrushKey).ToHex());
html = html.Replace("var(--horizontal-border-color)", VSColorTheme.GetThemedColor(EnvironmentColors.ClassDesignerDefaultShapeTextBrushKey).ToHex());
html = html.Replace("var(--code-background-color)", VSColorTheme.GetThemedColor(EnvironmentColors.ClassDesignerConnectionRouteBorderBrushKey).ToHex());
html = html.Replace("var(--code-background-color)", VSColorTheme.GetThemedColor(EnvironmentColors.EditorExpansionFillBrushKey).ToHex());

var ideHeaders = """
<head>
Expand Down
54 changes: 23 additions & 31 deletions Snyk.VisualStudio.Extension.2022/UI/Html/CodeHtmlProvider.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using Microsoft.VisualStudio.PlatformUI;
using Snyk.VisualStudio.Extension.Theme;

namespace Snyk.VisualStudio.Extension.UI.Html
{
Expand All @@ -23,49 +24,30 @@ public static CodeHtmlProvider Instance
public override string GetCss()
{
return base.GetCss() + Environment.NewLine + @"
.suggestion--header {
padding-top: 10px;
}
.suggestion .suggestion-text {
font-size: 1.5rem;
position: relative;
top: -5%;
}
.code-issue-container {
margin-top: 20px;
}
.summary .summary-item {
margin-bottom: 0.8em;
}
.summary .label {
font-size: 0.8rem;
}
.suggestion--header > h2,
.summary > h2 {
font-size: 0.9rem;
margin-bottom: 1.5em;
}
.identifiers {
padding-bottom: 20px;
}
.data-flow-table {
background-color: var(--container-background-color);
background-color: var(--code-background-color);
border: 1px solid transparent;
}
.tabs-nav {
margin: 21px 0 -21px;
}
.light .dark-only,
.high-contrast.high-contrast-light .dark-only {
display: none;
}
.dark .light-only,
.high-contrast:not(.high-contrast-light) .light-only {
display: none;
}
.tab-item {
cursor: pointer;
display: inline-block;
padding: 5px 10px;
border-bottom: 1px solid transparent;
font-size: 0.8rem;
color: var(--text-color);
text-transform: uppercase;
}
Expand Down Expand Up @@ -113,6 +95,7 @@ .summary .label {

public override string GetInitScript()
{
var themeScript = GetThemeScript();
var initScript = base.GetInitScript();
return initScript + Environment.NewLine + @"
function navigateToIssue(e, target) {
Expand Down Expand Up @@ -147,14 +130,23 @@ function navigateToIssue(e, target) {
if(document.getElementsByClassName('ignore-action-container') && document.getElementsByClassName('ignore-action-container')[0]){
document.getElementsByClassName('ignore-action-container')[0].className = 'hidden';
}
";
" + themeScript;
}

private string GetThemeScript()
{
var isDarkTheme = ThemeInfo.IsDarkTheme();
var isHighContrast = ThemeInfo.IsHighContrast();
var themeScript = $"var isDarkTheme = {isDarkTheme.ToString().ToLowerInvariant()};\n" +
$"var isHighContrast = {isHighContrast.ToString().ToLowerInvariant()};\n" +
"document.body.classList.add(isHighContrast ? 'high-contrast' : (isDarkTheme ? 'dark' : 'light'));";
return themeScript;
}

public override string ReplaceCssVariables(string html)
{
html = base.ReplaceCssVariables(html);

html = html.Replace("var(--container-background-color)", VSColorTheme.GetThemedColor(EnvironmentColors.BrandedUIBackgroundBrushKey).ToHex());
html = html.Replace("var(--line-removed)", VSColorTheme.GetThemedColor(EnvironmentColors.VizSurfaceRedDarkBrushKey).ToHex());
html = html.Replace("var(--line-added)", VSColorTheme.GetThemedColor(EnvironmentColors.VizSurfaceGreenDarkBrushKey).ToHex());

Expand Down
61 changes: 1 addition & 60 deletions Snyk.VisualStudio.Extension.2022/UI/Html/IacHtmlProvider.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using Microsoft.VisualStudio.PlatformUI;
using System;

namespace Snyk.VisualStudio.Extension.UI.Html
namespace Snyk.VisualStudio.Extension.UI.Html
{
public class IacHtmlProvider : BaseHtmlProvider
{
Expand All @@ -18,61 +15,5 @@ public static IacHtmlProvider Instance
return _instance;
}
}

public override string GetCss()
{
return base.GetCss() + Environment.NewLine + @"
.suggestion--header {
padding-top: 10px;
}
.suggestion .suggestion-text {
font-size: 1.5rem;
position: relative;
top: -5%;
}
.summary .summary-item {
margin-bottom: 0.8em;
}
.summary .label {
font-size: 0.8rem;
}
.suggestion--header > h2,
.summary > h2,
.vulnerability-overview > h2 {
font-size: 0.9rem;
margin-bottom: 1.5em;
}
.identifiers {
padding-bottom: 20px;
}
.vulnerability-overview pre {
background-color: var(--container-background-color);
border: 1px solid transparent;
overflow-x: auto;
border-radius: 4px;
}
.vulnerability-overview table {
background-color: var(--container-background-color);
}
p {
margin-top: 0;
margin-bottom: 2rem;
}
";
}

public override string ReplaceCssVariables(string html)
{
html = base.ReplaceCssVariables(html);
html = html.Replace("var(--container-background-color)", VSColorTheme.GetThemedColor(EnvironmentColors.ClassDesignerConnectionRouteBorderBrushKey).ToHex());

return html;
}
}
}
48 changes: 1 addition & 47 deletions Snyk.VisualStudio.Extension.2022/UI/Html/OssHtmlProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,56 +19,10 @@ public static OssHtmlProvider Instance
}
}

public override string GetCss()
{
return base.GetCss() + Environment.NewLine + @"
.suggestion--header {
padding-top: 10px;
}
.suggestion .suggestion-text {
font-size: 1.5rem;
position: relative;
top: -5%;
}
.suggestion {
display: block;
}
.summary .summary-item {
margin-bottom: 0.8em;
}
.summary .label {
font-size: 0.8rem;
}
.suggestion--header > h2,
.summary > h2,
.vulnerability-overview > h2 {
font-size: 0.9rem;
margin-bottom: 1.5em;
}
.identifiers {
padding-bottom: 20px;
}
.vulnerability-overview pre {
background-color: var(--container-background-color);
border: 1px solid transparent;
overflow-x: auto;
border-radius: 4px;
}
.vulnerability-overview table {
background-color: var(--container-background-color);
}
";
}

public override string ReplaceCssVariables(string html)
{
html = base.ReplaceCssVariables(html);
html = html.Replace("var(--container-background-color)", VSColorTheme.GetThemedColor(EnvironmentColors.ClassDesignerConnectionRouteBorderBrushKey).ToHex());
html = html.Replace("var(--container-background-color)", VSColorTheme.GetThemedColor(EnvironmentColors.EditorExpansionFillBrushKey).ToHex());

return html;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -760,17 +760,25 @@ private void FillHtmlPanel(string issueId, string product, string html)
{
var languageClientManager = LanguageClientHelper.LanguageClientManager();
if (languageClientManager == null) return;
ThreadHelper.JoinableTaskFactory.RunAsync(async () =>
ThreadHelper.JoinableTaskFactory.Run(async () =>
{
if (string.IsNullOrEmpty(html))
{
html = await languageClientManager.InvokeGenerateIssueDescriptionAsync(issueId,
SnykVSPackage.Instance.DisposalToken);
try
{
html = await languageClientManager.InvokeGenerateIssueDescriptionAsync(issueId,
SnykVSPackage.Instance.DisposalToken);
}
catch
{
Logger.Error("couldn't load html for issue {0}", issueId);
html = string.Empty;
}
}

await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
this.DescriptionPanel.SetContent(html, product);
}).FireAndForget();
});
}

private async Task HandleSnykCodeTreeNodeSelectedAsync()
Expand Down

0 comments on commit a8e4856

Please sign in to comment.