From 80e715c58c22efa96305ce680891fa946a7c7252 Mon Sep 17 00:00:00 2001 From: Bharathwaj G Date: Tue, 18 Oct 2022 13:01:55 +0530 Subject: [PATCH] fixes --- .../point_in_time_flyout.tsx | 7 +++++-- .../point_in_time_table.tsx | 19 +++++++++++-------- .../server/saved_objects/point_in_time.ts | 2 +- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/plugins/my_plugin_name/components/point_in_time_flyout/point_in_time_flyout.tsx b/plugins/my_plugin_name/components/point_in_time_flyout/point_in_time_flyout.tsx index bd9123babf5..66247cd07fc 100644 --- a/plugins/my_plugin_name/components/point_in_time_flyout/point_in_time_flyout.tsx +++ b/plugins/my_plugin_name/components/point_in_time_flyout/point_in_time_flyout.tsx @@ -64,7 +64,8 @@ export interface SavedObjectReference { export interface PointInTime { name: string, keepAlive: string, - id: string + id: string, + title: string } export async function getIndexPatterns(savedObjectsClient) { return ( @@ -131,6 +132,7 @@ export async function findByTitle(client, title: string) { interface Props extends RouteComponentProps { setIsFlyoutVisible: (isFlyoutVisible: boolean) => void; + isFlyoutVisible: boolean; } export const PointInTimeFlyout = (props:Props) => { @@ -192,6 +194,7 @@ export const PointInTimeFlyout = (props:Props) => { const response = await http.post(`${CREATE_POINT_IN_TIME_PATH}/${index}`); const pit:PointInTime = { name: pitName, + title: pitName, keepAlive: keepAlive, id: response.pit_id // Todo create pit and fill the pit id } @@ -229,7 +232,7 @@ export const PointInTimeFlyout = (props:Props) => { pointintime.id = response.id; setLoading(false); setIsFlyoutVisible(false); - props.setIsFlyoutVisible(true); + props.setIsFlyoutVisible(!props.isFlyoutVisible); return pointintime; } diff --git a/plugins/my_plugin_name/components/point_in_time_table/point_in_time_table.tsx b/plugins/my_plugin_name/components/point_in_time_table/point_in_time_table.tsx index 9c10f03d5e0..f9d8b548be6 100644 --- a/plugins/my_plugin_name/components/point_in_time_table/point_in_time_table.tsx +++ b/plugins/my_plugin_name/components/point_in_time_table/point_in_time_table.tsx @@ -43,6 +43,7 @@ import { } from '../../../../src/plugins/opensearch_dashboards_react/public'; import { PointInTimeFlyout } from '../point_in_time_flyout'; import { IndexPatternManagmentContext } from '../point_in_time_flyout/point_in_time_flyout'; +import moment from 'moment'; const pagination = { @@ -132,15 +133,17 @@ export async function getPits(savedObjects) { const name = pattern.get('name'); const keepAlive = pattern.get('keepAlive'); const source = pattern.references[0].name; - const creation = pattern.updated_at; + const creation = moment(pattern.updated_at).format("YYYYMMDD HH:mm:ss"); var date1 = new Date(); - var date2 = new Date(creation); - var diff = new Date(date2.getTime() - date1.getTime()); + var date2 = new Date(pattern.updated_at); + var diff = new Date(date1.getTime() - date2.getTime()); console.log(diff); - var years = diff.getUTCFullYear() - 1970; // Gives difference as year - var months = diff.getUTCMonth(); // Gives month count of difference - var days = diff.getUTCDate()-1; // Gives day count of difference - const expiration = diff.getUTCHours(); + let expiration = "0"; + if(keepAlive < diff.getUTCHours() + 1) + expiration = "Expired"; + else + expiration = (24 - (diff.getUTCHours() + 1)).toString(); + return { id, title: name, @@ -412,7 +415,7 @@ export const PointInTimeTable = ({ canSave, history }: Props) => { - + diff --git a/plugins/my_plugin_name/server/saved_objects/point_in_time.ts b/plugins/my_plugin_name/server/saved_objects/point_in_time.ts index 5109749358b..ae5df1ab21e 100644 --- a/plugins/my_plugin_name/server/saved_objects/point_in_time.ts +++ b/plugins/my_plugin_name/server/saved_objects/point_in_time.ts @@ -14,7 +14,7 @@ export const pointInTime: SavedObjectsType = { defaultSearchField: 'title', importableAndExportable: true, getTitle(obj) { - return obj.attributes.title; + return obj.attributes.name; }, // getEditUrl(obj) { // return `/management/opensearch-dashboards/dataSources/${encodeURIComponent(obj.id)}`;