Skip to content

Commit e8faaab

Browse files
authored
Invert Disable Drop (#108)
* Don't commit videos and screenshots * Configured a CI test workflow * Updated the contributing document
1 parent 453745b commit e8faaab

File tree

13 files changed

+1483
-994
lines changed

13 files changed

+1483
-994
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ jobs:
1414
registry-url: "https://registry.npmjs.org"
1515
- run: yarn
1616
- run: yarn build
17-
- run: yarn build:showcase
17+
- run: yarn test

CONTRIBUTING.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
# Testing Locally
22

33
1. Clone the repo
4-
2. From the root, run yarn start
4+
2. From the root, run yarn && yarn start
55
3. Visit localhost:3000
66

7+
# Running Tests
8+
9+
Run `yarn build && yarn test` from the root of the repo.
10+
11+
To test individual packages, cd into them and run `yarn test`. For example, running the unit tests would be `cd packages/react-arborist && yarn test`.
12+
713
# Publishing a Release
814

915
### Release Branch

package.json

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,19 @@
44
"./packages/*"
55
],
66
"scripts": {
7-
"bump": "yarn workspace react-arborist version",
8-
"start:showcase": "yarn workspace showcase dev",
9-
"start:library": "yarn workspace react-arborist watch",
107
"start": "run-p 'start:**'",
11-
"build": "yarn workspace react-arborist build",
12-
"watch": "yarn workspace react-arborist watch",
13-
"build:showcase": "yarn build && yarn workspace showcase build"
8+
"start:showcase": "yarn workspace showcase start",
9+
"start:library": "yarn workspace react-arborist start",
10+
"build": "run-s build:react-arborist build:showcase",
11+
"build:react-arborist": "yarn workspace react-arborist build",
12+
"build:showcase": "yarn workspace showcase build",
13+
"test": "run-p test:react-arborist test:e2e",
14+
"test:react-arborist": "yarn workspace react-arborist test",
15+
"test:e2e": "yarn workspace e2e test"
1416
},
1517
"private": true,
1618
"packageManager": "[email protected]",
1719
"devDependencies": {
18-
"@parcel/transformer-typescript-types": "2.7.0",
1920
"npm-run-all": "^4.1.5",
2021
"typescript": ">=3.0.0"
2122
}

packages/e2e/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
cypress/videos
2+
cypress/screenshots
3+
cypress/downloads

packages/e2e/cypress/e2e/spec.cy.ts renamed to packages/e2e/cypress/e2e/gmail-spec.cy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import "@4tw/cypress-drag-drop";
22

3-
describe("template spec", () => {
3+
describe("Testing the Gmail Demo", () => {
44
beforeEach(() => {
55
cy.visit("http://localhost:3000/gmail");
66
cy.get("[role=treeitem]").as("item");

packages/e2e/package.json

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
{
22
"name": "e2e",
33
"packageManager": "[email protected]",
4-
"dependencies": {
4+
"scripts": {
5+
"cy:run": "yarn cypress run",
6+
"start": "yarn cypress open",
7+
"serve": "yarn workspace showcase serve > /dev/null",
8+
"test": "start-server-and-test serve http://localhost:3000 cy:run"
9+
},
10+
"devDependencies": {
511
"@4tw/cypress-drag-drop": "^2.2.3",
612
"cypress": "^12.4.1",
713
"cypress-drag-drop": "^1.1.1",
14+
"serve": "^14.2.0",
15+
"start-server-and-test": "^1.15.3",
816
"typescript": "^4.9.4"
9-
},
10-
"scripts": {
11-
"test": "yarn cypress run",
12-
"open": "yarn cypress open"
1317
}
1418
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/** @type {import('ts-jest').JestConfigWithTsJest} */
2+
module.exports = {
3+
preset: 'ts-jest',
4+
testEnvironment: 'node',
5+
};

packages/react-arborist/package.json

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@
66
"main": "dist/index.js",
77
"module": "dist/module.js",
88
"types": "dist/index.d.ts",
9+
"scripts": {
10+
"start": "run-p 'watch:**'",
11+
"build": "npm-run-all clean -p 'build:**'",
12+
"test": "jest",
13+
"build:js": "parcel build --target main --target module",
14+
"build:types": "tsc --outDir dist",
15+
"clean": "rimraf dist",
16+
"start:js": "parcel watch --target main --target module --no-hmr --no-cache",
17+
"start:types": "tsc --outDir dist --watch",
18+
"prepack": "yarn build"
19+
},
920
"repository": {
1021
"type": "git",
1122
"url": "https://github.com/brimdata/react-arborist.git"
@@ -30,15 +41,6 @@
3041
"redux": "^4.1.1",
3142
"use-sync-external-store": "^1.2.0"
3243
},
33-
"scripts": {
34-
"build": "run-p 'build:**'",
35-
"build:js": "parcel build --target main --target module",
36-
"build:types": "tsc --outDir dist",
37-
"watch:js": "parcel watch --target main --target module --no-hmr --no-cache",
38-
"watch:types": "tsc --outDir dist --watch",
39-
"watch": "run-p 'watch:**'",
40-
"prepack": "yarn build"
41-
},
4244
"peerDependencies": {
4345
"react": ">= 16.14",
4446
"react-dom": ">= 16.14"
@@ -49,9 +51,11 @@
4951
"@types/react": "^18.0.0",
5052
"@types/react-window": "^1.8.5",
5153
"@types/use-sync-external-store": "^0.0.3",
52-
"jest": "^27.5.1",
54+
"jest": "^29.4.1",
5355
"npm-run-all": "^4.1.5",
5456
"parcel": "^2.3.2",
57+
"rimraf": "^4.1.2",
58+
"ts-jest": "^29.0.5",
5559
"typescript": "^4.6.2"
5660
}
5761
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { createStore } from "redux";
2+
import { rootReducer } from "../state/root-reducer";
3+
import { TreeProps } from "../types/tree-props";
4+
import { TreeApi } from "./tree-api";
5+
6+
function setupApi(props: TreeProps<any>) {
7+
const store = createStore(rootReducer);
8+
return new TreeApi(store, props, { current: null }, { current: null });
9+
}
10+
11+
test("tree.canDrop()", () => {
12+
expect(setupApi({ disableDrop: true }).canDrop()).toBe(false);
13+
expect(setupApi({ disableDrop: () => false }).canDrop()).toBe(true);
14+
expect(setupApi({ disableDrop: false }).canDrop()).toBe(true);
15+
});

packages/react-arborist/src/interfaces/tree-api.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ export class TreeApi<T> {
408408
if (this.isFiltered) return false;
409409
const parentNode = this.get(this.state.dnd.parentId) ?? this.root;
410410
const dragNodes = this.dragNodes;
411-
const check = this.props.disableDrop;
411+
const isDisabled = this.props.disableDrop;
412412

413413
for (const drag of dragNodes) {
414414
if (!drag) return false;
@@ -417,17 +417,17 @@ export class TreeApi<T> {
417417
}
418418

419419
// Allow the user to insert their own logic
420-
if (typeof check == "function") {
421-
return check({
420+
if (typeof isDisabled == "function") {
421+
return !isDisabled({
422422
parentNode,
423423
dragNodes: this.dragNodes,
424424
index: this.state.dnd.index,
425425
});
426-
} else if (typeof check == "string") {
426+
} else if (typeof isDisabled == "string") {
427427
// @ts-ignore
428-
return !!parentNode.data[check];
429-
} else if (typeof check === "boolean") {
430-
return check;
428+
return !parentNode.data[isDisabled];
429+
} else if (typeof isDisabled === "boolean") {
430+
return !isDisabled;
431431
} else {
432432
return true;
433433
}

0 commit comments

Comments
 (0)