Merge pull request #834 from ONLYOFFICE/feature/update-filters

Feature/update filters
This commit is contained in:
Alexey Safronov 2022-09-16 19:13:57 +03:00 committed by GitHub
commit 75a6cebfce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 94 additions and 51 deletions

View File

@ -147,9 +147,7 @@ const SectionFilterContent = ({
const owner = getOwner(data) || null;
const subjectId =
owner === FilterKeys.other
? null
: owner === FilterKeys.me
owner === FilterKeys.other || owner === FilterKeys.me
? userId
: owner;
@ -182,7 +180,7 @@ const SectionFilterContent = ({
newFilter.withoutTags = false;
}
newFilter.withoutMe = withoutMe;
newFilter.excludeSubject = withoutMe;
// newFilter.withSubfolders = withSubfolders;
// newFilter.searchInContent = withContent;
@ -192,11 +190,8 @@ const SectionFilterContent = ({
} else {
const filterType = getFilterType(data) || null;
const authorType = !!getAuthorType(data)
? getAuthorType(data).includes("user_")
? getAuthorType(data)
: `user_${getAuthorType(data)}`
: null;
const authorType = getAuthorType(data);
const withSubfolders = getSearchParams(data);
const withContent = getFilterContent(data);
@ -205,7 +200,14 @@ const SectionFilterContent = ({
newFilter.filterType = filterType;
newFilter.authorType = authorType;
if (authorType === FilterKeys.me || authorType === FilterKeys.other) {
newFilter.authorType = `user_${userId}`;
newFilter.excludeSubject = authorType === FilterKeys.other;
} else {
newFilter.authorType = authorType ? `user_${authorType}` : null;
newFilter.excludeSubject = null;
}
newFilter.withSubfolders =
withSubfolders === FilterKeys.excludeSubfolders ? "false" : "true";
newFilter.searchInContent = withContent === "true" ? "true" : null;
@ -369,7 +371,11 @@ const SectionFilterContent = ({
if (roomsFilter.subjectId) {
const isMe = userId === roomsFilter.subjectId;
let label = isMe ? t("Common:MeLabel") : null;
let label = isMe
? roomsFilter.excludeSubject
? t("Common:OtherLabel")
: t("Common:MeLabel")
: null;
if (!isMe) {
const user = await getUser(roomsFilter.subjectId);
@ -384,14 +390,6 @@ const SectionFilterContent = ({
});
}
if (roomsFilter.withoutMe) {
filterValues.push({
key: FilterKeys.other,
group: FilterGroups.roomFilterOwner,
label: t("Common:OtherLabel"),
});
}
// if (roomsFilter.withoutTags) {
// filterValues.push({
// key: [t("NoTag")],
@ -468,11 +466,28 @@ const SectionFilterContent = ({
}
if (filter.authorType) {
const user = await getUser(filter.authorType.replace("user_", ""));
const isMe = userId === filter.authorType.replace("user_", "");
let label = isMe
? filter.excludeSubject
? t("Common:OtherLabel")
: t("Common:MeLabel")
: null;
if (!isMe) {
const user = await getUser(filter.authorType.replace("user_", ""));
label = user.displayName;
}
filterValues.push({
key: `${filter.authorType}`,
key: isMe
? filter.excludeSubject
? FilterKeys.other
: FilterKeys.me
: filter.authorType.replace("user_", ""),
group: FilterGroups.filterAuthor,
label: user.displayName,
label: label,
});
}
}
@ -483,11 +498,12 @@ const SectionFilterContent = ({
filter.authorType,
filter.filterType,
filter.searchInContent,
filter.excludeSubject,
roomsFilter.type,
roomsFilter.subjectId,
roomsFilter.tags,
roomsFilter.tags?.length,
roomsFilter.withoutMe,
roomsFilter.excludeSubject,
roomsFilter.withoutTags,
// roomsFilter.withSubfolders,
// roomsFilter.searchInContent,
@ -753,20 +769,33 @@ const SectionFilterContent = ({
}
if (!isPersonalRoom) {
filterOptions.push(
const authorOption = [
{
key: FilterGroups.filterAuthor,
group: FilterGroups.filterAuthor,
label: t("ByAuthor"),
isHeader: true,
withMultiItems: true,
},
{
key: "user",
key: FilterKeys.me,
group: FilterGroups.filterAuthor,
label: t("Common:MeLabel"),
},
{
key: FilterKeys.other,
group: FilterGroups.filterAuthor,
label: t("Common:OtherLabel"),
},
{
key: FilterKeys.user,
group: FilterGroups.filterAuthor,
label: t("Translations:AddAuthor"),
isSelector: true,
}
);
},
];
filterOptions.push(...authorOption);
}
filterOptions.push(...typeOptions);
@ -934,7 +963,7 @@ const SectionFilterContent = ({
if (group === FilterGroups.roomFilterOwner) {
newFilter.subjectId = null;
newFilter.withoutMe = false;
newFilter.excludeSubject = false;
}
if (group === FilterGroups.roomFilterTags) {
@ -971,11 +1000,13 @@ const SectionFilterContent = ({
);
} else {
const newFilter = filter.clone();
if (group === FilterGroups.filterType) {
newFilter.filterType = null;
}
if (group === FilterGroups.filterAuthor) {
newFilter.authorType = null;
newFilter.excludeSubject = null;
}
if (group === FilterGroups.filterFolders) {
newFilter.withSubfolders = "true";

View File

@ -14,6 +14,7 @@ const DEFAULT_AUTHOR_TYPE = null;
const DEFAULT_SELECTED_ITEM = {};
const DEFAULT_FOLDER = "@my";
const DEFAULT_SEARCH_IN_CONTENT = null;
const DEFAULT_EXCLUDE_SUBJECT = null;
const SEARCH_TYPE = "withSubfolders";
const AUTHOR_TYPE = "authorType";
@ -27,6 +28,7 @@ const PAGE_COUNT = "count";
const FOLDER = "folder";
const PREVIEW = "preview";
const SEARCH_IN_CONTENT = "searchInContent";
const EXCLUDE_SUBJECT = "excludeSubject";
// TODO: add next params
// subjectGroup bool
@ -69,6 +71,8 @@ class FilesFilter {
const folder = urlFilter[FOLDER] || defaultFilter.folder;
const searchInContent =
urlFilter[SEARCH_IN_CONTENT] || defaultFilter.searchInContent;
const excludeSubject =
urlFilter[EXCLUDE_SUBJECT] || defaultFilter.excludeSubject;
const newFilter = new FilesFilter(
page,
@ -83,7 +87,8 @@ class FilesFilter {
authorType,
defaultFilter.selectedItem,
folder,
searchInContent
searchInContent,
excludeSubject
);
return newFilter;
@ -102,7 +107,8 @@ class FilesFilter {
authorType = DEFAULT_AUTHOR_TYPE,
selectedItem = DEFAULT_SELECTED_ITEM,
folder = DEFAULT_FOLDER,
searchInContent = DEFAULT_SEARCH_IN_CONTENT
searchInContent = DEFAULT_SEARCH_IN_CONTENT,
excludeSubject = DEFAULT_EXCLUDE_SUBJECT
) {
this.page = page;
this.pageCount = pageCount;
@ -117,6 +123,7 @@ class FilesFilter {
this.selectedItem = selectedItem;
this.folder = folder;
this.searchInContent = searchInContent;
this.excludeSubject = excludeSubject;
}
getStartIndex = () => {
@ -143,6 +150,7 @@ class FilesFilter {
withSubfolders,
startIndex,
searchInContent,
excludeSubject,
} = this;
const isFilterSet =
@ -165,6 +173,7 @@ class FilesFilter {
withSubfolders: isFilterSet,
userIdOrGroupId,
searchInContent,
excludeSubject,
};
const str = toUrlParams(dtoFilter, true);
@ -183,6 +192,7 @@ class FilesFilter {
sortOrder,
withSubfolders,
searchInContent,
excludeSubject,
} = this;
const dtoFilter = {};
@ -219,6 +229,10 @@ class FilesFilter {
dtoFilter[SEARCH_IN_CONTENT] = searchInContent;
}
if (excludeSubject) {
dtoFilter[EXCLUDE_SUBJECT] = excludeSubject;
}
dtoFilter[PAGE] = page + 1;
dtoFilter[SORT_BY] = sortBy;
dtoFilter[SORT_ORDER] = sortOrder;
@ -245,7 +259,8 @@ class FilesFilter {
this.authorType,
this.selectedItem,
this.folder,
this.searchInContent
this.searchInContent,
this.excludeSubject
);
}
@ -262,7 +277,8 @@ class FilesFilter {
this.selectedItem.key === filter.selectedItem.key &&
this.folder === filter.folder &&
this.pageCount === filter.pageCount &&
this.searchInContent === filter.searchInContent;
this.searchInContent === filter.searchInContent &&
this.excludeSubject === filter.excludeSubject;
return equals;
}

View File

@ -34,8 +34,8 @@ const DEFAULT_SORT_BY = "DateAndTime";
const SORT_ORDER = "sortorder";
const DEFAULT_SORT_ORDER = "descending";
const WITHOUT_ME = "withoutMe";
const DEFAULT_WITHOUT_ME = false;
const EXCLUDE_SUBJECT = "excludeSubject";
const DEFAULT_EXCLUDE_SUBJECT = false;
const WITHOUT_TAGS = "withoutTags";
const DEFAULT_WITHOUT_TAGS = false;
@ -94,7 +94,8 @@ class RoomsFilter {
const sortOrder = urlFilter[SORT_ORDER] || defaultFilter.sortOrder;
const withoutMe = urlFilter[WITHOUT_ME] || defaultFilter.withoutMe;
const excludeSubject =
urlFilter[EXCLUDE_SUBJECT] || defaultFilter.excludeSubject;
const withoutTags = urlFilter[WITHOUT_TAGS] || defaultFilter.withoutTags;
@ -111,7 +112,7 @@ class RoomsFilter {
tags,
sortBy,
sortOrder,
withoutMe,
excludeSubject,
withoutTags
);
@ -131,7 +132,7 @@ class RoomsFilter {
tags = DEFAULT_TAGS,
sortBy = DEFAULT_SORT_BY,
sortOrder = DEFAULT_SORT_ORDER,
withoutMe = DEFAULT_WITHOUT_ME,
excludeSubject = DEFAULT_EXCLUDE_SUBJECT,
withoutTags = DEFAULT_WITHOUT_TAGS
) {
this.page = page;
@ -146,7 +147,7 @@ class RoomsFilter {
this.tags = tags;
this.sortBy = sortBy;
this.sortOrder = sortOrder;
this.withoutMe = withoutMe;
this.excludeSubject = excludeSubject;
this.withoutTags = withoutTags;
}
@ -175,7 +176,7 @@ class RoomsFilter {
tags,
sortBy,
sortOrder,
withoutMe,
excludeSubject,
withoutTags,
} = this;
@ -192,7 +193,7 @@ class RoomsFilter {
tags: tags,
sortBy: sortBy,
sortOrder: sortOrder,
withoutMe: withoutMe,
excludeSubject: excludeSubject,
withoutTags: withoutTags,
};
@ -213,7 +214,7 @@ class RoomsFilter {
tags,
sortBy,
sortOrder,
withoutMe,
excludeSubject,
withoutTags,
} = this;
@ -247,8 +248,8 @@ class RoomsFilter {
dtoFilter[PAGE_COUNT] = pageCount;
}
if (withoutMe) {
dtoFilter[WITHOUT_ME] = withoutMe;
if (excludeSubject) {
dtoFilter[EXCLUDE_SUBJECT] = excludeSubject;
}
if (withoutTags) {
@ -282,7 +283,7 @@ class RoomsFilter {
this.tags,
this.sortBy,
this.sortOrder,
this.withoutMe,
this.excludeSubject,
this.withoutTags
);
}
@ -308,7 +309,7 @@ class RoomsFilter {
tagsEqual &&
this.sortBy === filter.sortBy &&
this.sortOrder === filter.sortOrder &&
this.withoutMe === filter.withoutMe &&
this.excludeSubject === filter.excludeSubject &&
this.withoutTags === filter.withoutTags;
return equals;

View File

@ -278,12 +278,7 @@ const FilterBlock = ({
show: false,
}));
changeFilterValue(
showSelector.group,
items[0].key,
false,
items[0].label
);
changeFilterValue(showSelector.group, items[0].id, false, items[0].label);
},
[showSelector.group, changeFilterValue]
);