Skip to content

Commit

Permalink
Disable plugin if we can't connect to the plugin server
Browse files Browse the repository at this point in the history
  • Loading branch information
kbolashev committed Jul 31, 2023
1 parent 53154c5 commit d1baf31
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
30 changes: 25 additions & 5 deletions packages/dagshub/src/Plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import {Card, CardContent, CardHeader, Stack} from "@mui/material";
import {SaveDatasetButton} from "./SaveDatasetButton";
import styled from "styled-components";
import {UpdateMetadataButton} from "./UpdateMetadataButton";
import {ErrorModalProvider} from "./ErrorModal";
import {ErrorModalProvider, useErrorModal} from "./ErrorModal";
import {AlertSnackbarProvider} from "./AlertSnackbar";
import {fetchOrFail} from "./util";

const CardStack = styled.div`
display: flex;
Expand All @@ -25,13 +26,31 @@ const ActionsCard = styled(Card)`
min-width: 300px;
`

export function Plugin() {
const dataset = useRecoilValue(fos.dataset);
const view = useRecoilValue(fos.view);
const filters = useRecoilValue(fos.filters);
const BoundDatasetInfo = styled.h3`
margin: 20px 20px 0;
`

export function Plugin() {
const settings = fop.usePluginSettings<Settings>("dagshub", DefaultSettings());

const [serverOnline, setServerOnline] = useState(false);
const [reconnectRetries, setReconnectRetries] = useState(0);

useEffect(() => {
console.log("Settings:", settings)
}, [settings.server, settings.datasource_name])

useEffect(() => {
fetchOrFail(settings.server).then(() => setServerOnline(true)).catch(() => setServerOnline(false));
}, [settings.server, settings.datasource_name, reconnectRetries])

if (!serverOnline) {
return <div>
<h1>The plugin server is not running</h1>
<Button onClick={() => setReconnectRetries(reconnectRetries + 1)}>Try to reconnect</Button>
</div>
}

const toLabelStudio = () => {
// TODO: fix to use Fetch Or Fail here
fetch(`${settings.server}/labelstudio`, {
Expand Down Expand Up @@ -68,6 +87,7 @@ export function Plugin() {
<>
<ErrorModalProvider>
<AlertSnackbarProvider>
<BoundDatasetInfo>Bound to datasource: {settings.datasource_name}</BoundDatasetInfo>
<CardStack>
<ActionsCard raised={true}>
<CardHeader title={"Metadata"}/>
Expand Down
2 changes: 2 additions & 0 deletions packages/dagshub/src/Settings.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
export interface Settings {
server: string
in_colab: boolean
datasource_name: string
}

export const DefaultSettings = (): Settings => {
return {
// server: "http://localhost:5152"
server: "",
in_colab: false,
datasource_name: "",
};
}

0 comments on commit d1baf31

Please sign in to comment.