(improvement)(chat-sdk) optimize message card width and show table when metrics count is greater than 1 (#1496)

This commit is contained in:
williamhliu
2024-07-31 15:32:50 +08:00
committed by GitHub
parent 27a70de1be
commit 55abc883ab
7 changed files with 38 additions and 24 deletions

View File

@@ -157,6 +157,7 @@
} }
.ant-select-selection-placeholder { .ant-select-selection-placeholder {
margin-bottom: 0 !important;
padding-left: 0 !important; padding-left: 0 !important;
line-height: 38px !important; line-height: 38px !important;
} }

View File

@@ -127,9 +127,7 @@ const ExecuteItem: React.FC<Props> = ({
data={data} data={data}
chartIndex={chartIndex} chartIndex={chartIndex}
triggerResize={triggerResize} triggerResize={triggerResize}
onMsgContentTypeChange={type => { onMsgContentTypeChange={setMsgContentType}
setMsgContentType(type);
}}
/> />
)} )}
</Spin> </Spin>

View File

@@ -80,14 +80,13 @@ const ChatItem: React.FC<Props> = ({
const [dataCache, setDataCache] = useState<Record<number, { tip: string; data?: MsgDataType }>>( const [dataCache, setDataCache] = useState<Record<number, { tip: string; data?: MsgDataType }>>(
{} {}
); );
const [selectedRange, setSelectedRange] = useState<RangeValue | null>(null);
const prefixCls = `${PREFIX_CLS}-item`; const prefixCls = `${PREFIX_CLS}-item`;
const updateData = (res: Result<MsgDataType>) => { const updateData = (res: Result<MsgDataType>) => {
let tip: string = ''; let tip: string = '';
let data: MsgDataType | undefined = undefined; let data: MsgDataType | undefined = undefined;
const { queryColumns, queryResults, queryState, queryMode, response, chatContext, textResult } = const { queryColumns, queryResults, queryState, queryMode, response, chatContext } =
res.data || {}; res.data || {};
if (res.code === 400 || res.code === 401 || res.code === 412) { if (res.code === 400 || res.code === 401 || res.code === 412) {
tip = res.msg; tip = res.msg;
@@ -239,7 +238,6 @@ const ChatItem: React.FC<Props> = ({
const onDateInfoChange = (dates: [Dayjs | null, Dayjs | null] | null) => { const onDateInfoChange = (dates: [Dayjs | null, Dayjs | null] | null) => {
if (dates && dates[0] && dates[1]) { if (dates && dates[0] && dates[1]) {
const [start, end] = dates; const [start, end] = dates;
setSelectedRange([start, end] as RangeValue);
setDateInfo({ setDateInfo({
...(dateInfo || {}), ...(dateInfo || {}),
startDate: dayjs(start).format('YYYY-MM-DD'), startDate: dayjs(start).format('YYYY-MM-DD'),
@@ -247,13 +245,10 @@ const ChatItem: React.FC<Props> = ({
dateMode: 'BETWEEN', dateMode: 'BETWEEN',
unit: 0, unit: 0,
}); });
} else {
setSelectedRange(null);
} }
}; };
const handlePresetClick = (range: RangeValue) => { const handlePresetClick = (range: RangeValue) => {
setSelectedRange(range);
setDateInfo({ setDateInfo({
...(dateInfo || {}), ...(dateInfo || {}),
startDate: dayjs(range[0]).format('YYYY-MM-DD'), startDate: dayjs(range[0]).format('YYYY-MM-DD'),
@@ -329,10 +324,8 @@ const ChatItem: React.FC<Props> = ({
return ( return (
<div className={prefixCls}> <div className={prefixCls}>
{!isMobile && integrateSystem !== 'wiki' && ( {!isMobile && <IconFont type="icon-zhinengsuanfa" className={`${prefixCls}-avatar`} />}
<IconFont type="icon-zhinengsuanfa" className={`${prefixCls}-avatar`} /> <div className={isMobile ? `${prefixCls}-mobile-msg-card` : ''}>
)}
<div className={isMobile ? `${prefixCls}-mobile-msg-card` : `${prefixCls}-msg-card`}>
<div className={contentClass}> <div className={contentClass}>
<ParseTip <ParseTip
isSimpleMode={isSimpleMode} isSimpleMode={isSimpleMode}

View File

@@ -97,18 +97,13 @@
width: 100%; width: 100%;
} }
&-msg-card {
flex: 1;
}
&-content { &-content {
position: relative; position: relative;
box-sizing: border-box; box-sizing: border-box;
min-width: 1px; min-width: 1px;
max-width: 100%; max-width: 100%;
padding: 12px 16px; padding: 12px 20px 12px 16px;
background: #fff; background: #fff;
min-height: 100px;
border: 1px solid transparent; border: 1px solid transparent;
border-radius: 12px; border-radius: 12px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.14), 0 0 2px rgba(0, 0, 0, 0.12); box-shadow: 0 2px 4px rgba(0, 0, 0, 0.14), 0 0 2px rgba(0, 0, 0, 0.12);

View File

@@ -20,7 +20,7 @@ type Props = {
triggerResize?: boolean; triggerResize?: boolean;
forceShowTable?: boolean; forceShowTable?: boolean;
isSimpleMode?: boolean; isSimpleMode?: boolean;
onMsgContentTypeChange?: (MsgContentTypeEnum) => void; onMsgContentTypeChange: (msgContentType: MsgContentTypeEnum) => void;
}; };
const ChatMsg: React.FC<Props> = ({ const ChatMsg: React.FC<Props> = ({
@@ -65,7 +65,9 @@ const ChatMsg: React.FC<Props> = ({
setDrillDownDimension(undefined); setDrillDownDimension(undefined);
setSecondDrillDownDimension(undefined); setSecondDrillDownDimension(undefined);
}, [data]); }, [data]);
const metricFields = columns.filter(item => item.showType === 'NUMBER'); const metricFields = columns.filter(item => item.showType === 'NUMBER');
const getMsgContentType = () => { const getMsgContentType = () => {
const singleData = dataSource.length === 1; const singleData = dataSource.length === 1;
const dateField = columns.find(item => item.showType === 'DATE' || item.type === 'DATE'); const dateField = columns.find(item => item.showType === 'DATE' || item.type === 'DATE');
@@ -123,7 +125,7 @@ const ChatMsg: React.FC<Props> = ({
const isMetricBar = const isMetricBar =
categoryField?.length > 0 && categoryField?.length > 0 &&
metricFields?.length > 0 && metricFields?.length === 1 &&
(isMobile ? dataSource?.length <= 5 : dataSource?.length <= 50); (isMobile ? dataSource?.length <= 5 : dataSource?.length <= 50);
if (isMetricBar) { if (isMetricBar) {
@@ -132,6 +134,28 @@ const ChatMsg: React.FC<Props> = ({
return MsgContentTypeEnum.TABLE; return MsgContentTypeEnum.TABLE;
}; };
const getMsgStyle = (type: MsgContentTypeEnum) => {
if (isMobile) {
return { maxWidth: 'calc(100vw - 20px)' };
}
if (!queryResults?.length || !queryColumns.length) {
return;
}
if (type === MsgContentTypeEnum.METRIC_BAR) {
return {
[queryResults.length > 5 ? 'width' : 'minWidth']: queryResults.length * 150,
};
}
if (type === MsgContentTypeEnum.TABLE) {
return {
[queryColumns.length > 5 ? 'width' : 'minWidth']: queryColumns.length * 150,
};
}
if (type === MsgContentTypeEnum.METRIC_TREND) {
return { width: 'calc(100vw - 410px)' };
}
};
useEffect(() => { useEffect(() => {
const type = getMsgContentType(); const type = getMsgContentType();
if (type) { if (type) {
@@ -312,8 +336,11 @@ const ChatMsg: React.FC<Props> = ({
recommendMetrics?.length > 0 && recommendMetrics?.length > 0 &&
queryColumns?.filter(column => column.showType === 'NUMBER').length === 1; queryColumns?.filter(column => column.showType === 'NUMBER').length === 1;
const type = getMsgContentType();
const style = type ? getMsgStyle(type) : undefined;
return ( return (
<div className={chartMsgClass}> <div className={chartMsgClass} style={style}>
{dataSource?.length === 0 ? ( {dataSource?.length === 0 ? (
<div></div> <div></div>
) : ( ) : (

View File

@@ -7,6 +7,7 @@
border: 1px solid var(--border-color-base); border: 1px solid var(--border-color-base);
border-radius: 4px; border-radius: 4px;
background: #f5f8fb; background: #f5f8fb;
max-width: calc(100vw - 410px);
&-bottom-tools { &-bottom-tools {
display: flex; display: flex;
@@ -24,4 +25,4 @@
&-metric-card-tools { &-metric-card-tools {
margin-top: 0; margin-top: 0;
} }
} }

View File

@@ -1,7 +1,6 @@
import axios from './axiosInstance'; import axios from './axiosInstance';
import { import {
ChatContextType, ChatContextType,
EntityInfoType,
HistoryMsgItemType, HistoryMsgItemType,
HistoryType, HistoryType,
MsgDataType, MsgDataType,