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

125 add analysis approval #127

Merged
merged 11 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 1 addition & 12 deletions components/MenuHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,7 @@ const items = ref([
{
label: "Projects",
icon: "pi pi-objects-column",
items: [
{
label: "Project List",
icon: "pi pi-clipboard",
route: "/projects",
},
{
label: "Proposals",
icon: "pi pi-list-check",
route: "/proposals",
},
],
route: "/projects",
},
{
label: "Analyses",
Expand Down
23 changes: 23 additions & 0 deletions components/analysis/AnalysesTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,15 @@ const onNavigate = () => {
const onCloseNavToast = () => {
toast.removeGroup("datastoreToastLink");
};

// function updateTable(newData: AnalysisNode) {
// for (let row of analyses.value) {
// if (row.id === newData.id) {
// row.approval_status = newData.approval_status;
// return;
// }
// }
// }
</script>

<template>
Expand Down Expand Up @@ -252,6 +261,20 @@ const onCloseNavToast = () => {
</Dropdown>
</template>
</Column>
<!-- <Column-->
<!-- field="id"-->
<!-- header="Set Approval"-->
<!-- style="min-width: 10em"-->
<!-- :exportable="false"-->
<!-- >-->
<!-- <template #body="slotProps">-->
<!-- <ApproveRejectButtons-->
<!-- :objectId="slotProps.data.id"-->
<!-- :objectClass="'analysis'"-->
<!-- @updatedRow="updateTable"-->
<!-- />-->
<!-- </template>-->
<!-- </Column>-->
<Column
field="analysis.build_status"
header="Build Status"
Expand Down
4 changes: 2 additions & 2 deletions components/data-stores/ResourceManagerTabs.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<script setup lang="ts">
import { getProposals } from "~/composables/useAPIFetch";
import { getProjectNodes } from "~/composables/useAPIFetch";
import type { ProjectNode } from "~/services/Api";

const availableProjects = ref();

const { data: projects, status: projStatus } = await getProposals();
const { data: projects, status: projStatus } = await getProjectNodes();

if (projStatus.value === "success") {
const projectData = projects.value.data as unknown as Array<ProjectNode>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { getProposals } from "~/composables/useAPIFetch";
import ApproveRejectButtons from "~/components/projects/ApproveRejectButtons.vue";
import { getProjectNodes } from "~/composables/useAPIFetch";
import ApproveRejectButtons from "~/components/table/ApproveRejectButtons.vue";
import { formatDataRow } from "~/utils/format-data-row";
import TableRowMetadata from "~/components/TableRowMetadata.vue";
import { ApprovalStatus, type ProjectNode } from "~/services/Api";
Expand All @@ -18,7 +18,7 @@ const expandRowEntries = [];

const approvalStatuses = Object.values(ApprovalStatus);

const { data: response, status, error, refresh } = await getProposals();
const { data: response, status, error, refresh } = await getProjectNodes();

function parseData() {
if (status.value === "success") {
Expand Down Expand Up @@ -187,7 +187,8 @@ const updateFilters = (filterText: string) => {
>
<template #body="slotProps">
<ApproveRejectButtons
:projectId="slotProps.data.id"
:objectId="slotProps.data.id"
:objectClass="'project'"
@updatedRow="updateTable"
/>
</template>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,36 @@
import { useToastService } from "~/composables/connectionErrorToast";

const props = defineProps({
projectId: String,
objectId: String,
objectClass: String,
});

const toast = useToastService();
const loading = ref(false);

const emit = defineEmits(["updatedRow"]);

async function onSubmitProjectApproval(isApproved: boolean) {
async function onSubmitApproval(isApproved: boolean) {
loading.value = true;

const formData = new FormData();
formData.append("approval_status", isApproved ? "approved" : "rejected");
const approvalResp = await useNuxtApp()
.$hubApi(`/project-nodes/${props.projectId}`, {
method: "POST",
body: formData,
})
.catch(() => null);
let approvalResp;

if (props.objectClass == "project") {
approvalResp = await useNuxtApp()
.$hubApi(`/project-nodes/${props.objectId}`, {
method: "POST",
body: formData,
})
.catch(() => null);
} else if (props.objectClass == "analysis") {
approvalResp = await useNuxtApp()
.$hubApi(`/analysis-nodes/${props.objectId}`, {
method: "POST",
body: formData,
})
.catch(() => null);
}
if (approvalResp) {
showSuccessfulSubmission(isApproved);
// Send data to parent component
Expand Down Expand Up @@ -61,15 +71,15 @@ const showFailedSubmission = () => {
severity="success"
:loading="loading"
style="margin-right: 10px"
@click="onSubmitProjectApproval(true)"
@click="onSubmitApproval(true)"
/>
<Button
icon="pi pi-times"
aria-label="Reject"
v-tooltip.top="'Send rejection'"
severity="danger"
:loading="loading"
@click="onSubmitProjectApproval(false)"
@click="onSubmitApproval(false)"
/>
</div>
</template>
Expand Down
25 changes: 25 additions & 0 deletions composables/connectionErrorToast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,28 @@ export const showDownstreamConnectionErrorToast = (service: string) => {
});
console.warn(`The ${service} service is unreachable`);
};

export const showInvalidRobotCredentialsToast = () => {
const toast = useToastService();
toast.add({
severity: "error",
summary: "Invalid Robot Credentials",
detail:
"The robot credentials provided during deployment are not valid. Please verify the correct robot ID and " +
"secret were used, then upgrade your installation",
life: 10000,
});
console.warn("Invalid robot credentials");
};

export const showWrongRobotIdToast = () => {
const toast = useToastService();
toast.add({
severity: "error",
summary: "Invalid Robot ID",
detail:
"The robot ID is not a valid UUID. Please verify the robot ID was used during deployment and not the name.",
life: 10000,
});
console.warn("Invalid robot ID");
};
2 changes: 1 addition & 1 deletion composables/useAPIFetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function useAPIFetch<T>(
}

// Hub endpoints
export function getProposals(opts?) {
export function getProjectNodes(opts?) {
return useAPIFetch<{ data: ListProjectNodes }>("/project-nodes", {
...opts,
method: "GET",
Expand Down
6 changes: 2 additions & 4 deletions pages/projects.vue
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
<script setup>
import ProjectTable from "~/components/projects/ProjectTable.vue";
import ProjectProposalTable from "~/components/projects/ProjectProposalTable.vue";

definePageMeta({
middleware: ["auth"],
});
</script>

<template>
<!-- <div v-if="loggedIn">-->
<ProjectTable />
<!-- </div>-->
<ProjectProposalTable />
</template>

<style scoped lang="scss"></style>
4 changes: 2 additions & 2 deletions pages/proposals.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<script setup lang="ts">
import ProposalTable from "~/components/projects/ProposalTable.vue";
import ProjectProposalTable from "~/components/projects/ProjectProposalTable.vue";

definePageMeta({
middleware: ["auth"],
});
</script>

<template>
<ProposalTable />
<ProjectProposalTable />
</template>

<style scoped lang="scss"></style>
9 changes: 9 additions & 0 deletions plugins/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import {
showKongConnectionErrorToast,
showHubAdapterConnectionErrorToast,
showDownstreamConnectionErrorToast,
showWrongRobotIdToast,
showInvalidRobotCredentialsToast,
} from "~/composables/connectionErrorToast";

export default defineNuxtPlugin(() => {
Expand Down Expand Up @@ -42,6 +44,13 @@ export default defineNuxtPlugin(() => {
downstreamService = "for this process";
}
showDownstreamConnectionErrorToast(downstreamService);
} else if (response.status === 400) {
navigateTo("/");
if (response._data.detail.code === "invalid_credentials") {
showInvalidRobotCredentialsToast();
} else {
showWrongRobotIdToast();
}
}
},
});
Expand Down