Skip to content
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

Fix object null in deeply nested obejcts - devtools #158

Merged
merged 5 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion devtools/client/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ js_pipeline(
"//:node_modules/@player-ui/react",
"//:node_modules/@devtools-ui/plugin",
"//:node_modules/@types/react",
"//:node_modules/dset",
"//:node_modules/immer",
"//:node_modules/lodash.set",
"//:node_modules/@types/lodash.set",
"//:node_modules/react",
"//:node_modules/react-error-boundary",
"//:node_modules/dequal",
Expand Down
20 changes: 10 additions & 10 deletions devtools/client/src/state/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type {
ExtensionSupportedEvents,
Transaction,
} from "@player-tools/devtools-types";
import { dset } from "dset/merge";
import set from "lodash.set";
import { produce } from "immer";

/** Extension state reducer */
Expand All @@ -18,15 +18,15 @@ export const reducer = (
sender,
payload: { plugins },
} = transaction;
dset(draft, ["current", "player"], sender);
dset(
set(draft, ["current", "player"], sender);
set(
draft,
["current", "plugin"],
draft.current.plugin || plugins[Object.keys(plugins)[0]].id
);

dset(draft, ["players", sender, "plugins"], plugins);
dset(draft, ["players", sender, "active"], true);
set(draft, ["players", sender, "plugins"], plugins);
set(draft, ["players", sender, "active"], true);
});
case "PLAYER_DEVTOOLS_PLUGIN_FLOW_CHANGE":
return produce(state, (draft) => {
Expand All @@ -35,15 +35,15 @@ export const reducer = (
payload: { flow, pluginID },
} = transaction;

dset(draft, ["players", sender, "plugins", pluginID, "flow"], flow);
set(draft, ["players", sender, "plugins", pluginID, "flow"], flow);
});
case "PLAYER_DEVTOOLS_PLUGIN_DATA_CHANGE":
return produce(state, (draft) => {
const {
sender,
payload: { data, pluginID },
} = transaction;
dset(
set(
draft,
["players", sender, "plugins", pluginID, "flow", "data"],
data
Expand All @@ -57,17 +57,17 @@ export const reducer = (
return produce(state, (draft) => {
const { sender } = transaction;

dset(draft, ["players", sender, "active"], false);
set(draft, ["players", sender, "active"], false);
});
case "PLAYER_DEVTOOLS_PLAYER_SELECTED":
return produce(state, (draft) => {
const { playerID } = transaction.payload;
dset(draft, ["current", "player"], playerID);
set(draft, ["current", "player"], playerID);
});
case "PLAYER_DEVTOOLS_PLUGIN_SELECTED":
return produce(state, (draft) => {
const { pluginID } = transaction.payload;
dset(draft, ["current", "plugin"], pluginID);
set(draft, ["current", "plugin"], pluginID);
});
default:
return state;
Expand Down
3 changes: 2 additions & 1 deletion devtools/plugins/desktop/basic/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ dependencies = [
"//:node_modules/react",
"//:node_modules/immer",
"//:node_modules/uuid",
"//:node_modules/lodash.set",
"//:node_modules/@types/lodash.set",
"//:node_modules/@types/uuid",
"//:node_modules/dset",
"//:node_modules/dequal",
]

Expand Down
6 changes: 3 additions & 3 deletions devtools/plugins/desktop/basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"version": "0.0.0-PLACEHOLDER",
"main": "src/index.tsx",
"dependencies": {
"@player-tools/devtools-types": "workspace:*",
"@player-tools/cli": "workspace:*",
"@player-tools/devtools-desktop-plugins-common": "workspace:*",
"@player-tools/dsl": "workspace:*",
"@player-tools/cli": "workspace:*"
"@player-tools/devtools-types": "workspace:*",
"@player-tools/dsl": "workspace:*"
}
}
13 changes: 6 additions & 7 deletions devtools/plugins/desktop/basic/src/WrapperComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
} from "@player-tools/devtools-types";
import type { Flow } from "@player-ui/react";
import { dequal } from "dequal";
import { dset } from "dset/merge";
import { produce } from "immer";
import set from "lodash.set";

Check warning on line 11 in devtools/plugins/desktop/basic/src/WrapperComponent.tsx

View check run for this annotation

Codecov / codecov/patch

devtools/plugins/desktop/basic/src/WrapperComponent.tsx#L11

Added line #L11 was not covered by tests
import React, { useCallback, useEffect } from "react";
import { BASE_PLUGIN_DATA, INTERACTIONS } from "./constants";
import type { Evaluation, WrapperComponentProps } from "./types";
Expand Down Expand Up @@ -49,12 +49,11 @@
payload
) {
const result = expEvaluator(payload);

const newState = produce(state, (draft) => {
const current: Array<Evaluation> =
(state?.plugins?.[id]?.flow?.data?.history as Array<Evaluation>) ||
[];
dset(
set(

Check warning on line 56 in devtools/plugins/desktop/basic/src/WrapperComponent.tsx

View check run for this annotation

Codecov / codecov/patch

devtools/plugins/desktop/basic/src/WrapperComponent.tsx#L56

Added line #L56 was not covered by tests
draft,
["plugins", id, "flow", "data", "history"],
[...current, result]
Expand Down Expand Up @@ -95,7 +94,7 @@

// inject playerConfig into the plugin data
const pluginDataWithPlayerConfig = produce(pluginData, (draft) => {
dset(draft, ["flow", "data", "playerConfig"], playerConfig);
set(draft, ["flow", "data", "playerConfig"], playerConfig);

Check warning on line 97 in devtools/plugins/desktop/basic/src/WrapperComponent.tsx

View check run for this annotation

Codecov / codecov/patch

devtools/plugins/desktop/basic/src/WrapperComponent.tsx#L97

Added line #L97 was not covered by tests
});

// Initial plugin content
Expand Down Expand Up @@ -132,7 +131,7 @@
if (dequal(state.plugins[id]?.flow?.data?.data, data)) return;

const newState = produce(state, (draft) => {
dset(draft, ["plugins", id, "flow", "data", "data"], data);
set(draft, ["plugins", id, "flow", "data", "data"], data);

Check warning on line 134 in devtools/plugins/desktop/basic/src/WrapperComponent.tsx

View check run for this annotation

Codecov / codecov/patch

devtools/plugins/desktop/basic/src/WrapperComponent.tsx#L134

Added line #L134 was not covered by tests
});

const transaction = genDataChangeTransaction({
Expand All @@ -149,7 +148,7 @@
if (dequal(state.plugins[id]?.flow?.data?.logs, logs)) return;

const newState = produce(state, (draft) => {
dset(draft, ["plugins", id, "flow", "data", "logs"], logs);
set(draft, ["plugins", id, "flow", "data", "logs"], logs);

Check warning on line 151 in devtools/plugins/desktop/basic/src/WrapperComponent.tsx

View check run for this annotation

Codecov / codecov/patch

devtools/plugins/desktop/basic/src/WrapperComponent.tsx#L151

Added line #L151 was not covered by tests
});

const transaction = genDataChangeTransaction({
Expand All @@ -166,7 +165,7 @@
if (dequal(state.plugins[id]?.flow?.data?.flow, flow)) return;

const newState = produce(state, (draft) => {
dset(draft, ["plugins", id, "flow", "data", "flow"], flow);
set(draft, ["plugins", id, "flow", "data", "flow"], flow);

Check warning on line 168 in devtools/plugins/desktop/basic/src/WrapperComponent.tsx

View check run for this annotation

Codecov / codecov/patch

devtools/plugins/desktop/basic/src/WrapperComponent.tsx#L168

Added line #L168 was not covered by tests
});

const transaction = genDataChangeTransaction({
Expand Down
4 changes: 2 additions & 2 deletions devtools/plugins/desktop/basic/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
ReactPlayerPlugin,
ViewInstance,
} from "@player-ui/react";
import { dset } from "dset/merge";
import set from "lodash.set";

Check warning on line 10 in devtools/plugins/desktop/basic/src/index.tsx

View check run for this annotation

Codecov / codecov/patch

devtools/plugins/desktop/basic/src/index.tsx#L10

Added line #L10 was not covered by tests
import { produce } from "immer";
import React from "react";
import { WrapperComponent } from "./WrapperComponent";
Expand Down Expand Up @@ -58,7 +58,7 @@
dataController.hooks.onUpdate.tap(this.name, (updates) => {
const newPlayerState = produce(this.data, (draft) => {
updates.forEach(({ binding, newValue }) => {
dset(draft, ["data", ...binding.asArray()], newValue);
set(draft, ["data", ...binding.asArray()], newValue);

Check warning on line 61 in devtools/plugins/desktop/basic/src/index.tsx

View check run for this annotation

Codecov / codecov/patch

devtools/plugins/desktop/basic/src/index.tsx#L61

Added line #L61 was not covered by tests
});
});
this.data = newPlayerState;
Expand Down
3 changes: 2 additions & 1 deletion devtools/plugins/desktop/common/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ js_pipeline(
deps = [
":node_modules/@player-tools/devtools-messenger",
":node_modules/@player-tools/devtools-types",
"//:node_modules/dset",
"//:node_modules/dequal",
"//:node_modules/immer",
"//:node_modules/lodash.set",
"//:node_modules/@types/lodash.set",
"//:node_modules/js-flipper",
"//:node_modules/tiny-uid",
],
Expand Down
8 changes: 4 additions & 4 deletions devtools/plugins/desktop/common/src/state/reducer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { produce } from "immer";
import { dset } from "dset/merge";
import { dequal } from "dequal";
import type {
DevtoolsDataChangeEvent,
Expand All @@ -8,6 +7,7 @@ import type {
PlayerInitEvent,
Transaction,
} from "@player-tools/devtools-types";
import set from "lodash.set";

const containsInteraction = (
interactions: DevtoolsPluginsStore["interactions"],
Expand All @@ -25,7 +25,7 @@ export const reducer = (
case "PLAYER_DEVTOOLS_PLAYER_INIT":
return produce(state, (draft) => {
const { payload } = transaction;
dset(draft, "plugins", payload.plugins);
set(draft, "plugins", payload.plugins);

const message: PlayerInitEvent = {
type: "PLAYER_DEVTOOLS_PLAYER_INIT",
Expand All @@ -40,7 +40,7 @@ export const reducer = (

if (!payload.data) return state;

dset(
set(
draft.plugins,
[transaction.payload.pluginID, "flow", "data"],
transaction.payload.data
Expand All @@ -57,7 +57,7 @@ export const reducer = (
return produce(state, (draft) => {
if (containsInteraction(draft.interactions, transaction)) return state;

dset(draft, ["interactions"], [...draft.interactions, transaction]);
set(draft, ["interactions"], [...draft.interactions, transaction]);
});
default:
return state;
Expand Down
3 changes: 2 additions & 1 deletion devtools/plugins/desktop/profiler/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ dependencies = [
"//:node_modules/immer",
"//:node_modules/uuid",
"//:node_modules/@types/uuid",
"//:node_modules/dset",
"//:node_modules/dequal",
"//:node_modules/lodash.set",
"//:node_modules/@types/lodash.set",
]

dsl_input = "src/content/index.ts"
Expand Down
18 changes: 9 additions & 9 deletions devtools/plugins/desktop/profiler/src/WrapperComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
Transaction,
} from "@player-tools/devtools-types";
import type { Flow } from "@player-ui/react";
import { dset } from "dset/merge";
import { produce } from "immer";
import set from "lodash.set";

Check warning on line 10 in devtools/plugins/desktop/profiler/src/WrapperComponent.tsx

View check run for this annotation

Codecov / codecov/patch

devtools/plugins/desktop/profiler/src/WrapperComponent.tsx#L10

Added line #L10 was not covered by tests
import React, { useCallback, useEffect } from "react";
import { BASE_PLUGIN_DATA, INTERACTIONS } from "./constants";
import type { WrapperComponentProps } from "./types";
Expand Down Expand Up @@ -59,13 +59,13 @@
lastProcessedInteraction.current += 1;

const newState = produce(state, (draft) => {
dset(draft, ["plugins", id, "flow", "data", "rootNode"], {
set(draft, ["plugins", id, "flow", "data", "rootNode"], {

Check warning on line 62 in devtools/plugins/desktop/profiler/src/WrapperComponent.tsx

View check run for this annotation

Codecov / codecov/patch

devtools/plugins/desktop/profiler/src/WrapperComponent.tsx#L62

Added line #L62 was not covered by tests
name: "root",
children: [],
});
dset(draft, ["plugins", id, "flow", "data", "durations"], []);
dset(draft, ["plugins", id, "flow", "data", "profiling"], true);
dset(
set(draft, ["plugins", id, "flow", "data", "durations"], []);
set(draft, ["plugins", id, "flow", "data", "profiling"], true);
set(

Check warning on line 68 in devtools/plugins/desktop/profiler/src/WrapperComponent.tsx

View check run for this annotation

Codecov / codecov/patch

devtools/plugins/desktop/profiler/src/WrapperComponent.tsx#L66-L68

Added lines #L66 - L68 were not covered by tests
draft,
["plugins", id, "flow", "data", "displayFlameGraph"],
false
Expand All @@ -86,10 +86,10 @@
lastProcessedInteraction.current += 1;

const newState = produce(state, (draft) => {
dset(draft, ["plugins", id, "flow", "data", "rootNode"], rootNode);
dset(draft, ["plugins", id, "flow", "data", "durations"], durations);
dset(draft, ["plugins", id, "flow", "data", "profiling"], false);
dset(
set(draft, ["plugins", id, "flow", "data", "rootNode"], rootNode);
set(draft, ["plugins", id, "flow", "data", "durations"], durations);
set(draft, ["plugins", id, "flow", "data", "profiling"], false);
set(

Check warning on line 92 in devtools/plugins/desktop/profiler/src/WrapperComponent.tsx

View check run for this annotation

Codecov / codecov/patch

devtools/plugins/desktop/profiler/src/WrapperComponent.tsx#L89-L92

Added lines #L89 - L92 were not covered by tests
draft,
["plugins", id, "flow", "data", "displayFlameGraph"],
true
Expand Down
3 changes: 2 additions & 1 deletion devtools/plugins/desktop/template/BUILD.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ dependencies = [
"//:node_modules/immer",
"//:node_modules/uuid",
"//:node_modules/@types/uuid",
"//:node_modules/dset",
"//:node_modules/lodash.set",
"//:node_modules/@types/lodash.set",
"//:node_modules/dequal",
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {
} from "@player-tools/devtools-types";
import type { Flow } from "@player-ui/react";
import { dequal } from "dequal";
import { dset } from "dset/merge";
import set from "lodash.set";
import { produce } from "immer";
import React, { useCallback, useEffect } from "react";
import { BASE_PLUGIN_DATA, INTERACTIONS } from "./constants";
Expand Down Expand Up @@ -120,7 +120,7 @@ export const WrapperComponent = ({
if (dequal(state.plugins[id]?.flow?.data?.logs, logs)) return;

const newState = produce(state, (draft) => {
dset(draft, ["plugins", id, "flow", "data", "logs"], logs);
set(draft, ["plugins", id, "flow", "data", "logs"], logs);
});

const transaction = genDataChangeTransaction({
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"@testing-library/user-event": "^14.5.2",
"@types/babel__register": "^7.17.0",
"@types/fs-extra": "^9.0.13",
"@types/lodash.set": "^4.3.9",
"@types/micromatch": "^4.0.2",
"@types/mkdirp": "^1.0.2",
"@types/node": "^18.18.0",
Expand Down Expand Up @@ -92,7 +93,6 @@
"dequal": "^2.0.2",
"detect-indent": "^6.0.0",
"dlv": "^1.1.3",
"dset": "^3.1.3",
"duplicate-package-checker-webpack-plugin": "^3.0.0",
"easy-table": "1.2.0",
"elegant-spinner": "^2.0.0",
Expand All @@ -117,6 +117,7 @@
"jsonc-parser": "^2.3.1",
"lcov-result-merger": "^3.1.0",
"lint-staged": "^11.2.3",
"lodash.set": "^4.3.2",
"log-symbols": "^4.0.0",
"log-update": "^4.0.0",
"micromatch": "^4.0.2",
Expand Down
Loading