mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fix issues
Signed-off-by: Pavel Ashevskiy <pavel.ashevskiy@ifellow.ru>
This commit is contained in:
parent
30ce887273
commit
997c38ba06
@ -31,17 +31,21 @@ export class CreateResourceStore extends DockTabStore<string> {
|
||||
getTemplates(templatesPath: string, defaultGroup: string) {
|
||||
const templates = filehound.create().path(templatesPath).ext("yaml").depth(1).findSync();
|
||||
|
||||
return templates ? (groupBy(templates,(v:string) => path.relative(templatesPath,v).split(path.sep).length>1
|
||||
? path.parse(path.relative(templatesPath,v)).dir
|
||||
: defaultGroup)) : {};
|
||||
return templates ? this.groupTemplates(templates, templatesPath, defaultGroup) : {};
|
||||
}
|
||||
|
||||
groupTemplates(templates: string[], templatesPath: string, defaultGroup: string) {
|
||||
return groupBy(templates,(v:string) =>
|
||||
path.relative(templatesPath,v).split(path.sep).length>1
|
||||
? path.parse(path.relative(templatesPath,v)).dir
|
||||
: defaultGroup);
|
||||
}
|
||||
|
||||
async getMergedTemplates() {
|
||||
return {...this.getTemplates(this.userTemplatesFolder, "ungrouped"),...this.lensTemplates};
|
||||
}
|
||||
|
||||
async watchUserTemplates(calback: ()=> void){
|
||||
calback();
|
||||
async watchUserTemplates(callback: ()=> void){
|
||||
watch(this.userTemplatesFolder, {
|
||||
depth: 1,
|
||||
ignoreInitial: true,
|
||||
@ -49,7 +53,7 @@ export class CreateResourceStore extends DockTabStore<string> {
|
||||
stabilityThreshold: 500
|
||||
}
|
||||
}).on("all", () => {
|
||||
calback();
|
||||
callback();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -26,19 +26,20 @@ export class CreateResource extends React.Component<Props> {
|
||||
@observable error = "";
|
||||
@observable templates:GroupSelectOption<SelectOption>[] = [];
|
||||
|
||||
async componentDidMount(){
|
||||
createResourceStore.watchUserTemplates(()=> {
|
||||
this.templates = [];
|
||||
createResourceStore.getMergedTemplates().then(
|
||||
templatesDictionary => {
|
||||
Object.keys(templatesDictionary).forEach(group => {
|
||||
this.templates.push(this.convertEntryToGroup(group, templatesDictionary[group]));
|
||||
});
|
||||
});
|
||||
componentDidMount() {
|
||||
createResourceStore.getMergedTemplates().then(v => this.updateGroupSelecOptions(v));
|
||||
createResourceStore.watchUserTemplates(() => createResourceStore.getMergedTemplates().then(v => this.updateGroupSelecOptions(v)));
|
||||
}
|
||||
|
||||
updateGroupSelecOptions(templates :{[x:string]: string[]}) {
|
||||
this.templates = [];
|
||||
|
||||
Object.keys(templates).forEach(group => {
|
||||
this.templates.push(this.convertToGroup(group, templates[group]));
|
||||
});
|
||||
}
|
||||
|
||||
convertEntryToGroup(group:string, items:string[]):GroupSelectOption {
|
||||
convertToGroup(group:string, items:string[]):GroupSelectOption {
|
||||
const options = items.map(v => ({label: path.parse(v).name, value: v}));
|
||||
|
||||
return {label: group, options};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user