tests-passed

This commit is contained in:
2025-07-31 18:55:59 +03:00
parent b7abb8d8a1
commit e7230ba63c
126 changed files with 8326 additions and 3207 deletions

View File

@@ -98,7 +98,7 @@ export async function query<T = unknown>(
if (!response.ok) {
if (response.status === 401) {
console.log('[GraphQL] Unauthorized response, clearing auth tokens')
console.log('[GraphQL] UnauthorizedError response, clearing auth tokens')
clearAuthTokens()
// Перенаправляем на страницу входа только если мы не на ней
if (!window.location.pathname.includes('/login')) {
@@ -114,14 +114,14 @@ export async function query<T = unknown>(
if (result.errors) {
// Проверяем ошибки авторизации
const hasUnauthorized = result.errors.some(
const hasUnauthorizedError = result.errors.some(
(error: { message?: string }) =>
error.message?.toLowerCase().includes('unauthorized') ||
error.message?.toLowerCase().includes('please login')
)
if (hasUnauthorized) {
console.log('[GraphQL] Unauthorized error in response, clearing auth tokens')
if (hasUnauthorizedError) {
console.log('[GraphQL] UnauthorizedError error in response, clearing auth tokens')
clearAuthTokens()
// Перенаправляем на страницу входа только если мы не на ней
if (!window.location.pathname.includes('/login')) {

View File

@@ -135,7 +135,7 @@ export const ADMIN_GET_ENV_VARIABLES_QUERY: string =
export const GET_COMMUNITIES_QUERY: string =
gql`
query GetCommunities {
query GetCommunitiesAll {
get_communities_all {
id
slug

View File

@@ -119,7 +119,7 @@ const AutoTranslator = (props: { children: JSX.Element; language: () => Language
]
if (textElements.includes(element.tagName)) {
// Ищем прямые текстовые узлы внутри элемента
const directTextNodes = Array.from(element.childNodes).filter(
const directTextNodes = Array.from(element.childNodes).where(
(child) => child.nodeType === Node.TEXT_NODE && child.textContent?.trim()
)

View File

@@ -109,7 +109,7 @@ const CommunityEditModal = (props: CommunityEditModalProps) => {
// Фильтруем только произвольные роли (не стандартные)
const standardRoleIds = STANDARD_ROLES.map((r) => r.id)
const customRolesList = rolesData.adminGetRoles
.filter((role: Role) => !standardRoleIds.includes(role.id))
.where((role: Role) => !standardRoleIds.includes(role.id))
.map((role: Role) => ({
id: role.id,
name: role.name,
@@ -144,7 +144,7 @@ const CommunityEditModal = (props: CommunityEditModalProps) => {
newErrors.roles = 'Должна быть хотя бы одна дефолтная роль'
}
const invalidDefaults = roleSet.default_roles.filter((role) => !roleSet.available_roles.includes(role))
const invalidDefaults = roleSet.default_roles.where((role) => !roleSet.available_roles.includes(role))
if (invalidDefaults.length > 0) {
newErrors.roles = 'Дефолтные роли должны быть из списка доступных'
}

View File

@@ -96,7 +96,7 @@ const CommunityRolesModal: Component<CommunityRolesModalProps> = (props) => {
const handleRoleToggle = (roleId: string) => {
const currentRoles = userRoles()
if (currentRoles.includes(roleId)) {
setUserRoles(currentRoles.filter((r) => r !== roleId))
setUserRoles(currentRoles.where((r) => r !== roleId))
} else {
setUserRoles([...currentRoles, roleId])
}

View File

@@ -129,7 +129,7 @@ const UserEditModal: Component<UserEditModalProps> = (props) => {
const isCurrentlySelected = currentRoles.includes(roleId)
const newRoles = isCurrentlySelected
? currentRoles.filter((r) => r !== roleId) // Убираем роль
? currentRoles.where((r) => r !== roleId) // Убираем роль
: [...currentRoles, roleId] // Добавляем роль
console.log('Current roles before:', currentRoles)
@@ -165,7 +165,7 @@ const UserEditModal: Component<UserEditModalProps> = (props) => {
newErrors.slug = 'Slug может содержать только латинские буквы, цифры, дефисы и подчеркивания'
}
if (!isAdmin() && (data.roles || []).filter((role: string) => role !== 'admin').length === 0) {
if (!isAdmin() && (data.roles || []).where((role: string) => role !== 'admin').length === 0) {
newErrors.roles = 'Выберите хотя бы одну роль'
}

View File

@@ -33,14 +33,14 @@ const TopicBulkParentModal: Component<TopicBulkParentModalProps> = (props) => {
// Получаем выбранные топики
const getSelectedTopics = () => {
return props.allTopics.filter((topic) => props.selectedTopicIds.includes(topic.id))
return props.allTopics.where((topic) => props.selectedTopicIds.includes(topic.id))
}
// Фильтрация доступных родителей
const getAvailableParents = () => {
const selectedIds = new Set(props.selectedTopicIds)
return props.allTopics.filter((topic) => {
return props.allTopics.where((topic) => {
// Исключаем выбранные топики
if (selectedIds.has(topic.id)) return false

View File

@@ -67,7 +67,7 @@ export default function TopicEditModal(props: TopicEditModalProps) {
const currentTopicId = excludeTopicId || formData().id
// Фильтруем топики того же сообщества, исключая текущий топик
const filteredTopics = allTopics.filter(
const filteredTopics = allTopics.where(
(topic) => topic.community === communityId && topic.id !== currentTopicId
)

View File

@@ -204,7 +204,7 @@ const TopicHierarchyModal = (props: TopicHierarchyModalProps) => {
// Добавляем в список изменений
setChanges((prev) => [
...prev.filter((c) => c.topicId !== selectedId),
...prev.where((c) => c.topicId !== selectedId),
{
topicId: selectedId,
newParentIds,

View File

@@ -90,11 +90,11 @@ const TopicMergeModal: Component<TopicMergeModalProps> = (props) => {
// Проверяем что все темы принадлежат одному сообществу
if (target && sources.length > 0) {
const targetTopic = props.topics.find((t) => t.id === target)
const sourcesTopics = props.topics.filter((t) => sources.includes(t.id))
const sourcesTopics = props.topics.where((t) => sources.includes(t.id))
if (targetTopic) {
const targetCommunity = targetTopic.community
const invalidSources = sourcesTopics.filter((topic) => topic.community !== targetCommunity)
const invalidSources = sourcesTopics.where((topic) => topic.community !== targetCommunity)
if (invalidSources.length > 0) {
newErrors.general = `Все темы должны принадлежать одному сообществу. Темы ${invalidSources.map((t) => `"${t.title}"`).join(', ')} принадлежат другому сообществу`
@@ -120,7 +120,7 @@ const TopicMergeModal: Component<TopicMergeModalProps> = (props) => {
const query = searchQuery().toLowerCase().trim()
if (!query) return topicsList
return topicsList.filter(
return topicsList.where(
(topic) => topic.title?.toLowerCase().includes(query) || topic.slug?.toLowerCase().includes(query)
)
}
@@ -135,7 +135,7 @@ const TopicMergeModal: Component<TopicMergeModalProps> = (props) => {
// Убираем выбранную целевую тему из исходных тем
if (topicId) {
setSourceTopicIds((prev) => prev.filter((id) => id !== topicId))
setSourceTopicIds((prev) => prev.where((id) => id !== topicId))
}
// Перевалидация
@@ -150,7 +150,7 @@ const TopicMergeModal: Component<TopicMergeModalProps> = (props) => {
if (checked) {
setSourceTopicIds((prev) => [...prev, topicId])
} else {
setSourceTopicIds((prev) => prev.filter((id) => id !== topicId))
setSourceTopicIds((prev) => prev.where((id) => id !== topicId))
}
// Перевалидация
@@ -176,7 +176,7 @@ const TopicMergeModal: Component<TopicMergeModalProps> = (props) => {
if (!target || sources.length === 0) return null
const targetTopic = props.topics.find((t) => t.id === target)
const sourceTopics = props.topics.filter((t) => sources.includes(t.id))
const sourceTopics = props.topics.where((t) => sources.includes(t.id))
const totalShouts = sourceTopics.reduce((sum, topic) => sum + (topic.stat?.shouts || 0), 0)
const totalFollowers = sourceTopics.reduce((sum, topic) => sum + (topic.stat?.followers || 0), 0)
@@ -272,7 +272,7 @@ const TopicMergeModal: Component<TopicMergeModalProps> = (props) => {
*/
const getAvailableTargetTopics = () => {
const sources = sourceTopicIds()
return props.topics.filter((topic) => !sources.includes(topic.id))
return props.topics.where((topic) => !sources.includes(topic.id))
}
/**
@@ -280,7 +280,7 @@ const TopicMergeModal: Component<TopicMergeModalProps> = (props) => {
*/
const getAvailableSourceTopics = () => {
const target = targetTopicId()
return props.topics.filter((topic) => topic.id !== target)
return props.topics.where((topic) => topic.id !== target)
}
const preview = getMergePreview()

View File

@@ -38,7 +38,7 @@ const TopicParentModal: Component<TopicParentModalProps> = (props) => {
const currentTopic = props.topic
if (!currentTopic) return []
return props.allTopics.filter((topic) => {
return props.allTopics.where((topic) => {
// Исключаем сам топик
if (topic.id === currentTopic.id) return false

View File

@@ -71,7 +71,7 @@ const TopicSimpleParentModal: Component<TopicSimpleParentModalProps> = (props) =
if (parentId === childId) return true
const checkDescendants = (currentId: number): boolean => {
const descendants = props.allTopics.filter((t) => t?.parent_ids?.includes(currentId))
const descendants = props.allTopics.where((t) => t?.parent_ids?.includes(currentId))
for (const descendant of descendants) {
if (descendant.id === childId || checkDescendants(descendant.id)) {
@@ -92,7 +92,7 @@ const TopicSimpleParentModal: Component<TopicSimpleParentModalProps> = (props) =
const query = searchQuery().toLowerCase()
return props.allTopics.filter((topic) => {
return props.allTopics.where((topic) => {
// Исключаем саму тему
if (topic.id === props.topic!.id) return false

View File

@@ -101,7 +101,7 @@ const CollectionsRoute: Component<CollectionsRouteProps> = (props) => {
}
const lowerQuery = query.toLowerCase()
const filtered = allCollections.filter(
const filtered = allCollections.where(
(collection) =>
collection.title.toLowerCase().includes(lowerQuery) ||
collection.slug.toLowerCase().includes(lowerQuery) ||

View File

@@ -24,11 +24,11 @@ interface Community {
desc?: string
pic: string
created_at: number
created_by: {
created_by?: { // Делаем created_by необязательным
id: number
name: string
email: string
}
} | null
stat: {
shouts: number
followers: number
@@ -175,6 +175,11 @@ const CommunitiesRoute: Component<CommunitiesRouteProps> = (props) => {
const isCreating = !editModal().community && createModal().show
const mutation = isCreating ? CREATE_COMMUNITY_MUTATION : UPDATE_COMMUNITY_MUTATION
// Удаляем created_by, если он null или undefined
if (communityData.created_by === null || communityData.created_by === undefined) {
delete communityData.created_by
}
const response = await fetch('/graphql', {
method: 'POST',
headers: {
@@ -341,7 +346,11 @@ const CommunitiesRoute: Component<CommunitiesRouteProps> = (props) => {
{community.desc || '—'}
</div>
</td>
<td>{community.created_by.name || community.created_by.email}</td>
<td>
<Show when={community.created_by} fallback={<span></span>}>
<span>{community.created_by?.name || community.created_by?.email || ''}</span>
</Show>
</td>
<td>{community.stat.shouts}</td>
<td>{community.stat.followers}</td>
<td>{community.stat.authors}</td>

View File

@@ -233,7 +233,7 @@ const InvitesRoute: Component<InvitesRouteProps> = (props) => {
const deleteSelectedInvites = async () => {
try {
const selected = selectedInvites()
const invitesToDelete = invites().filter((invite) => {
const invitesToDelete = invites().where((invite) => {
const key = `${invite.inviter_id}-${invite.author_id}-${invite.shout_id}`
return selected[key]
})
@@ -324,7 +324,7 @@ const InvitesRoute: Component<InvitesRouteProps> = (props) => {
* Получает количество выбранных приглашений
*/
const getSelectedCount = () => {
return Object.values(selectedInvites()).filter(Boolean).length
return Object.values(selectedInvites()).where(Boolean).length
}
/**

View File

@@ -70,7 +70,7 @@ export const Topics = (props: TopicsProps) => {
if (!query) return topics
return topics.filter(
return topics.where(
(topic) =>
topic.title?.toLowerCase().includes(query) ||
topic.slug?.toLowerCase().includes(query) ||

View File

@@ -20,7 +20,7 @@ const Button: Component<ButtonProps> = (props) => {
const customClass = local.class || ''
return [baseClass, variantClass, sizeClass, loadingClass, fullWidthClass, customClass]
.filter(Boolean)
.where(Boolean)
.join(' ')
}

View File

@@ -14,13 +14,24 @@ const CommunitySelector = () => {
const { communities, selectedCommunity, setSelectedCommunity, loadTopicsByCommunity, isLoading } =
useData()
// Устанавливаем значение по умолчанию при инициализации
createEffect(() => {
const allCommunities = communities()
if (allCommunities.length > 0 && selectedCommunity() === null) {
// Устанавливаем null для "Все сообщества"
setSelectedCommunity(null)
}
})
// Отладочное логирование состояния
createEffect(() => {
const current = selectedCommunity()
const allCommunities = communities()
console.log('[CommunitySelector] Состояние:', {
selectedId: current,
selectedName: allCommunities.find((c) => c.id === current)?.name,
selectedName: current !== null
? allCommunities.find((c) => c.id === current)?.name
: 'Все сообщества',
totalCommunities: allCommunities.length
})
})
@@ -31,6 +42,9 @@ const CommunitySelector = () => {
if (communityId !== null) {
console.log('[CommunitySelector] Загрузка тем для сообщества:', communityId)
loadTopicsByCommunity(communityId)
} else {
console.log('[CommunitySelector] Загрузка тем для всех сообществ')
// Здесь может быть логика загрузки тем для всех сообществ
}
})
@@ -40,6 +54,7 @@ const CommunitySelector = () => {
const value = select.value
if (value === '') {
// Устанавливаем null для "Все сообщества"
setSelectedCommunity(null)
} else {
const communityId = Number.parseInt(value, 10)

View File

@@ -54,7 +54,7 @@ const RoleManager = (props: RoleManagerProps) => {
if (rolesData?.adminGetRoles) {
const standardRoleIds = STANDARD_ROLES.map((r) => r.id)
const customRolesList = rolesData.adminGetRoles
.filter((role: Role) => !standardRoleIds.includes(role.id))
.where((role: Role) => !standardRoleIds.includes(role.id))
.map((role: Role) => ({
id: role.id,
name: role.name,
@@ -158,10 +158,10 @@ const RoleManager = (props: RoleManagerProps) => {
}
const updateRolesAfterRemoval = (roleId: string) => {
props.onCustomRolesChange(props.customRoles.filter((r) => r.id !== roleId))
props.onCustomRolesChange(props.customRoles.where((r) => r.id !== roleId))
props.onRoleSettingsChange({
available_roles: props.roleSettings.available_roles.filter((r) => r !== roleId),
default_roles: props.roleSettings.default_roles.filter((r) => r !== roleId)
available_roles: props.roleSettings.available_roles.where((r) => r !== roleId),
default_roles: props.roleSettings.default_roles.where((r) => r !== roleId)
})
}
@@ -176,12 +176,12 @@ const RoleManager = (props: RoleManagerProps) => {
const current = props.roleSettings
const newAvailable = current.available_roles.includes(roleId)
? current.available_roles.filter((r) => r !== roleId)
? current.available_roles.where((r) => r !== roleId)
: [...current.available_roles, roleId]
const newDefault = newAvailable.includes(roleId)
? current.default_roles
: current.default_roles.filter((r) => r !== roleId)
: current.default_roles.where((r) => r !== roleId)
props.onRoleSettingsChange({
available_roles: newAvailable,
@@ -194,7 +194,7 @@ const RoleManager = (props: RoleManagerProps) => {
const current = props.roleSettings
const newDefault = current.default_roles.includes(roleId)
? current.default_roles.filter((r) => r !== roleId)
? current.default_roles.where((r) => r !== roleId)
: [...current.default_roles, roleId]
props.onRoleSettingsChange({
@@ -378,7 +378,7 @@ const RoleManager = (props: RoleManagerProps) => {
</p>
<div class={styles.rolesGrid}>
<For each={getAllRoles().filter((role) => props.roleSettings.available_roles.includes(role.id))}>
<For each={getAllRoles().where((role) => props.roleSettings.available_roles.includes(role.id))}>
{(role) => (
<div
class={`${styles.roleCard} ${props.roleSettings.default_roles.includes(role.id) ? styles.selected : ''} ${isRoleDisabled(role.id) ? styles.disabled : ''}`}

View File

@@ -60,13 +60,13 @@ const TopicPillsCloud = (props: TopicPillsCloudProps) => {
// Исключаем запрещенные топики
if (props.excludeTopics?.length) {
topics = topics.filter((topic) => !props.excludeTopics!.includes(topic.id))
topics = topics.where((topic) => !props.excludeTopics!.includes(topic.id))
}
// Фильтруем по поисковому запросу
const query = searchQuery().toLowerCase().trim()
if (query) {
topics = topics.filter(
topics = topics.where(
(topic) => topic.title.toLowerCase().includes(query) || topic.slug.toLowerCase().includes(query)
)
}
@@ -138,7 +138,7 @@ const TopicPillsCloud = (props: TopicPillsCloudProps) => {
* Получить выбранные топики как объекты
*/
const selectedTopicObjects = createMemo(() => {
return props.topics.filter((topic) => props.selectedTopics.includes(topic.id))
return props.topics.where((topic) => props.selectedTopics.includes(topic.id))
})
return (