-
Notifications
You must be signed in to change notification settings - Fork 537
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make Indicator Panel works with the global vars in the message path (#…
…320) **User-Facing Changes** <!-- will be used as a changelog entry --> Enables the user to use global variables in the Indicator panel when selecting the topic in the message path input. Indicator panel working with _$testVariable_: <img width="1500" alt="image" src="https://github.com/user-attachments/assets/66a7ee6d-afb4-4dfe-a03b-2c21fc1ddc91" /> Autocomplete with the list of global variables: <img width="489" alt="Screenshot 2025-01-07 at 20 39 15" src="https://github.com/user-attachments/assets/9f7b605e-7bdf-4a96-94e1-f1f76db2663b" /> **Description** - Reused existent logic to fill the paths when using global variables. - Improved performance of the component using the proper react state hooks. - Improved coding with good practices. <!-- link relevant GitHub issues --> <!-- add `docs` label if this PR requires documentation updates --> <!-- add relevant metric tracking for experimental / new features --> **Checklist** - [x] The web version was tested and it is running ok - [x] The desktop version was tested and it is running ok - [x] This change is covered by unit tests - [x] Files constants.ts, types.ts and *.style.ts have been checked and relevant code snippets have been relocated
- Loading branch information
Showing
15 changed files
with
360 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
packages/suite-base/src/panels/Indicator/Indicator.style.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// SPDX-FileCopyrightText: Copyright (C) 2023-2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)<[email protected]> | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
import { makeStyles } from "tss-react/mui"; | ||
|
||
export const useStyles = makeStyles()({ | ||
root: { | ||
width: 40, | ||
height: 40, | ||
borderRadius: "50%", | ||
position: "relative", | ||
backgroundImage: [ | ||
`radial-gradient(transparent, transparent 55%, rgba(255,255,255,0.4) 80%, rgba(255,255,255,0.4))`, | ||
`radial-gradient(circle at 38% 35%, rgba(255,255,255,0.8), transparent 30%, transparent)`, | ||
`radial-gradient(circle at 46% 44%, transparent, transparent 61%, rgba(0,0,0,0.7) 74%, rgba(0,0,0,0.7))`, | ||
].join(","), | ||
}, | ||
}); |
106 changes: 106 additions & 0 deletions
106
packages/suite-base/src/panels/Indicator/Indicator.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/** @jest-environment jsdom */ | ||
// SPDX-FileCopyrightText: Copyright (C) 2023-2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)<[email protected]> | ||
// SPDX-License-Identifier: MPL-2.0 | ||
import { userEvent } from "@storybook/testing-library"; | ||
import { render, screen } from "@testing-library/react"; | ||
import React from "react"; | ||
|
||
import { PanelExtensionContext } from "@lichtblick/suite"; | ||
import MockPanelContextProvider from "@lichtblick/suite-base/components/MockPanelContextProvider"; | ||
import { PanelExtensionAdapter } from "@lichtblick/suite-base/components/PanelExtensionAdapter"; | ||
import Indicator from "@lichtblick/suite-base/panels/Indicator"; | ||
import { getMatchingRule } from "@lichtblick/suite-base/panels/Indicator/getMatchingRule"; | ||
import { IndicatorConfig, IndicatorProps } from "@lichtblick/suite-base/panels/Indicator/types"; | ||
import PanelSetup from "@lichtblick/suite-base/stories/PanelSetup"; | ||
import BasicBuilder from "@lichtblick/suite-base/testing/builders/BasicBuilder"; | ||
import IndicatorBuilder from "@lichtblick/suite-base/testing/builders/IndicatorBuilder"; | ||
import ThemeProvider from "@lichtblick/suite-base/theme/ThemeProvider"; | ||
|
||
jest.mock("./getMatchingRule", () => ({ | ||
getMatchingRule: jest.fn(), | ||
})); | ||
|
||
type Setup = { | ||
configOverride?: Partial<IndicatorConfig>; | ||
contextOverride?: Partial<PanelExtensionContext>; | ||
}; | ||
|
||
describe("Indicator Component", () => { | ||
beforeEach(() => { | ||
jest.spyOn(console, "error").mockImplementation(() => {}); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
function setup({ contextOverride, configOverride }: Setup = {}) { | ||
const props: IndicatorProps = { | ||
context: { | ||
initialState: {}, | ||
layout: { | ||
addPanel: jest.fn(), | ||
}, | ||
onRender: undefined, | ||
panelElement: document.createElement("div"), | ||
saveState: jest.fn(), | ||
setDefaultPanelTitle: jest.fn(), | ||
setParameter: jest.fn(), | ||
setPreviewTime: jest.fn(), | ||
setSharedPanelState: jest.fn(), | ||
setVariable: jest.fn(), | ||
subscribe: jest.fn(), | ||
subscribeAppSettings: jest.fn(), | ||
unsubscribeAll: jest.fn(), | ||
updatePanelSettingsEditor: jest.fn(), | ||
watch: jest.fn(), | ||
...contextOverride, | ||
}, | ||
}; | ||
|
||
const config: IndicatorConfig = { | ||
...IndicatorBuilder.config(), | ||
...configOverride, | ||
}; | ||
const saveConfig = () => {}; | ||
const initPanel = jest.fn(); | ||
|
||
const ui: React.ReactElement = ( | ||
<ThemeProvider isDark> | ||
<MockPanelContextProvider> | ||
<PanelSetup> | ||
<PanelExtensionAdapter config={config} saveConfig={saveConfig} initPanel={initPanel}> | ||
<Indicator {...props} /> | ||
</PanelExtensionAdapter> | ||
</PanelSetup> | ||
</MockPanelContextProvider> | ||
</ThemeProvider> | ||
); | ||
|
||
const matchingRule = { | ||
color: "#68e24a", | ||
label: BasicBuilder.string(), | ||
}; | ||
(getMatchingRule as jest.Mock).mockReturnValue(matchingRule); | ||
|
||
const augmentColor = jest.fn(({ color: { main } }) => ({ | ||
contrastText: `${main}-contrast`, | ||
})); | ||
|
||
return { | ||
...render(ui), | ||
config, | ||
matchingRule, | ||
props, | ||
user: userEvent.setup(), | ||
augmentColor, | ||
}; | ||
} | ||
|
||
it("renders Indicator component", () => { | ||
const { matchingRule } = setup(); | ||
|
||
const element = screen.getByText(matchingRule.label); | ||
expect(element).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// SPDX-FileCopyrightText: Copyright (C) 2023-2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)<[email protected]> | ||
// SPDX-License-Identifier: MPL-2.0 | ||
import { IndicatorConfig } from "./types"; | ||
|
||
export const DEFAULT_CONFIG: IndicatorConfig = { | ||
path: "", | ||
style: "bulb", | ||
fallbackColor: "#a0a0a0", | ||
fallbackLabel: "False", | ||
rules: [{ operator: "=", rawValue: "true", color: "#68e24a", label: "True" }], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.