Skip to content

Commit 9f195f9

Browse files
author
Whitney Shake
committed
Reverted to prior commit and re-incorporated new logic
1 parent 6b7e81b commit 9f195f9

45 files changed

Lines changed: 4277 additions & 12 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/dotnet/APIView/ClientSPA/src/app/_components/code-panel/code-panel.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<ng-container *ngIf="item.type === CodePanelRowDatatype.CommentThread">
2626
<app-comment-thread
2727
[codePanelRowData]="item"
28-
[associatedCodeLine]="codePanelData!.nodeMetaData[item.nodeIdHashed]!.codeLines[item.associatedRowPositionInGroup]!"
28+
[associatedCodeLine]="getAssociatedCodeLine(item)"
2929
(cancelCommentActionEmitter)="handleCancelCommentActionEmitter($event)"
3030
(saveCommentActionEmitter)="handleSaveCommentActionEmitter($event)"
3131
(deleteCommentActionEmitter)="handleDeleteCommentActionEmitter($event)"

src/dotnet/APIView/ClientSPA/src/app/_components/code-panel/code-panel.component.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,13 @@ export class CodePanelComponent implements OnChanges{
136136
return "";
137137
}
138138

139+
getAssociatedCodeLine(item: CodePanelRowData): CodePanelRowData | undefined {
140+
if (this.codePanelData?.nodeMetaData && this.codePanelData.nodeMetaData[item.nodeIdHashed]) {
141+
return this.codePanelData.nodeMetaData[item.nodeIdHashed].codeLines[item.associatedRowPositionInGroup] || undefined;
142+
}
143+
return undefined;
144+
}
145+
139146
toggleNodeComments(target: Element) {
140147
const nodeIdHashed = target.closest('.code-line')!.getAttribute('data-node-id');
141148
const rowPositionInGroup = parseInt(target.closest('.code-line')!.getAttribute('data-row-position-in-group')!, 10);

src/dotnet/APIView/ClientSPA/src/app/_components/shared/comment-thread/comment-thread.component.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ export class CommentThreadComponent {
105105
if (changes['codePanelRowData']) {
106106
this.setCommentResolutionState();
107107
}
108+
if (changes['associatedCodeLine']) {
109+
}
108110
}
109111

110112
setCommentResolutionState() {
@@ -170,20 +172,23 @@ export class CommentThreadComponent {
170172
const target = (event.originalEvent?.target as Element).closest("a") as Element;
171173
const commentId = target.getAttribute("data-item-id");
172174
const commentData = this.codePanelRowData?.comments?.find(comment => comment.id === commentId)?.commentText.replace(/<[^>]*>/g, '').trim();
173-
175+
174176
const codeLineContent = this.associatedCodeLine
175-
? this.associatedCodeLine.rowOfTokens
176-
.filter(token => token.kind !== 'nonBreakingSpace')
177-
.map(token => token.value)
178-
.join('')
179-
: '';
180-
181-
const apiViewUrl = `${window.location.href.split("#")[0]}%23${encodeURIComponent(encodeURIComponent(event.item?.title!))}`;
182-
const issueBody = encodeURIComponent(`\`\`\`${event.item?.title}\n${codeLineContent}\n\`\`\`\n#\n${commentData}\n#\n[Created from ApiView comment]\n(${apiViewUrl})`);
183-
177+
? this.associatedCodeLine.rowOfTokens
178+
.filter(token => token.kind !== 'nonBreakingSpace')
179+
.map(token => token.value)
180+
.join(' ')
181+
.replace(/\s+/g, ' ')
182+
.trim()
183+
: '';
184+
185+
const nodeId: string = this.codePanelRowData?.nodeId ?? 'defaultNodeId';
186+
const apiViewUrl = `${window.location.href.split("#")[0]}&nId=${encodeURIComponent(nodeId)}`;
187+
const issueBody = encodeURIComponent(`\`\`\`${event.item?.title}\n${codeLineContent}\n\`\`\`\n#\n${commentData}\n#\n[Created from ApiView comment](${apiViewUrl})`);
188+
184189
window.open(`https://github.com/Azure/${repo}/issues/new?body=${issueBody}`, '_blank');
185190
}
186-
191+
187192
showReplyEditor(event: Event) {
188193
this.codePanelRowData!.showReplyTextBox = true;
189194
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { expect, test } from "vitest";
2+
import { findApiVersionInRestClient, getApiVersionType } from "../../mlc/apiVersion/apiVersionTypeExtractor";
3+
import { join } from "path";
4+
import { ApiVersionType } from "../../common/types";
5+
6+
test("MLC api-version Extractor: new createClient function", async () => {
7+
const clientPath = join(__dirname, 'testCases/new/src/rest/newClient.ts');
8+
const version = findApiVersionInRestClient(clientPath);
9+
expect(version).toBe('2024-03-01-preview');
10+
});
11+
12+
test("MLC api-version Extractor: get api version type from new createClient function", async () => {
13+
const root = join(__dirname, 'testCases/new/');
14+
const version = getApiVersionType(root);
15+
expect(version).toBe(ApiVersionType.Preview);
16+
});
17+
18+
test("MLC api-version Extractor: old createClient function 1", async () => {
19+
const clientPath = join(__dirname, 'testCases/old1/src/rest/oldClient.ts');
20+
const version = findApiVersionInRestClient(clientPath);
21+
expect(version).toBe('v1.1-preview.1');
22+
});
23+
24+
test("MLC api-version Extractor: get api version type from old createClient function 1", async () => {
25+
const root = join(__dirname, 'testCases/old1/');
26+
const version = getApiVersionType(root);
27+
expect(version).toBe(ApiVersionType.Preview);
28+
});
29+
30+
test("MLC api-version Extractor: old createClient function 2", async () => {
31+
const clientPath = join(__dirname, 'testCases/old2/src/rest/oldClient.ts');
32+
const version = findApiVersionInRestClient(clientPath);
33+
expect(version).toBe('2024-03-01');
34+
});
35+
36+
test("MLC api-version Extractor: get api version type from old createClient function 2", async () => {
37+
const root = join(__dirname, 'testCases/old2/');
38+
const version = getApiVersionType(root);
39+
expect(version).toBe(ApiVersionType.Stable);
40+
});
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT license.
3+
4+
import { getClient, ClientOptions } from "@azure-rest/core-client";
5+
import { logger } from "../logger.js";
6+
import { TokenCredential } from "@azure/core-auth";
7+
import { DocumentDBContext } from "./clientDefinitions.js";
8+
9+
/** The optional parameters for the client */
10+
export interface DocumentDBContextOptions extends ClientOptions {
11+
/** The api version option of the client */
12+
apiVersion?: string;
13+
}
14+
15+
/**
16+
* Initialize a new instance of `DocumentDBContext`
17+
* @param credentials - uniquely identify client credential
18+
* @param options - the parameter for all optional parameters
19+
*/
20+
export default function createClient(
21+
credentials: TokenCredential,
22+
{
23+
apiVersion = "2024-03-01-preview",
24+
...options
25+
}: DocumentDBContextOptions = {},
26+
): DocumentDBContext {
27+
const endpointUrl =
28+
options.endpoint ?? options.baseUrl ?? `https://management.azure.com`;
29+
const userAgentInfo = `azsdk-js-arm-mongocluster/1.0.0-beta.1`;
30+
const userAgentPrefix =
31+
options.userAgentOptions && options.userAgentOptions.userAgentPrefix
32+
? `${options.userAgentOptions.userAgentPrefix} ${userAgentInfo}`
33+
: `${userAgentInfo}`;
34+
options = {
35+
...options,
36+
userAgentOptions: {
37+
userAgentPrefix,
38+
},
39+
loggingOptions: {
40+
logger: options.loggingOptions?.logger ?? logger.info,
41+
},
42+
credentials: {
43+
scopes: options.credentials?.scopes ?? [`${endpointUrl}/.default`],
44+
},
45+
};
46+
const client = getClient(
47+
endpointUrl,
48+
credentials,
49+
options,
50+
) as DocumentDBContext;
51+
52+
client.pipeline.removePolicy({ name: "ApiVersionPolicy" });
53+
client.pipeline.addPolicy({
54+
name: "ClientApiVersionPolicy",
55+
sendRequest: (req, next) => {
56+
// Use the apiVersion defined in request url directly
57+
// Append one if there is no apiVersion and we have one at client options
58+
const url = new URL(req.url);
59+
if (!url.searchParams.get("api-version") && apiVersion) {
60+
req.url = `${req.url}${Array.from(url.searchParams.keys()).length > 0 ? "&" : "?"
61+
}api-version=${apiVersion}`;
62+
}
63+
64+
return next(req);
65+
},
66+
});
67+
return client;
68+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT license.
3+
4+
import { getClient, ClientOptions } from "@azure-rest/core-client";
5+
import { logger } from "./logger.js";
6+
import { TokenCredential, KeyCredential } from "@azure/core-auth";
7+
import { FaceClient } from "./clientDefinitions.js";
8+
import { Versions } from "./models.js";
9+
10+
export interface FaceClientOptions extends ClientOptions {
11+
apiVersion?: Versions;
12+
}
13+
14+
/**
15+
* Initialize a new instance of `FaceClient`
16+
* @param endpointParam - Supported Cognitive Services endpoints (protocol and hostname, for example:
17+
* https://{resource-name}.cognitiveservices.azure.com).
18+
* @param credentials - uniquely identify client credential
19+
* @param options - the parameter for all optional parameters
20+
*/
21+
export default function createClient(
22+
endpointParam: string,
23+
credentials: TokenCredential | KeyCredential,
24+
options: FaceClientOptions = {},
25+
): FaceClient {
26+
const apiVersion = options.apiVersion ?? "v1.1-preview.1";
27+
const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}/face/${apiVersion}`;
28+
29+
const userAgentInfo = `azsdk-js-ai-vision-face-rest/1.0.0-beta.1`;
30+
const userAgentPrefix =
31+
options.userAgentOptions && options.userAgentOptions.userAgentPrefix
32+
? `${options.userAgentOptions.userAgentPrefix} ${userAgentInfo}`
33+
: `${userAgentInfo}`;
34+
options = {
35+
...options,
36+
userAgentOptions: {
37+
userAgentPrefix,
38+
},
39+
loggingOptions: {
40+
logger: options.loggingOptions?.logger ?? logger.info,
41+
},
42+
credentials: {
43+
scopes: options.credentials?.scopes ?? ["https://cognitiveservices.azure.com/.default"],
44+
apiKeyHeaderName: options.credentials?.apiKeyHeaderName ?? "Ocp-Apim-Subscription-Key",
45+
},
46+
};
47+
48+
const client = getClient(endpointUrl, credentials, options) as FaceClient;
49+
50+
client.pipeline.removePolicy({ name: "ApiVersionPolicy" });
51+
52+
client.pipeline.addPolicy({
53+
name: "VerifyImageFilenamePolicy",
54+
sendRequest: (request, next) => {
55+
for (const part of request.multipartBody?.parts ?? []) {
56+
const contentDisposition = part.headers.get("content-disposition");
57+
if (
58+
contentDisposition &&
59+
contentDisposition.includes(`name="VerifyImage"`) &&
60+
!contentDisposition.includes("filename=")
61+
) {
62+
part.headers.set("content-disposition", `form-data; name="VerifyImage"; filename="blob"`);
63+
}
64+
}
65+
return next(request);
66+
},
67+
});
68+
69+
return client;
70+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT license.
3+
4+
import { getClient, ClientOptions } from "@azure-rest/core-client";
5+
import { logger } from "../logger.js";
6+
import { TokenCredential, KeyCredential } from "@azure/core-auth";
7+
import { OpenAIContext } from "./clientDefinitions.js";
8+
9+
/**
10+
* Initialize a new instance of `OpenAIContext`
11+
* @param endpoint - Supported Cognitive Services endpoints (protocol and hostname, for example:
12+
* https://westus.api.cognitive.microsoft.com).
13+
* @param credentials - uniquely identify client credential
14+
* @param options - the parameter for all optional parameters
15+
*/
16+
export default function createClient(
17+
endpoint: string,
18+
credentials: TokenCredential | KeyCredential,
19+
options: ClientOptions = {},
20+
): OpenAIContext {
21+
const baseUrl = options.baseUrl ?? `${endpoint}/openai`;
22+
options.apiVersion = options.apiVersion ?? "2024-03-01";
23+
const userAgentInfo = `azsdk-js-openai-rest/1.0.0-beta.12`;
24+
const userAgentPrefix =
25+
options.userAgentOptions && options.userAgentOptions.userAgentPrefix
26+
? `${options.userAgentOptions.userAgentPrefix} ${userAgentInfo}`
27+
: `${userAgentInfo}`;
28+
options = {
29+
...options,
30+
userAgentOptions: {
31+
userAgentPrefix,
32+
},
33+
loggingOptions: {
34+
logger: options.loggingOptions?.logger ?? logger.info,
35+
},
36+
credentials: {
37+
scopes: options.credentials?.scopes ?? ["https://cognitiveservices.azure.com/.default"],
38+
apiKeyHeaderName: options.credentials?.apiKeyHeaderName ?? "api-key",
39+
},
40+
};
41+
42+
const client = getClient(baseUrl, credentials, options) as OpenAIContext;
43+
44+
return client;
45+
}

0 commit comments

Comments
 (0)