Skip to content

Commit

Permalink
Fixed types.
Browse files Browse the repository at this point in the history
  • Loading branch information
huwshimi committed Jan 15, 2024
1 parent 82e2354 commit 97d2c88
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import process from "process";

import { Notification, Strip } from "@canonical/react-components";
import * as Sentry from "@sentry/browser";
import type { ReactNode } from "react";
import { StrictMode } from "react";
import type { Root } from "react-dom/client";
import { createRoot } from "react-dom/client";
import { Provider } from "react-redux";

Expand Down Expand Up @@ -64,11 +64,11 @@ export const getControllerAPIEndpointErrors = (
return null;
};

const renderRoot = (content: ReactNode) => {
const getRoot = (): Root | undefined => {
const rootElement = document.getElementById(ROOT_ID);
if (rootElement) {
const root = createRoot(rootElement);
root.render(content);
return root;
}
};

Expand Down Expand Up @@ -109,7 +109,7 @@ function bootstrap() {
);
error = error ?? controllerEndpointError;
if (error || !config) {
renderRoot(
getRoot()?.render(
<Strip>
<Notification severity="negative" title="Error">
The dashboard is not configured correctly. {error}
Expand Down Expand Up @@ -149,7 +149,7 @@ function bootstrap() {
.catch((error) => console.error(Label.POLLING_ERROR, error));
}

renderRoot(
getRoot()?.render(
<Provider store={reduxStore}>
<StrictMode>
<App />
Expand Down
3 changes: 2 additions & 1 deletion src/juju/watchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ function _processDelta<M extends WatcherModelData, E extends keyof M>(
};
mergeWith(modelData[entityType], formatted);
} else if (actionType === DeltaChangeTypes.REMOVE && entityType !== "model") {
if (entityId in modelData[entityType]) {
const data = modelData[entityType];
if (data && typeof data === "object" && entityId in data) {
delete modelData[entityType][entityId as keyof M[E]];
}
}
Expand Down

0 comments on commit 97d2c88

Please sign in to comment.