Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add export run #34 #48

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ require (
github.com/GeertJohan/go.rice v1.0.0
github.com/aws/aws-sdk-go v1.35.9
github.com/aymerick/raymond v2.0.2+incompatible
github.com/davecgh/go-spew v1.1.1
github.com/facebook/ent v0.4.3
github.com/gin-contrib/logger v0.0.2
github.com/gin-gonic/gin v1.6.3
Expand Down
137 changes: 137 additions & 0 deletions internal/graph/generated/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions internal/graph/mutation.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ input UpdateTemplateInput {
template: TemplateInput!
}

input ImportRunInput {
template: TemplateInput!
}

input DuplicateRunInput {
runID: ID!
# If toProjectID is nil, it will duplicate in the same project
Expand Down Expand Up @@ -267,6 +271,11 @@ type Mutation {
"""
duplicateRun(input: DuplicateRunInput): Run! @hasRole(role: ADMIN)

"""
Import a Run.
"""
importRun(input: ImportRunInput): Run! @hasRole(role: ADMIN)

"""
Create Run.
"""
Expand Down
4 changes: 4 additions & 0 deletions internal/graph/mutation.resolvers.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,10 @@ func (r *mutationResolver) DuplicateRun(ctx context.Context, input *model.Duplic
return result, nil
}

func (r *mutationResolver) ImportRun(ctx context.Context, input *model.ImportRunInput) (*ent.Run, error) {
panic(fmt.Errorf("not implemented"))
}

func (r *mutationResolver) CreateRun(ctx context.Context, input *model.CreateRunInput) (*ent.Run, error) {
tx, err := r.Store.Tx(ctx)
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions internal/model/models_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion web/src/components/misc/OptionsMenu.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
href="/"
class="block px-4 py-2 text-sm leading-5 text-gray-700
hover:bg-gray-100 hover:text-gray-900 focus:outline-none
focus:bg-gray-100 focus:text-gray-900 w-full"
focus:bg-gray-100 focus:text-gray-900 w-full text-left"
role="menuitem">
{option.text}
</button>
Expand Down
28 changes: 28 additions & 0 deletions web/src/components/runs/Run.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
} from "../../lib/queries";
import { push } from "../../lib/routing";
import { deepCopy } from "../../utils/copy";
import { exportJson } from "../../lib/models/run/run";
import { handleErrorMessage } from "../../utils/errorQuery";
import { debounce } from "../../utils/timing";
import StatusBadge from "../misc/StatusBadge.svelte";
Expand Down Expand Up @@ -179,6 +180,24 @@
}
};

const exportRun = async () => {
try {
exportJson(template);
notify({
success: true,
title: `Run Exported`,
});
} catch (error) {
console.error("export run ", error);
notify({
failed: true,
title: `Could not export Run`,
body:
"Something happened on the server, and we could not export the Run.",
});
}
};

let template = deepCopy(run.template);

function handleClick(event) {
Expand Down Expand Up @@ -212,6 +231,8 @@
case "duplicate":
duplicateRun();
break;
case "export":
exportRun();
default:
break;
}
Expand Down Expand Up @@ -241,6 +262,13 @@
actions = [];
facts = [];

actions.push({
text: "Export",
action: "export",
icon: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><path d="M400 208h-73.8V80c0-26.5-21.5-48-48-48H169.8c-26.5 0-48 21.5-48 48v128H48.1c-42.6 0-64.2 51.7-33.9 81.9l175.9 176c18.7 18.7 49.1 18.7 67.9 0l176-176c30-30.1 8.7-81.9-34-81.9zM224 432L48 256h121.8V80h108.3v176H400L224 432z"/></svg>`,
primary: false,
});

actions.push({
text: "Duplicate",
action: "duplicate",
Expand Down
37 changes: 34 additions & 3 deletions web/src/components/runs/RunLine.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script>
import { mutate } from "svelte-apollo";
import { mutate, query } from "svelte-apollo";
import { client } from "../../lib/apollo";
import { DUPLICATE_RUN } from "../../lib/queries";
import { DUPLICATE_RUN, GET_RUN } from "../../lib/queries";
import { push } from "../../lib/routing";
import { handleErrorMessage } from "../../utils/errorQuery";
import Link from "../base/Link.svelte";
Expand All @@ -10,6 +10,8 @@
import RelativeTime from "../misc/RelativeTime.svelte";
import StatusBadge from "../misc/StatusBadge.svelte";
import { notify } from "../overlays/Notification.svelte";
import { exportJson } from "../../lib/models/run/run";
import { deepCopy } from "../../utils/copy";

export let index = 0;
export let projectID;
Expand Down Expand Up @@ -54,7 +56,36 @@
}
};

const menuOptions = [{ text: "Duplicate", onClick: handleDuplicate }];
const handleExport = async () => {
try {
const runQuery = query(client, {
query: GET_RUN,
variables: { projectID: projectName, runID },
});

const result = await runQuery.refetch();
const template = deepCopy(result.data.project.runs[0].template);
exportJson(template);
notify({
failed: false,
title: `Run Exported`,
});
} catch (error) {
console.error("error ", error);
handleErrorMessage(error);
notify({
failed: true,
title: `Could not export Run`,
body:
"Something happened on the server, and we could not export the Run.",
});
}
};

const menuOptions = [
{ text: "Duplicate", onClick: handleDuplicate },
{ text: "Export", onClick: handleExport },
];
</script>

<li class={index !== 0 && 'border-t border-gray-200'}>
Expand Down
11 changes: 11 additions & 0 deletions web/src/lib/models/run/run.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import dayjs from "dayjs";

import { download } from "../../../utils/download";

export function exportJson(template) {
const content = JSON.stringify(template);
const mime = "application/json;charset=utf-8";
const date = dayjs().format("YYYY-MM-DDTHH:mm:ss");
const filename = `Empirica recruitment export Run - ${template.name} – ${date}.json`;
download(content, filename, mime);
}