From f1a41ed76ccffef18162684ea421a9484515df18 Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Thu, 20 Jun 2024 16:55:17 -0700 Subject: [PATCH] feat: allow date_nanos dates in timestamp selection (#795) (#799) Signed-off-by: Babacar Diasse (cherry picked from commit 89b60569713935a1338c34afcc96f536a0beec15) Co-authored-by: jehuty0shift --- .../components/Timestamp/Timestamp.tsx | 10 +- .../Timestamp/__tests__/Timestamp.test.tsx | 105 ++++++++++++ .../__snapshots__/Timestamp.test.tsx.snap | 157 ++++++++++++++++++ public/redux/reducers/opensearch.ts | 1 + 4 files changed, 271 insertions(+), 2 deletions(-) create mode 100644 public/pages/DefineDetector/components/Timestamp/__tests__/Timestamp.test.tsx create mode 100644 public/pages/DefineDetector/components/Timestamp/__tests__/__snapshots__/Timestamp.test.tsx.snap diff --git a/public/pages/DefineDetector/components/Timestamp/Timestamp.tsx b/public/pages/DefineDetector/components/Timestamp/Timestamp.tsx index 48431fe8..6c454306 100644 --- a/public/pages/DefineDetector/components/Timestamp/Timestamp.tsx +++ b/public/pages/DefineDetector/components/Timestamp/Timestamp.tsx @@ -52,9 +52,15 @@ export function Timestamp(props: TimestampProps) { get(opensearchState, 'dataTypes.date', []) as string[] ); - const timeStampFieldOptions = isEmpty(dateFields) + const dateNanoFields = Array.from( + get(opensearchState, 'dataTypes.date_nanos', []) as string[] + ); + + const allDateFields = dateFields.concat(dateNanoFields); + + const timeStampFieldOptions = isEmpty(allDateFields) ? [] - : dateFields.map((dateField) => ({ label: dateField })); + : allDateFields.map((dateField) => ({ label: dateField })); return ( ; + +describe(' spec', () => { + test('renders the component', () => { + const { container } = render( + + + + ( + + + + + + )} + /> + + + + ); + expect(container.firstChild).toMatchSnapshot(); + }); +}); diff --git a/public/pages/DefineDetector/components/Timestamp/__tests__/__snapshots__/Timestamp.test.tsx.snap b/public/pages/DefineDetector/components/Timestamp/__tests__/__snapshots__/Timestamp.test.tsx.snap new file mode 100644 index 00000000..e08375b8 --- /dev/null +++ b/public/pages/DefineDetector/components/Timestamp/__tests__/__snapshots__/Timestamp.test.tsx.snap @@ -0,0 +1,157 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[` spec renders the component 1`] = ` +
+
+
+

+ Timestamp +

+
+
+ Select the time field you want to use for the time filter. +
+
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+ +
+
+
+
+`; diff --git a/public/redux/reducers/opensearch.ts b/public/redux/reducers/opensearch.ts index fd153bca..4a9a3d32 100644 --- a/public/redux/reducers/opensearch.ts +++ b/public/redux/reducers/opensearch.ts @@ -45,6 +45,7 @@ export interface DataTypes { half_float?: string[]; boolean?: string[]; date?: string[]; + date_nanos?: string[]; keyword?: string[]; text?: string[]; integer_range?: string[];