mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Highlight general entities in hotbar if their route matches
Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
parent
2705519932
commit
0047289e8d
@ -19,7 +19,9 @@
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { navigate } from "../../renderer/navigation";
|
||||
import { reaction, when } from "mobx";
|
||||
import { catalogEntityRegistry } from "../../renderer/api/catalog-entity-registry";
|
||||
import { isActiveRoute, navigate, navigation } from "../../renderer/navigation";
|
||||
import { CatalogCategory, CatalogEntity, CatalogEntityMetadata, CatalogEntitySpec, CatalogEntityStatus } from "../catalog";
|
||||
import { catalogCategoryRegistry } from "../catalog/catalog-category-registry";
|
||||
|
||||
@ -71,6 +73,23 @@ export class GeneralCategory extends CatalogCategory {
|
||||
kind: "General"
|
||||
}
|
||||
};
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
reaction(() => navigation.location, () => this.setEntityOnRouteMatch(), { fireImmediately: true });
|
||||
}
|
||||
|
||||
async setEntityOnRouteMatch() {
|
||||
await when(() => catalogEntityRegistry.entities.size > 0);
|
||||
|
||||
const entities = catalogEntityRegistry.getItemsForCategory(this);
|
||||
const activeEntity = entities.find(entity => isActiveRoute(entity.spec.path));
|
||||
|
||||
if (activeEntity) {
|
||||
catalogEntityRegistry.activeEntity = activeEntity;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
catalogCategoryRegistry.add(new GeneralCategory());
|
||||
|
||||
@ -103,21 +103,9 @@ export class Catalog extends React.Component<Props> {
|
||||
Notifications.error(<p>Unknown category: {routeTab}</p>);
|
||||
}
|
||||
}, {fireImmediately: true}),
|
||||
|
||||
reaction(() => catalogEntityRegistry.getById("catalog-entity"), () => {
|
||||
this.setActiveEntity();
|
||||
}, {fireImmediately: true})
|
||||
]);
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
this.removeActiveEntity();
|
||||
}
|
||||
|
||||
setActiveEntity() {
|
||||
catalogEntityRegistry.activeEntity = catalogEntityRegistry.getById("catalog-entity");
|
||||
}
|
||||
|
||||
removeActiveEntity() {
|
||||
catalogEntityRegistry.activeEntity = null;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user