Skip to content

Commit

Permalink
fix: deselect item on delete
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisvxd committed Jan 13, 2025
1 parent 88e0f0e commit f27871b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
32 changes: 31 additions & 1 deletion packages/core/reducer/__tests__/state.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { defaultAppState } from "../../components/Puck/context";
import { rootDroppableId } from "../../lib/root-droppable-id";
import { DuplicateAction, SetUiAction, createReducer } from "../../reducer";
import {
DuplicateAction,
RemoveAction,
SetUiAction,
createReducer,
} from "../../reducer";
import { AppState, Config, Data, UiState } from "../../types";

type Props = {
Expand Down Expand Up @@ -65,4 +70,29 @@ describe("State reducer", () => {
expect(newState.ui.itemSelector?.zone).toBe(rootDroppableId);
});
});

describe("remove action", () => {
it("should deselect the item", () => {
const state: AppState = {
ui: defaultUi,
data: {
...defaultData,
content: [
{
type: "Comp",
props: { id: "sampleId", prop: "Some example data" },
},
],
},
};
const action: RemoveAction = {
type: "remove",
index: 0,
zone: rootDroppableId,
};

const newState = reducer(state, action);
expect(newState.ui.itemSelector).toBeNull();
});
});
});
7 changes: 7 additions & 0 deletions packages/core/reducer/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,12 @@ export const reduceUi = (ui: UiState, action: PuckAction): UiState => {
};
}

if (action.type === "remove") {
return {
...ui,
itemSelector: null,
};
}

return ui;
};

0 comments on commit f27871b

Please sign in to comment.