mirror of
https://github.com/stablyai/orca.git
synced 2026-11-19 04:23:57 +00:00
* fix(github-project): derive built-in field display and ordering from content * fix(i18n): register linked PR summary overflow fallback * fix: satisfy project projection static checks * test(github-project): cover normalized phone metadata and update field contracts * fix(github-project): narrow optional grouping values explicitly * test(github-project): place fixture safety rationale at assertion start * test(github-project): isolate Node and native regression boundaries
292 lines
10 KiB
TypeScript
292 lines
10 KiB
TypeScript
import { projectContentField } from '../../../src/shared/github/project-content-field'
|
|
import type { ConnectionPresentationModel } from './use-mobile-tasks-connection-presentation'
|
|
import { translate } from '../i18n/mobile-i18n'
|
|
import {
|
|
View,
|
|
colors,
|
|
Text,
|
|
Pressable,
|
|
FlatList,
|
|
spacing,
|
|
ChevronDown,
|
|
TaskProviderLogo,
|
|
type MobileColorScheme
|
|
} from './mobile-tasks-dependencies'
|
|
import { Inbox } from 'lucide-react-native'
|
|
import {
|
|
MobileLoadErrorState,
|
|
MobileNoMatchState,
|
|
MobileStateView
|
|
} from '../components/MobileStateView'
|
|
import { clearMobileTasksSearch } from './mobile-tasks-search-control'
|
|
import { styles } from './mobile-tasks-legacy-styles'
|
|
import {
|
|
projectGroupMeta,
|
|
formatUpdatedAt,
|
|
getRepoBadgeColor,
|
|
projectFieldDisplayLabel,
|
|
projectRowStatusLabel
|
|
} from './mobile-tasks-legacy-foundation'
|
|
import type { GitHubProjectField, GitHubProjectRow } from './mobile-tasks-view-state-types'
|
|
import { pressedStyle } from '../theme/mobile-theme'
|
|
|
|
function isProjectFieldEmpty(row: GitHubProjectRow, field: GitHubProjectField): boolean {
|
|
const contentValue = projectContentField(row.content, field.dataType)
|
|
if (contentValue !== undefined) {
|
|
return contentValue === null
|
|
}
|
|
switch (field.dataType) {
|
|
case 'ASSIGNEES':
|
|
return row.content.assignees.map((user) => user.login).join(', ') === ''
|
|
case 'LABELS':
|
|
return row.content.labels.map((label) => label.name).join(', ') === ''
|
|
case 'ISSUE_TYPE':
|
|
return row.content.issueType?.name == null
|
|
case 'TITLE':
|
|
return false
|
|
}
|
|
const value = row.fieldValuesByFieldId?.[field.id]
|
|
if (!value) {
|
|
return true
|
|
}
|
|
switch (value.kind) {
|
|
case 'text':
|
|
return !value.text
|
|
case 'labels':
|
|
return value.labels.map((label) => label.name).join(', ') === ''
|
|
case 'users':
|
|
return value.users.map((user) => user.login).join(', ') === ''
|
|
case 'date':
|
|
case 'iteration':
|
|
case 'number':
|
|
case 'single-select':
|
|
return false
|
|
}
|
|
}
|
|
|
|
export function renderMobileTasksGitHubProjectList(
|
|
model: ConnectionPresentationModel,
|
|
colorScheme: MobileColorScheme,
|
|
bottomBarHeight: number
|
|
) {
|
|
const {
|
|
activeGitHubProject,
|
|
findProjectRowRepo,
|
|
githubProjectError,
|
|
githubProjectListEntries,
|
|
githubProjectLoading,
|
|
githubProjectRepoSlugReady,
|
|
githubProjectSummaryFields,
|
|
githubProjectTable,
|
|
hasSearch,
|
|
insets,
|
|
refreshGitHubProject,
|
|
setCollapsedGitHubProjectGroups,
|
|
setProjectRowItem,
|
|
setShowGitHubProjectPicker,
|
|
taskUiReady,
|
|
visibleGitHubProjectRows
|
|
} = model
|
|
const count = githubProjectSummaryFields.length - 4
|
|
return githubProjectLoading ? (
|
|
<MobileStateView
|
|
loading
|
|
title={translate('tasks.githubProjectList.loading', 'Loading project…')}
|
|
bottomInset={bottomBarHeight}
|
|
/>
|
|
) : !activeGitHubProject ? (
|
|
<View style={[styles.centered, { paddingBottom: bottomBarHeight }]}>
|
|
<Text style={styles.emptyText}>
|
|
{translate('tasks.githubProjectList.chooseProject', 'Choose a GitHub project')}
|
|
</Text>
|
|
<Pressable
|
|
style={({ pressed }) => [
|
|
styles.targetButton,
|
|
styles.centerActionButton,
|
|
pressed && pressedStyle
|
|
]}
|
|
disabled={!taskUiReady}
|
|
onPress={() => {
|
|
if (!taskUiReady) {
|
|
return
|
|
}
|
|
setShowGitHubProjectPicker(true)
|
|
}}
|
|
>
|
|
<Text style={styles.targetButtonText}>
|
|
{translate('tasks.githubProjectList.browseProjects', 'Browse projects')}
|
|
</Text>
|
|
</Pressable>
|
|
</View>
|
|
) : githubProjectError ? (
|
|
<MobileLoadErrorState
|
|
error={githubProjectError}
|
|
onRetry={() => void refreshGitHubProject()}
|
|
bottomInset={bottomBarHeight}
|
|
/>
|
|
) : githubProjectTable && !githubProjectRepoSlugReady ? (
|
|
<MobileStateView
|
|
loading
|
|
title={translate('tasks.githubProjectList.loading', 'Loading project…')}
|
|
bottomInset={bottomBarHeight}
|
|
/>
|
|
) : (!githubProjectTable || visibleGitHubProjectRows.length === 0) && hasSearch ? (
|
|
<MobileNoMatchState
|
|
message={translate('tasks.githubProjectList.noMatches', 'No project items match.')}
|
|
onClear={() => clearMobileTasksSearch(model)}
|
|
bottomInset={bottomBarHeight}
|
|
/>
|
|
) : !githubProjectTable || visibleGitHubProjectRows.length === 0 ? (
|
|
<MobileStateView
|
|
icon={Inbox}
|
|
title={translate('tasks.githubProjectList.noItems', 'No project items')}
|
|
bottomInset={bottomBarHeight}
|
|
/>
|
|
) : (
|
|
<FlatList
|
|
data={githubProjectListEntries}
|
|
extraData={colorScheme}
|
|
keyExtractor={(entry) => (entry.type === 'group' ? `group:${entry.group.key}` : entry.row.id)}
|
|
ItemSeparatorComponent={() => <View style={styles.separator} />}
|
|
contentContainerStyle={[
|
|
styles.list,
|
|
{ paddingBottom: spacing.lg + Math.max(insets.bottom, bottomBarHeight) }
|
|
]}
|
|
refreshing={githubProjectLoading}
|
|
onRefresh={refreshGitHubProject}
|
|
renderItem={({ item: entry }) => {
|
|
if (entry.type === 'group') {
|
|
return (
|
|
<Pressable
|
|
style={({ pressed }) => [styles.projectGroupHeader, pressed && pressedStyle]}
|
|
onPress={() =>
|
|
setCollapsedGitHubProjectGroups((current) => {
|
|
const next = new Set(current)
|
|
if (next.has(entry.group.key)) {
|
|
next.delete(entry.group.key)
|
|
} else {
|
|
next.add(entry.group.key)
|
|
}
|
|
return next
|
|
})
|
|
}
|
|
>
|
|
<ChevronDown
|
|
size={14}
|
|
color={colors.textMuted}
|
|
style={entry.collapsed ? styles.projectGroupChevronCollapsed : undefined}
|
|
/>
|
|
<Text style={styles.projectGroupTitle} numberOfLines={1}>
|
|
{entry.group.label || translate('tasks.githubProjectList.items', 'Items')}
|
|
</Text>
|
|
<Text style={styles.projectGroupMeta}>{projectGroupMeta(entry.group)}</Text>
|
|
</Pressable>
|
|
)
|
|
}
|
|
const row = entry.row
|
|
const repo = findProjectRowRepo(row)
|
|
return (
|
|
<Pressable
|
|
style={({ pressed }) => [styles.taskRow, pressed && styles.taskRowPressed]}
|
|
onPress={() => {
|
|
setProjectRowItem(row)
|
|
}}
|
|
>
|
|
<View style={styles.taskIcon}>
|
|
<TaskProviderLogo provider="github" size={15} color={colors.textSecondary} />
|
|
</View>
|
|
<View style={styles.taskMain}>
|
|
<View style={styles.taskTitleRow}>
|
|
<Text style={styles.taskTitle} numberOfLines={2}>
|
|
{row.content.title}
|
|
</Text>
|
|
<Text style={styles.updatedAt}>{formatUpdatedAt(row.updatedAt)}</Text>
|
|
</View>
|
|
<View style={styles.metaRow}>
|
|
<View
|
|
style={[
|
|
styles.repoDot,
|
|
{
|
|
backgroundColor: getRepoBadgeColor(repo ?? undefined)
|
|
}
|
|
]}
|
|
/>
|
|
<Text style={styles.subtitle} numberOfLines={1}>
|
|
{row.itemType === 'PULL_REQUEST'
|
|
? translate(
|
|
'tasks.githubProjectList.pullRequestSubtitle',
|
|
'Pull request · {{repository}}{{number}}',
|
|
{
|
|
repository: row.content.repository ?? githubProjectTable.project.title,
|
|
number: row.content.number ? ` #${row.content.number}` : ''
|
|
}
|
|
)
|
|
: row.itemType === 'ISSUE'
|
|
? translate(
|
|
'tasks.githubProjectList.issueSubtitle',
|
|
'Issue · {{repository}}{{number}}',
|
|
{
|
|
repository: row.content.repository ?? githubProjectTable.project.title,
|
|
number: row.content.number ? ` #${row.content.number}` : ''
|
|
}
|
|
)
|
|
: translate(
|
|
'tasks.githubProjectList.itemSubtitle',
|
|
'Project item · {{repository}}{{number}}',
|
|
{
|
|
repository: row.content.repository ?? githubProjectTable.project.title,
|
|
number: row.content.number ? ` #${row.content.number}` : ''
|
|
}
|
|
)}
|
|
</Text>
|
|
</View>
|
|
{githubProjectSummaryFields.length > 0 ? (
|
|
<View style={styles.projectFieldPillRow}>
|
|
{githubProjectSummaryFields.slice(0, 4).map((field) => {
|
|
const isEmpty = isProjectFieldEmpty(row, field)
|
|
const value = isEmpty
|
|
? translate('tasks.githubProjectList.emptyField', 'Empty')
|
|
: projectFieldDisplayLabel(row, field)
|
|
return (
|
|
<View key={field.id} style={styles.projectFieldPill}>
|
|
<Text style={styles.projectFieldPillText} numberOfLines={1}>
|
|
{field.name}:{' '}
|
|
<Text style={isEmpty ? styles.projectFieldPillEmptyText : undefined}>
|
|
{value}
|
|
</Text>
|
|
</Text>
|
|
</View>
|
|
)
|
|
})}
|
|
{githubProjectSummaryFields.length > 4 ? (
|
|
<View style={styles.projectFieldPill}>
|
|
<Text style={styles.projectFieldPillText}>
|
|
{count === 1
|
|
? translate(
|
|
'tasks.githubProjectList.moreFields_one',
|
|
'+{{count}} field',
|
|
{ count }
|
|
)
|
|
: translate(
|
|
'tasks.githubProjectList.moreFields_other',
|
|
'+{{count}} fields',
|
|
{ count }
|
|
)}
|
|
</Text>
|
|
</View>
|
|
) : null}
|
|
</View>
|
|
) : null}
|
|
</View>
|
|
<View style={styles.statusPill}>
|
|
<Text style={styles.statusText} numberOfLines={1}>
|
|
{projectRowStatusLabel(row)}
|
|
</Text>
|
|
</View>
|
|
</Pressable>
|
|
)
|
|
}}
|
|
/>
|
|
)
|
|
}
|