perf(前端): 模板排序

dev/voice
Lei OT 7 months ago
parent a8156f33ed
commit c10319e8d5

@ -11,9 +11,6 @@ import dayjs from 'dayjs';
*/
export const fetchTemplates = async (params) => {
const data = await fetchJSON(`${API_HOST}/listtemplates`, params);
const canUseTemplates = (data?.result?.items || [])
.filter((_t) => _t.status === 'APPROVED' && !['say_hello_from_trip_advisor','free_style_7','free_style_1','free_style_2'].includes(_t.name))
.map((ele, i) => ({ ...ele, components_origin: ele.components, components: groupBy(ele.components, (_c) => _c.type.toLowerCase()), key:ele.name, displayName: templatesDisplayNameMap?.[ele.name] || ele.name}));
const topName = [
'order_updated_specialist_assigned_sharon',
'online_inquiry_received',
@ -23,11 +20,23 @@ export const fetchTemplates = async (params) => {
'order_resumed_specialist_followup_schedule_sharon',
// 'free_style_3',
// 'free_style_4',
]
const top = sortArrayByOrder( canUseTemplates.filter((_t) => topName.includes(_t.name)), 'name', topName);
];
const canUseTemplates = (data?.result?.items || [])
.filter((_t) => _t.status === 'APPROVED' && !['say_hello_from_trip_advisor', 'free_style_7', 'free_style_1', 'free_style_2'].includes(_t.name))
.map((ele, i) => ({
...ele,
components_origin: ele.components,
components: groupBy(ele.components, (_c) => _c.type.toLowerCase()),
key: ele.name,
displayName: ele.name.startsWith('order_updated') ? templatesDisplayNameMap['order_updated'] : templatesDisplayNameMap?.[ele.name] || ele.name,
}))
const top2Name = topName.concat(canUseTemplates.filter(_t => _t.name.startsWith('order_updated')).map(_tem => _tem.name));
const top = sortArrayByOrder( canUseTemplates.filter((_t) => top2Name.includes(_t.name)), 'name', topName);
const second = canUseTemplates.filter(_t => _t.name.includes('free_style'));
const secondS = second.sort(sortBy('name'));
const raw = canUseTemplates.filter((_t) => !topName.includes(_t.name) && !_t.name.includes('free_style'));
const raw = canUseTemplates.filter((_t) => !top2Name.includes(_t.name) && !_t.name.includes('free_style'));
return [...top, ...secondS, ...raw];
};
/**
@ -42,6 +51,7 @@ const templatesDisplayNameMap = {
'order_updated_specialist_assigned_christy': 'specialist_followup',
'online_inquiry_received': 'online_inquiry_received/say_hello',
'order_resumed_specialist_followup_schedule_sharon': 'order_resumed/specialist_followup',
'order_updated': 'specialist_followup',
};
export const CONVERSATION_PAGE_SIZE = 50;

@ -3,7 +3,7 @@ import { App, Popover, Flex, Button, List, Input, Tabs, Tag, Alert, Divider } fr
import { MessageOutlined, SendOutlined } from '@ant-design/icons';
import useAuthStore from '@/stores/AuthStore';
import useConversationStore from '@/stores/ConversationStore';
import { cloneDeep, getNestedValue, groupBy, objectMapper, removeFormattingChars, sortArrayByOrder, TagColorStyle } from '@/utils/commons';
import { cloneDeep, getNestedValue, groupBy, objectMapper, removeFormattingChars, sortArrayByOrder, sortObjectsByKeysMap, TagColorStyle } from '@/utils/commons';
import { replaceTemplateString } from '@/channel/bubbleMsgUtils';
import { isEmpty } from '@/utils/commons';
import useStyleStore from '@/stores/StyleStore';
@ -184,7 +184,7 @@ const InputTemplate = ({ disabled = false, invokeSendMessage, channel }) => {
setDataSource([]);
// setDataSource(templates);
const mappedByCategory = groupBy(templates, 'category');
const mappedByLang = groupBy(templates, 'language');
const mappedByLang = sortObjectsByKeysMap(groupBy(templates, 'language'), ['en']); // todo:
setTemplateCMapped(mappedByCategory);
setTemplateLangMapped(mappedByLang);
return () => {};

Loading…
Cancel
Save