1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/src/renderer/telemetry/capture-with-id.injectable.ts
Juho Heikka c3c0b71ba3 Remove unnecessary console.logs
Signed-off-by: Juho Heikka <juho.heikka@gmail.com>
2022-08-01 15:58:42 +03:00

35 lines
1.1 KiB
TypeScript

/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import type { AppEvent } from "../../common/app-event-bus/event-bus";
import appEventBusInjectable from "../../common/app-event-bus/app-event-bus.injectable";
import type { EventEmitter } from "../../common/event-emitter";
// foo_bar-baz => Foo Bar Baz
function getNameFromId(id: string) {
return id.split(/[/,-,_,--]/).filter(Boolean).map((part) => `${part[0].toUpperCase()+part.substring(1)}`).join(" ");
}
function captureWithId(eventBus: EventEmitter<[AppEvent]>, id: string, action: string) {
const target = getNameFromId(id);
eventBus.emit({
name: target,
action,
destination: "AutoCapture",
});
}
const captureWithIdInjectable = getInjectable({
id: "capture-with-id",
instantiate: (di) => {
return (id: string, action: string) => {
return captureWithId(di.inject(appEventBusInjectable), id, action);
};
},
});
export default captureWithIdInjectable;