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

Merge remote-tracking branch 'origin/master' into mobx-6.2

# Conflicts:
#	src/renderer/components/+catalog/catalog.tsx
This commit is contained in:
Roman 2021-05-03 18:51:40 +03:00
commit a840eccc28
3 changed files with 31 additions and 26 deletions

View File

@ -64,7 +64,7 @@ export class CatalogEntityItem implements ItemObject {
} }
export class CatalogEntityStore extends ItemStore<CatalogEntityItem> { export class CatalogEntityStore extends ItemStore<CatalogEntityItem> {
@observable activeCategory: CatalogCategory; @observable activeCategory?: CatalogCategory;
constructor() { constructor() {
super(); super();
@ -73,7 +73,9 @@ export class CatalogEntityStore extends ItemStore<CatalogEntityItem> {
} }
@computed get entities() { @computed get entities() {
if (!this.activeCategory) return []; if (!this.activeCategory) {
return catalogEntityRegistry.items.map(entity => new CatalogEntityItem(entity));
}
return catalogEntityRegistry.getItemsForCategory(this.activeCategory).map(entity => new CatalogEntityItem(entity)); return catalogEntityRegistry.getItemsForCategory(this.activeCategory).map(entity => new CatalogEntityItem(entity));
} }

View File

@ -28,7 +28,7 @@ enum sortBy {
export class Catalog extends React.Component { export class Catalog extends React.Component {
@observable private catalogEntityStore?: CatalogEntityStore; @observable private catalogEntityStore?: CatalogEntityStore;
@observable private contextMenu: CatalogEntityContextMenuContext; @observable private contextMenu: CatalogEntityContextMenuContext;
@observable activeTab: string; @observable activeTab?: string;
constructor(props: object) { constructor(props: object) {
super(props); super(props);
@ -82,14 +82,11 @@ export class Catalog extends React.Component {
} }
@action @action
onTabChange = (tabId: string) => { onTabChange = (tabId: string | null) => {
this.activeTab = tabId; const activeCategory = this.categories.find(category => category.getId() === tabId);
const activeCategory = this.categories.find((category) => category.getId() === tabId); this.catalogEntityStore.activeCategory = activeCategory;
this.activeTab = activeCategory?.getId();
if (activeCategory) {
this.catalogEntityStore.activeCategory = activeCategory;
}
}; };
renderNavigation() { renderNavigation() {
@ -97,9 +94,19 @@ export class Catalog extends React.Component {
<Tabs className="flex column" scrollable={false} onChange={this.onTabChange} value={this.activeTab}> <Tabs className="flex column" scrollable={false} onChange={this.onTabChange} value={this.activeTab}>
<div className="sidebarHeader">Catalog</div> <div className="sidebarHeader">Catalog</div>
<div className="sidebarTabs"> <div className="sidebarTabs">
{this.categories.map((category, index) => { <Tab
return <Tab value={category.getId()} key={index} label={category.metadata.name} data-testid={`${category.getId()}-tab`}/>; value={undefined}
})} key="*"
label="Browse"
data-testid="*-tab"
/>
{this.categories.map(category => (
<Tab
value={category.getId()}
key={category.getId()} label={category.metadata.name} data-testid={`${category.getId()}-tab`}
/>
))
}
</div> </div>
</Tabs> </Tabs>
); );
@ -108,22 +115,18 @@ export class Catalog extends React.Component {
@autobind() @autobind()
renderItemMenu(item: CatalogEntityItem) { renderItemMenu(item: CatalogEntityItem) {
const menuItems = this.contextMenu.menuItems.filter((menuItem) => !menuItem.onlyVisibleForSource || menuItem.onlyVisibleForSource === item.entity.metadata.source); const menuItems = this.contextMenu.menuItems.filter((menuItem) => !menuItem.onlyVisibleForSource || menuItem.onlyVisibleForSource === item.entity.metadata.source);
const onOpen = async () => {
await item.onContextMenuOpen(this.contextMenu);
};
return ( return (
<MenuActions onOpen={() => onOpen()}> <MenuActions onOpen={() => item.onContextMenuOpen(this.contextMenu)}>
<MenuItem key="add-to-hotbar" onClick={() => this.addToHotbar(item)}> <MenuItem key="add-to-hotbar" onClick={() => this.addToHotbar(item)}>
<Icon material="add" small interactive={true} title="Add to hotbar"/> Add to Hotbar <Icon material="add" small interactive={true} title="Add to hotbar"/> Add to Hotbar
</MenuItem> </MenuItem>
{menuItems.map((menuItem, index) => { {menuItems.map((menuItem, index) => (
return (
<MenuItem key={index} onClick={() => this.onMenuItemClick(menuItem)}> <MenuItem key={index} onClick={() => this.onMenuItemClick(menuItem)}>
<Icon material={menuItem.icon} small interactive={true} title={menuItem.title}/> {menuItem.title} <Icon material={menuItem.icon} small interactive={true} title={menuItem.title} /> {menuItem.title}
</MenuItem> </MenuItem>
); ))
})} }
</MenuActions> </MenuActions>
); );
} }
@ -140,7 +143,7 @@ export class Catalog extends React.Component {
provideBackButtonNavigation={false} provideBackButtonNavigation={false}
contentGaps={false}> contentGaps={false}>
<ItemListLayout <ItemListLayout
renderHeaderTitle={this.catalogEntityStore.activeCategory?.metadata.name} renderHeaderTitle={this.catalogEntityStore.activeCategory?.metadata.name ?? "Browse All"}
isClusterScoped isClusterScoped
isSearchable={true} isSearchable={true}
isSelectable={false} isSelectable={false}

View File

@ -12897,9 +12897,9 @@ sshpk@^1.7.0:
tweetnacl "~0.14.0" tweetnacl "~0.14.0"
ssri@^6.0.0, ssri@^6.0.1: ssri@^6.0.0, ssri@^6.0.1:
version "6.0.1" version "6.0.2"
resolved "https://registry.yarnpkg.com/ssri/-/ssri-6.0.1.tgz#2a3c41b28dd45b62b63676ecb74001265ae9edd8" resolved "https://registry.yarnpkg.com/ssri/-/ssri-6.0.2.tgz#157939134f20464e7301ddba3e90ffa8f7728ac5"
integrity sha512-3Wge10hNcT1Kur4PDFwEieXSCMCJs/7WvSACcrMYrNp+b8kDL1/0wJch5Ni2WrtwEa2IO8OsVfeKIciKCDx/QA== integrity sha512-cepbSq/neFK7xB6A50KHN0xHDotYzq58wWCa5LeWqnPrHG8GzfEjO/4O8kpmcGW+oaxkvhEJCWgbgNk4/ZV93Q==
dependencies: dependencies:
figgy-pudding "^3.5.1" figgy-pudding "^3.5.1"