Skip to content

Commit 309dce7

Browse files
committed
improve the compute server filter -- it shouldn't vanish on edit
- surprisingly tricky....
1 parent 5d398c5 commit 309dce7

File tree

2 files changed

+53
-12
lines changed

2 files changed

+53
-12
lines changed

src/packages/frontend/compute/compute-server.tsx

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ interface Server1 extends Omit<ComputeServerUserInfo, "id"> {
2929

3030
interface Controls {
3131
setShowDeleted?: (showDeleted: boolean) => void;
32-
setSearch?: (search: string) => void;
3332
onTitleChange?;
3433
onColorChange?;
3534
onCloudChange?;
@@ -44,6 +43,9 @@ interface Props {
4443
modalOnly?: boolean;
4544
close?: () => void;
4645
}
46+
export const currentlyEditing = {
47+
id: 0,
48+
};
4749

4850
export default function ComputeServer({
4951
server,
@@ -74,7 +76,6 @@ export default function ComputeServer({
7476

7577
const {
7678
setShowDeleted,
77-
setSearch,
7879
onTitleChange,
7980
onColorChange,
8081
onCloudChange,
@@ -88,6 +89,11 @@ export default function ComputeServer({
8889
if (!edit && close != null) {
8990
close();
9091
}
92+
if (edit) {
93+
currentlyEditing.id = id ?? 0;
94+
} else {
95+
currentlyEditing.id = 0;
96+
}
9197
};
9298

9399
if (id == null && modalOnly) {
@@ -112,11 +118,6 @@ export default function ComputeServer({
112118
key="edit"
113119
type="text"
114120
onClick={() => {
115-
if (!edit) {
116-
// clear the search -- otherwise changing the title a little
117-
// closes the modal!
118-
setSearch?.("");
119-
}
120121
setEdit(!edit);
121122
}}
122123
>
@@ -304,7 +305,8 @@ export default function ComputeServer({
304305
{buttons}
305306
<Divider />
306307
<Icon name="edit" style={{ marginRight: "15px" }} />{" "}
307-
{editable ? "Edit" : ""} Compute Server With Id={project_specific_id}
308+
{editable ? "Edit" : ""} Compute Server With Id=
309+
{project_specific_id}
308310
</>
309311
}
310312
footer={
@@ -368,7 +370,9 @@ export default function ComputeServer({
368370
name={cloud == "onprem" ? "global" : "server"}
369371
style={{ fontSize: "30px", color: color ?? "#666" }}
370372
/>
371-
{id != null && <div style={{ color: "#888" }}>Id: {project_specific_id}</div>}
373+
{id != null && (
374+
<div style={{ color: "#888" }}>Id: {project_specific_id}</div>
375+
)}
372376
{id != null && (
373377
<ComputeServerLog id={id} style={{ marginLeft: "-15px" }} />
374378
)}

src/packages/frontend/compute/compute-servers.tsx

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
import { A } from "@cocalc/frontend/components/A";
2-
import ComputeServer from "./compute-server";
2+
import ComputeServer, { currentlyEditing } from "./compute-server";
33
import CreateComputeServer from "./create-compute-server";
44
import { useTypedRedux } from "@cocalc/frontend/app-framework";
55
import { cmp, plural } from "@cocalc/util/misc";
66
import { availableClouds } from "./config";
7-
import { Input, Card, Checkbox, Radio, Switch, Tooltip } from "antd";
7+
import {
8+
Alert,
9+
Button,
10+
Input,
11+
Card,
12+
Checkbox,
13+
Radio,
14+
Switch,
15+
Tooltip,
16+
} from "antd";
817
import { useEffect, useState } from "react";
918
const { Search } = Input;
1019
import { search_match, search_split } from "@cocalc/util/misc";
@@ -166,6 +175,7 @@ function ComputeServerTable({
166175
>(
167176
(get_local_storage(`${project_id}-compute-server-sort`) ?? "custom") as any,
168177
);
178+
169179
if (!computeServers || computeServers.size == 0) {
170180
return (
171181
<div style={{ textAlign: "center" }}>
@@ -179,7 +189,14 @@ function ComputeServerTable({
179189
const search_words = search_split(search.toLowerCase());
180190
const ids: number[] = [];
181191
let numDeleted = 0;
192+
let numSkipped = 0;
182193
for (const [id] of computeServers) {
194+
if (currentlyEditing.id == id) {
195+
// always include the one that is currently being edited. We wouldn't want,
196+
// e.g., changing the title shouldn't make the editing modal vanish!
197+
ids.push(id);
198+
continue;
199+
}
183200
const isDeleted = !!computeServers.getIn([id, "deleted"]);
184201
if (isDeleted) {
185202
numDeleted += 1;
@@ -191,6 +208,7 @@ function ComputeServerTable({
191208
if (
192209
!search_match(computeServerToSearch(computeServers, id), search_words)
193210
) {
211+
numSkipped += 1;
194212
continue;
195213
}
196214
}
@@ -258,7 +276,7 @@ function ComputeServerTable({
258276
style={{ marginBottom: "10px" }}
259277
key={`${id}`}
260278
editable={account_id == server.account_id}
261-
controls={{ setShowDeleted, setSearch }}
279+
controls={{ setShowDeleted }}
262280
/>
263281
</div>
264282
);
@@ -347,6 +365,25 @@ function ComputeServerTable({
347365
</Checkbox>
348366
)}
349367
</div>
368+
{numSkipped > 0 && (
369+
<Alert
370+
showIcon
371+
style={{ margin: "15px auto", maxWidth: "600px" }}
372+
type="warning"
373+
message={
374+
<div style={{ marginTop: "5px" }}>
375+
Not showing {numSkipped} compute servers due to current filter.
376+
<Button
377+
type="text"
378+
style={{ float: "right", marginTop: "-5px" }}
379+
onClick={() => setSearch("")}
380+
>
381+
Clear
382+
</Button>
383+
</div>
384+
}
385+
/>
386+
)}
350387
<div
351388
style={{ /* maxHeight: "60vh", overflow: "auto", */ width: "100%" }}
352389
>

0 commit comments

Comments
 (0)