Skip to content

Commit

Permalink
Move and change messagePipeline selector that maps schemas by topic name
Browse files Browse the repository at this point in the history
  • Loading branch information
FraLab09 committed Aug 20, 2024
1 parent 08b42f0 commit 0368e6d
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 12 deletions.
2 changes: 1 addition & 1 deletion packages/hooks/src/selectWithUnstableIdentityWarning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function selectWithUnstableIdentityWarning<T, U>(value: T, selector: (val
const secondResult = selector(value);
if (result !== secondResult) {
log.warn(`Selector ${selector.toString()} produced different values for the same input.
This will cause unecesessery re-renders of your component.`);
This will cause unecesessery re-renders of your component.`);
}
return secondResult;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/suite-base/src/PanelAPI/useConfigById.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as _ from "lodash-es";
import { useCallback } from "react";
import { DeepPartial } from "ts-essentials";

import { useMessagePipeline } from "@foxglove/studio-base/components/MessagePipeline";
import { useMessagePipeline } from "@lichtblick/suite-base/components/MessagePipeline";
import {
LayoutState,
useCurrentLayoutActions,
Expand Down
5 changes: 0 additions & 5 deletions packages/suite-base/src/components/MessagePipeline/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,3 @@ function createPlayerListener(args: {
},
};
}

export const getTopicToSchemaNameMap = (
state: MessagePipelineContext,
): Record<string, string | undefined> =>
_.mapValues(_.keyBy(state.sortedTopics, "name"), ({ schemaName }) => schemaName);
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// SPDX-FileCopyrightText: Copyright (C) 2023-2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)<[email protected]>
// SPDX-License-Identifier: MPL-2.0

// This Source Code Form is subject to the terms of the Mozilla Public
// License, v2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/

import { getTopicToSchemaNameMap } from "@lichtblick/suite-base/components/MessagePipeline/selectors";
import { MessagePipelineContext } from "@lichtblick/suite-base/components/MessagePipeline/types";
import { PlayerPresence } from "@lichtblick/suite-base/players/types";

it("map schema names by topic name", () => {
const state: MessagePipelineContext = {
sortedTopics: [
{ name: "topic1", schemaName: "schema1" },
{ name: "topic2", schemaName: "schema2" },
],
playerState: {
presence: PlayerPresence.PRESENT,
progress: {},
capabilities: [],
profile: undefined,
playerId: "",
},
callService: jest.fn(),
datatypes: new Map(),
fetchAsset: jest.fn(),
messageEventsBySubscriberId: new Map(),
pauseFrame: jest.fn(),
publish: jest.fn(),
seekPlayback: jest.fn(),
setParameter: jest.fn(),
setPublishers: jest.fn(),
setSubscriptions: jest.fn(),
subscriptions: [],
getMetadata: jest.fn(),
};
const result = getTopicToSchemaNameMap(state);
expect(result).toEqual({
topic1: "schema1",
topic2: "schema2",
});
});
15 changes: 15 additions & 0 deletions packages/suite-base/src/components/MessagePipeline/selectors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// SPDX-FileCopyrightText: Copyright (C) 2023-2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)<[email protected]>
// SPDX-License-Identifier: MPL-2.0

// This Source Code Form is subject to the terms of the Mozilla Public
// License, v2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/

import * as _ from "lodash-es";

import { MessagePipelineContext } from "@lichtblick/suite-base/components/MessagePipeline/types";

export const getTopicToSchemaNameMap = (
state: MessagePipelineContext,
): Record<string, string | undefined> =>
_.mapValues(_.keyBy(state.sortedTopics, "name"), ({ schemaName }) => schemaName);
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import { produce } from "immer";

import { PanelSettings } from "@lichtblick/suite";
import { PlayerPresence } from "@lichtblick/suite-base/players/types";

import { BuilderRenderStateInput, initRenderStateBuilder } from "./renderState";
Expand Down Expand Up @@ -957,7 +958,7 @@ describe("renderState", () => {
const state2 = buildRenderState(
produce(initialState, (draft) => {
draft.currentFrame = undefined;
draft.playerState.progress.messageCache = undefined;
draft.playerState!.progress.messageCache = undefined;
draft.subscriptions.push({ topic: "test", convertTo: "anotherSchema", preload: true });
}),
);
Expand Down
6 changes: 2 additions & 4 deletions packages/suite-base/src/components/PanelSettings/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ import { SettingsTree } from "@lichtblick/suite";
import { AppSetting } from "@lichtblick/suite-base/AppSetting";
import { useConfigById } from "@lichtblick/suite-base/PanelAPI";
import EmptyState from "@lichtblick/suite-base/components/EmptyState";
import {
getTopicToSchemaNameMap,
useMessagePipeline,
} from "@lichtblick/suite-base/components/MessagePipeline";
import { useMessagePipeline } from "@lichtblick/suite-base/components/MessagePipeline";
import { getTopicToSchemaNameMap } from "@lichtblick/suite-base/components/MessagePipeline/selectors";
import { ActionMenu } from "@lichtblick/suite-base/components/PanelSettings/ActionMenu";
import SettingsTreeEditor from "@lichtblick/suite-base/components/SettingsTreeEditor";
import { ShareJsonModal } from "@lichtblick/suite-base/components/ShareJsonModal";
Expand Down

0 comments on commit 0368e6d

Please sign in to comment.