-
-
Notifications
You must be signed in to change notification settings - Fork 569
fix: add background color to TLP badges and include TLP in job API. C… #3284
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
base: develop
Are you sure you want to change the base?
fix: add background color to TLP badges and include TLP in job API. C… #3284
Conversation
…loses intelowlproject#3150 - Added backgroundColor property to TLP badge component styling - Implemented accessible text color logic (black for CLEAR/GREEN/AMBER, white for RED) - Added tlp field to JobSerializer to return TLP value in job details API response - Fixed issue where TLP badges showed only borders without background colors on job report page
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Fixes incorrect TLP badge rendering in the job report UI and ensures the job retrieve API returns the tlp field so the frontend can display it consistently (closes #3150).
Changes:
- Add
backgroundColorand explicit text color selection forTLPTagbadges. - Include
tlpinJobSerializerfields so/api/jobs/{id}returns the value.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| frontend/src/components/common/TLPTag.jsx | Updates TLP badge styling (background + text color) used across job/investigation/plugin UIs. |
| api_app/serializers/job.py | Adds tlp to the job retrieve serializer output. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const badgeId = `tlptag-badge__${value}`; | ||
| const color = TLPColors?.[value] || "#dfe1e2"; | ||
| const tooltipText = TLPDescriptions?.[value] || "invalid"; | ||
| const textColorMap = { | ||
| CLEAR: "#000000", |
Copilot
AI
Feb 7, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
badgeId is derived only from the TLP value, which will produce duplicate DOM ids whenever multiple rows/cards render the same TLP (common in job/investigation tables). Duplicate ids break HTML validity and can cause UncontrolledTooltip to attach to the wrong element. Consider generating a unique id per component instance (e.g., React useId()), or accept an explicit id prop and fall back to a unique default.
| @@ -18,7 +24,9 @@ export function TLPTag(props) { | |||
| style={{ | |||
| borderRadius: 5, | |||
| userSelect: "none", | |||
| backgroundColor: color, | |||
| border: `1px solid ${color}`, | |||
| color: textColor, | |||
Copilot
AI
Feb 7, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new background/text color styling logic isn’t covered by any frontend unit test (there are no existing tests exercising TLPTag). Since this component is reused across multiple pages, add a small Jest test to assert the rendered badge has the expected backgroundColor and text color for at least one light TLP (e.g. CLEAR) and RED.
- Replace simple value-based IDs with counter-based unique IDs to prevent duplicate DOM IDs when multiple badges with same TLP value are rendered - Add comprehensive Jest tests for TLPTag component covering: * Background and text color rendering for all TLP levels (CLEAR, RED, GREEN, AMBER) * Unique ID generation for multiple instances - Addresses Copilot review feedback for duplicate ID issue and missing test coverage
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // CLEAR should have white background (#ffffff) and black text | ||
| expect(badge).toHaveStyle({ | ||
| backgroundColor: "#ffffff", | ||
| color: "#000000", | ||
| }); | ||
| }); | ||
|
|
||
| test("RED TLP renders with correct background and text color", () => { | ||
| const { container } = render(<TLPTag value="RED" />); | ||
|
|
||
| const badge = container.querySelector('[id^="tlptag-badge__RED"]'); | ||
| expect(badge).toBeInTheDocument(); | ||
| expect(badge).toHaveTextContent("RED"); | ||
|
|
||
| // RED should have red background (#ff0033) and white text | ||
| expect(badge).toHaveStyle({ | ||
| backgroundColor: "#ff0033", | ||
| color: "#FFFFFF", | ||
| }); | ||
| }); | ||
|
|
||
| test("GREEN TLP renders with correct background and text color", () => { | ||
| const { container } = render(<TLPTag value="GREEN" />); | ||
|
|
||
| const badge = container.querySelector('[id^="tlptag-badge__GREEN"]'); | ||
| expect(badge).toBeInTheDocument(); | ||
| expect(badge).toHaveTextContent("GREEN"); | ||
|
|
||
| // GREEN should have green background (#33ff00) and black text | ||
| expect(badge).toHaveStyle({ | ||
| backgroundColor: "#33ff00", | ||
| color: "#000000", | ||
| }); | ||
| }); | ||
|
|
||
| test("AMBER TLP renders with correct background and text color", () => { | ||
| const { container } = render(<TLPTag value="AMBER" />); | ||
|
|
||
| const badge = container.querySelector('[id^="tlptag-badge__AMBER"]'); | ||
| expect(badge).toBeInTheDocument(); | ||
| expect(badge).toHaveTextContent("AMBER"); | ||
|
|
||
| // AMBER should have amber background (#ffc000) and black text | ||
| expect(badge).toHaveStyle({ | ||
| backgroundColor: "#ffc000", | ||
| color: "#000000", | ||
| }); |
Copilot
AI
Feb 7, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tests hardcode TLP hex colors instead of asserting against the shared TLPColors constant. Using the constant (or another shared source of truth) would reduce duplication and keep the test aligned if the palette ever changes.
| @@ -0,0 +1,81 @@ | |||
| import React from "react"; | |||
| import "@testing-library/jest-dom"; | |||
| import { render, screen } from "@testing-library/react"; | |||
Copilot
AI
Feb 7, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
screen is imported from @testing-library/react but never used in this test file. Please remove the unused import to keep the test clean and avoid future lint noise if test files are ever added to the lint target.
| import { render, screen } from "@testing-library/react"; | |
| import { render } from "@testing-library/react"; |
mlodic
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please address CI failures.
Also pull the most recent changes from develop and test it again because there were some GUI changes
- Import TLPColors constant to avoid hardcoding hex values in tests - Remove unused screen import from @testing-library/react - Addresses Copilot review feedback
- Replace postfix increment (idCounter++) with prefix increment (idCounter += 1) - Maintains unique ID generation for TLP badges without ESLint violations
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
frontend/src/components/common/TLPTag.jsx:40
{...rest}is spread afterid={badgeId}, so a caller-providedidwill override the badge's DOM id while the tooltip still targetsbadgeId, breaking the tooltip (and potentially reintroducing the original issue). Consider explicitly handling anidprop (use it for both the<Badge>and tooltiptarget) or ensureidcannot be overridden by moving{...rest}beforeid={badgeId}/ omittingidfromrest.
<Badge
id={badgeId}
color={null}
style={{
borderRadius: 5,
userSelect: "none",
backgroundColor: color,
border: `1px solid ${color}`,
color: textColor,
}}
{...rest}
>
{value}
<UncontrolledTooltip target={badgeId} placement="top" fade={false}>
{tooltipText}
</UncontrolledTooltip>
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Description
Fixed TLP badge display issue where badges were showing only borders without background colors on the job report page.
This PR includes:
Changes made:
Closes #3150
Type of change
ScreenShot
Checklist
developdumpplugincommand and added it in the project as a data migration. ("How to share a plugin with the community")test_files.zipand you added the default tests for that mimetype in test_classes.py.FREE_TO_USE_ANALYZERSplaybook by following this guide.urlthat contains this information. This is required for Health Checks (HEAD HTTP requests).get_mocker_response()method of the unittest class. This serves us to provide a valid sample for testing.DataModelfor the new analyzer following the documentation# This file is a part of IntelOwl https://github.com/intelowlproject/IntelOwl # See the file 'LICENSE' for copying permission.Black,Flake,Isort) gave 0 errors. If you have correctly installed pre-commit, it does these checks and adjustments on your behalf.testsfolder). All the tests (new and old ones) gave 0 errors.DeepSource,Django Doctorsor other third-party linters have triggered any alerts during the CI checks, I have solved those alerts.Important Rules