From 5ffd617431465f284d6219dcade35725fd7eafe5 Mon Sep 17 00:00:00 2001 From: williamhliu <137068196+williamhliu@users.noreply.github.com> Date: Sat, 8 Jul 2023 11:51:26 +0800 Subject: [PATCH] metric trend add default date option selected (#12) * [feature](webapp) modify multy-turn conversation and optimize css styles * [feature](chat-sdk) add default date option selected --- .../src/components/ChatMsg/MetricTrend/index.tsx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/webapp/packages/chat-sdk/src/components/ChatMsg/MetricTrend/index.tsx b/webapp/packages/chat-sdk/src/components/ChatMsg/MetricTrend/index.tsx index ee3acb445..268bacbb3 100644 --- a/webapp/packages/chat-sdk/src/components/ChatMsg/MetricTrend/index.tsx +++ b/webapp/packages/chat-sdk/src/components/ChatMsg/MetricTrend/index.tsx @@ -17,12 +17,18 @@ type Props = { const MetricTrend: React.FC = ({ data, triggerResize, onApplyAuth, onCheckMetricInfo }) => { const { queryColumns, queryResults, entityInfo, chatContext } = data; + + const dateOptions = DATE_TYPES[chatContext?.dateInfo?.period] || DATE_TYPES[0]; + const initialDateOption = dateOptions.find( + (option: any) => option.value === chatContext?.dateInfo?.unit + )?.value; + const [columns, setColumns] = useState(queryColumns); const currentMetricField = columns.find((column: any) => column.showType === 'NUMBER'); const [activeMetricField, setActiveMetricField] = useState(chatContext.metrics?.[0]); const [dataSource, setDataSource] = useState(queryResults); - const [currentDateOption, setCurrentDateOption] = useState(); + const [currentDateOption, setCurrentDateOption] = useState(initialDateOption); const [loading, setLoading] = useState(false); const dateField: any = columns.find( @@ -36,8 +42,6 @@ const MetricTrend: React.FC = ({ data, triggerResize, onApplyAuth, onChec setDataSource(queryResults); }, [queryResults]); - const dateOptions = DATE_TYPES[chatContext?.dateInfo?.period] || DATE_TYPES[0]; - const onLoadData = async (value: any) => { setLoading(true); const { data } = await queryData({