From b3e03054bc8d1e1c9e5fb9807bbc80cf76aa75c8 Mon Sep 17 00:00:00 2001 From: Tyler Ohlsen Date: Tue, 26 Mar 2024 15:22:49 -0700 Subject: [PATCH] Integrate with update timestamps (#115) Signed-off-by: Tyler Ohlsen --- common/constants.ts | 2 ++ common/utils.ts | 6 ++++++ public/pages/workflows/workflow_list/columns.tsx | 15 ++++++++++++++- server/routes/helpers.ts | 8 ++------ 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/common/constants.ts b/common/constants.ts index 20a7a2a7..eb10828f 100644 --- a/common/constants.ts +++ b/common/constants.ts @@ -37,3 +37,5 @@ export const GET_PRESET_WORKFLOWS_NODE_API_PATH = `${BASE_WORKFLOW_NODE_API_PATH export const NEW_WORKFLOW_ID_URL = 'new'; export const START_FROM_SCRATCH_WORKFLOW_NAME = 'Start From Scratch'; export const DEFAULT_NEW_WORKFLOW_NAME = 'new_workflow'; +export const DATE_FORMAT_PATTERN = 'MM/DD/YY hh:mm A'; +export const EMPTY_FIELD_STRING = '--'; diff --git a/common/utils.ts b/common/utils.ts index fabdb327..aaf0d788 100644 --- a/common/utils.ts +++ b/common/utils.ts @@ -3,6 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ +import moment from 'moment'; import { WorkspaceFlowState, ReactFlowComponent, @@ -13,6 +14,7 @@ import { ReactFlowEdge, TemplateFlows, WorkflowTemplate, + DATE_FORMAT_PATTERN, } from './'; // TODO: implement this and remove hardcoded return values @@ -91,3 +93,7 @@ export function validateWorkflowTemplate( ): boolean { return true; } + +export function toFormattedDate(timestampMillis: number): String { + return moment(new Date(timestampMillis)).format(DATE_FORMAT_PATTERN); +} diff --git a/public/pages/workflows/workflow_list/columns.tsx b/public/pages/workflows/workflow_list/columns.tsx index 9f7ae6ae..45615cb4 100644 --- a/public/pages/workflows/workflow_list/columns.tsx +++ b/public/pages/workflows/workflow_list/columns.tsx @@ -5,7 +5,12 @@ import React from 'react'; import { EuiLink } from '@elastic/eui'; -import { PLUGIN_ID, Workflow } from '../../../../common'; +import { + EMPTY_FIELD_STRING, + PLUGIN_ID, + Workflow, + toFormattedDate, +} from '../../../../common'; export const columns = (actions: any[]) => [ { @@ -30,11 +35,19 @@ export const columns = (actions: any[]) => [ field: 'lastUpdated', name: 'Last updated', sortable: true, + render: (lastUpdated: number) => + lastUpdated !== undefined + ? toFormattedDate(lastUpdated) + : EMPTY_FIELD_STRING, }, { field: 'lastLaunched', name: 'Last launched', sortable: true, + render: (lastLaunched: number) => + lastLaunched !== undefined + ? toFormattedDate(lastLaunched) + : EMPTY_FIELD_STRING, }, { name: 'Actions', diff --git a/server/routes/helpers.ts b/server/routes/helpers.ts index 58b813ac..8fddfe8f 100644 --- a/server/routes/helpers.ts +++ b/server/routes/helpers.ts @@ -30,9 +30,8 @@ function toWorkflowObj(workflowHit: any): Workflow { description: hitSource.description || '', version: hitSource.version, workflows: hitSource.workflows, - // TODO: this needs to be persisted by backend. Tracking issue: - // https://github.com/opensearch-project/flow-framework/issues/548 - lastUpdated: 1234, + lastUpdated: hitSource.last_updated_time, + lastLaunched: hitSource.last_provisioned_time, } as Workflow; } @@ -57,9 +56,6 @@ export function getWorkflowsFromResponses( ...workflowDict[workflowHit._id], // @ts-ignore state: WORKFLOW_STATE[workflowState], - // TODO: this needs to be persisted by backend. Tracking issue: - // https://github.com/opensearch-project/flow-framework/issues/548 - lastLaunched: 1234, }; } });