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

Don't clear cluster icon on cancel (#3191)

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2021-07-05 04:05:40 -04:00 committed by GitHub
parent 3f01abbddf
commit 4cae802a08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -48,44 +48,36 @@ export class ClusterIconSetting extends React.Component<Props> {
@boundMethod @boundMethod
async onIconPick([file]: File[]) { async onIconPick([file]: File[]) {
if (!file) {
return;
}
const { cluster } = this.props; const { cluster } = this.props;
try { try {
if (file) {
const buf = Buffer.from(await file.arrayBuffer()); const buf = Buffer.from(await file.arrayBuffer());
cluster.preferences.icon = `data:${file.type};base64,${buf.toString("base64")}`; cluster.preferences.icon = `data:${file.type};base64,${buf.toString("base64")}`;
} else {
// this has to be done as a seperate branch (and not always) because `cluster`
// is observable and triggers an update loop.
cluster.preferences.icon = undefined;
}
} catch (e) { } catch (e) {
this.errorText = e.toString(); this.errorText = e.toString();
this.status = GeneralInputStatus.ERROR; this.status = GeneralInputStatus.ERROR;
} }
} }
clearIcon() {
this.props.cluster.preferences.icon = undefined;
}
@boundMethod @boundMethod
onUploadClick() { onUploadClick() {
const input = this.element.current.querySelector("input[type=file]") as HTMLInputElement; this.element
.current
input.click(); .querySelector<HTMLInputElement>("input[type=file]")
.click();
} }
render() { render() {
const { entity } = this.props; const { entity } = this.props;
const label = (
<>
<HotbarIcon
uid={entity.metadata.uid}
title={entity.metadata.name}
source={entity.metadata.source}
src={entity.spec.icon?.src}
size={53}
/>
</>
);
return ( return (
<div ref={this.element}> <div ref={this.element}>
@ -93,16 +85,28 @@ export class ClusterIconSetting extends React.Component<Props> {
<div className="mr-5"> <div className="mr-5">
<FilePicker <FilePicker
accept="image/*" accept="image/*"
label={label} label={
<HotbarIcon
uid={entity.metadata.uid}
title={entity.metadata.name}
source={entity.metadata.source}
src={entity.spec.icon?.src}
size={53}
/>
}
onOverSizeLimit={OverSizeLimitStyle.FILTER} onOverSizeLimit={OverSizeLimitStyle.FILTER}
handler={this.onIconPick} handler={this.onIconPick}
/> />
</div> </div>
<MenuActions toolbar={false} autoCloseOnSelect={true} triggerIcon={{ material: "more_horiz" }}> <MenuActions
toolbar={false}
autoCloseOnSelect={true}
triggerIcon={{ material: "more_horiz" }}
>
<MenuItem onClick={this.onUploadClick}> <MenuItem onClick={this.onUploadClick}>
Upload Icon Upload Icon
</MenuItem> </MenuItem>
<MenuItem onClick={() => this.onIconPick([])} disabled={!this.props.cluster.preferences.icon}> <MenuItem onClick={() => this.clearIcon()} disabled={!this.props.cluster.preferences.icon}>
Clear Clear
</MenuItem> </MenuItem>
</MenuActions> </MenuActions>