fix: 同步岗位配置中的模板名称
This commit is contained in:
parent
362a468d67
commit
c7ac95fc8f
@ -301,6 +301,49 @@ describe('PerformanceSurveyAdminConfig', () => {
|
||||
expect(screen.queryByRole('button', { name: '复制岗位' })).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
test('岗位模板搜索和已选考核项同步显示模板栏的最新名称', async () => {
|
||||
const configuration = {
|
||||
...config,
|
||||
groups: config.groups.map((group: any) => group.id === 'group-1'
|
||||
? {
|
||||
...group,
|
||||
effectivePlan: {
|
||||
...group.effectivePlan,
|
||||
templateVersionIds: [],
|
||||
},
|
||||
}
|
||||
: group),
|
||||
templates: config.templates.map((template: any) => template.id === 'template-1'
|
||||
? {
|
||||
...template,
|
||||
versions: [{
|
||||
...template.versions[0],
|
||||
id: 'version-draft-2',
|
||||
version: 2,
|
||||
status: 'draft',
|
||||
effectiveMonth: null,
|
||||
definition: {
|
||||
...template.versions[0].definition,
|
||||
name: '品牌创意部门',
|
||||
},
|
||||
}, template.versions[0]],
|
||||
}
|
||||
: template),
|
||||
}
|
||||
const request = createRequest(configuration)
|
||||
render(<PerformanceSurveyAdminConfig mode="positions" request={request} />)
|
||||
|
||||
await waitFor(() => expect(screen.getByRole('heading', { name: '岗位考核项' })).toBeInTheDocument())
|
||||
fireEvent.change(screen.getByLabelText('添加考核项'), { target: { value: '品牌创意部门' } })
|
||||
|
||||
const option = screen.getByRole('button', { name: /品牌创意部门.*v1/ })
|
||||
expect(option).toBeInTheDocument()
|
||||
expect(screen.queryByRole('button', { name: /视觉案例评分.*v1/ })).not.toBeInTheDocument()
|
||||
|
||||
fireEvent.click(option)
|
||||
expect(screen.getByText('品牌创意部门')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
test('新增岗位使用确定的 collection POST 契约', async () => {
|
||||
const request = createRequest()
|
||||
render(<PerformanceSurveyAdminConfig mode="positions" request={request} />)
|
||||
|
||||
@ -305,6 +305,10 @@ function getTemplateAvailability(template: TemplateRecord, month: string) {
|
||||
}
|
||||
}
|
||||
|
||||
function getTemplateDisplayName(template: TemplateRecord) {
|
||||
return template.versions[0]?.definition.name?.trim() || template.name
|
||||
}
|
||||
|
||||
function getTemplateListState(template: TemplateRecord, month: string): {
|
||||
label: string
|
||||
tone: StatusTone
|
||||
@ -891,7 +895,9 @@ function PositionConfigWorkspace({
|
||||
return availableTemplateVersions.filter(({ template, version }) => (
|
||||
!templateVersionIds.includes(version.id)
|
||||
&& !selectedTemplateIds.has(template.id)
|
||||
&& `${version.definition.name} ${template.name}`.toLocaleLowerCase('zh-CN').includes(keyword)
|
||||
&& `${getTemplateDisplayName(template)} ${version.definition.name} ${template.name}`
|
||||
.toLocaleLowerCase('zh-CN')
|
||||
.includes(keyword)
|
||||
)).slice(0, 8)
|
||||
}, [availableTemplateVersions, templateSearch, templateVersionIds, versionById])
|
||||
|
||||
@ -1164,7 +1170,7 @@ function PositionConfigWorkspace({
|
||||
className="flex min-h-11 w-full items-center justify-between gap-3 border-b border-[#eeeeee] px-3 py-2 text-left last:border-b-0 hover:bg-[#f4f6ff]"
|
||||
>
|
||||
<span className="min-w-0">
|
||||
<span className="block truncate text-[13px] font-bold text-[#1a1c1c]">{version.definition.name}</span>
|
||||
<span className="block truncate text-[13px] font-bold text-[#1a1c1c]">{getTemplateDisplayName(template)}</span>
|
||||
</span>
|
||||
<span className="shrink-0 text-[11px] text-[#5f5e5e]">v{version.version}</span>
|
||||
</button>
|
||||
@ -1181,7 +1187,7 @@ function PositionConfigWorkspace({
|
||||
return (
|
||||
<div key={id} className="grid grid-cols-[minmax(0,1fr)_auto] items-center gap-3 border border-[#c2c6d8] px-3 py-3">
|
||||
<div className="min-w-0">
|
||||
<div className="truncate text-[13px] font-bold text-[#1a1c1c]">{item?.version.definition.name || item?.template.name || '历史模板'}</div>
|
||||
<div className="truncate text-[13px] font-bold text-[#1a1c1c]">{item ? getTemplateDisplayName(item.template) : '历史模板'}</div>
|
||||
<div className="mt-0.5 text-[11px] text-[#727687]">
|
||||
第 {index + 1} 项{item ? ` · v${item.version.version}` : ''}
|
||||
</div>
|
||||
@ -1449,7 +1455,7 @@ function TemplateConfigWorkspace({
|
||||
}
|
||||
|
||||
const selectedTemplateName = selectedTemplate
|
||||
? selectedTemplate.versions[0]?.definition.name || selectedTemplate.name
|
||||
? getTemplateDisplayName(selectedTemplate)
|
||||
: '新建模板'
|
||||
const selectedTemplateState = selectedTemplate
|
||||
? getTemplateListState(selectedTemplate, month)
|
||||
@ -1482,7 +1488,7 @@ function TemplateConfigWorkspace({
|
||||
<option value="new">+ 新建模板</option>
|
||||
{data.templates.map((template) => (
|
||||
<option key={template.id} value={template.id}>
|
||||
{template.versions[0]?.definition.name || template.name}
|
||||
{getTemplateDisplayName(template)}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
@ -1506,7 +1512,7 @@ function TemplateConfigWorkspace({
|
||||
</div>
|
||||
{data.templates.map((template) => {
|
||||
const state = getTemplateListState(template, month)
|
||||
const templateName = template.versions[0]?.definition.name || template.name
|
||||
const templateName = getTemplateDisplayName(template)
|
||||
return (
|
||||
<button
|
||||
key={template.id}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user