Skip to content

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

feature: extracting tagpreview as component, using it in the grid perspective

Ilian Sapundshiev42440468da2f
diff --git a/app/components/EntryContainer.tsx b/app/components/EntryContainer.tsx
index 43cc2ae3d..3bcd034ba 100644
--- a/app/components/EntryContainer.tsx
+++ b/app/components/EntryContainer.tsx
@@ -48,6 +48,7 @@ import RefreshIcon from '@material-ui/icons/Refresh';
import Box from '@material-ui/core/Box';
import { Split } from 'ts-react-splitter';
import EntryProperties from '-/components/EntryProperties';
+import TagsPreview from '-/components/TagsPreview';
import ConfirmDialog from '-/components/dialogs/ConfirmDialog';
import AppConfig from '-/config';
import PlatformIO from '-/services/platform-facade';
@@ -107,6 +108,7 @@ const styles: any = (theme: any) => ({
flexDirection: 'row',
flex: '1 1',
display: 'flex',
+ alignItems: 'center',
overflowX: AppConfig.isFirefox ? 'auto' : 'overlay',
paddingRight: 100
},
@@ -818,36 +820,6 @@ const EntryContainer = (props: Props) => {
</div>
);
- const previewTags = () => {
- if (!openedFile.tags || openedFile.tags.length < 1) {
- return;
- }
- let tagNames = i18n.t('core:searchTags') + ': ';
- openedFile.tags.forEach(tag => {
- tagNames = tagNames + tag.title + '; ';
- });
- const firstTagColor = openedFile.tags[0].color || defaultTagColor;
- let secondTagColor = defaultTagColor;
- if (openedFile.tags[1] && openedFile.tags[1].color) {
- secondTagColor = openedFile.tags[1].color;
- }
- return (
- <Tooltip title={tagNames}>
- <span
- style={{
- width: 15,
- height: 15,
- marginTop: 13,
- marginLeft: 5,
- borderRadius: 6,
- boxShadow: '4px 0px 0px 0px ' + secondTagColor,
- backgroundColor: firstTagColor
- }}
- />
- </Tooltip>
- );
- };
-
const { classes, keyBindings, theme, defaultTagColor } = props;
const fileTitle: string = openedFile.path
@@ -956,7 +928,10 @@ const EntryContainer = (props: Props) => {
</Box>
</Button>
)}
- {previewTags()}
+ <TagsPreview
+ tags={openedFile.tags}
+ defaultTagColor={defaultTagColor}
+ />
</Box>
<div className={classes.entryCloseSection}>
{editingSupported && openedFile.editMode && (
diff --git a/app/components/TagsPreview.tsx b/app/components/TagsPreview.tsx
new file mode 100644
index 000000000..afe7885fe
--- /dev/null
+++ b/app/components/TagsPreview.tsx
@@ -0,0 +1,69 @@
+/**
+ * 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 Tooltip from '@material-ui/core/Tooltip';
+import { TS } from '-/tagspaces.namespace';
+import i18n from '-/services/i18n';
+
+interface Props {
+ tags: Array<TS.Tag>;
+ defaultTagColor?: string;
+}
+
+const TagsPreview = (props: Props) => {
+ const { tags, defaultTagColor } = props;
+ if (!tags || tags.length < 1) {
+ return <></>;
+ }
+ let tagNames = i18n.t('core:searchTags') + ': ';
+ tags.forEach(tag => {
+ tagNames = tagNames + tag.title + ' ';
+ });
+ const firstTagColor = tags[0].color || defaultTagColor;
+ let secondTagColor = defaultTagColor;
+ let moreThanOne = false;
+ if (tags[1]) {
+ moreThanOne = true;
+ if (tags[1].color) {
+ secondTagColor = tags[1].color;
+ }
+ }
+ return (
+ <Tooltip title={tagNames}>
+ <span
+ style={{
+ display: 'inline-block',
+ width: 15,
+ height: 15,
+ marginLeft: 5,
+ borderRadius: 7,
+ borderRight: moreThanOne ? 'white 1px solid' : 'initial',
+ boxShadow: moreThanOne ? '4px 0px 0px 0px ' + secondTagColor : 'none',
+ backgroundColor: firstTagColor,
+ fontSize: 11,
+ color: 'white',
+ textAlign: 'center'
+ }}
+ >
+ {moreThanOne ? tags.length : '1'}
+ </span>
+ </Tooltip>
+ );
+};
+export default TagsPreview;
diff --git a/app/perspectives/grid-perspective/components/CellContent.tsx b/app/perspectives/grid-perspective/components/CellContent.tsx
index ef5e51ca2..67f744477 100644
--- a/app/perspectives/grid-perspective/components/CellContent.tsx
+++ b/app/perspectives/grid-perspective/components/CellContent.tsx
@@ -20,12 +20,10 @@ import React from 'react';
import classNames from 'classnames';
import Grid from '@material-ui/core/Grid';
import Typography from '@material-ui/core/Typography';
-import IconButton from '@material-ui/core/IconButton';
import Paper from '@material-ui/core/Paper';
import FolderIcon from '@material-ui/icons/Folder';
import SelectedIcon from '@material-ui/icons/CheckBox';
import UnSelectedIcon from '@material-ui/icons/CheckBoxOutlineBlank';
-import TagIcon from '@material-ui/icons/LocalOfferOutlined';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import { formatFileSize, formatDateTime } from '-/utils/misc';
@@ -37,12 +35,14 @@ import {
} from '-/services/utils-io';
import TagContainerDnd from '-/components/TagContainerDnd';
import TagContainer from '-/components/TagContainer';
+import TagsPreview from '-/components/TagsPreview';
import i18n from '-/services/i18n';
import PlatformIO from '-/services/platform-facade';
import AppConfig from '-/config';
import EntryIcon from '-/components/EntryIcon';
import { TS } from '-/tagspaces.namespace';
import TaggingActions from '-/reducers/tagging-actions';
+import { getTagColor } from '-/reducers/settings';
const maxDescriptionPreviewLength = 100;
@@ -71,6 +71,7 @@ interface Props {
handleGridCellClick: (event: Object, fsEntry: TS.FileSystemEntry) => void;
editTagForEntry?: (path: string, tag: TS.Tag) => void;
reorderTags: boolean;
+ defaultTagColor?: string;
}
const CellContent = (props: Props) => {
@@ -95,7 +96,8 @@ const CellContent = (props: Props) => {
openFsEntry,
selectEntry,
deselectEntry,
- isLast
+ isLast,
+ defaultTagColor
} = props;
const entryTitle = extractTitle(
fsEntry.name,
@@ -141,18 +143,9 @@ const CellContent = (props: Props) => {
});
}
tagTitles = tagTitles.substring(0, tagTitles.length - 2);
- const tagPlaceholder =
- tagTitles.length > 0 ? (
- <IconButton
- title={tagTitles}
- onClick={e => {
- e.stopPropagation();
- openFsEntry(fsEntry);
- }}
- >
- <TagIcon />
- </IconButton>
- ) : null;
+ const tagPlaceholder = (
+ <TagsPreview tags={entryTags} defaultTagColor={defaultTagColor} />
+ );
function renderGridCell() {
return (
@@ -467,6 +460,7 @@ const CellContent = (props: Props) => {
function mapStateToProps(state) {
return {
+ defaultTagColor: getTagColor(state),
reorderTags: state.settings.reorderTags
};
}
diff --git a/app/perspectives/grid-perspective/components/styles.css.tsx b/app/perspectives/grid-perspective/components/styles.css.tsx
index f545b78d8..6a571acc6 100644
--- a/app/perspectives/grid-perspective/components/styles.css.tsx
+++ b/app/perspectives/grid-perspective/components/styles.css.tsx
@@ -74,11 +74,11 @@ export default (theme: any): any => ({
},
gridCellTags: {
padding: 0,
- zIndex: 100,
+ paddingTop: 2,
maxHeight: 100,
overflowY: 'auto',
- overflowX: 'hidden'
- // opacity: 0.9
+ overflowX: 'hidden',
+ position: 'relative'
},
gridCellDescription: {
padding: 2,