1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

clean up / responding to comments

Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
Roman 2021-10-18 15:38:59 +03:00
parent 6f8b9a6c97
commit 9a2af17c47
4 changed files with 12 additions and 16 deletions

View File

@ -22,13 +22,16 @@
import fs from "fs-extra"; import fs from "fs-extra";
import path from "path"; import path from "path";
import os from "os"; import os from "os";
import { action, makeObservable, observable } from "mobx";
import logger from "../../../common/logger";
import { DockTabStore } from "./dock-tab.store"; import { DockTabStore } from "./dock-tab.store";
import { dockStore, DockTabCreateSpecific, TabKind } from "./dock.store"; import { dockStore, DockTabCreateSpecific, TabKind } from "./dock.store";
import { action, makeObservable, observable } from "mobx";
export interface TemplatesGroup { export interface TemplatesGroup {
label: string; label: string;
templates: Record<string/*filename*/, string /*contents*/>; templates: {
[filename: string]: string;
};
} }
export class CreateResourceStore extends DockTabStore<string> { export class CreateResourceStore extends DockTabStore<string> {
@ -40,7 +43,7 @@ export class CreateResourceStore extends DockTabStore<string> {
readonly templateGroups: Record<string, TemplatesGroup> = observable({ readonly templateGroups: Record<string, TemplatesGroup> = observable({
[this.appTemplatesFolder]: { [this.appTemplatesFolder]: {
label: "Lens Templates", label: "Lens Templates",
templates: {} as Record<string/*filename*/, string /*contents*/>, templates: {},
}, },
[this.userTemplatesFolder]: { [this.userTemplatesFolder]: {
label: "Custom templates", label: "Custom templates",
@ -54,7 +57,7 @@ export class CreateResourceStore extends DockTabStore<string> {
} }
get userTemplatesFolder(): string { get userTemplatesFolder(): string {
return path.resolve(os.homedir(), "~/.k8slens/templates"); return path.resolve(os.homedir(), ".k8slens/templates");
} }
async init() { async init() {
@ -79,7 +82,7 @@ export class CreateResourceStore extends DockTabStore<string> {
fileNames.map(fileName => [fileName, "" /* empty: content not loaded yet */]) fileNames.map(fileName => [fileName, "" /* empty: content not loaded yet */])
); );
} catch (error) { } catch (error) {
console.error(`[CREATE-RESOURCE]: scanning template folders error: ${error}`); logger.error(`[CREATE-RESOURCE]: scanning template folders error: ${error}`);
} }
} }
@ -109,16 +112,11 @@ export class CreateResourceStore extends DockTabStore<string> {
return textContent; return textContent;
} catch (error) { } catch (error) {
console.error(`[CREATE-RESOURCE]: reading "${sourceFolder}/${fileName}" has failed: ${error}`); logger.error(`[CREATE-RESOURCE]: reading "${sourceFolder}/${fileName}" has failed: ${error}`);
} }
return ""; return "";
} }
// bundled app templates via webpack.renderer.ts, "?raw"-query loads content as text
async getBundledTemplate(fileName: string, ext = "yaml"): Promise<string> {
return import(`${this.appTemplatesFolder}/${fileName}.${ext}?raw`);
}
} }
export const createResourceStore = new CreateResourceStore(); export const createResourceStore = new CreateResourceStore();

View File

@ -217,12 +217,12 @@ export class DockStore implements DockStorageState {
return reaction(() => this.selectedTab, ((tab, prevTab) => { return reaction(() => this.selectedTab, ((tab, prevTab) => {
if (!tab) return; // skip if (!tab) return; // skip
if (tabKind && tabKind !== tab.kind) return; if (tabKind && tabKind !== tab.kind) return; // handle specific tab.kind only
if (dockIsVisible && !this.isOpen) return; if (dockIsVisible && !this.isOpen) return;
callback({ callback({
tab, prevTab, tab, prevTab,
tabId: this.selectedTabId, tabId: tab.id,
}); });
}), reactionOpts); }), reactionOpts);
} }

View File

@ -44,7 +44,7 @@ export class EditResourceStore extends DockTabStore<EditingResource> {
super.init(); super.init();
this.dispose.push( this.dispose.push(
dockStore.onTabChange(({ tabId }) => editResourceStore.editResource(tabId), { dockStore.onTabChange(({ tabId }) => this.editResource(tabId), {
tabKind: TabKind.EDIT_RESOURCE, tabKind: TabKind.EDIT_RESOURCE,
fireImmediately: true, fireImmediately: true,
}) })

View File

@ -44,5 +44,3 @@ export const monacoValidators = {
yaml: yamlValidator, yaml: yamlValidator,
json: jsonValidator, json: jsonValidator,
}; };
export type MonacoValidatorKey = keyof typeof monacoValidators;