From 9d6598421c2eb1f02d211cf268079b430486dee6 Mon Sep 17 00:00:00 2001 From: Sarangan Rajamanickam Date: Wed, 30 Oct 2024 10:40:59 -0700 Subject: [PATCH 1/2] [@azure-tools/cadl-ranch-dashboard] Add Number of Scenarios under each heading (#765) * Initial Commit * Added changeset * Format * Use useMemo to improve performance --- .changeset/quick-coins-speak.md | 5 ++++ packages/cadl-ranch-dashboard/package.json | 2 +- .../components/tree-table/row-label-cell.tsx | 28 +++++++++++++++++-- 3 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 .changeset/quick-coins-speak.md diff --git a/.changeset/quick-coins-speak.md b/.changeset/quick-coins-speak.md new file mode 100644 index 000000000..9485b06da --- /dev/null +++ b/.changeset/quick-coins-speak.md @@ -0,0 +1,5 @@ +--- +"@azure-tools/cadl-ranch-dashboard": minor +--- + +Added number of scenarios under each row diff --git a/packages/cadl-ranch-dashboard/package.json b/packages/cadl-ranch-dashboard/package.json index e46b32a59..411864d5a 100644 --- a/packages/cadl-ranch-dashboard/package.json +++ b/packages/cadl-ranch-dashboard/package.json @@ -1,7 +1,7 @@ { "name": "@azure-tools/cadl-ranch-dashboard", "private": true, - "version": "0.9.0", + "version": "0.10.0", "description": "Cadl Ranch Dashboard website", "main": "dist/index.js", "type": "module", diff --git a/packages/cadl-ranch-dashboard/src/components/tree-table/row-label-cell.tsx b/packages/cadl-ranch-dashboard/src/components/tree-table/row-label-cell.tsx index e0710d686..a82f6f48f 100644 --- a/packages/cadl-ranch-dashboard/src/components/tree-table/row-label-cell.tsx +++ b/packages/cadl-ranch-dashboard/src/components/tree-table/row-label-cell.tsx @@ -1,5 +1,5 @@ -import { FunctionComponent } from "react"; -import { TreeTableRow } from "./types.js"; +import { FunctionComponent, useMemo } from "react"; +import { ManifestTreeNode, TreeTableRow } from "./types.js"; import { Button, Popover, PopoverSurface, PopoverTrigger, Title3, Tooltip } from "@fluentui/react-components"; import ReactMarkdown from "react-markdown"; import { ScenarioData } from "@azure-tools/cadl-ranch-coverage-sdk"; @@ -17,6 +17,7 @@ const INDENT_SIZE = 14; export const RowLabelCell: FunctionComponent = ({ row }) => { const caret = row.hasChildren ? row.expanded ? : : null; const marginLeft = row.depth * INDENT_SIZE; + const rowLabel = getLabelForRow(row); return ( = ({ row }) => { flex: 1, }} > - {row.item.name} + {rowLabel}
{row.item.scenario && } @@ -98,3 +99,24 @@ const GotoSourceButton: FunctionComponent = ({ scenario } function getGithubLineNumber(value: number): `L${number}` { return `L${value + 1}`; } + +function getLabelForRow(row: TreeTableRow): string { + return useMemo(() => { + const countLeafChildren = (node: ManifestTreeNode): number => { + if (Object.keys(node.children).length === 0) { + return 1; + } + + return Object.values(node.children).reduce((acc, child) => acc + countLeafChildren(child), 0); + }; + + const { name } = row.item; + + if (!row.hasChildren) { + return name; + } + + const totalLeafChildren = countLeafChildren(row.item); + return `${name} (${totalLeafChildren} scenarios)`; + }, [row.item, row.hasChildren]); +} From 33170173a91560c5cd4b3883582d1766b0f3471e Mon Sep 17 00:00:00 2001 From: mcgallan <88413158+mcgallan@users.noreply.github.com> Date: Thu, 31 Oct 2024 09:59:08 +0800 Subject: [PATCH 2/2] Fix Issue In current Versioning\Removed (#736) * fix * Update main.tsp * update * Update cadl-ranch-summary.md * Update cadl-ranch-summary.md * update * Update mockapi.ts * fix doc * Update mockapi.ts * Update mockapi.ts * Update mockapi.ts --- .changeset/witty-frogs-rush.md | 5 ++ .../cadl-ranch-specs/cadl-ranch-summary.md | 43 ++++++++++++ .../http/versioning/removed/main.tsp | 70 ++++++++++++++++++- .../http/versioning/removed/mockapi.ts | 47 +++++++++++++ 4 files changed, 162 insertions(+), 3 deletions(-) create mode 100644 .changeset/witty-frogs-rush.md diff --git a/.changeset/witty-frogs-rush.md b/.changeset/witty-frogs-rush.md new file mode 100644 index 000000000..82b573ed0 --- /dev/null +++ b/.changeset/witty-frogs-rush.md @@ -0,0 +1,5 @@ +--- +"@azure-tools/cadl-ranch-specs": patch +--- + +Fix Issue In Versioning\Removed. diff --git a/packages/cadl-ranch-specs/cadl-ranch-summary.md b/packages/cadl-ranch-specs/cadl-ranch-summary.md index 997161e40..fbaf634ef 100644 --- a/packages/cadl-ranch-specs/cadl-ranch-summary.md +++ b/packages/cadl-ranch-specs/cadl-ranch-summary.md @@ -9108,6 +9108,49 @@ Expected request body: { "prop": "foo" } ``` +### Versioning_Removed_modelV3 + +- Endpoint: `post /versioning/removed/api-version:{version}/v3` + +path: "/versioning/removed/api-version[:]v1/v3" +Expected request body: + +```json +{ "id": "123", "enumProp": "enumMemberV1" } +``` + +Expected response body: + +```json +{ "id": "123", "enumProp": "enumMemberV1" } +``` + +path: "/versioning/removed/api-version[:]v2preview/v3" +Expected request body: + +```json +{ "id": "123" } +``` + +Expected response body: + +```json +{ "id": "123" } +``` + +path: "/versioning/removed/api-version[:]v2/v3" +Expected request body: + +```json +{ "id": "123", "enumProp": "enumMemberV1" } +``` + +Expected response body: + +```json +{ "id": "123", "enumProp": "enumMemberV1" } +``` + ### Versioning_Removed_v2 - Endpoint: `post /versioning/removed/api-version:{version}/v2` diff --git a/packages/cadl-ranch-specs/http/versioning/removed/main.tsp b/packages/cadl-ranch-specs/http/versioning/removed/main.tsp index 858c5bcc3..6e3d228f6 100644 --- a/packages/cadl-ranch-specs/http/versioning/removed/main.tsp +++ b/packages/cadl-ranch-specs/http/versioning/removed/main.tsp @@ -1,9 +1,11 @@ import "@typespec/http"; import "@azure-tools/cadl-ranch-expect"; import "@typespec/versioning"; +import "@azure-tools/typespec-azure-core"; using TypeSpec.Http; using TypeSpec.Versioning; +using TypeSpec.Rest; /** * Test for the `@removed` decorator. @@ -20,7 +22,7 @@ using TypeSpec.Versioning; endpoint: url, /** - * Need to be set as 'v1' or 'v2' in client. + * Need to be set as 'v1', 'v2preview' or 'v2' in client. */ version: Versions, } @@ -32,12 +34,17 @@ namespace Versioning.Removed; */ enum Versions { /** - * The version v1. + * The original version v1. */ v1: "v1", /** - * The version v2. + * The V2 Preview version. + */ + v2preview: "v2preview", + + /** + * The latest version v2. */ v2: "v2", } @@ -66,6 +73,14 @@ model ModelV2 { unionProp: UnionV2; } +model ModelV3 { + id: string; + + @removed(Versions.v2preview) + @added(Versions.v2) + enumProp: EnumV3; +} + enum EnumV2 { @removed(Versions.v2) enumMemberV1, @@ -73,6 +88,14 @@ enum EnumV2 { enumMemberV2, } +enum EnumV3 { + @removed(Versions.v2preview) + @added(Versions.v2) + enumMemberV1, + + enumMemberV2Preview, +} + @removed(Versions.v2) union UnionV1 { string, @@ -123,3 +146,44 @@ interface InterfaceV1 { @route("/v1") v1InInterface(@body body: ModelV1): ModelV1; } + +/** This operation will pass different paths and different request bodies based on different versions. */ +@scenario +@scenarioDoc(""" + path: "/versioning/removed/api-version[:]v1/v3" + Expected request body: + ```json + { "id": "123", "enumProp": "enumMemberV1" } + ``` + + Expected response body: + ```json + { "id": "123", "enumProp": "enumMemberV1" } + ``` + + path: "/versioning/removed/api-version[:]v2preview/v3" + Expected request body: + ```json + { "id": "123"} + ``` + + Expected response body: + ```json + { "id": "123"} + ``` + + path: "/versioning/removed/api-version[:]v2/v3" + Expected request body: + ```json + { "id": "123", "enumProp": "enumMemberV1" } + ``` + + Expected response body: + ```json + { "id": "123", "enumProp": "enumMemberV1" } + ``` + + """) +@post +@route("/v3") +op modelV3(@body body: ModelV3): ModelV3; diff --git a/packages/cadl-ranch-specs/http/versioning/removed/mockapi.ts b/packages/cadl-ranch-specs/http/versioning/removed/mockapi.ts index 0b1d1c46c..1b468af07 100644 --- a/packages/cadl-ranch-specs/http/versioning/removed/mockapi.ts +++ b/packages/cadl-ranch-specs/http/versioning/removed/mockapi.ts @@ -19,3 +19,50 @@ Scenarios.Versioning_Removed_v2 = passOnSuccess({ }, kind: "MockApiDefinition", }); + +Scenarios.Versioning_Removed_modelV3 = passOnSuccess({ + uri: `/versioning/removed/api-version[:]v1/v3`, + method: "post", + request: { + body: { + id: "123", + enumProp: "enumMemberV1", + }, + }, + response: { + status: 200, + body: json({ id: "123", enumProp: "enumMemberV1" }), + }, + kind: "MockApiDefinition", +}); + +Scenarios.Versioning_Removed_modelV3_V2 = passOnSuccess({ + uri: `/versioning/removed/api-version[:]v2/v3`, + method: "post", + request: { + body: { + id: "123", + enumProp: "enumMemberV1", + }, + }, + response: { + status: 200, + body: json({ id: "123", enumProp: "enumMemberV1" }), + }, + kind: "MockApiDefinition", +}); + +Scenarios.Versioning_Removed_modelV3_V2preview = passOnSuccess({ + uri: `/versioning/removed/api-version[:]v2preview/v3`, + method: "post", + request: { + body: { + id: "123", + }, + }, + response: { + status: 200, + body: json({ id: "123" }), + }, + kind: "MockApiDefinition", +});