Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Rename TreePermutation to TreeOperation

dominik-zeglen6ac1d69a7aa1
diff --git a/saleor/static/dashboard-next/navigation/components/MenuDetailsPage/MenuDetailsPage.tsx b/saleor/static/dashboard-next/navigation/components/MenuDetailsPage/MenuDetailsPage.tsx
index fa88f2f155..9326eda60a 100644
--- a/saleor/static/dashboard-next/navigation/components/MenuDetailsPage/MenuDetailsPage.tsx
+++ b/saleor/static/dashboard-next/navigation/components/MenuDetailsPage/MenuDetailsPage.tsx
@@ -11,7 +11,7 @@ import SaveButtonBar from "../../../components/SaveButtonBar";
import i18n from "../../../i18n";
import { maybe } from "../../../misc";
import { MenuDetails_menu } from "../../types/MenuDetails";
-import MenuItems, { TreePermutation } from "../MenuItems";
+import MenuItems, { TreeOperation } from "../MenuItems";
import MenuProperties from "../MenuProperties";
import { computeTree } from "./tree";
@@ -20,7 +20,7 @@ export interface MenuDetailsFormData {
}
export interface MenuDetailsSubmitData extends MenuDetailsFormData {
- operations: TreePermutation[];
+ operations: TreeOperation[];
}
export interface MenuDetailsPageProps {
@@ -46,7 +46,7 @@ const MenuDetailsPage: React.StatelessComponent<MenuDetailsPageProps> = ({
name: maybe(() => menu.name, "")
};
- const [treeOperations, setTreeOperations] = React.useState<TreePermutation[]>(
+ const [treeOperations, setTreeOperations] = React.useState<TreeOperation[]>(
[]
);
@@ -61,7 +61,7 @@ const MenuDetailsPage: React.StatelessComponent<MenuDetailsPageProps> = ({
}
};
- const handleChange = (operation: TreePermutation) => {
+ const handleChange = (operation: TreeOperation) => {
if (!!operation) {
setTreeOperations([...treeOperations, operation]);
}
diff --git a/saleor/static/dashboard-next/navigation/components/MenuDetailsPage/tree.test.ts b/saleor/static/dashboard-next/navigation/components/MenuDetailsPage/tree.test.ts
index bab8a4d585..6b12e5ed4f 100644
--- a/saleor/static/dashboard-next/navigation/components/MenuDetailsPage/tree.test.ts
+++ b/saleor/static/dashboard-next/navigation/components/MenuDetailsPage/tree.test.ts
@@ -1,6 +1,6 @@
import { menu } from "../../fixtures";
import { MenuDetails_menu_items } from "../../types/MenuDetails";
-import { TreePermutation } from "../MenuItems";
+import { TreeOperation } from "../MenuItems";
import { computeTree } from "./tree";
// Readability FTW
@@ -23,7 +23,7 @@ function treeToString(tree: MenuDetails_menu_items[]): string {
}
describe("Properly computes trees", () => {
- const testTable: TreePermutation[][] = [
+ const testTable: TreeOperation[][] = [
[],
[
{ id: "1glasses", parentId: "0jewelry", sortOrder: 0, operation: "move" },
diff --git a/saleor/static/dashboard-next/navigation/components/MenuDetailsPage/tree.ts b/saleor/static/dashboard-next/navigation/components/MenuDetailsPage/tree.ts
index 1c6f44e439..36915f06ce 100644
--- a/saleor/static/dashboard-next/navigation/components/MenuDetailsPage/tree.ts
+++ b/saleor/static/dashboard-next/navigation/components/MenuDetailsPage/tree.ts
@@ -1,5 +1,5 @@
import { MenuDetails_menu_items } from "../../types/MenuDetails";
-import { TreePermutation } from "../MenuItems";
+import { TreeOperation } from "../MenuItems";
function findNode(tree: MenuDetails_menu_items[], id: string): number[] {
const foundNodeIndex = tree.findIndex(node => node.id === id);
@@ -68,7 +68,7 @@ function insertNode(
function removeNodeAndChildren(
tree: MenuDetails_menu_items[],
- operation: TreePermutation
+ operation: TreeOperation
): MenuDetails_menu_items[] {
const sourcePath = findNode(tree, operation.id);
const node = getNode(tree, sourcePath);
@@ -91,7 +91,7 @@ function removeNodeAndChildren(
function permuteNode(
tree: MenuDetails_menu_items[],
- permutation: TreePermutation
+ permutation: TreeOperation
): MenuDetails_menu_items[] {
const sourcePath = findNode(tree, permutation.id);
const node = getNode(tree, sourcePath);
@@ -114,7 +114,7 @@ function permuteNode(
function executeOperation(
tree: MenuDetails_menu_items[],
- operation: TreePermutation
+ operation: TreeOperation
): MenuDetails_menu_items[] {
return operation.operation === "move"
? permuteNode(tree, operation)
@@ -123,7 +123,7 @@ function executeOperation(
export function computeTree(
tree: MenuDetails_menu_items[],
- operations: TreePermutation[]
+ operations: TreeOperation[]
) {
const newTree = operations.reduce(
(acc, operation) => executeOperation(acc, operation),
diff --git a/saleor/static/dashboard-next/navigation/components/MenuItems/MenuItems.tsx b/saleor/static/dashboard-next/navigation/components/MenuItems/MenuItems.tsx
index d8e6889c06..198c81738a 100644
--- a/saleor/static/dashboard-next/navigation/components/MenuItems/MenuItems.tsx
+++ b/saleor/static/dashboard-next/navigation/components/MenuItems/MenuItems.tsx
@@ -26,7 +26,7 @@ import {
getNodeData,
getNodeQuantity,
TreeNode,
- TreePermutation
+ TreeOperation
} from "./tree";
const NODE_HEIGHT = 56;
@@ -35,7 +35,7 @@ const NODE_MARGIN = 40;
export interface MenuItemsProps {
canUndo: boolean;
items: MenuDetails_menu_items[];
- onChange: (operation: TreePermutation) => void;
+ onChange: (operation: TreeOperation) => void;
onItemAdd: () => void;
onUndo: () => void;
}
diff --git a/saleor/static/dashboard-next/navigation/components/MenuItems/tree.ts b/saleor/static/dashboard-next/navigation/components/MenuItems/tree.ts
index 814d31d5ce..76e4822259 100644
--- a/saleor/static/dashboard-next/navigation/components/MenuItems/tree.ts
+++ b/saleor/static/dashboard-next/navigation/components/MenuItems/tree.ts
@@ -3,7 +3,7 @@ import { TreeItem } from "react-sortable-tree";
import { MenuDetails_menu_items } from "../../types/MenuDetails";
-export interface TreePermutation {
+export interface TreeOperation {
id: string;
operation: "move" | "remove";
parentId?: string;
@@ -34,11 +34,11 @@ function treeToMap(tree: TreeNode[], parent: string): Record<string, string[]> {
export function getDiff(
originalTree: TreeNode[],
newTree: TreeNode[]
-): TreePermutation {
+): TreeOperation {
const originalMap = treeToMap(originalTree, "root");
const newMap = treeToMap(newTree, "root");
- const diff: TreePermutation[] = Object.keys(newMap).map(key => {
+ const diff: TreeOperation[] = Object.keys(newMap).map(key => {
const originalNode = originalMap[key];
const newNode = newMap[key];
@@ -62,7 +62,7 @@ export function getDiff(
export function getNodeData(
item: MenuDetails_menu_items,
- onChange: (operation: TreePermutation) => void
+ onChange: (operation: TreeOperation) => void
): TreeNode {
return {
children: item.children.map(child => getNodeData(child, onChange)),