Skip to content

Commit

Permalink
feat: show resource version in toolbar text
Browse files Browse the repository at this point in the history
Fixes #4790
  • Loading branch information
starpit committed Jun 6, 2020
1 parent eabe9f7 commit 6d32eb5
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 16 deletions.
2 changes: 1 addition & 1 deletion plugins/plugin-kubectl/i18n/resources_de.json
@@ -1,6 +1,6 @@
{
"startedOn": "Gestartet am",
"createdOn": "Erstellt am {0}",
"createdOn": "Erstellt am **{0}**",
"readonly": "Sie verwenden den schreibgeschützten Anzeigemodus",
"contextsTableTitle": "Kubernetes-Kontexte",
"deleteResource": "Diese Ressource löschen",
Expand Down
4 changes: 3 additions & 1 deletion plugins/plugin-kubectl/i18n/resources_en_US.json
Expand Up @@ -5,7 +5,9 @@
"Namespace": "Namespace",
"Usage": "Usage",
"startedOn": "Started on",
"createdOn": "Created on {0}",
"createdOn": "Created on **{0}**",
"createdOn=X resourceVersion=Y": "Created on **{0}**. Showing resource version **{1}**.",
"resourceVersion=Y": "Showing resource version **{0}**",
"readonly": "You are in read-only view mode",
"contextsTableTitle": "Kubernetes Contexts",
"deleteResource": "Delete this resource",
Expand Down
2 changes: 1 addition & 1 deletion plugins/plugin-kubectl/i18n/resources_es.json
@@ -1,6 +1,6 @@
{
"startedOn": "Iniciado el",
"createdOn": "Creado el",
"createdOn": "Creado el **{0}**",
"readonly": "Está en modalidad de vista de solo lectura",
"contextsTableTitle": "Contextos de Kubernetes",
"deleteResource": "Suprimir este recurso",
Expand Down
2 changes: 1 addition & 1 deletion plugins/plugin-kubectl/i18n/resources_fr.json
@@ -1,6 +1,6 @@
{
"startedOn": "Démarré le",
"createdOn": "Créé le {0}",
"createdOn": "Créé le **{0}**",
"readonly": "Vous êtes en mode d'affichage lecture seule",
"contextsTableTitle": "Contextes Kubernetes",
"deleteResource": "Supprimer cette ressource",
Expand Down
2 changes: 1 addition & 1 deletion plugins/plugin-kubectl/i18n/resources_it.json
@@ -1,6 +1,6 @@
{
"startedOn": "Avviato il",
"createdOn": "Creato il {0}",
"createdOn": "Creato il **{0}**",
"readonly": "Si sta utilizzando la modalità di visualizzazione sola lettura",
"contextsTableTitle": "Contesti Kubernetes",
"deleteResource": "Elimina questa risorsa",
Expand Down
2 changes: 1 addition & 1 deletion plugins/plugin-kubectl/i18n/resources_ja.json
@@ -1,6 +1,6 @@
{
"startedOn": "開始日時",
"createdOn": "作成日: {0}",
"createdOn": "作成日: **{0}**",
"readonly": "読み取り専用表示モードです",
"contextsTableTitle": "Kubernetes コンテキスト",
"deleteResource": "このリソースの削除",
Expand Down
2 changes: 1 addition & 1 deletion plugins/plugin-kubectl/i18n/resources_pt_BR.json
@@ -1,6 +1,6 @@
{
"startedOn": "Iniciado em",
"createdOn": "Criado em {0}",
"createdOn": "Criado em **{0}**",
"readonly": "Você está no modo de visualização somente leitura",
"contextsTableTitle": "Contextos do Kubernetes",
"deleteResource": "Excluir este recurso",
Expand Down
2 changes: 1 addition & 1 deletion plugins/plugin-kubectl/i18n/resources_zh_CN.json
@@ -1,6 +1,6 @@
{
"startedOn": "开始日期",
"createdOn": "创建于 {0}",
"createdOn": "创建于 **{0}**",
"readonly": "您处于只读模式",
"contextsTableTitle": "Kubernetes 上下文",
"deleteResource": "删除此资源",
Expand Down
2 changes: 1 addition & 1 deletion plugins/plugin-kubectl/i18n/resources_zh_TW.json
@@ -1,6 +1,6 @@
{
"startedOn": "開始日期",
"createdOn": "創建於 {0}",
"createdOn": "創建於 **{0}**",
"readonly": "您正在使用唯讀檢視模式",
"contextsTableTitle": "Kubernetes 環境定義",
"deleteResource": "刪除此資源",
Expand Down
39 changes: 32 additions & 7 deletions plugins/plugin-kubectl/src/controller/kubectl/get.ts
Expand Up @@ -25,9 +25,15 @@ import commandPrefix from '../command-prefix'
import doGetWatchTable from './watch/get-watch'
import extractAppAndName from '../../lib/util/name'
import { isUsage, doHelp } from '../../lib/util/help'
import { KubeResource, isKubeResource, isKubeItems, sameResourceVersion } from '../../lib/model/resource'
import { KubeOptions, isEntityRequest, isTableRequest, formatOf, isWatchRequest, getNamespace } from './options'
import { stringToTable, KubeTableResponse, isKubeTableResponse } from '../../lib/view/formatTable'
import {
KubeResource,
isKubeResource,
isKubeItems,
sameResourceVersion,
hasResourceVersion
} from '../../lib/model/resource'

const strings = i18n('plugin-kubectl')

Expand Down Expand Up @@ -104,6 +110,30 @@ export async function doGetAsEntity(args: Arguments<KubeOptions>, response: RawR
}
}

/** Pretty-print creationTimestamp */
function creationTimestamp(resource: KubeResource) {
return new Date(resource.metadata.creationTimestamp).toLocaleString()
}

/** ToolbarText presentation */
function toolbarText(resource: KubeResource) {
const type = 'info' as const

const hasTimestamp = resource.metadata.creationTimestamp !== undefined
const hasVersion = hasResourceVersion(resource)

if (hasTimestamp && hasVersion) {
return {
type,
text: strings('createdOn=X resourceVersion=Y', creationTimestamp(resource), resource.metadata.resourceVersion)
}
} else if (hasTimestamp) {
return { type, text: strings('createdOn', creationTimestamp(resource)) }
} else if (hasVersion) {
return { type, text: strings('resourceVersion=Y', creationTimestamp(resource), resource.metadata.resourceVersion) }
}
}

/**
* `kubectl get` as entity response
*
Expand Down Expand Up @@ -140,12 +170,7 @@ export async function doGetAsMMR(
comparator: sameResourceVersion,
originatingCommand: args.command,
isKubeResource: true,
toolbarText: !resource.metadata.creationTimestamp
? undefined
: {
type: 'info',
text: strings('createdOn', new Date(resource.metadata.creationTimestamp).toLocaleString())
},
toolbarText: toolbarText(resource),
onclick: {
kind: `kubectl get ${kindAndNamespaceOf(resource)}`,
name: `kubectl get ${kindAndNamespaceOf(resource)} ${resource.metadata.name}`,
Expand Down

0 comments on commit 6d32eb5

Please sign in to comment.