/** * Copyright (c) OpenLens Authors. All rights reserved. * Licensed under MIT License. See LICENSE in root directory for more information. */ import "./config-map-details.scss"; import React from "react"; import { autorun, makeObservable, observable } from "mobx"; import { disposeOnUnmount, observer } from "mobx-react"; import { DrawerTitle } from "../drawer"; import { Notifications } from "../notifications"; import { Input } from "../input"; import { Button } from "../button"; import { configMapStore } from "./legacy-store"; import type { KubeObjectDetailsProps } from "../kube-object-details"; import { ConfigMap } from "../../../common/k8s-api/endpoints"; import { KubeObjectMeta } from "../kube-object-meta"; import logger from "../../../common/logger"; export interface ConfigMapDetailsProps extends KubeObjectDetailsProps { } @observer export class ConfigMapDetails extends React.Component { @observable isSaving = false; @observable data = observable.map(); constructor(props: ConfigMapDetailsProps) { super(props); makeObservable(this); } async componentDidMount() { disposeOnUnmount(this, [ autorun(() => { const { object: configMap } = this.props; if (configMap) { this.data.replace(configMap.data); // refresh } }), ]); } save = async () => { const { object: configMap } = this.props; try { this.isSaving = true; await configMapStore.update(configMap, { ...configMap, data: Object.fromEntries(this.data), }); Notifications.ok((

{"ConfigMap "} {configMap.getName()} {" successfully updated."}

)); } catch (error) { Notifications.error(`Failed to save config map: ${error}`); } finally { this.isSaving = false; } }; render() { const { object: configMap } = this.props; if (!configMap) { return null; } if (!(configMap instanceof ConfigMap)) { logger.error("[ConfigMapDetails]: passed object that is not an instanceof ConfigMap", configMap); return null; } const data = Array.from(this.data.entries()); return (
{ data.length > 0 && ( <> Data { data.map(([name, value]) => (
{name}
this.data.set(name, v)} />
)) }
); } }