Skip to content

Commit a70f065

Browse files
fix(ui): hide line numbers in CLI command remediation block (#11061)
Co-authored-by: Hugo Pereira Brito <101209179+HugoPBrito@users.noreply.github.com>
1 parent fae4fbc commit a70f065

4 files changed

Lines changed: 46 additions & 11 deletions

File tree

ui/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
All notable changes to the **Prowler UI** are documented in this file.
44

5+
## [1.25.3] (Prowler UNRELEASED)
6+
7+
### 🐞 Fixed
8+
9+
- CLI command in the finding drawer no longer renders the line-number gutter, matching the original styled block while removing the leading `1` [(#11059)](https://github.com/prowler-cloud/prowler/pull/11059)
10+
11+
---
12+
513
## [1.25.2] (Prowler v5.25.2)
614

715
### 🔄 Changed

ui/components/findings/table/resource-detail-drawer/resource-detail-drawer-content.test.tsx

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -219,21 +219,25 @@ vi.mock("@/components/shared/query-code-editor", () => ({
219219
language,
220220
value,
221221
copyValue,
222+
showLineNumbers = true,
222223
}: {
223224
ariaLabel: string;
224225
language?: string;
225226
value: string;
226227
copyValue?: string;
228+
showLineNumbers?: boolean;
227229
}) => (
228230
<div
229231
data-testid="query-code-editor"
230232
data-aria-label={ariaLabel}
231233
data-language={language}
234+
data-show-line-numbers={String(showLineNumbers)}
232235
>
233236
<span>{ariaLabel}</span>
234237
<span>{value}</span>
235238
<button
236239
type="button"
240+
aria-label={`Copy ${ariaLabel}`}
237241
onClick={() => mockClipboardWriteText(copyValue ?? value)}
238242
>
239243
Copy editor code
@@ -255,7 +259,22 @@ vi.mock("@/components/icons/services/IconServices", () => ({
255259
}));
256260

257261
vi.mock("@/components/ui/code-snippet/code-snippet", () => ({
258-
CodeSnippet: ({ value }: { value: string }) => <span>{value}</span>,
262+
CodeSnippet: ({
263+
value,
264+
formatter,
265+
ariaLabel = "Copy to clipboard",
266+
}: {
267+
value: string;
268+
formatter?: (value: string) => string;
269+
ariaLabel?: string;
270+
}) => (
271+
<div data-testid="code-snippet">
272+
<span>{formatter ? formatter(value) : value}</span>
273+
<button type="button" onClick={() => mockClipboardWriteText(value)}>
274+
{ariaLabel}
275+
</button>
276+
</div>
277+
),
259278
}));
260279

261280
vi.mock("@/components/ui/custom/custom-link", () => ({
@@ -592,7 +611,7 @@ describe("ResourceDetailDrawerContent — Fix 2: Remediation heading labels", ()
592611
expect(allText).toContain("CLI Command");
593612
});
594613

595-
it("should render remediation snippets with the shared code editor and copy CLI without the visual prompt", async () => {
614+
it("should render CLI remediation in the code editor without line numbers and copy without the visual prompt", async () => {
596615
// Given
597616
const user = userEvent.setup();
598617
render(
@@ -612,17 +631,19 @@ describe("ResourceDetailDrawerContent — Fix 2: Remediation heading labels", ()
612631

613632
// When
614633
const editors = screen.getAllByTestId("query-code-editor");
615-
await user.click(
616-
within(editors[0]).getByRole("button", { name: "Copy editor code" }),
617-
);
634+
await user.click(screen.getByRole("button", { name: "Copy CLI Command" }));
618635

619636
// Then
620637
expect(editors).toHaveLength(3);
638+
expect(editors[0]).toHaveAttribute("data-aria-label", "CLI Command");
639+
expect(editors[0]).toHaveAttribute("data-show-line-numbers", "false");
640+
expect(editors[1]).toHaveAttribute("data-show-line-numbers", "true");
641+
expect(editors[2]).toHaveAttribute("data-show-line-numbers", "true");
621642
expect(mockClipboardWriteText).toHaveBeenCalledWith("aws s3 ...");
622643
expect(screen.getByText("$ aws s3 ...")).toBeInTheDocument();
623644
});
624645

625-
it("should pass syntax highlighting languages to each remediation editor", () => {
646+
it("should pass syntax highlighting languages to all remediation editors", () => {
626647
// Given
627648
render(
628649
<ResourceDetailDrawerContent
@@ -643,10 +664,12 @@ describe("ResourceDetailDrawerContent — Fix 2: Remediation heading labels", ()
643664
const editors = screen.getAllByTestId("query-code-editor");
644665

645666
// Then
667+
expect(editors).toHaveLength(3);
646668
expect(editors[0]).toHaveAttribute("data-language", "shell");
647669
expect(editors[1]).toHaveAttribute("data-language", "hcl");
648670
expect(editors[2]).toHaveAttribute("data-language", "yaml");
649671
expect(editors[0]).toHaveAttribute("data-aria-label", "CLI Command");
672+
expect(editors[1]).toHaveAttribute("data-aria-label", "Terraform");
650673
expect(editors[2]).toHaveAttribute("data-aria-label", "CloudFormation");
651674
});
652675
});

ui/components/findings/table/resource-detail-drawer/resource-detail-drawer-content.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,13 @@ function renderRemediationCodeBlock({
120120
value,
121121
copyValue,
122122
language = QUERY_EDITOR_LANGUAGE.PLAIN_TEXT,
123+
showLineNumbers = true,
123124
}: {
124125
label: string;
125126
value: string;
126127
copyValue?: string;
127128
language?: QueryEditorLanguage;
129+
showLineNumbers?: boolean;
128130
}) {
129131
return (
130132
<QueryCodeEditor
@@ -135,6 +137,7 @@ function renderRemediationCodeBlock({
135137
editable={false}
136138
minHeight={96}
137139
showCopyButton
140+
showLineNumbers={showLineNumbers}
138141
onChange={() => {}}
139142
/>
140143
);
@@ -889,6 +892,7 @@ export function ResourceDetailDrawerContent({
889892
copyValue: stripCodeFences(
890893
checkMeta.remediation.code.cli,
891894
),
895+
showLineNumbers: false,
892896
})}
893897
</div>
894898
)}

ui/components/shared/query-code-editor.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import { EditorState } from "@codemirror/state";
1010
import { tags } from "@lezer/highlight";
1111
import CodeMirror, {
1212
EditorView,
13-
highlightActiveLineGutter,
14-
lineNumbers,
1513
placeholder as codeEditorPlaceholder,
1614
} from "@uiw/react-codemirror";
1715
import { Check, Copy } from "lucide-react";
@@ -1177,6 +1175,7 @@ interface QueryCodeEditorProps
11771175
editable?: boolean;
11781176
minHeight?: number;
11791177
showCopyButton?: boolean;
1178+
showLineNumbers?: boolean;
11801179
onChange: (value: string) => void;
11811180
onBlur?: () => void;
11821181
}
@@ -1195,6 +1194,7 @@ export const QueryCodeEditor = ({
11951194
editable = true,
11961195
minHeight = 320,
11971196
showCopyButton = false,
1197+
showLineNumbers = true,
11981198
onChange,
11991199
onBlur,
12001200
...props
@@ -1208,8 +1208,6 @@ export const QueryCodeEditor = ({
12081208
: lightHighlightStyle;
12091209

12101210
const extensions = [
1211-
lineNumbers(),
1212-
highlightActiveLineGutter(),
12131211
EditorView.lineWrapping,
12141212
codeEditorPlaceholder(placeholder ?? ""),
12151213
EditorView.contentAttributes.of({
@@ -1260,6 +1258,7 @@ export const QueryCodeEditor = ({
12601258
<div
12611259
data-testid="query-code-editor"
12621260
data-language={language}
1261+
data-show-line-numbers={String(showLineNumbers)}
12631262
className={cn(
12641263
"border-border-neutral-secondary bg-bg-neutral-primary overflow-hidden rounded-xl border",
12651264
invalid && "border-border-error-primary",
@@ -1307,8 +1306,9 @@ export const QueryCodeEditor = ({
13071306
basicSetup={{
13081307
foldGutter: false,
13091308
highlightActiveLine: false,
1310-
highlightActiveLineGutter: false,
1309+
highlightActiveLineGutter: showLineNumbers,
13111310
searchKeymap: false,
1311+
lineNumbers: showLineNumbers,
13121312
}}
13131313
editable={editable}
13141314
onChange={onChange}

0 commit comments

Comments
 (0)