in apps/chat/src/utils/app/common.ts [113:196]
folderId: updateFolderId(f.folderId),
}));
const newUniqueFolderIds = uniq(allFolderIds).map((id) => updateFolderId(id));
const updatedFolders = combineEntities(
getFoldersFromIds(newUniqueFolderIds, FolderType.Chat),
updatedExistedFolders,
);
const updatedOpenedFoldersIds = openedFoldersIds.map(
(id) => updateFolderId(id)!,
);
return { updatedFolders, updatedOpenedFoldersIds };
};
export const trimEndDots = (str: string) => trimEnd(str, '. \t\r\n');
export const prepareEntityName = (
name: string,
options?: Partial<PrepareNameOptions>,
) => {
const clearName = options?.forRenaming
? name
.replace(
notAllowedSymbolsRegex,
options?.replaceWithSpacesForRenaming ? ' ' : '',
)
.trim()
: (name
.replace(/\r\n|\r/gm, '\n')
.split('\n')
.map((s) => s.replace(notAllowedSymbolsRegex, ' ').trim())
.filter(Boolean)[0] ?? '');
const result =
clearName.length > MAX_ENTITY_LENGTH
? substring(clearName, 0, MAX_ENTITY_LENGTH)
: clearName;
const additionalCuttedResult =
result.length > MAX_ENTITY_LENGTH
? result.substring(0, MAX_ENTITY_LENGTH)
: result;
return !options?.forRenaming || options?.trimEndDotsRequired
? trimEndDots(additionalCuttedResult)
: additionalCuttedResult.trim();
};
export const isSearchTermMatched = (entity: ShareEntity, searchTerm?: string) =>
!searchTerm || doesEntityContainSearchTerm(entity, searchTerm);
export const isSearchFilterMatched = (
entity: ShareEntity,
filters: EntityFilters,
) => filters.searchFilter?.(entity) ?? true;
export const isSectionFilterMatched = (
entity: ShareEntity,
filters: EntityFilters,
ignoreSectionFilter?: boolean,
) => ignoreSectionFilter || (filters.sectionFilter?.(entity) ?? true);
export const isVersionFilterMatched = (
entity: ShareEntity,
filters: EntityFilters,
versionGroups: PublicVersionGroups,
ignoreVersionFilter?: boolean,
) => {
if (ignoreVersionFilter) return true;
const version = entity.publicationInfo?.version;
if (!version || !filters.versionFilter) return true;
const currentVersionGroup =
versionGroups[getPublicItemIdWithoutVersion(version, entity.id)];
return currentVersionGroup
? filters.versionFilter(entity, currentVersionGroup.selectedVersion.version)
: true;
};
export const isVersionValid = (version: string | undefined) => {
if (!version) {