Skip to content

Commit

Permalink
Merge pull request #332 from dolthub/taylor/refresh
Browse files Browse the repository at this point in the history
web: Don't use cache-only for status, reset button resets cache store
  • Loading branch information
tbantle22 authored Dec 18, 2024
2 parents 5d5b2c5 + 31c3a88 commit e5f34d2
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,16 @@ import { useState } from "react";
import css from "./index.module.css";

export default function ResetConnectionButton() {
const { mutateFn, loading, err, setErr } = useMutation({
const { mutateFn, loading, err, setErr, client } = useMutation({
hook: useResetDatabaseMutation,
});
const [errorModalOpen, setErrorModalOpen] = useState(false);

const onClick = async () => {
await mutateFn();
await client.resetStore();
};

const onClose = () => {
setErrorModalOpen(false);
setErr(undefined);
Expand All @@ -26,9 +31,9 @@ export default function ResetConnectionButton() {
<>
<Button.Link
className={css.resetButton}
onClick={async () => mutateFn()}
data-tooltip-content="Reset connection"
data-tooltip-id="reset-connection"
onClick={onClick}
data-tooltip-content="Refresh connection"
data-tooltip-id="refresh-connection"
>
<SmallLoader
loaded={!loading}
Expand All @@ -37,11 +42,11 @@ export default function ResetConnectionButton() {
<IoReloadSharp />
</SmallLoader>
</Button.Link>
<Tooltip id="reset-connection" className={css.tooltip} />
<Tooltip id="refresh-connection" className={css.tooltip} />
<Modal
isOpen={errorModalOpen}
onRequestClose={onClose}
title="Error resetting connection"
title="Error refreshing connection"
>
<ErrorMsg err={err} />
</Modal>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Btn } from "@dolthub/react-components";
import { OptionalRefParams } from "@lib/params";
import { GiHamburgerMenu } from "@react-icons/all-files/gi/GiHamburgerMenu";
import AddItemDropdown from "./AddItemDropdown";
import ResetConnectionButton from "./ResetConnectionButton";
import RefreshConnectionButton from "./RefreshConnectionButton";
import css from "./index.module.css";

type Props = {
Expand All @@ -13,7 +13,7 @@ type Props = {
export default function RightHeaderButtons(props: Props) {
return (
<div className={css.topRight}>
<ResetConnectionButton />
<RefreshConnectionButton />
<AddItemDropdown params={props.params} />
<div className={css.menu}>
<Btn onClick={props.onMenuClick}>
Expand Down
5 changes: 4 additions & 1 deletion web/renderer/components/StatusWithOptions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ function Inner(props: InnerProps) {
}

export default function StatusWithOptions(props: Props) {
const res = useGetStatusQuery({ variables: props.params });
const res = useGetStatusQuery({
variables: props.params,
fetchPolicy: "cache-and-network",
});
if (res.loading) return <Loader loaded={false} />;
if (res.error || !res.data || res.data.status.length === 0) {
return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { getCommit } from "@components/CommitGraph/utils";
import Link from "@components/links/Link";
import { Button, ErrorMsg, Loader } from "@dolthub/react-components";
import {
CommitForHistoryFragment,
StatusFragment,
useGetStatusQuery,
} from "@gen/graphql-types";
import { useCommitOverview } from "@hooks/useCommitListForCommitGraph/useCommitOverview";
import { RefParams, RequiredCommitsParams } from "@lib/params";
import { diff } from "@lib/urls";
import cx from "classnames";
import { DiffSection } from "commit-graph";
import { getCommit } from "@components/CommitGraph/utils";
import { useCommitOverview } from "@hooks/useCommitListForCommitGraph/useCommitOverview";
import css from "./index.module.css";

type Props = {
Expand Down Expand Up @@ -127,7 +127,10 @@ function Inner(props: InnerProps) {
}

export default function Uncommitted(props: Props) {
const res = useGetStatusQuery({ variables: props.params });
const res = useGetStatusQuery({
variables: props.params,
fetchPolicy: "cache-and-network",
});
if (res.loading) return <Loader loaded={false} />;
if (res.error || !res.data || res.data.status.length === 0) {
return null;
Expand Down

0 comments on commit e5f34d2

Please sign in to comment.