kui-shell
Version:
This is the monorepo for Kui, the hybrid command-line/GUI electron-based Kubernetes tool
107 lines • 4.6 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const debug_1 = require("debug");
const events_1 = require("@kui-shell/core/api/events");
const util_1 = require("../util/util");
const states_1 = require("../model/states");
const debug = debug_1.default('k8s/util/formatEntity');
exports.formatContextAttr = (context, extraCSS) => {
return [
{
key: 'context',
value: context,
outerCSS: `${extraCSS ? extraCSS + ' ' : ''}entity-name-group entity-name-group-narrow hide-with-sidecar`
}
];
};
exports.formatEntity = (parsedOptions, context) => (kubeEntity) => __awaiter(void 0, void 0, void 0, function* () {
if (!kubeEntity.metadata) {
return kubeEntity;
}
const finalState = parsedOptions['final-state'] || states_1.FinalState.NotPendingLike;
const { apiVersion, kind, metadata: { name, namespace, labels, annotations = {} } } = kubeEntity;
const { type, actionName, packageName, fqn } = util_1.toOpenWhiskFQN(kubeEntity);
const { cssForState } = states_1.rendering;
const title = annotations && annotations['kui.tools/title'];
const targetNamespace = annotations && annotations['kui.tools/targetNamespace'];
const masqueradeKind = annotations && annotations['kui.tools/category'];
const kindForDisplay = masqueradeKind || kind;
const kindAttr = [{ key: 'kind', value: kindForDisplay, outerCSS: 'entity-kind' }];
const contextAttr = parsedOptions.multi || !context ? [] : exports.formatContextAttr(context);
const watch = {
apiVersion,
kind,
name,
namespace,
type,
fqn,
context,
labels
};
const eventType = '/kubectl/state/expect';
const listener = ({ watch: other, finalState: otherFinalState }) => {
if (watch.kind === other.kind &&
watch.name === other.name &&
watch.context === other.context &&
finalState !== otherFinalState) {
debug('conflicting final states', watch, finalState, otherFinalState);
events_1.default.removeListener(eventType, listener);
}
};
events_1.default.on(eventType, listener);
events_1.default.emit('/kubectl/state/expect', { watch, finalState });
const namespaceAttrs = !watch.kind || watch.kind.match(/(ns|Namespace)/i)
? []
: [
{
key: 'namespace',
value: targetNamespace || namespace,
outerCSS: 'pretty-narrow hide-with-sidecar'
}
];
const status = yield states_1.watchStatus(watch, finalState);
const statusAttrs = parsedOptions['no-status']
? []
: [
{
key: 'STATUS',
value: status.value,
placeholderValue: true,
tag: 'badge',
outerCSS: status.outerCSS,
css: cssForState(status.value)
},
{
key: 'message',
value: status.others && status.others.find(other => other.key === 'message')
? status.others.find(other => other.key === 'message').value
: '',
css: 'somewhat-smaller-text slightly-deemphasize',
outerCSS: 'hide-with-sidecar not-too-wide min-width-date-like'
}
];
const attributes = kindAttr
.concat(contextAttr)
.concat(namespaceAttrs)
.concat(statusAttrs);
return Object.assign({}, kubeEntity, {
type: 'status',
prettyType: kindForDisplay,
name: title || actionName || fqn,
packageName,
noSort: true,
onclick: parsedOptions.onclickFn ? parsedOptions.onclickFn(kubeEntity) : status.onclick ? status.onclick : false,
done: status.done,
attributes
});
});
//# sourceMappingURL=formatEntity.js.map