<?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: TimeframeSelector with useDqlQuery() in Developer Q&amp;A Forum</title>
    <link>https://community.dynatrace.com/t5/Developer-Q-A-Forum/TimeframeSelector-with-useDqlQuery/m-p/251470#M1033</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.dynatrace.com/t5/user/viewprofilepage/user-id/47129"&gt;@jegron&lt;/a&gt;, the type&amp;nbsp;&lt;CODE&gt;TimeframeSelectorProps['value']&lt;/CODE&gt; is nullable, and the type checker can't infer that &lt;CODE&gt;value&lt;/CODE&gt; is actually defined. You have two options:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Use the non-null assertion operator &lt;CODE&gt;!&lt;/CODE&gt; like this &lt;CODE&gt;value!.from&lt;/CODE&gt;. This is usually not recommended and will likely lead to a &lt;CODE&gt;Forbidden non-null assertion&lt;/CODE&gt; warning.&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN&gt;Use the optional chaining &lt;CODE&gt;?&lt;/CODE&gt; and nullish&amp;nbsp;coalescing &lt;CODE&gt;??&lt;/CODE&gt; operators, which allow you&amp;nbsp;to fall back to a default value when dealing with &lt;CODE&gt;null&lt;/CODE&gt; or &lt;CODE&gt;undefined&lt;/CODE&gt;. Here's how to use them:&lt;/SPAN&gt;&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;const DEFAULT_FROM = 'now()-14d';

const [value, setValue] = useState&amp;lt;TimeframeSelectorProps['value']&amp;gt;({
  from: DEFAULT_FROM,
  to: 'now()',
});

const CLUSTER = `fetch logs, from:'${value?.from ?? DEFAULT_FROM}'
| filter contains(log.source, "Dynatrace Automation Script")
| makeTimeseries count(), by:{content.cluster}, interval:30m`;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 24 Jul 2024 07:57:17 GMT</pubDate>
    <dc:creator>educampver</dc:creator>
    <dc:date>2024-07-24T07:57:17Z</dc:date>
    <item>
      <title>TimeframeSelector with useDqlQuery()</title>
      <link>https://community.dynatrace.com/t5/Developer-Q-A-Forum/TimeframeSelector-with-useDqlQuery/m-p/251338#M1029</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;How can I use TimeframeSelector with my DQL requests ?&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;A href="https://developer.dynatrace.com/reference/design-system/preview/forms/TimeframeSelector/" target="_blank" rel="noopener"&gt;https://developer.dynatrace.com/reference/design-system/preview/forms/TimeframeSelector/&lt;/A&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;My initial value is set correctly :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;const [value, setValue] = useState&amp;lt;TimeframeSelectorProps['value']&amp;gt;({
    from: 'now()-14d',
    to: 'now()',
  });

const CLUSTER = `fetch logs, from:'${value.from}'
| filter contains(log.source, "Dynatrace Automation Script")
| makeTimeseries count(), by:{content.cluster}, interval:30m`;

const cluster_result = useDqlQuery({
    body: {
      query: CLUSTER,
    },
  });&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But I failed to use it in my DQL because of :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;'value' is possibly 'null' or 'undefined'.ts(18049)
const value: RequireAtLeastOne&amp;lt;{
    from: string;
    to: string;
}&amp;gt; | RequireAtLeastOne&amp;lt;TimeframeV2&amp;gt; | null | undefined&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;Do you have an example to help me ?&lt;/P&gt;&lt;P&gt;Julien&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jul 2024 13:39:05 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Developer-Q-A-Forum/TimeframeSelector-with-useDqlQuery/m-p/251338#M1029</guid>
      <dc:creator>jegron</dc:creator>
      <dc:date>2024-07-23T13:39:05Z</dc:date>
    </item>
    <item>
      <title>Re: TimeframeSelector with useDqlQuery()</title>
      <link>https://community.dynatrace.com/t5/Developer-Q-A-Forum/TimeframeSelector-with-useDqlQuery/m-p/251470#M1033</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.dynatrace.com/t5/user/viewprofilepage/user-id/47129"&gt;@jegron&lt;/a&gt;, the type&amp;nbsp;&lt;CODE&gt;TimeframeSelectorProps['value']&lt;/CODE&gt; is nullable, and the type checker can't infer that &lt;CODE&gt;value&lt;/CODE&gt; is actually defined. You have two options:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Use the non-null assertion operator &lt;CODE&gt;!&lt;/CODE&gt; like this &lt;CODE&gt;value!.from&lt;/CODE&gt;. This is usually not recommended and will likely lead to a &lt;CODE&gt;Forbidden non-null assertion&lt;/CODE&gt; warning.&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN&gt;Use the optional chaining &lt;CODE&gt;?&lt;/CODE&gt; and nullish&amp;nbsp;coalescing &lt;CODE&gt;??&lt;/CODE&gt; operators, which allow you&amp;nbsp;to fall back to a default value when dealing with &lt;CODE&gt;null&lt;/CODE&gt; or &lt;CODE&gt;undefined&lt;/CODE&gt;. Here's how to use them:&lt;/SPAN&gt;&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;const DEFAULT_FROM = 'now()-14d';

const [value, setValue] = useState&amp;lt;TimeframeSelectorProps['value']&amp;gt;({
  from: DEFAULT_FROM,
  to: 'now()',
});

const CLUSTER = `fetch logs, from:'${value?.from ?? DEFAULT_FROM}'
| filter contains(log.source, "Dynatrace Automation Script")
| makeTimeseries count(), by:{content.cluster}, interval:30m`;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jul 2024 07:57:17 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Developer-Q-A-Forum/TimeframeSelector-with-useDqlQuery/m-p/251470#M1033</guid>
      <dc:creator>educampver</dc:creator>
      <dc:date>2024-07-24T07:57:17Z</dc:date>
    </item>
    <item>
      <title>Re: TimeframeSelector with useDqlQuery()</title>
      <link>https://community.dynatrace.com/t5/Developer-Q-A-Forum/TimeframeSelector-with-useDqlQuery/m-p/251632#M1037</link>
      <description>&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;My timeframe are now correctly update onChange :&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;&amp;lt;TimeframeSelector value={value} onChange={newValue =&amp;gt; {
          console.log('New timeframe selected:', newValue);
          setValue(newValue);
        }} clearable/&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jegron_0-1721917247590.png" style="width: 618px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/21394iF91E897D71860609/image-dimensions/618x85?v=v2" width="618" height="85" role="button" title="jegron_0-1721917247590.png" alt="jegron_0-1721917247590.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;But my "useDQLQuery()" requests/results are not refetch. What is the best way to do it ?&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jul 2024 14:25:47 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Developer-Q-A-Forum/TimeframeSelector-with-useDqlQuery/m-p/251632#M1037</guid>
      <dc:creator>jegron</dc:creator>
      <dc:date>2024-07-25T14:25:47Z</dc:date>
    </item>
    <item>
      <title>Re: TimeframeSelector with useDqlQuery()</title>
      <link>https://community.dynatrace.com/t5/Developer-Q-A-Forum/TimeframeSelector-with-useDqlQuery/m-p/252304#M1050</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://community.dynatrace.com/t5/user/viewprofilepage/user-id/47129"&gt;@jegron&lt;/a&gt;, the useDqlQuery hook returns a refetch function, which you could use in your onChange to refetch fresh grail data. Here is a code example on the &lt;A href="https://developer.dynatrace.com/develop/sdks/react-hooks/#simplified-data-querying-from-grail" target="_self"&gt;Dynatrace Developer Portal&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Aug 2024 06:32:56 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Developer-Q-A-Forum/TimeframeSelector-with-useDqlQuery/m-p/252304#M1050</guid>
      <dc:creator>StefanKern</dc:creator>
      <dc:date>2024-08-02T06:32:56Z</dc:date>
    </item>
  </channel>
</rss>

