<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Adding timeframe selector in CustomApp in Developer Q&amp;A Forum</title>
    <link>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Adding-timeframe-selector-in-CustomApp/m-p/269591#M1303</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.dynatrace.com/t5/user/viewprofilepage/user-id/75062"&gt;@Tanveermd&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I was also creating one app having same use case, i did it using the below simple steps.&lt;BR /&gt;1) Create a hook for state variable as&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;  const [value, setValue] = useState&amp;lt;TimeframeV2 | null&amp;gt;(null);&lt;/LI-CODE&gt;&lt;P&gt;2) Use TimeFrame Component as below with &lt;STRONG&gt;onChange prop &lt;/STRONG&gt;that will help you to get new selected timeframe object &lt;STRONG&gt;and value prop&amp;nbsp;&lt;/STRONG&gt; which is an object contains two sub objects&amp;nbsp;&lt;STRONG&gt;from&lt;/STRONG&gt; and &lt;STRONG&gt;to.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;=======================&lt;BR /&gt;&lt;/STRONG&gt;from : value.from.value&lt;BR /&gt;to: value.to.value&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;=======================&lt;/STRONG&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;TimeframeSelector style={{ alignItems: "right" }} value={value} onChange={setValue} /&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;3)Finally if you have to now give dynamic timeframe to dql query here is the query with null conditions resolved.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;const fetchDistinctBizEvents = `fetch bizevents, from:{${value == null ? "now()-24h" : value?.from.value}}, to:{${value == null ? "now()" : value?.to.value}}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;BR /&gt;Thanks&lt;/P&gt;</description>
    <pubDate>Mon, 10 Feb 2025 11:33:08 GMT</pubDate>
    <dc:creator>zaid-bashir</dc:creator>
    <dc:date>2025-02-10T11:33:08Z</dc:date>
    <item>
      <title>Adding timeframe selector in CustomApp</title>
      <link>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Adding-timeframe-selector-in-CustomApp/m-p/267853#M1271</link>
      <description>&lt;P&gt;Hello there, I have created a custom app to display the trend of problems in a bar chart and how are they trending over a period of time side by side, it all looks well when built, but I think I am only able to see last 2 hours of data by default and I wanted to add timeframe selector to control the data display...I have referred&amp;nbsp;&amp;nbsp;&lt;A href="https://developer.dynatrace.com/design/components-preview/forms/TimeframeSelector/" target="_blank" rel="noopener"&gt;https://developer.dynatrace.com/design/components-preview/forms/TimeframeSelector/&lt;/A&gt;&amp;nbsp;but when adding this to the code, it doesn't appear to apply...I am fairly new to ReactJS and need help here pl.&lt;/P&gt;
&lt;P&gt;Highlighted in bold is the code I have added referring to the Dynatrace Developer documentation but I no luck so far&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;import React,&lt;STRONG&gt; { useState }&lt;/STRONG&gt; from 'react';&lt;BR /&gt;import { Flex } from '@dynatrace/strato-components/layouts';&lt;BR /&gt;import { TitleBar } from '@dynatrace/strato-components-preview/layouts';&lt;BR /&gt;import { ProgressCircle } from '@dynatrace/strato-components/content';&lt;BR /&gt;import { convertToTimeseries&amp;nbsp;} from '@dynatrace/strato-components-preview/conversion-utilities';&lt;BR /&gt;import {&amp;nbsp;DataTable,TableColumn } from '@dynatrace/strato-components-preview/tables';&lt;BR /&gt;import { useDqlQuery } from '@dynatrace-sdk/react-hooks';&lt;BR /&gt;import { PROBLEMS_QUERY } from '../queries';&lt;BR /&gt;import { Colors } from '@dynatrace/strato-design-tokens';&lt;BR /&gt;&lt;STRONG&gt;import type { TimeframeV2 } from '@dynatrace/strato-components-preview/core';&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;import { TimeframeSelector } from '@dynatrace/strato-components-preview/forms';&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;export const ProblemsList = () =&amp;gt; {&lt;BR /&gt;const result = useDqlQuery({&lt;BR /&gt;body: {&lt;BR /&gt;query: PROBLEMS_QUERY,&lt;BR /&gt;},&lt;BR /&gt;});&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;const Controlled = () =&amp;gt; {&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;const [value, setValue] = useState&amp;lt;TimeframeV2 | null&amp;gt;(null);&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;return &amp;lt;TimeframeSelector value={value} onChange={setValue} /&amp;gt;;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;};&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;const columns: TableColumn[] = [&lt;BR /&gt;{&lt;BR /&gt;header: 'Event Category',&lt;/P&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jan 2025 08:28:54 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Adding-timeframe-selector-in-CustomApp/m-p/267853#M1271</guid>
      <dc:creator>Tanveermd</dc:creator>
      <dc:date>2025-01-20T08:28:54Z</dc:date>
    </item>
    <item>
      <title>Re: Adding timeframe selector in CustomApp</title>
      <link>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Adding-timeframe-selector-in-CustomApp/m-p/267862#M1272</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://community.dynatrace.com/t5/user/viewprofilepage/user-id/75062"&gt;@Tanveermd&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;Before rendering the DataTable control,&amp;nbsp; you may need to check &lt;STRONG&gt;&lt;EM&gt;isLoading&lt;/EM&gt;&lt;/STRONG&gt;&amp;nbsp;property from the &lt;STRONG&gt;&lt;EM&gt;result&lt;/EM&gt;&lt;/STRONG&gt;.&lt;BR /&gt;If &lt;EM&gt;true&lt;/EM&gt;, show something that is loading the data, once is &lt;EM&gt;false&lt;/EM&gt;, show the DataTable.&lt;BR /&gt;You may also consider the examples related to DataTableV2 control.&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jan 2025 04:22:15 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Adding-timeframe-selector-in-CustomApp/m-p/267862#M1272</guid>
      <dc:creator>chris_cho</dc:creator>
      <dc:date>2025-01-20T04:22:15Z</dc:date>
    </item>
    <item>
      <title>Re: Adding timeframe selector in CustomApp</title>
      <link>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Adding-timeframe-selector-in-CustomApp/m-p/268021#M1276</link>
      <description>&lt;P&gt;&lt;a href="https://community.dynatrace.com/t5/user/viewprofilepage/user-id/75062"&gt;@Tanveermd&lt;/a&gt;&amp;nbsp;You have to pass the value from the timeframe selector to the useDqlQuery hook to make it work, as following:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;const queryResult = useDqlQuery({
    body: {
      query: "fetch logs",
      defaultTimeframeStart: value?.from.absoluteDate,
      defaultTimeframeEnd: value?.to.absoluteDate,
    }
});&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;BR /&gt;Let me know it works&lt;BR /&gt;Indermohan Singh&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jan 2025 15:28:15 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Adding-timeframe-selector-in-CustomApp/m-p/268021#M1276</guid>
      <dc:creator>imsingh</dc:creator>
      <dc:date>2025-01-21T15:28:15Z</dc:date>
    </item>
    <item>
      <title>Re: Adding timeframe selector in CustomApp</title>
      <link>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Adding-timeframe-selector-in-CustomApp/m-p/269416#M1299</link>
      <description>&lt;P&gt;take in consideration if you've any dependent components like filtration bar form you'll need to save its state before refetch your DQL Query when you change the timeframe value try the below&lt;/P&gt;&lt;P&gt;queries.ts&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;export const PROBLEMS_QUERY = (timeframeFrom, timeframeTo) =&amp;gt; {
    return `fetch ..problems.. , from:${timeframe}, to:${timeframeTo}`
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ProblemList.tsx&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;import React, { useState } from 'react';
import { Flex } from '@dynatrace/strato-components/layouts';
import { TitleBar } from '@dynatrace/strato-components-preview/layouts';
import { ProgressCircle } from '@dynatrace/strato-components/content';
import { convertToTimeseries } from '@dynatrace/strato-components-preview/conversion-utilities';
import { DataTable,TableColumn } from '@dynatrace/strato-components-preview/tables';
import { useDqlQuery } from '@dynatrace-sdk/react-hooks';
import { PROBLEMS_QUERY } from '../queries';
import { Colors } from '@dynatrace/strato-design-tokens';
import type { TimeframeV2 } from '@dynatrace/strato-components-preview/core';
import { TimeframeSelector } from '@dynatrace/strato-components-preview/forms';

export const ProblemsList = () =&amp;gt; {
    const [timeframeValue, setTimeframeValue] = useState&amp;lt;TimeframeV2 | null&amp;gt;(null);
    const [filtrationValues, setFiltraionValues] = useState&amp;lt;object | null&amp;gt;(null);

    const queryResult = useDqlQuery({
        body: {
            query: PROBLEMS_QUERY(timeframeValue.from, timeframeValue.to)
    });

    const handleProblemFilterChange = (filterValues) =&amp;gt; {
        setFilterValues(filterValues);
        // the rest of your filtration logic
    }

    useEffect(() =&amp;gt; {
        if(filtrationValues !== null) {
            handleProblemFilterChange(filtrationValues);
        }
    }, [queryResult]);
    return (.. your react components ..)
});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;without this, every time you change the timeframe values the other dependent components states will be reset to nulls &lt;EM&gt;(e.g. problem state)&lt;/EM&gt; and you've to re-select its old values again.&lt;/P&gt;&lt;P&gt;hope this helps,&lt;BR /&gt;Mostafa Hussein.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Feb 2025 11:25:26 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Adding-timeframe-selector-in-CustomApp/m-p/269416#M1299</guid>
      <dc:creator>MostafaHussein</dc:creator>
      <dc:date>2025-02-06T11:25:26Z</dc:date>
    </item>
    <item>
      <title>Re: Adding timeframe selector in CustomApp</title>
      <link>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Adding-timeframe-selector-in-CustomApp/m-p/269591#M1303</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.dynatrace.com/t5/user/viewprofilepage/user-id/75062"&gt;@Tanveermd&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I was also creating one app having same use case, i did it using the below simple steps.&lt;BR /&gt;1) Create a hook for state variable as&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;  const [value, setValue] = useState&amp;lt;TimeframeV2 | null&amp;gt;(null);&lt;/LI-CODE&gt;&lt;P&gt;2) Use TimeFrame Component as below with &lt;STRONG&gt;onChange prop &lt;/STRONG&gt;that will help you to get new selected timeframe object &lt;STRONG&gt;and value prop&amp;nbsp;&lt;/STRONG&gt; which is an object contains two sub objects&amp;nbsp;&lt;STRONG&gt;from&lt;/STRONG&gt; and &lt;STRONG&gt;to.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;=======================&lt;BR /&gt;&lt;/STRONG&gt;from : value.from.value&lt;BR /&gt;to: value.to.value&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;=======================&lt;/STRONG&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;TimeframeSelector style={{ alignItems: "right" }} value={value} onChange={setValue} /&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;3)Finally if you have to now give dynamic timeframe to dql query here is the query with null conditions resolved.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;const fetchDistinctBizEvents = `fetch bizevents, from:{${value == null ? "now()-24h" : value?.from.value}}, to:{${value == null ? "now()" : value?.to.value}}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;BR /&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 10 Feb 2025 11:33:08 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Adding-timeframe-selector-in-CustomApp/m-p/269591#M1303</guid>
      <dc:creator>zaid-bashir</dc:creator>
      <dc:date>2025-02-10T11:33:08Z</dc:date>
    </item>
  </channel>
</rss>

