Skip to content

Commit

Permalink
wrap operator placements with suspense
Browse files Browse the repository at this point in the history
  • Loading branch information
imanjra committed May 8, 2023
1 parent ae4a70b commit c971e71
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
5 changes: 4 additions & 1 deletion app/packages/operators/src/OperatorPlacements.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import { Link } from "@fiftyone/components";
import styled from "styled-components";
import { types } from ".";
import { Operator } from "./operators";
import { withSuspense } from "@fiftyone/state";

export default function OperatorPlacements(props: OperatorPlacementsProps) {
function OperatorPlacements(props: OperatorPlacementsProps) {
const { place } = props;
const { placements } = useOperatorPlacements(place);

Expand All @@ -19,6 +20,8 @@ export default function OperatorPlacements(props: OperatorPlacementsProps) {
));
}

export default withSuspense(OperatorPlacements, () => null);

const componentByView = {
Button: ButtonPlacement,
};
Expand Down
1 change: 1 addition & 0 deletions app/packages/state/src/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,4 @@ export { default as useToPatches } from "./useToPatches";
export { default as useUpdateSamples } from "./useUpdateSamples";
export { default as useSchemaSettings } from "./useSchemaSettings";
export { settingsModal } from "./useSchemaSettings";
export { default as withSuspense } from "./withSuspense";
22 changes: 22 additions & 0 deletions app/packages/state/src/hooks/withSuspense.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from "react";
import { Suspense } from "react";

export default function withSuspense<ComponentProps>(
Component: React.ComponentType<ComponentProps>,
LoaderComponent: React.ComponentType<ComponentProps>
) {
const ComponentWithSuspense = (props: ComponentProps) => {
const Loading = LoaderComponent || DefaultLoader;
return (
<Suspense fallback={<Loading {...props} />}>
<Component {...props} />
</Suspense>
);
};

return ComponentWithSuspense;
}

function DefaultLoader() {
return null;
}
3 changes: 2 additions & 1 deletion app/packages/state/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"noImplicitReturns": true,
"noImplicitAny": false,
"plugins": [{ "name": "typescript-plugin-css-modules" }],
"composite": true
"composite": true,
"jsx": "react"
},
"include": ["./__mocks__", "./src", "tests/recoil/options.test.ts"],
"exclude": ["node_modules"]
Expand Down

0 comments on commit c971e71

Please sign in to comment.