Skip to content

Commit

Permalink
fix: UI refresh timing bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
garethgeorge committed May 27, 2024
1 parent ce42f68 commit ba005ae
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 62 deletions.
2 changes: 1 addition & 1 deletion webui/src/components/ActivityBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const ActivityBar = () => {
return () => {
unsubscribeFromOperations(callback);
};
});
}, []);

const details = activeOperations.map((op) => {
return {
Expand Down
6 changes: 3 additions & 3 deletions webui/src/components/OperationList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const OperationList = ({
setBackups(backups);
},
100,
{ leading: true, trailing: true }
{ trailing: true }
)
);

Expand Down Expand Up @@ -108,11 +108,11 @@ export const OperationList = ({
itemLayout="horizontal"
size="small"
dataSource={operations}
renderItem={(op) => {
renderItem={(op, index) => {
return (
<OperationRow
alertApi={alertApi!}
key={op.id}
key={op.id + "-" + index}
operation={op}
showPlan={showPlan || false}
/>
Expand Down
2 changes: 1 addition & 1 deletion webui/src/components/OperationRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ export const OperationRow = ({
children.push(body);

return (
<List.Item>
<List.Item key={operation.id}>
<List.Item.Meta title={title} avatar={avatar} description={children} />
</List.Item>
);
Expand Down
70 changes: 37 additions & 33 deletions webui/src/components/StatsPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
BackupInfoCollector,
getOperations,
subscribeToOperations,
unsubscribeFromOperations,
} from "../state/oplog";
import { MAX_OPERATION_HISTORY } from "../constants";
import { GetOperationsRequest, OpSelector } from "../../gen/ts/v1/service_pb";
Expand All @@ -36,38 +37,42 @@ const StatsPanel = ({ repoId }: { repoId: string }) => {
return;
}

const refreshOperations = _.debounce(() => {
const backupCollector = new BackupInfoCollector((op) => {
return (
op.status === OperationStatus.STATUS_SUCCESS &&
op.op.case === "operationStats" &&
!!op.op.value.stats
);
});
const refreshOperations = _.debounce(
() => {
const backupCollector = new BackupInfoCollector((op) => {
return (
op.status === OperationStatus.STATUS_SUCCESS &&
op.op.case === "operationStats" &&
!!op.op.value.stats
);
});

getOperations(
new GetOperationsRequest({
selector: new OpSelector({
repoId: repoId,
}),
lastN: BigInt(MAX_OPERATION_HISTORY),
})
)
.then((ops) => {
backupCollector.bulkAddOperations(ops);
getOperations(
new GetOperationsRequest({
selector: new OpSelector({
repoId: repoId,
}),
lastN: BigInt(MAX_OPERATION_HISTORY),
})
)
.then((ops) => {
backupCollector.bulkAddOperations(ops);

const operations = backupCollector
.getAll()
.flatMap((b) => b.operations);
operations.sort((a, b) => {
return Number(b.unixTimeEndMs - a.unixTimeEndMs);
const operations = backupCollector
.getAll()
.flatMap((b) => b.operations);
operations.sort((a, b) => {
return Number(b.unixTimeEndMs - a.unixTimeEndMs);
});
setOperations(() => operations);
})
.catch((e) => {
alertApi!.error("Failed to fetch operations: " + e.message);
});
setOperations(operations);
})
.catch((e) => {
alertApi!.error("Failed to fetch operations: " + e.message);
});
}, 1000);
},
100,
{ trailing: true }
);

refreshOperations();

Expand All @@ -82,7 +87,9 @@ const StatsPanel = ({ repoId }: { repoId: string }) => {

subscribeToOperations(handler);

return () => {}; // cleanup
return () => {
unsubscribeFromOperations(handler);
};
}, [repoId]);

if (operations.length === 0) {
Expand All @@ -108,9 +115,6 @@ const StatsPanel = ({ repoId }: { repoId: string }) => {
};
});

const minTime = Math.min(...dataset.map((d) => d.time));
const maxTime = Math.max(...dataset.map((d) => d.time));

return (
<>
<Row>
Expand Down
2 changes: 2 additions & 0 deletions webui/src/state/oplog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export const subscribeToOperations = (
callback: (event: OperationEvent) => void,
) => {
subscribers.push(callback);
console.log("subscribed to operations, subscriber count: ", subscribers.length);
};

export const unsubscribeFromOperations = (
Expand All @@ -55,6 +56,7 @@ export const unsubscribeFromOperations = (
subscribers[index] = subscribers[subscribers.length - 1];
subscribers.pop();
}
console.log("unsubscribed from operations, subscriber count: ", subscribers.length);
};

export const getStatusForSelector = async (sel: OpSelector) => {
Expand Down
44 changes: 23 additions & 21 deletions webui/src/views/GettingStartedGuide.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,28 +64,30 @@ export const GettingStartedGuide = () => {
configured either at the plan or repo level.
</li>
</ul>
<Divider orientation="left">Config View</Divider>
{isDevBuild && (
<Collapse
size="small"
items={[
{
key: "1",
label: "Config JSON hidden for security",
children: config ? (
<Typography>
<pre>
{config.toJsonString({
prettySpaces: 2,
})}
</pre>
</Typography>
) : (
<Spin />
),
},
]}
/>
<>
<Divider orientation="left">Config View</Divider>
<Collapse
size="small"
items={[
{
key: "1",
label: "Config JSON hidden for security",
children: config ? (
<Typography>
<pre>
{config.toJsonString({
prettySpaces: 2,
})}
</pre>
</Typography>
) : (
<Spin />
),
},
]}
/>
</>
)}
</Typography.Text>
</>
Expand Down
6 changes: 3 additions & 3 deletions webui/src/views/LoginModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@ export const LoginModal = () => {
new LoginRequest({
username: "default",
password: "password",
}),
})
)
.then((loginResponse) => {
alertApi.success(
"No users configured yet, logged in with default credentials",
5,
5
);
setAuthToken(loginResponse.token);
setTimeout(() => {
window.location.reload();
}, 500);
})
.catch((e) => {});
});
}, []);

const onFinish = async (values: any) => {
const loginReq = new LoginRequest({
Expand Down

0 comments on commit ba005ae

Please sign in to comment.