-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Artifact list column creation time (#2105)
* Add artifact creation date in artifact list UI * Clean up code * Basic error handling for artifact list page creation time fetching.
- Loading branch information
1 parent
f2b1437
commit 4166e7a
Showing
2 changed files
with
70 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { Event } from '../generated/src/apis/metadata/metadata_store_pb'; | ||
import { GetEventsByArtifactIDsRequest, GetEventsByArtifactIDsResponse } from '../generated/src/apis/metadata/metadata_store_service_pb'; | ||
import { Apis } from '../lib/Apis'; | ||
import { formatDateString, serviceErrorToString } from './Utils'; | ||
|
||
export const getArtifactCreationTime = (artifactId: number): Promise<string> => { | ||
return new Promise((resolve, reject) => { | ||
const eventsRequest = new GetEventsByArtifactIDsRequest(); | ||
if (!artifactId) { | ||
return reject(new Error('artifactId is empty')); | ||
} | ||
|
||
eventsRequest.setArtifactIdsList([artifactId]); | ||
Apis.getMetadataServiceClient().getEventsByArtifactIDs(eventsRequest, (err, res) => { | ||
if (err) { | ||
return reject(new Error(serviceErrorToString(err))); | ||
} else { | ||
const data = (res as GetEventsByArtifactIDsResponse).getEventsList().map(event => ({ | ||
time: event.getMillisecondsSinceEpoch(), | ||
type: event.getType() || Event.Type.UNKNOWN, | ||
})); | ||
// The last output event is the event that produced current artifact. | ||
const lastOutputEvent = data.reverse().find(event => | ||
event.type === Event.Type.DECLARED_OUTPUT || event.type === Event.Type.OUTPUT | ||
); | ||
if (lastOutputEvent && lastOutputEvent.time) { | ||
resolve(formatDateString(new Date(lastOutputEvent.time))); | ||
} else { | ||
// No valid time found, just return empty | ||
resolve(''); | ||
} | ||
} | ||
}); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters