You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-12-02 22:49:09 +02:00
Revert "All: Added support for hierarchical/nested tags (#2572)"
This reverts commit e11e57f1d8.
This commit is contained in:
@@ -103,13 +103,13 @@ class NoteTagsDialogComponent extends React.Component {
|
||||
const tagListData = this.props.tags.map(tag => {
|
||||
return {
|
||||
id: tag.id,
|
||||
title: Tag.getCachedFullTitle(tag.id),
|
||||
title: tag.title,
|
||||
selected: tagIds.indexOf(tag.id) >= 0,
|
||||
};
|
||||
});
|
||||
|
||||
tagListData.sort((a, b) => {
|
||||
return naturalCompare.caseInsensitive(Tag.getCachedFullTitle(a.id), Tag.getCachedFullTitle(b.id));
|
||||
return naturalCompare.caseInsensitive(a.title, b.title);
|
||||
});
|
||||
|
||||
this.setState({ tagListData: tagListData });
|
||||
|
||||
@@ -183,8 +183,7 @@ class NotesScreenComponent extends BaseScreenComponent {
|
||||
if (props.notesParentType == 'Folder') {
|
||||
output = Folder.byId(props.folders, props.selectedFolderId);
|
||||
} else if (props.notesParentType == 'Tag') {
|
||||
const tag = Tag.byId(props.tags, props.selectedTagId);
|
||||
output = Object.assign({}, tag, { title: Tag.getCachedFullTitle(tag.id) });
|
||||
output = Tag.byId(props.tags, props.selectedTagId);
|
||||
} else if (props.notesParentType == 'SmartFilter') {
|
||||
output = { id: this.props.selectedSmartFilterId, title: _('All notes') };
|
||||
} else {
|
||||
|
||||
@@ -70,7 +70,7 @@ class TagsScreenComponent extends BaseScreenComponent {
|
||||
}}
|
||||
>
|
||||
<View style={this.styles().listItem}>
|
||||
<Text style={this.styles().listItemText}>{Tag.getCachedFullTitle(tag.id)}</Text>
|
||||
<Text style={this.styles().listItemText}>{tag.title}</Text>
|
||||
</View>
|
||||
</TouchableOpacity>
|
||||
);
|
||||
@@ -83,7 +83,7 @@ class TagsScreenComponent extends BaseScreenComponent {
|
||||
async componentDidMount() {
|
||||
const tags = await Tag.allWithNotes();
|
||||
tags.sort((a, b) => {
|
||||
return Tag.getCachedFullTitle(a.id).toLowerCase() < Tag.getCachedFullTitle(b.id).toLowerCase() ? -1 : +1;
|
||||
return a.title.toLowerCase() < b.title.toLowerCase() ? -1 : +1;
|
||||
});
|
||||
this.setState({ tags: tags });
|
||||
}
|
||||
|
||||
@@ -15,10 +15,6 @@ const reduxSharedMiddleware = async function(store, next, action) {
|
||||
Setting.setValue('collapsedFolderIds', newState.collapsedFolderIds);
|
||||
}
|
||||
|
||||
if (action.type == 'TAG_SET_COLLAPSED' || action.type == 'TAG_TOGGLE') {
|
||||
Setting.setValue('collapsedTagIds', newState.collapsedTagIds);
|
||||
}
|
||||
|
||||
if (action.type === 'SETTING_UPDATE_ONE' && !!action.key.match(/^sync\.\d+\.path$/)) {
|
||||
reg.resetSyncTarget();
|
||||
}
|
||||
|
||||
@@ -1,55 +1,39 @@
|
||||
const BaseItem = require('lib/models/BaseItem');
|
||||
const Folder = require('lib/models/Folder');
|
||||
const BaseModel = require('lib/BaseModel');
|
||||
|
||||
const shared = {};
|
||||
|
||||
function itemHasChildren_(items, itemId) {
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
const item = items[i];
|
||||
if (item.parent_id === itemId) return true;
|
||||
function folderHasChildren_(folders, folderId) {
|
||||
for (let i = 0; i < folders.length; i++) {
|
||||
const folder = folders[i];
|
||||
if (folder.parent_id === folderId) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function itemIsVisible(items, itemId, collapsedItemIds) {
|
||||
if (!collapsedItemIds || !collapsedItemIds.length) return true;
|
||||
function folderIsVisible(folders, folderId, collapsedFolderIds) {
|
||||
if (!collapsedFolderIds || !collapsedFolderIds.length) return true;
|
||||
|
||||
while (true) {
|
||||
const item = BaseModel.byId(items, itemId);
|
||||
if (!item) throw new Error(`No item with id ${itemId}`);
|
||||
if (!item.parent_id) return true;
|
||||
if (collapsedItemIds.indexOf(item.parent_id) >= 0) return false;
|
||||
itemId = item.parent_id;
|
||||
const folder = BaseModel.byId(folders, folderId);
|
||||
if (!folder) throw new Error(`No folder with id ${folder.id}`);
|
||||
if (!folder.parent_id) return true;
|
||||
if (collapsedFolderIds.indexOf(folder.parent_id) >= 0) return false;
|
||||
folderId = folder.parent_id;
|
||||
}
|
||||
}
|
||||
|
||||
function renderItemsRecursive_(props, renderItem, items, parentId, depth, order, itemType) {
|
||||
let itemsKey = '';
|
||||
let notesParentType = '';
|
||||
let collapsedItemsKey = '';
|
||||
let selectedItemKey = '';
|
||||
if (itemType === BaseModel.TYPE_FOLDER) {
|
||||
itemsKey = 'folders';
|
||||
notesParentType = 'Folder';
|
||||
collapsedItemsKey = 'collapsedFolderIds';
|
||||
selectedItemKey = 'selectedFolderId';
|
||||
} else if (itemType === BaseModel.TYPE_TAG) {
|
||||
itemsKey = 'tags';
|
||||
notesParentType = 'Tag';
|
||||
collapsedItemsKey = 'collapsedTagIds';
|
||||
selectedItemKey = 'selectedTagId';
|
||||
}
|
||||
|
||||
const propItems = props[itemsKey];
|
||||
for (let i = 0; i < propItems.length; i++) {
|
||||
const item = propItems[i];
|
||||
if (!BaseItem.getClassByItemType(itemType).idsEqual(item.parent_id, parentId)) continue;
|
||||
if (!itemIsVisible(props[itemsKey], item.id, props[collapsedItemsKey])) continue;
|
||||
const hasChildren = itemHasChildren_(propItems, item.id);
|
||||
order.push(item.id);
|
||||
items.push(renderItem(item, props[selectedItemKey] == item.id && props.notesParentType == notesParentType, hasChildren, depth));
|
||||
function renderFoldersRecursive_(props, renderItem, items, parentId, depth, order) {
|
||||
const folders = props.folders;
|
||||
for (let i = 0; i < folders.length; i++) {
|
||||
const folder = folders[i];
|
||||
if (!Folder.idsEqual(folder.parent_id, parentId)) continue;
|
||||
if (!folderIsVisible(props.folders, folder.id, props.collapsedFolderIds)) continue;
|
||||
const hasChildren = folderHasChildren_(folders, folder.id);
|
||||
order.push(folder.id);
|
||||
items.push(renderItem(folder, props.selectedFolderId == folder.id && props.notesParentType == 'Folder', hasChildren, depth));
|
||||
if (hasChildren) {
|
||||
const result = renderItemsRecursive_(props, renderItem, items, item.id, depth + 1, order, itemType);
|
||||
const result = renderFoldersRecursive_(props, renderItem, items, folder.id, depth + 1, order);
|
||||
items = result.items;
|
||||
order = result.order;
|
||||
}
|
||||
@@ -61,11 +45,25 @@ function renderItemsRecursive_(props, renderItem, items, parentId, depth, order,
|
||||
}
|
||||
|
||||
shared.renderFolders = function(props, renderItem) {
|
||||
return renderItemsRecursive_(props, renderItem, [], '', 0, [], BaseModel.TYPE_FOLDER);
|
||||
return renderFoldersRecursive_(props, renderItem, [], '', 0, []);
|
||||
};
|
||||
|
||||
shared.renderTags = function(props, renderItem) {
|
||||
return renderItemsRecursive_(props, renderItem, [], '', 0, [], BaseModel.TYPE_TAG);
|
||||
const tags = props.tags.slice();
|
||||
tags.sort((a, b) => {
|
||||
return a.title < b.title ? -1 : +1;
|
||||
});
|
||||
const tagItems = [];
|
||||
const order = [];
|
||||
for (let i = 0; i < tags.length; i++) {
|
||||
const tag = tags[i];
|
||||
order.push(tag.id);
|
||||
tagItems.push(renderItem(tag, props.selectedTagId == tag.id && props.notesParentType == 'Tag'));
|
||||
}
|
||||
return {
|
||||
items: tagItems,
|
||||
order: order,
|
||||
};
|
||||
};
|
||||
|
||||
// shared.renderSearches = function(props, renderItem) {
|
||||
|
||||
@@ -402,7 +402,6 @@ const SideMenuContent = connect(state => {
|
||||
// Don't do the opacity animation as it means re-rendering the list multiple times
|
||||
// opacity: state.sideMenuOpenPercent,
|
||||
collapsedFolderIds: state.collapsedFolderIds,
|
||||
collapsedTagIds: state.collapsedTagIds,
|
||||
decryptionWorker: state.decryptionWorker,
|
||||
resourceFetcher: state.resourceFetcher,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user