mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
review changes
Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
parent
3fb9599ca0
commit
f7c263490b
@ -49,8 +49,8 @@ export class KubernetesCluster implements CatalogEntity {
|
|||||||
{
|
{
|
||||||
icon: "settings",
|
icon: "settings",
|
||||||
title: "Settings",
|
title: "Settings",
|
||||||
onClick: async () => context.navigate(`/entity/${this.metadata.uid}/settings`),
|
onlyVisibleForSource: "local",
|
||||||
onlyVisibleForSource: "local"
|
onClick: async () => context.navigate(`/entity/${this.metadata.uid}/settings`)
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
icon: "delete",
|
icon: "delete",
|
||||||
|
|||||||
@ -16,10 +16,6 @@ export class CatalogEntityRegistry {
|
|||||||
return Array.from(this.sources.values()).flat();
|
return Array.from(this.sources.values()).flat();
|
||||||
}
|
}
|
||||||
|
|
||||||
getById(id: string) {
|
|
||||||
return this.items.find((entity) => entity.metadata.uid === id);
|
|
||||||
}
|
|
||||||
|
|
||||||
getItemsForApiKind<T extends CatalogEntity>(apiVersion: string, kind: string): T[] {
|
getItemsForApiKind<T extends CatalogEntity>(apiVersion: string, kind: string): T[] {
|
||||||
const items = this.items.filter((item) => item.apiVersion === apiVersion && item.kind === kind);
|
const items = this.items.filter((item) => item.apiVersion === apiVersion && item.kind === kind);
|
||||||
|
|
||||||
|
|||||||
@ -26,7 +26,7 @@ export interface RegisteredEntitySetting extends EntitySettingRegistration {
|
|||||||
export class EntitySettingRegistry extends BaseRegistry<EntitySettingRegistration, RegisteredEntitySetting> {
|
export class EntitySettingRegistry extends BaseRegistry<EntitySettingRegistration, RegisteredEntitySetting> {
|
||||||
getRegisteredItem(item: EntitySettingRegistration): RegisteredEntitySetting {
|
getRegisteredItem(item: EntitySettingRegistration): RegisteredEntitySetting {
|
||||||
return {
|
return {
|
||||||
id: item.id || item.title.toLowerCase().replace(/[^0-9a-zA-Z]+/g, "-"),
|
id: item.id || item.title.toLowerCase(),
|
||||||
...item,
|
...item,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -36,7 +36,7 @@ export class EntitySettingRegistry extends BaseRegistry<EntitySettingRegistratio
|
|||||||
return item.kind === kind && item.apiVersions.includes(apiVersion);
|
return item.kind === kind && item.apiVersions.includes(apiVersion);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (source && source !== "") {
|
if (source) {
|
||||||
return items.filter((item) => {
|
return items.filter((item) => {
|
||||||
return !item.source || item.source === source;
|
return !item.source || item.source === source;
|
||||||
});
|
});
|
||||||
|
|||||||
@ -12,7 +12,6 @@ import { catalogEntityRegistry } from "../../api/catalog-entity-registry";
|
|||||||
import { entitySettingRegistry } from "../../../extensions/registries";
|
import { entitySettingRegistry } from "../../../extensions/registries";
|
||||||
import { EntitySettingsRouteParams } from "./entity-settings.route";
|
import { EntitySettingsRouteParams } from "./entity-settings.route";
|
||||||
|
|
||||||
|
|
||||||
interface Props extends RouteComponentProps<EntitySettingsRouteParams> {
|
interface Props extends RouteComponentProps<EntitySettingsRouteParams> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,7 +36,7 @@ export class EntitySettings extends React.Component<Props> {
|
|||||||
async componentDidMount() {
|
async componentDidMount() {
|
||||||
const { hash } = navigation.location;
|
const { hash } = navigation.location;
|
||||||
|
|
||||||
this.activeTab = this.menuItems[0]?.id;
|
this.ensureActiveTab();
|
||||||
|
|
||||||
document.getElementById(hash.slice(1))?.scrollIntoView();
|
document.getElementById(hash.slice(1))?.scrollIntoView();
|
||||||
}
|
}
|
||||||
@ -52,23 +51,35 @@ export class EntitySettings extends React.Component<Props> {
|
|||||||
<h2>{this.entity.metadata.name}</h2>
|
<h2>{this.entity.metadata.name}</h2>
|
||||||
<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="header">Settings</div>
|
<div className="header">Settings</div>
|
||||||
{ this.menuItems.map((setting) => {
|
{ this.menuItems.map((setting) => (
|
||||||
return <Tab key={setting.id} value={setting.id} label={setting.title} data-testid={`${setting.id}-tab`} />;
|
<Tab
|
||||||
})}
|
key={setting.id}
|
||||||
|
value={setting.id}
|
||||||
|
label={setting.title}
|
||||||
|
data-testid={`${setting.id}-tab`}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
</Tabs>
|
</Tabs>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ensureActiveTab() {
|
||||||
|
if (!this.activeTab) {
|
||||||
|
this.activeTab = this.menuItems[0]?.id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
if (!this.entity) return null;
|
if (!this.entity) {
|
||||||
|
console.error("entity not found", this.entityId);
|
||||||
|
|
||||||
const activeSetting = this.menuItems.find((setting) => setting.id === this.activeTab);
|
|
||||||
|
|
||||||
if (!activeSetting) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.ensureActiveTab();
|
||||||
|
const activeSetting = this.menuItems.find((setting) => setting.id === this.activeTab);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PageLayout
|
<PageLayout
|
||||||
className="CatalogEntitySettings"
|
className="CatalogEntitySettings"
|
||||||
|
|||||||
@ -11,6 +11,17 @@ import { ClusterKubeconfig } from "./components/cluster-kubeconfig";
|
|||||||
import { entitySettingRegistry } from "../../../extensions/registries";
|
import { entitySettingRegistry } from "../../../extensions/registries";
|
||||||
import { CatalogEntity } from "../../api/catalog-entity";
|
import { CatalogEntity } from "../../api/catalog-entity";
|
||||||
|
|
||||||
|
|
||||||
|
function getClusterForEntity(entity: CatalogEntity) {
|
||||||
|
const cluster = clusterStore.getById(entity.metadata.uid);
|
||||||
|
|
||||||
|
if (!cluster?.enabled) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return cluster;
|
||||||
|
}
|
||||||
|
|
||||||
entitySettingRegistry.add([
|
entitySettingRegistry.add([
|
||||||
{
|
{
|
||||||
apiVersions: ["entity.k8slens.dev/v1alpha1"],
|
apiVersions: ["entity.k8slens.dev/v1alpha1"],
|
||||||
@ -19,7 +30,7 @@ entitySettingRegistry.add([
|
|||||||
title: "General",
|
title: "General",
|
||||||
components: {
|
components: {
|
||||||
View: (props: { entity: CatalogEntity }) => {
|
View: (props: { entity: CatalogEntity }) => {
|
||||||
const cluster = clusterStore.enabledClustersList.find((cluster) => cluster.id === props.entity.metadata.uid);
|
const cluster = getClusterForEntity(props.entity);
|
||||||
|
|
||||||
if (!cluster) {
|
if (!cluster) {
|
||||||
return null;
|
return null;
|
||||||
@ -44,7 +55,7 @@ entitySettingRegistry.add([
|
|||||||
title: "Proxy",
|
title: "Proxy",
|
||||||
components: {
|
components: {
|
||||||
View: (props: { entity: CatalogEntity }) => {
|
View: (props: { entity: CatalogEntity }) => {
|
||||||
const cluster = clusterStore.enabledClustersList.find((cluster) => cluster.id === props.entity.metadata.uid);
|
const cluster = getClusterForEntity(props.entity);
|
||||||
|
|
||||||
if (!cluster) {
|
if (!cluster) {
|
||||||
return null;
|
return null;
|
||||||
@ -64,7 +75,7 @@ entitySettingRegistry.add([
|
|||||||
title: "Terminal",
|
title: "Terminal",
|
||||||
components: {
|
components: {
|
||||||
View: (props: { entity: CatalogEntity }) => {
|
View: (props: { entity: CatalogEntity }) => {
|
||||||
const cluster = clusterStore.enabledClustersList.find((cluster) => cluster.id === props.entity.metadata.uid);
|
const cluster = getClusterForEntity(props.entity);
|
||||||
|
|
||||||
if (!cluster) {
|
if (!cluster) {
|
||||||
return null;
|
return null;
|
||||||
@ -84,7 +95,7 @@ entitySettingRegistry.add([
|
|||||||
title: "Namespaces",
|
title: "Namespaces",
|
||||||
components: {
|
components: {
|
||||||
View: (props: { entity: CatalogEntity }) => {
|
View: (props: { entity: CatalogEntity }) => {
|
||||||
const cluster = clusterStore.enabledClustersList.find((cluster) => cluster.id === props.entity.metadata.uid);
|
const cluster = getClusterForEntity(props.entity);
|
||||||
|
|
||||||
if (!cluster) {
|
if (!cluster) {
|
||||||
return null;
|
return null;
|
||||||
@ -105,7 +116,7 @@ entitySettingRegistry.add([
|
|||||||
title: "Metrics",
|
title: "Metrics",
|
||||||
components: {
|
components: {
|
||||||
View: (props: { entity: CatalogEntity }) => {
|
View: (props: { entity: CatalogEntity }) => {
|
||||||
const cluster = clusterStore.enabledClustersList.find((cluster) => cluster.id === props.entity.metadata.uid);
|
const cluster = getClusterForEntity(props.entity);
|
||||||
|
|
||||||
if (!cluster) {
|
if (!cluster) {
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@ -48,7 +48,6 @@
|
|||||||
padding: 6px 10px;
|
padding: 6px 10px;
|
||||||
overflow-wrap: anywhere;
|
overflow-wrap: anywhere;
|
||||||
color: var(--textColorAccent);
|
color: var(--textColorAccent);
|
||||||
text-transform: uppercase;
|
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user