mirror of
https://github.com/stablyai/orca.git
synced 2026-11-16 02:47:34 +00:00
fix(folder-workspaces): match hook search to workspace descriptions
This commit is contained in:
@@ -68,3 +68,53 @@ it('keeps a searched repository section editable when the query does not name th
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it.each([
|
||||
['folder', 'new workspace', 'Setup script'],
|
||||
['folder', 'workspace is removed', 'Archive script'],
|
||||
['git', 'new worktree', 'Setup script'],
|
||||
['git', 'worktree is archived', 'Archive script']
|
||||
] as const)('finds editable %s hooks for %s', (kind, query, scriptLabel) => {
|
||||
const repo: Repo = {
|
||||
id: 'project-1',
|
||||
path: '/tmp/sample-project',
|
||||
displayName: 'Sample project',
|
||||
badgeColor: '',
|
||||
addedAt: 0,
|
||||
...(kind === 'folder' ? { kind: 'folder' as const } : {})
|
||||
}
|
||||
const updateRepo = vi.fn()
|
||||
useAppStore.setState({
|
||||
settings: getDefaultSettings('/tmp'),
|
||||
settingsSearchQuery: query,
|
||||
repos: [repo]
|
||||
})
|
||||
render(
|
||||
<TooltipProvider>
|
||||
<RepositoryPane
|
||||
repo={repo}
|
||||
yamlHooks={null}
|
||||
hasHooksFile={false}
|
||||
hooksInspectionReady
|
||||
mayNeedUpdate={false}
|
||||
updateRepo={updateRepo}
|
||||
removeProject={vi.fn()}
|
||||
/>
|
||||
</TooltipProvider>
|
||||
)
|
||||
|
||||
const editor = screen.getByRole('textbox', { name: scriptLabel })
|
||||
fireEvent.change(editor, { target: { value: 'echo workspace-hook' } })
|
||||
fireEvent.blur(editor)
|
||||
expect(updateRepo).toHaveBeenCalledWith(
|
||||
'project-1',
|
||||
expect.objectContaining({
|
||||
hookSettings: expect.objectContaining({
|
||||
scripts: expect.objectContaining({
|
||||
[scriptLabel === 'Setup script' ? 'setup' : 'archive']: 'echo workspace-hook'
|
||||
})
|
||||
})
|
||||
}),
|
||||
expect.anything()
|
||||
)
|
||||
})
|
||||
|
||||
@@ -31,6 +31,7 @@ import {
|
||||
import { RepositoryIssueCommandSetting } from './RepositoryIssueCommandSetting'
|
||||
import { useRepositoryHookSettingsDraft } from './use-repository-hook-settings-draft'
|
||||
import { useRepositoryIssueCommand } from './use-repository-issue-command'
|
||||
import { getRepositoryHookScriptDescription } from './repository-git-hooks-search-entries'
|
||||
|
||||
type RepositoryHooksSectionProps = {
|
||||
repo: Repo
|
||||
@@ -126,17 +127,7 @@ export function RepositoryHooksSection({
|
||||
>
|
||||
<SearchableSetting
|
||||
title={t('auto.components.settings.RepositoryHooksSection.1ecf0b115a', 'Setup script')}
|
||||
description={
|
||||
isFolder
|
||||
? t(
|
||||
'components.settings.RepositoryHooksSection.folderSetupDescription',
|
||||
'Local and shared scripts that run after a new workspace is created.'
|
||||
)
|
||||
: t(
|
||||
'auto.components.settings.RepositoryHooksSection.30d555acd2',
|
||||
'Local and shared scripts that run after a new worktree is created.'
|
||||
)
|
||||
}
|
||||
description={getRepositoryHookScriptDescription(repo, 'setup', t)}
|
||||
className="py-4"
|
||||
forceVisible={forceVisible}
|
||||
keywords={[
|
||||
@@ -188,17 +179,7 @@ export function RepositoryHooksSection({
|
||||
</SearchableSetting>
|
||||
<SearchableSetting
|
||||
title={t('auto.components.settings.RepositoryHooksSection.bfdb1266ce', 'Archive script')}
|
||||
description={
|
||||
isFolder
|
||||
? t(
|
||||
'components.settings.RepositoryHooksSection.folderArchiveDescription',
|
||||
'Local and shared scripts that run before a workspace is removed.'
|
||||
)
|
||||
: t(
|
||||
'auto.components.settings.RepositoryHooksSection.b91a0f297d',
|
||||
'Local and shared scripts that run before a worktree is archived.'
|
||||
)
|
||||
}
|
||||
description={getRepositoryHookScriptDescription(repo, 'archive', t)}
|
||||
className="py-4"
|
||||
forceVisible={forceVisible}
|
||||
keywords={[
|
||||
|
||||
+29
-8
@@ -5,6 +5,33 @@ import { translate } from '@/i18n/i18n'
|
||||
import type { Translate } from '@/i18n/use-translate'
|
||||
import { searchKeywordTranslator } from '../../search/settings-search-keywords'
|
||||
|
||||
export function getRepositoryHookScriptDescription(
|
||||
repo: Repo,
|
||||
hook: 'setup' | 'archive',
|
||||
t: Translate
|
||||
): string {
|
||||
if (hook === 'setup') {
|
||||
return isFolderRepo(repo)
|
||||
? t(
|
||||
'components.settings.RepositoryHooksSection.folderSetupDescription',
|
||||
'Local and shared scripts that run after a new workspace is created.'
|
||||
)
|
||||
: t(
|
||||
'auto.components.settings.RepositoryHooksSection.30d555acd2',
|
||||
'Local and shared scripts that run after a new worktree is created.'
|
||||
)
|
||||
}
|
||||
return isFolderRepo(repo)
|
||||
? t(
|
||||
'components.settings.RepositoryHooksSection.folderArchiveDescription',
|
||||
'Local and shared scripts that run before a workspace is removed.'
|
||||
)
|
||||
: t(
|
||||
'auto.components.settings.RepositoryHooksSection.b91a0f297d',
|
||||
'Local and shared scripts that run before a worktree is archived.'
|
||||
)
|
||||
}
|
||||
|
||||
export function getRepositoryGitHooksSearchEntries(
|
||||
repo: Repo,
|
||||
t: Translate = translate
|
||||
@@ -13,10 +40,7 @@ export function getRepositoryGitHooksSearchEntries(
|
||||
return [
|
||||
{
|
||||
title: t('auto.components.settings.repository.search.810b9f4106', 'Setup script'),
|
||||
description: t(
|
||||
'auto.components.settings.repository.search.baaf70bb37',
|
||||
'Local and shared scripts that run after a new worktree is created.'
|
||||
),
|
||||
description: getRepositoryHookScriptDescription(repo, 'setup', t),
|
||||
keywords: [
|
||||
repo.displayName,
|
||||
...translateSearchKeyword('auto.components.settings.repository.search.8655e3387b', 'hooks'),
|
||||
@@ -42,10 +66,7 @@ export function getRepositoryGitHooksSearchEntries(
|
||||
},
|
||||
{
|
||||
title: t('auto.components.settings.repository.search.1617bc353d', 'Archive script'),
|
||||
description: t(
|
||||
'auto.components.settings.repository.search.acd1157f0c',
|
||||
'Local and shared scripts that run before a worktree is archived.'
|
||||
),
|
||||
description: getRepositoryHookScriptDescription(repo, 'archive', t),
|
||||
keywords: [
|
||||
repo.displayName,
|
||||
...translateSearchKeyword('auto.components.settings.repository.search.8655e3387b', 'hooks'),
|
||||
|
||||
Reference in New Issue
Block a user