You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@inlong.apache.org by do...@apache.org on 2022/03/28 14:46:59 UTC

[incubator-inlong] branch master updated: [INLONG-3390][Dashboard] Text form support date and array dataType (#3391)

This is an automated email from the ASF dual-hosted git repository.

dockerzhang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-inlong.git


The following commit(s) were added to refs/heads/master by this push:
     new ef4a8e8  [INLONG-3390][Dashboard] Text form support date and array dataType (#3391)
ef4a8e8 is described below

commit ef4a8e8f5eb1cb9d04d916630ec771f144e35bd5
Author: Daniel <le...@outlook.com>
AuthorDate: Mon Mar 28 22:46:52 2022 +0800

    [INLONG-3390][Dashboard] Text form support date and array dataType (#3391)
---
 .../src/components/FormGenerator/plugins.tsx       | 28 +++++++++++++---------
 1 file changed, 17 insertions(+), 11 deletions(-)

diff --git a/inlong-dashboard/src/components/FormGenerator/plugins.tsx b/inlong-dashboard/src/components/FormGenerator/plugins.tsx
index d71764a..30edbbb 100644
--- a/inlong-dashboard/src/components/FormGenerator/plugins.tsx
+++ b/inlong-dashboard/src/components/FormGenerator/plugins.tsx
@@ -18,6 +18,7 @@
  */
 
 import React from 'react';
+import dayjs from 'dayjs';
 import {
   Input,
   DatePicker,
@@ -36,17 +37,22 @@ import HighSelect from '@/components/HighSelect';
 import i18n from '@/i18n';
 
 const text: React.FC<Record<string, any>> = ({ value, options }) => {
-  if (!Array.isArray(options)) return <span>{value}</span>;
-
-  return (
-    (options &&
-      (Array.isArray(value)
-        ? options
-            .filter(item => value.includes(item.value))
-            .map(item => item.label)
-            .join(', ')
-        : options.find(item => item.value === value)?.label)) || <span>{value}</span>
-  );
+  if (dayjs.isDayjs[value]) {
+    return value.format('YYYY-MM-DD HH:mm');
+  }
+  if (Array.isArray(value) && value.every(dayjs.isDayjs)) {
+    return value.map(item => item.format('YYYY-MM-DD HH:mm')).join(' ~ ');
+  }
+  if (!Array.isArray(options) || !options) {
+    return <span>{Array.isArray(value) ? value.join(', ') : value}</span>;
+  }
+
+  return Array.isArray(value)
+    ? options
+        .filter(item => value.includes(item.value))
+        .map(item => item.label)
+        .join(', ')
+    : options.find(item => item.value === value)?.label || value || null;
 };
 
 const select = props => (