Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show the license section of content matches only for licensed users #1019

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/features/lightspeed/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ export class LightSpeedManager {
this.context,
this.client,
this.settingsManager,
this.apiInstance
this.apiInstance,
this.lightSpeedAuthenticationProvider
);

// create a new project lightspeed status bar item that we can manage
Expand Down
24 changes: 18 additions & 6 deletions src/features/lightspeed/contentMatchesWebview.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as vscode from "vscode";
import { LanguageClient } from "vscode-languageclient/node";
import { LightSpeedAPI } from "./api";
import { LightSpeedAuthenticationProvider } from "./lightSpeedOAuthProvider";
import { SettingsManager } from "../../settings";
import {
ContentMatchesRequestParams,
Expand All @@ -17,6 +18,7 @@ export class ContentMatchesWebview implements vscode.WebviewViewProvider {
private _view?: vscode.WebviewView;
private _extensionUri: vscode.Uri;
private context;
private lightSpeedAuthProvider: LightSpeedAuthenticationProvider;
public client;
public settingsManager: SettingsManager;
public apiInstance: LightSpeedAPI;
Expand All @@ -26,13 +28,15 @@ export class ContentMatchesWebview implements vscode.WebviewViewProvider {
context: vscode.ExtensionContext,
client: LanguageClient,
settingsManager: SettingsManager,
apiInstance: LightSpeedAPI
apiInstance: LightSpeedAPI,
lightSpeedAuthProvider: LightSpeedAuthenticationProvider
) {
this.context = context;
this.client = client;
this.settingsManager = settingsManager;
this.apiInstance = apiInstance;
this._extensionUri = context.extensionUri;
this.lightSpeedAuthProvider = lightSpeedAuthProvider;
}

public async resolveWebviewView(
Expand Down Expand Up @@ -150,6 +154,7 @@ export class ContentMatchesWebview implements vscode.WebviewViewProvider {
return noContentMatchesFoundHtml;
}

const rhUserHasSeat = await this.lightSpeedAuthProvider.rhUserHasSeat();
for (let taskIndex = 0; taskIndex < suggestedTasks.length; taskIndex++) {
let taskNameDescription = suggestedTasks[taskIndex].name;
if (!taskNameDescription) {
Expand All @@ -159,7 +164,8 @@ export class ContentMatchesWebview implements vscode.WebviewViewProvider {
const contentMatchValue = contentMatchResponses.contentmatches[taskIndex];
contentMatchesHtml += this.renderContentMatchWithTasKDescription(
<IContentMatchParams[]>(<IContentMatch>contentMatchValue).contentmatch,
taskNameDescription || ""
taskNameDescription || "",
rhUserHasSeat === true
);
}
const html = `<html>
Expand All @@ -172,16 +178,20 @@ export class ContentMatchesWebview implements vscode.WebviewViewProvider {
}

private renderContentMatches(
contentMatchResponse: IContentMatchParams
contentMatchResponse: IContentMatchParams,
rhUserHasSeat: boolean
): string {
const licenseLine = rhUserHasSeat
? `<li>License: ${contentMatchResponse.license}</li>`
: "";
return `
<details>
<summary>${contentMatchResponse.repo_name}</summary>
<ul>
<li>URL: <a href=${contentMatchResponse.repo_url}>${contentMatchResponse.repo_url}</a></li>
<li>Path: ${contentMatchResponse.path}</li>
<li>Data Source: ${contentMatchResponse.data_source_description}</li>
<li>License: ${contentMatchResponse.license}</li>
${licenseLine}
<li>Score: ${contentMatchResponse.score}</li>
</ul>
</details>
Expand All @@ -190,12 +200,14 @@ export class ContentMatchesWebview implements vscode.WebviewViewProvider {

private renderContentMatchWithTasKDescription(
contentMatchesResponse: IContentMatchParams[],
taskDescription: string
taskDescription: string,
rhUserHasSeat: boolean
): string {
let taskContentMatch = "";
for (let index = 0; index < contentMatchesResponse.length; index++) {
taskContentMatch += `${this.renderContentMatches(
contentMatchesResponse[index]
contentMatchesResponse[index],
rhUserHasSeat
)}`;
}

Expand Down