Skip to content

Commit

Permalink
implement view snapshot button
Browse files Browse the repository at this point in the history
This commit implements issue Raathigesh#186. I can't know if there is a snapshot for each
but I can add a button to the summary that opens the snapshot for the file
in the code editor. That's what this commit does. It adds the button to the
UI and a mutation to send to the server to open the snapshot in the editor.
  • Loading branch information
Greg Veres committed May 15, 2020
1 parent 0356052 commit 08edc68
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
13 changes: 13 additions & 0 deletions server/api/app/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as launch from "launch-editor";
import { App } from "./app";
import FileWatcher, { WatcherEvents } from "../../services/file-watcher";
import { pubsub } from "../../event-emitter";
import { dirname, basename } from "path";

@Resolver(App)
export default class AppResolver {
Expand Down Expand Up @@ -45,6 +46,18 @@ export default class AppResolver {
return "";
}

@Mutation(returns => String)
openSnapInEditor(@Arg("path") path: string) {
var dir = dirname(path)
var file = basename(path);

var snap = dir + '/__snapshots__/' + file + '.snap'
console.log("opening the snapshot:", snap);
this.openInEditor(snap);

return "";
}

@Mutation(returns => String)
openFailure(@Arg("failure") failure: string) {
// The following regex matches the first line of the form: \w at <some text> (<file path>)
Expand Down
19 changes: 18 additions & 1 deletion ui/test-file/summary/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ import {
CheckCircle,
Frown,
ZapOff,
Circle
Circle,
Eye
} from "react-feather";
import Button from "../../components/button";
import OPEN_IN_EDITOR from "./open-in-editor.gql";
import OPEN_SNAP_IN_EDITOR from "./open-snap-in-editor.gql";
import { Tooltip } from "react-tippy";
import { useMutation } from "react-apollo-hooks";

Expand Down Expand Up @@ -138,6 +140,12 @@ export default function FileSummary({
}
});

const openSnapshotInEditor = useMutation(OPEN_SNAP_IN_EDITOR, {
variables: {
path
}
});

return (
<Container p={4} bg="slightDark">
{(isRunning || isLoadingResult) && <ContainerBG />}
Expand Down Expand Up @@ -204,6 +212,15 @@ export default function FileSummary({
Update Snapshot
</Button>
</Tooltip>
<Tooltip title="Open snapshot in editor" size="small" position="bottom">
<Button
icon={<Eye size={14} />}
minimal
onClick={() => {
openSnapshotInEditor();
}}
/>
</Tooltip>
</ActionPanel>
</Container>
);
Expand Down
3 changes: 3 additions & 0 deletions ui/test-file/summary/open-snap-in-editor.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mutation OpenSnapInEditor($path: String!) {
openSnapInEditor(path: $path)
}

0 comments on commit 08edc68

Please sign in to comment.