Skip to content

TagSpaces is an offline, open source, document manager with tagging support

TSN658 DnD tagGroups (#1474)

Stanimirfbc23bb7504a
diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml
index fcd13011c..b3c8be606 100644
--- a/.github/workflows/pull_request.yml
+++ b/.github/workflows/pull_request.yml
@@ -29,7 +29,7 @@ jobs:
# run: yarn test-unit
e2eTestsWin:
- name: Validating Windows
+ name: Test Desktop App Windows
runs-on: windows-latest
steps:
@@ -61,7 +61,7 @@ jobs:
if: always() # Run regardless of whether other steps failed
with:
access-token: ${{ secrets.GITHUB_TOKEN }}
- check-name: Jest Report Electron
+ check-name: Report Desktop App Windows
working-directory: tests
- uses: actions/upload-artifact@v2
if: failure()
@@ -71,7 +71,7 @@ jobs:
tests/test-pages/
tests/test-reports/
e2eTestsWebWin:
- name: E2E Windows Web
+ name: Test Web App Windows
runs-on: windows-latest
steps:
- name: Checking out default branch
@@ -114,7 +114,7 @@ jobs:
if: always() # Run regardless of whether other steps failed
with:
access-token: ${{ secrets.GITHUB_TOKEN }}
- check-name: Jest Report Web
+ check-name: Report Web App Windows
working-directory: tests
- uses: actions/upload-artifact@v2
if: failure()
diff --git a/app/components/DragItemTypes.tsx b/app/components/DragItemTypes.tsx
index 9eabb0096..3b98e74d2 100644
--- a/app/components/DragItemTypes.tsx
+++ b/app/components/DragItemTypes.tsx
@@ -18,5 +18,6 @@
export default {
TAG: 'tag',
+ TAG_GROUP: 'tag_group',
FILE: 'file_move'
};
diff --git a/app/components/SidePanels.css.tsx b/app/components/SidePanels.css.tsx
index fa8116b42..c0b36be4d 100644
--- a/app/components/SidePanels.css.tsx
+++ b/app/components/SidePanels.css.tsx
@@ -115,19 +115,5 @@ export default (theme: any) =>
},
leftIcon: {
marginRight: theme.spacing(1)
- },
- badge: {
- display: 'inline-block',
- minWidth: 10,
- padding: '3px 7px',
- fontSize: 10,
- fontWeight: 'normal',
- color: '#ffffff',
- lineHeight: 1,
- verticalAlign: 'middle',
- whiteSpace: 'nowrap',
- textAlign: 'center',
- backgroundColor: '#bbbbbb',
- borderRadius: 10
}
} as any);
diff --git a/app/components/TagGroupTitleDnD.tsx b/app/components/TagGroupTitleDnD.tsx
new file mode 100644
index 000000000..1557c56fe
--- /dev/null
+++ b/app/components/TagGroupTitleDnD.tsx
@@ -0,0 +1,213 @@
+/**
+ * TagSpaces - universal file and folder organizer
+ * Copyright (C) 2017-present TagSpaces UG (haftungsbeschraenkt)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License (version 3) as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+import React from 'react';
+import Typography from '@material-ui/core/Typography';
+import IconButton from '@material-ui/core/IconButton';
+import MoreVertIcon from '@material-ui/icons/MoreVert';
+import ArrowDownIcon from '@material-ui/icons/KeyboardArrowDown';
+import ArrowRightIcon from '@material-ui/icons/KeyboardArrowRight';
+import {
+ ConnectDragSource,
+ ConnectDropTarget,
+ DragSource,
+ DropTarget
+} from 'react-dnd';
+import Grid from '@material-ui/core/Grid';
+import { TS } from '-/tagspaces.namespace';
+import DragItemTypes from '-/components/DragItemTypes';
+
+interface Props {
+ classes: any;
+ index: number;
+ tagGroup: TS.TagGroup;
+ handleTagGroupMenu: (
+ event: React.ChangeEvent<HTMLInputElement>,
+ tagGroup: TS.TagGroup
+ ) => void;
+ toggleTagGroup: (uuid: string) => void;
+ moveTagGroup: (tagGroupUuid: TS.Uuid, position: number) => void;
+ locations: Array<TS.Location>;
+ tagGroupCollapsed: Array<string>;
+ isReadOnly: boolean;
+ connectDragSource?: ConnectDragSource;
+ connectDropTarget: ConnectDropTarget;
+}
+
+const TagGroupTitleDnD = (props: Props) => {
+ const handleTagGroupTitleClick = (event: Object, tagGroup) => {
+ props.toggleTagGroup(tagGroup.uuid);
+ };
+
+ function getLocationName(locationId: string) {
+ if (locationId) {
+ const location: TS.Location = props.locations.find(
+ l => l.uuid === locationId
+ );
+ if (location) {
+ return ' (' + location.name + ')';
+ }
+ }
+ return '';
+ }
+
+ const {
+ tagGroup,
+ handleTagGroupMenu,
+ connectDropTarget,
+ connectDragSource
+ } = props;
+
+ const tagGroupTitle = (
+ <div
+ data-tid={'tagLibraryTagGroupTitle_' + tagGroup.title}
+ className={props.classes.listItem}
+ title={'Number of tags in this tag group: ' + tagGroup.children.length}
+ >
+ <Grid
+ container
+ direction="row"
+ alignItems="stretch"
+ alignContent="center"
+ style={{ flexWrap: 'nowrap' }}
+ >
+ <Grid item xs={2} style={{ maxWidth: 40 }}>
+ <IconButton
+ style={{ minWidth: 'auto', padding: 7 }}
+ onClick={(event: any) => handleTagGroupTitleClick(event, tagGroup)}
+ >
+ {tagGroup.expanded ? <ArrowDownIcon /> : <ArrowRightIcon />}
+ </IconButton>
+ </Grid>
+ <Grid item xs={8} style={{ alignSelf: 'center' }}>
+ <Typography
+ variant="inherit"
+ className={props.classes.header}
+ style={{ paddingLeft: 0 }}
+ data-tid="locationTitleElement"
+ noWrap
+ onClick={(event: any) => handleTagGroupTitleClick(event, tagGroup)}
+ >
+ {tagGroup.title + getLocationName(tagGroup.locationId)}
+ {!tagGroup.expanded && (
+ <span
+ style={{
+ display: 'inline-block',
+ minWidth: 10,
+ padding: '3px 7px',
+ fontSize: 10,
+ fontWeight: 'normal',
+ marginLeft: 4,
+ color: '#ffffff',
+ lineHeight: 1,
+ verticalAlign: 'middle',
+ whiteSpace: 'nowrap',
+ textAlign: 'center',
+ backgroundColor: '#bbbbbb',
+ borderRadius: 10
+ }}
+ >
+ {tagGroup.children.length}
+ </span>
+ )}
+ </Typography>
+ </Grid>
+ <Grid item xs={2} style={{ textAlign: 'end' }}>
+ {!props.isReadOnly && (
+ <IconButton
+ style={{ minWidth: 'auto', padding: 7 }}
+ data-tid={
+ 'tagLibraryMoreButton_' + tagGroup.title.replace(/ /g, '_')
+ }
+ onClick={(event: any) => handleTagGroupMenu(event, tagGroup)}
+ >
+ <MoreVertIcon />
+ </IconButton>
+ )}
+ </Grid>
+ </Grid>
+ </div>
+ );
+ if (tagGroup.readOnly) {
+ return tagGroupTitle;
+ }
+ return connectDropTarget(connectDragSource(tagGroupTitle));
+};
+
+const boxSource = {
+ beginDrag(props) {
+ return { tagGroup: props.tagGroup, index: props.index };
+ } /* ,
+ endDrag(props, monitor) {
+ const item = monitor.getItem();
+ const dropResult = monitor.getDropResult();
+ } */
+};
+
+/**
+ * Specifies which props to inject into your component.
+ */
+const collectSource = (connect, monitor) => ({
+ // Call this function inside render()
+ // to let React DnD handle the drag events:
+ connectDragSource: connect.dragSource(),
+ // You can ask the monitor about the current drag preview
+ connectDragPreview: connect.dragPreview(),
+ // You can ask the monitor about the current drag state:
+ isDragging: monitor.isDragging()
+});
+
+const boxTarget = {
+ // Expected the drop target specification to only have some of the following keys: canDrop, hover, drop
+ /* canDrop(props, monitor) {
+ const dragItem = monitor.getItem();
+ return dragItem.tag.type === props.tag.type;
+ }, */
+ hover(props, monitor) {
+ const dragItem = monitor.getItem();
+ const dragIndex = dragItem.index;
+ const hoverIndex = props.index;
+ // Don't replace items with themselves
+ if (dragIndex === hoverIndex) {
+ return;
+ }
+ props.moveTagGroup(dragItem.tagGroup.uuid, hoverIndex);
+ // Note: we're mutating the monitor item here!
+ // Generally it's better to avoid mutations,
+ // but it's good here for the sake of performance
+ // to avoid expensive index searches.
+ dragItem.index = hoverIndex;
+ }
+};
+const collectTarget = (connect, monitor) => ({
+ connectDropTarget: connect.dropTarget(),
+ isOver: monitor.isOver(),
+ canDrop: monitor.canDrop()
+});
+
+export default DragSource(
+ DragItemTypes.TAG_GROUP,
+ boxSource,
+ collectSource
+)(
+ DropTarget(
+ DragItemTypes.TAG_GROUP,
+ boxTarget,
+ collectTarget
+ )(TagGroupTitleDnD)
+);
diff --git a/app/components/TagLibrary.tsx b/app/components/TagLibrary.tsx
index adfbc2f56..c522365b5 100644
--- a/app/components/TagLibrary.tsx
+++ b/app/components/TagLibrary.tsx
@@ -22,15 +22,9 @@ import { connect } from 'react-redux';
import classNames from 'classnames';
import { withStyles } from '@material-ui/core/styles';
import Typography from '@material-ui/core/Typography';
-import List from '@material-ui/core/List';
-import ListItem from '@material-ui/core/ListItem';
-import ListItemIcon from '@material-ui/core/ListItemIcon';
-import ListItemSecondaryAction from '@material-ui/core/ListItemSecondaryAction';
import IconButton from '@material-ui/core/IconButton';
import Collapse from '@material-ui/core/Collapse';
import MoreVertIcon from '@material-ui/icons/MoreVert';
-import ArrowDownIcon from '@material-ui/icons/KeyboardArrowDown';
-import ArrowRightIcon from '@material-ui/icons/KeyboardArrowRight';
import TagContainerDnd from './TagContainerDnd';
import TagContainer from './TagContainer';
import ConfirmDialog from './dialogs/ConfirmDialog';
@@ -66,6 +60,7 @@ import EditTagDialog from '-/components/dialogs/EditTagDialog';
import { TS } from '-/tagspaces.namespace';
import { getLocations } from '-/reducers/locations';
import { Pro } from '-/pro';
+import TagGroupTitleDnD from '-/components/TagGroupTitleDnD';
interface Props {
classes?: any;
@@ -105,6 +100,7 @@ interface Props {
tagGroupCollapsed: Array<string>;
locations: Array<TS.Location>;
saveTagInLocation: boolean;
+ moveTagGroup: (tagGroupUuid: TS.Uuid, position: number) => void;
}
const TagLibrary = (props: Props) => {
@@ -174,10 +170,6 @@ const TagLibrary = (props: Props) => {
const isTagLibraryReadOnly =
window.ExtTagLibrary && window.ExtTagLibrary.length > 0;
- const handleTagGroupTitleClick = (event: Object, tagGroup) => {
- props.toggleTagGroup(tagGroup.uuid);
- };
-
const handleTagGroupMenu = (
event: React.ChangeEvent<HTMLInputElement>,
tagGroup
@@ -242,19 +234,7 @@ const TagLibrary = (props: Props) => {
setTagGroupMenuAnchorEl(null);
};
- function getLocationName(locationId: string) {
- if (locationId) {
- const location: TS.Location = props.locations.find(
- l => l.uuid === locationId
- );
- if (location) {
- return ' (' + location.name + ')';
- }
- }
- return '';
- }
-
- const renderTagGroup = tagGroup => {
+ const renderTagGroup = (tagGroup, index) => {
// eslint-disable-next-line no-param-reassign
tagGroup.expanded = !(
props.tagGroupCollapsed && props.tagGroupCollapsed.includes(tagGroup.uuid)
@@ -262,60 +242,24 @@ const TagLibrary = (props: Props) => {
const isReadOnly = tagGroup.readOnly || isTagLibraryReadOnly;
return (
<div key={tagGroup.uuid}>
- <ListItem
- data-tid={'tagLibraryTagGroupTitle_' + tagGroup.title}
- button
- style={{ maxWidth: 250 }}
- className={props.classes.listItem}
- onClick={(event: any) => handleTagGroupTitleClick(event, tagGroup)}
- onContextMenu={(event: any) => handleTagGroupMenu(event, tagGroup)}
- title={
- 'Number of tags in this tag group: ' + tagGroup.children.length
- }
- >
- <ListItemIcon style={{ minWidth: 'auto' }}>
- {tagGroup.expanded ? <ArrowDownIcon /> : <ArrowRightIcon />}
- </ListItemIcon>
- <Typography
- variant="inherit"
- className={props.classes.header}
- style={{ paddingLeft: 0 }}
- data-tid="locationTitleElement"
- noWrap
- >
- {tagGroup.title + getLocationName(tagGroup.locationId)}
- {!tagGroup.expanded && (
- <span className={props.classes.badge}>
- {tagGroup.children.length}
- </span>
- )}
- </Typography>
- {!isReadOnly && (
- <ListItemSecondaryAction>
- <IconButton
- aria-label={i18n.t('core:options')}
- aria-haspopup="true"
- edge="end"
- data-tid={
- 'tagLibraryMoreButton_' + tagGroup.title.replace(/ /g, '_')
- }
- onClick={(event: any) => handleTagGroupMenu(event, tagGroup)}
- onContextMenu={(event: any) =>
- handleTagGroupMenu(event, tagGroup)
- }
- >
- <MoreVertIcon />
- </IconButton>
- </ListItemSecondaryAction>
- )}
- </ListItem>
+ <TagGroupTitleDnD
+ index={index}
+ classes={classes}
+ tagGroup={tagGroup}
+ moveTagGroup={props.moveTagGroup}
+ handleTagGroupMenu={handleTagGroupMenu}
+ toggleTagGroup={props.toggleTagGroup}
+ locations={props.locations}
+ tagGroupCollapsed={props.tagGroupCollapsed}
+ isReadOnly={isReadOnly}
+ />
<Collapse in={tagGroup.expanded} unmountOnExit>
<TagGroupContainer
taggroup={tagGroup}
data-tid={'tagGroupContainer_' + tagGroup.title}
>
{tagGroup.children &&
- tagGroup.children.map((tag: TS.Tag, index) => {
+ tagGroup.children.map((tag: TS.Tag, idx) => {
if (props.isReadOnlyMode) {
return (
<TagContainer
@@ -333,7 +277,7 @@ const TagLibrary = (props: Props) => {
<TagContainerDnd
key={tagGroup.uuid + tag.title}
tagContainerRef={tagContainerRef}
- index={index}
+ index={idx}
tag={tag}
tagGroup={tagGroup}
handleTagMenu={handleTagMenuCallback}
@@ -493,11 +437,11 @@ const TagLibrary = (props: Props) => {
)}
<div className={classes.taggroupsArea} data-tid="tagLibraryTagGroupList">
{AppConfig.showSmartTags && (
- <List style={{ paddingTop: 0, paddingBottom: 0 }}>
+ <div style={{ paddingTop: 0, paddingBottom: 0 }}>
{SmartTags(i18n).map(renderTagGroup)}
- </List>
+ </div>
)}
- <List style={{ paddingTop: 0 }}>{tagGroups.map(renderTagGroup)}</List>
+ <div style={{ paddingTop: 0 }}>{tagGroups.map(renderTagGroup)}</div>
</div>
</div>
);
@@ -523,6 +467,7 @@ function mapDispatchToProps(dispatch) {
toggleTagGroup: SettingsActions.toggleTagGroup,
removeTagGroup: TagLibraryActions.removeTagGroup,
moveTagGroupUp: TagLibraryActions.moveTagGroupUp,
+ moveTagGroup: TagLibraryActions.moveTagGroup,
moveTagGroupDown: TagLibraryActions.moveTagGroupDown,
sortTagGroup: TagLibraryActions.sortTagGroup,
importTagGroups: TagLibraryActions.importTagGroups,
diff --git a/app/reducers/taglibrary.ts b/app/reducers/taglibrary.ts
index 3785c3bb6..80404c3ff 100644
--- a/app/reducers/taglibrary.ts
+++ b/app/reducers/taglibrary.ts
@@ -38,6 +38,7 @@ export const types = {
// REMOVE_TAG: 'REMOVE_TAG',
// UPDATE_TAG: 'UPDATE_TAG',
SORT_TAG_GROUP_UP: 'SORT_TAG_GROUP_UP',
+ MOVE_TAG_GROUP: 'MOVE_TAG_GROUP',
MOVE_TAG_GROUP_UP: 'MOVE_TAG_GROUP_UP',
MOVE_TAG_GROUP_DOWN: 'MOVE_TAG_GROUP_DOWN',
EDIT_TAG_COLOR: 'EDIT_TAG_COLOR',
@@ -280,6 +281,21 @@ export default (state: Array<TS.TagGroup> = defaultTagLibrary, action: any) => {
}
return state;
}
+ case types.MOVE_TAG_GROUP: {
+ let indexForUpdating = -1;
+ state.forEach((tagGroup, index) => {
+ if (tagGroup.uuid === action.uuid) {
+ indexForUpdating = index;
+ }
+ });
+ if (indexForUpdating > -1 && indexForUpdating !== action.position) {
+ const tagGroups = Array.from(state);
+ const [removed] = tagGroups.splice(indexForUpdating, 1);
+ tagGroups.splice(action.position, 0, removed);
+ return tagGroups;
+ }
+ return state;
+ }
case types.MOVE_TAG_GROUP_UP: {
let indexForUpdating = -1;
state.forEach((tagGroup, index) => {
@@ -650,6 +666,11 @@ export const actions = {
tagTitle,
uuid: parentTagGroupUuid
}), */
+ moveTagGroup: (tagGroupUuid: TS.Uuid, position: number) => ({
+ type: types.MOVE_TAG_GROUP,
+ uuid: tagGroupUuid,
+ position
+ }),
moveTagGroupUp: (parentTagGroupUuid: TS.Uuid) => ({
type: types.MOVE_TAG_GROUP_UP,
uuid: parentTagGroupUuid
diff --git a/package.json b/package.json
index b52b05cb9..67e3a6ada 100644
--- a/package.json
+++ b/package.json
@@ -90,9 +90,9 @@
"test-unit": "cross-env NODE_JEST=unit_test BABEL_DISABLE_CACHE=1 jest --config=jest.config.unit.js --verbose ./tests/unit/",
"test-all": "yarn build && yarn test-unit && yarn build-e2e && yarn test-e2e",
"test-one": "cross-env HEADLESS_MODE=true jest --detectOpenHandles --config=jest.config.web.js -t 'TST5016' --runInBand --verbose ./tests/e2e/",
- "test-playwright": "rimraf tests/testdata-tmp && cross-env DISABLE_WORKER=true NODE_ENV=test jest --config=jest.config.playwright.js -t 'electron' --verbose ./tests/e2e/fileopener.pw.e2e.js",
- "test-playwright-web": "rimraf tests/testdata-tmp && cross-env DEBUG=pw:api PLAYWRIGHT=test_playwright jest --config=jest.config.web.js -t 'web' --verbose ./tests/e2e/fileopener.pw.e2e.js",
- "test-playwright-web-headless": "rimraf tests/testdata-tmp && cross-env PLAYWRIGHT=test_playwright HEADLESS_MODE=true jest --config=jest.config.web.js -t 'web' --verbose ./tests/e2e/fileopener.pw.e2e.js",
+ "test-playwright": "rimraf tests/testdata-tmp && cross-env DISABLE_WORKER=true NODE_ENV=test jest --config=jest.config.playwright.js -t 'electron' --verbose ./tests/e2e/",
+ "test-playwright-web": "rimraf tests/testdata-tmp && cross-env DEBUG=pw:api PLAYWRIGHT=test_playwright jest --config=jest.config.web.js -t 'web' --verbose ./tests/e2e/",
+ "test-playwright-web-headless": "rimraf tests/testdata-tmp && cross-env PLAYWRIGHT=test_playwright HEADLESS_MODE=true jest --config=jest.config.web.js -t 'web' --verbose ./tests/e2e/",
"playwright-show-trace": "npx playwright show-trace \"tests/test-reports/TST0813 - Delete file [web,minio,electron].zip\"",
"test-one-suite-headless": "cross-env HEADLESS_MODE=true jest --config=jest.config.web.js --verbose ./tests/e2e/fileopener.e2e.js",
"test-one-suite": "cross-env jest --config=jest.config.web.js --verbose ./tests/e2e/perspective-grid-right-button.e2e.js",
diff --git a/tests/e2e/hook.js b/tests/e2e/hook.js
index 51af01903..df28a61f5 100644
--- a/tests/e2e/hook.js
+++ b/tests/e2e/hook.js
@@ -205,7 +205,7 @@ function setWdioImageComparisonService(browser) {
}
export async function stopSpectronApp() {
- if (global.isPlaywright) {
+ if (global.isPlaywright && global.app) {
await global.app.close();
} else if (global.isWeb) {
await global.client.closeWindow();
@@ -216,7 +216,7 @@ export async function stopSpectronApp() {
}
}
-export function testDataRefresh() {
+export async function testDataRefresh() {
const fse = require('fs-extra');
const src = pathLib.join(
__dirname,
@@ -230,6 +230,9 @@ export function testDataRefresh() {
let newPath = pathLib.join(dst, pathLib.basename(src));
fse.emptyDirSync(newPath);
fse.copySync(src, newPath, { overwrite: true });
+ if (global.isElectron && global.client) {
+ await global.client.waitForTimeout(1000);
+ }
}
export async function takeScreenshot(name = expect.getState().currentTestName) {
diff --git a/tests/setup-after-env.js b/tests/setup-after-env.js
index db1ebe554..c04a885ae 100644
--- a/tests/setup-after-env.js
+++ b/tests/setup-after-env.js
@@ -47,7 +47,7 @@ jasmine.getEnv().addReporter({
});*/
beforeAll(async () => {
- testDataRefresh();
+ await testDataRefresh();
await startSpectronApp();
});