TagSpaces is an offline, open source, document manager with tagging support
chore: optimizing exports
Ilian Sapundshiev5423d2794ed7
diff --git a/app/components/dialogs/ImportExportTagGroupsDialog.tsx b/app/components/dialogs/ImportExportTagGroupsDialog.tsxindex 6536fa682..31a5980e6 100644--- a/app/components/dialogs/ImportExportTagGroupsDialog.tsx+++ b/app/components/dialogs/ImportExportTagGroupsDialog.tsx@@ -28,8 +28,6 @@ import FormGroup from '@material-ui/core/FormGroup';import FormControlLabel from '@material-ui/core/FormControlLabel';import Checkbox from '@material-ui/core/Checkbox';import Dialog from '@material-ui/core/Dialog';-import IconButton from '@material-ui/core/IconButton';-import CloseIcon from '@material-ui/icons/Close';import TagGroupContainer from '../TagGroupContainer';import TagContainer from '../TagContainer';import i18n from '-/services/i18n';@@ -73,11 +71,6 @@ const ImportExportTagGroupsDialog = (props: Props) => {);};- /* const handleChange = name => (event: any, checked: boolean) => {- // @ts-ignore- this.setState({ [name]: !checked });- }; */-const isSelected = () => tagGroupList.some(n => n.selected === true);const handleTagGroup = (tagGroup: any, checked: boolean, index) => {diff --git a/app/reducers/taglibrary.ts b/app/reducers/taglibrary.tsindex 80404c3ff..c727d925f 100644--- a/app/reducers/taglibrary.ts+++ b/app/reducers/taglibrary.ts@@ -16,7 +16,12 @@**/import uuidv1 from 'uuid';-import { immutablySwapItems, formatDateTime4Tag, extend } from '-/utils/misc';+import {+ immutablySwapItems,+ formatDateTime4Tag,+ extend,+ prepareTagGroupForExport+} from '-/utils/misc';import { parseNewTags, saveAsTextFile } from '-/services/utils-io';import versionMeta from '../version.json';import defaultTagLibrary from './taglibrary-default';@@ -724,7 +729,7 @@ export const actions = {dispatch(actions.importTagGroups(tagGroups, true));}}, */- exportTagGroups: (entry: Array<Object>) => (+ exportTagGroups: (entry: Array<TS.TagGroup>) => (dispatch: (actions: Object) => void,getState: () => any) => {@@ -738,12 +743,15 @@ export const actions = {'", "settingsVersion": ' +settings.settingsVersion +', "tagGroups": ';- const getAllTags = [];+ const allTagGroups = [];tagLibrary.forEach(value => {- getAllTags.push(value);+ const preparedTagGroup = prepareTagGroupForExport(value);+ if (preparedTagGroup.title && preparedTagGroup.uuid) {+ allTagGroups.push(preparedTagGroup);+ }});- const blob = new Blob([jsonFormat + JSON.stringify(getAllTags) + '}'], {+ const blob = new Blob([jsonFormat + JSON.stringify(allTagGroups) + '}'], {type: 'application/json'});const dateTimeTag = formatDateTime4Tag(new Date(), true);diff --git a/app/services/utils-io.ts b/app/services/utils-io.tsindex 135e53772..f8cc88312 100644--- a/app/services/utils-io.ts+++ b/app/services/utils-io.ts@@ -39,7 +39,7 @@ import { getThumbnailURLPromise } from '-/services/thumbsgenerator';import { OpenedEntry, actions as AppActions } from '-/reducers/app';import { getLocation } from '-/reducers/locations';import { TS } from '-/tagspaces.namespace';-import { locationType } from '-/utils/misc';+import { locationType, prepareTagForExport } from '-/utils/misc';export function enhanceDirectoryContent(dirEntries,@@ -871,19 +871,7 @@ export function cleanMetaData(if (metaData.tags && metaData.tags.length > 0) {cleanedMeta.tags = [];metaData.tags.forEach(tag => {- const cleanedTag: TS.Tag = {};- if (tag.title) {- cleanedTag.title = tag.title;- }- if (tag.type) {- cleanedTag.type = tag.type;- }- if (tag.color) {- cleanedTag.color = tag.color;- }- if (tag.textcolor) {- cleanedTag.textcolor = tag.textcolor;- }+ const cleanedTag = prepareTagForExport(tag);if (cleanedTag.title) {cleanedMeta.tags.push(cleanedTag);}diff --git a/app/tagspaces.namespace.d.ts b/app/tagspaces.namespace.d.tsindex 3a103dc48..966f38712 100644--- a/app/tagspaces.namespace.d.ts+++ b/app/tagspaces.namespace.d.ts@@ -98,6 +98,7 @@ export namespace TS {color?: string;textcolor?: string;children?: Array<Tag>;+ selected?: boolean;created_date?: number;modified_date?: number;}diff --git a/app/utils/misc.ts b/app/utils/misc.tsindex 58eaa77bc..d2b8a73bf 100644--- a/app/utils/misc.ts+++ b/app/utils/misc.ts@@ -24,6 +24,57 @@ export const locationType = {TYPE_AMPLIFY: '2'};+export function prepareTagGroupForExport(tagGroup: TS.TagGroup): TS.TagGroup {+ const preparedTagGroup: TS.TagGroup = {+ title: tagGroup.title,+ uuid: tagGroup.uuid,+ children: []+ };+ if (tagGroup.created_date) {+ preparedTagGroup.created_date = tagGroup.created_date;+ }+ if (tagGroup.color) {+ preparedTagGroup.color = tagGroup.color;+ }+ if (tagGroup.textcolor) {+ preparedTagGroup.textcolor = tagGroup.textcolor;+ }+ if (tagGroup.modified_date) {+ preparedTagGroup.modified_date = tagGroup.modified_date;+ }+ if (tagGroup.expanded) {+ preparedTagGroup.expanded = tagGroup.expanded;+ }+ if (tagGroup.children && tagGroup.children.length > 0) {+ tagGroup.children.forEach(tag => {+ const cleanedTag = prepareTagForExport(tag);+ if (cleanedTag.title) {+ preparedTagGroup.children.push(prepareTagForExport(cleanedTag));+ }+ });+ }+ return preparedTagGroup;+}++export function prepareTagForExport(tag: TS.Tag): TS.Tag {+ const preparedTag: TS.Tag = {+ title: tag.title+ };+ if (tag.color) {+ preparedTag.color = tag.color;+ }+ if (tag.textcolor) {+ preparedTag.textcolor = tag.textcolor;+ }+ if (tag.type) {+ preparedTag.type = tag.type;+ }+ if (tag.description) {+ preparedTag.description = tag.description;+ }+ return preparedTag;+}+/** Returns true is a string is plus code e.g. 8FWH4HVG+3V 8FWH4HVG+ 8FWH4H+ */export function isPlusCode(plusCode: string): boolean {if (!plusCode) {