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: new common job form #683

Merged
merged 1 commit into from
Dec 23, 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
125 changes: 125 additions & 0 deletions src/frontend/src/dialogs/AppendResource.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
<template>
<DialogComponent
v-model="showDialog"
@emitSubmit="submit"
:hideDraftBtn="true"
>
<template #title>
<label id="modalTitle">
Assign {{ childResourceType }} for '{{ parentResourceObj.name }}'
</label>
</template>
<q-select
outlined
dense
v-model="childResourceObjs"
use-input
use-chips
multiple
option-label="name"
option-value="id"
input-debounce="100"
:options="childResourceOptions"
@filter="getChildResources"
>
<template v-slot:before>
<div class="field-label text-capitalize">{{ childResourceType }}:</div>
</template>
<template v-slot:selected>
<div>
<div
v-for="(resource, i) in childResourceObjs"
:key="resource.id"
:class="i > 0 ? 'q-mt-xs' : ''"
>
<q-chip
removable
color="secondary"
text-color="white"
class="q-ml-xs "
@remove="childResourceObjs.splice(i, 1)"
>
{{ resource.name }}
</q-chip>
</div>
</div>
</template>
</q-select>
</DialogComponent>
</template>

<script setup>
import { ref, watch, computed } from 'vue'
import DialogComponent from './DialogComponent.vue'
import * as api from '@/services/dataApi'
import * as notify from '../notify'


const props = defineProps(['parentResourceType', 'parentResourceObj', 'childResourceType' ])
const emit = defineEmits(['submit'])

const showDialog = defineModel()

const childResourceObjs = ref([])
const selectedChildIds = computed(() => {
return childResourceObjs.value.map((obj) => obj.id)
})

const childResourceOptions = ref([])
const originalChildIds = ref()

watch(showDialog, (newVal) => {
if(newVal) {
console.log('props = ', props.parentResourceObj)
childResourceObjs.value = JSON.parse(JSON.stringify(props.parentResourceObj[props.childResourceType]))
originalChildIds.value = JSON.parse(JSON.stringify(props.parentResourceObj[props.childResourceType].map((obj) => obj.id)))
}
})

async function submit() {
let childIdsToAdd = []
let childIdsToRemove = []

selectedChildIds.value.forEach((id) => {
if (!originalChildIds.value.includes(id)) {
childIdsToAdd.push(id)
}
})

originalChildIds.value.forEach((id) => {
if (!selectedChildIds.value.includes(id)) {
childIdsToRemove.push(id)
}
})

try {
if(childIdsToAdd.length > 0) {
await api.appendResource(props.parentResourceType, props.parentResourceObj.id, props.childResourceType, childIdsToAdd)
}
for(const id of childIdsToRemove) {
await api.removeResourceFromResource(props.parentResourceType, props.parentResourceObj.id, props.childResourceType, id)
}
notify.success(`Successfully updated ${props.childResourceType} for '${props.parentResourceObj.name}'`)
showDialog.value = false
emit('submit')
} catch (err) {
notify.error(err.message)
}
}

async function getChildResources(val = '', update) {
update(async () => {
try {
const res = await api.getData(props.childResourceType, {
search: val,
rowsPerPage: 0, // get all
index: 0
})
childResourceOptions.value = res.data.data.filter((ep) => !selectedChildIds.value.includes(ep.id))
} catch(err) {
notify.error(err.response.data.message)
}
})
}

</script>
4 changes: 4 additions & 0 deletions src/frontend/src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ const router = createRouter({
path: '/experiments/:id/jobs/:jobId',
component: () => import('../views/CreateJob.vue')
},
{
path: '/jobs/new',
component: () => import('../views/CreateJob.vue')
},
{
path: '/experiments/:id',
component: () => import('../views/CreateExperiment.vue')
Expand Down
8 changes: 8 additions & 0 deletions src/frontend/src/services/dataApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,14 @@ export async function removePluginFromEntrypoint(entrypointId: string, pluginId:
return await axios.delete(`/api/entrypoints/${entrypointId}/plugins/${pluginId}`)
}

export async function appendResource<T extends ItemType>(parentResourceType: T, parentResourceId: number, childResourceType: T, ids: number[]) {
return await axios.post(`/api/${parentResourceType}/${parentResourceId}/${childResourceType}`, {ids})
}

export async function removeResourceFromResource<T extends ItemType>(parentResourceType: T, parentResourceId: number, childResourceType: T, id: number) {
return await axios.delete(`/api/${parentResourceType}/${parentResourceId}/${childResourceType}/${id}`)
}

export async function getVersions(id: string,) {
return await axios.get(`/api/models/${id}/versions`)
}
Expand Down
6 changes: 5 additions & 1 deletion src/frontend/src/views/AllJobsView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@
ref="tableRef"
:hideEditBtn="true"
@editTags="(row) => { editObjTags = row; showTagsDialog = true }"
:hideCreateBtn="true"
@create="router.push('/jobs/new')"
>
<template #body-cell-experiment="props">
{{ props.row.experiment.name }}
</template>
<template #body-cell-entrypoint="props">
{{ props.row.entrypoint.name }}
</template>
Expand Down Expand Up @@ -61,6 +64,7 @@
const columns = [
{ name: 'description', label: 'Description', align: 'left', field: 'description', sortable: true, },
{ name: 'id', label: 'Job ID', align: 'left', field: 'id', sortable: false, },
{ name: 'experiment', label: 'Experiment', align: 'left', field: 'experiment', sortable: false, },
{ name: 'entrypoint', label: 'Entrypoint', align: 'left', field: 'entrypoint', sortable: false, },
{ name: 'queue', label: 'Queue', align: 'left', field: 'queue', sortable: false, },
{ name: 'status', label: 'Status', align: 'left', field: 'status', sortable: true },
Expand Down
Loading