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({