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: entrypoint drafts in UI #569

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions src/frontend/src/components/CodeEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
:indent-with-tab="true"
:tab-size="2"
:extensions="extensions"
:disabled="readOnly"
@ready="handleReady"
@change="console.log('change', $event)"
@focus="console.log('focus', $event)"
Expand Down
52 changes: 47 additions & 5 deletions src/frontend/src/components/TableComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,51 @@
</template>

<template #top-right>
<q-btn v-if="!hideEditBtn" color="secondary" icon="edit" label="Edit" class="q-mr-lg" @click="$emit('edit')" :disabled="!selected?.length" />
<q-btn v-if="!hideDeleteBtn" color="negative" icon="sym_o_delete" label="Delete" class="q-mr-lg" @click="$emit('delete')" :disabled="!selected?.length" />
<q-btn
v-if="!hideEditBtn" color="secondary"
icon="edit"
label="Edit"
class="q-mr-lg"
@click="() => { if(!selected[0]?.hasDraft) $emit('edit') }"
:disabled="!selected?.length"
>
<q-menu v-if="selected[0]?.hasDraft">
<q-list style="min-width: 100px">
<q-item clickable v-close-popup @click="$emit('edit')">
<q-item-section>
Edit {{ title.substring(0, title.length - 1) }}
</q-item-section>
</q-item>
<q-separator />
<q-item clickable v-close-popup @click="$emit('editResourceDraft')">
<q-item-section>Edit Draft</q-item-section>
</q-item>
</q-list>
</q-menu>
</q-btn>
<q-btn
v-if="!hideDeleteBtn"
color="negative"
icon="sym_o_delete"
label="Delete"
class="q-mr-lg"
@click="() => { if(!selected[0]?.hasDraft) $emit('delete') }"
:disabled="!selected?.length"
>
<q-menu v-if="selected[0]?.hasDraft">
<q-list style="min-width: 100px">
<q-item clickable v-close-popup @click="$emit('delete')">
<q-item-section>
Delete {{ title.substring(0, title.length - 1) }}
</q-item-section>
</q-item>
<q-separator />
<q-item clickable v-close-popup @click="$emit('deleteResourceDraft')">
<q-item-section>Delete Draft</q-item-section>
</q-item>
</q-list>
</q-menu>
</q-btn>
<q-input v-if="!hideSearch" v-model="filter" debounce="300" dense placeholder="Search" outlined>
<template #append>
<q-icon name="search" />
Expand All @@ -114,7 +157,7 @@
push
:options="[
{label: title, value: false},
{label: 'Drafts', value: true},
{label: 'New Drafts', value: true},
]"
@click="refreshTable"
/>
Expand All @@ -129,7 +172,7 @@
const isMobile = inject('isMobile')

const props = defineProps(['columns', 'rows', 'title', 'showExpand', 'hideEditBtn', 'hideDeleteBtn', 'showToggleDraft', 'hideSearch', 'disableSelect', 'rightCaption'])
const emit = defineEmits(['edit', 'delete', 'request', 'expand', 'editTags'])
const emit = defineEmits(['edit', 'delete', 'request', 'expand', 'editTags', 'deleteResourceDraft', 'editResourceDraft'])

const finalColumns = computed(() => {
let defaultColumns = [ ...props.columns ]
Expand All @@ -154,7 +197,6 @@
const filter = ref('')
const selected = defineModel('selected')
const radioSelected = ref('')
//const showDrafts = ref(false)
const showDrafts = defineModel('showDrafts')

function handleClick(tableProps) {
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/dialogs/AssignTagsDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
try {
const res = await api.getData('tags', {index: 0, rowsPerPage: 50, search: ''})
tags.value = res.data.data
if(props.editObj.tags.length > 0) {
if(props.editObj.tags?.length > 0) {
props.editObj.tags.forEach((tag) => {
selectedTagIDs.value.push(tag.id)
})
Expand Down
16 changes: 12 additions & 4 deletions src/frontend/src/dialogs/DeleteDialog.vue
Original file line number Diff line number Diff line change
@@ -1,27 +1,35 @@
<template>
<DialogComponent
v-model="showDialog"
@emitSubmit="$emit('submit')"
@emitSubmit="$emit('submit', resourceDraftMode ? true : false)"
:hideDraftBtn="true"
>
<template #title>
<label id="modalTitle">
Delete {{ type }}
Delete {{ type }} {{ resourceDraftMode ? 'Draft' : '' }}
</label>
</template>
<q-card-section class="q-pt-none">
Are you sure you want to delete this {{ type }}? <br>
Are you sure you want to delete
<span v-if="resourceDraftMode"> the <span class="text-bold">draft</span> for </span>
this {{ type }}? <br>
Name: <span class="text-bold">{{ name }}</span>
</q-card-section>
</DialogComponent>
</template>

<script setup>
import { watch } from 'vue'
import DialogComponent from './DialogComponent.vue'

defineEmits(['submit'])
defineProps(['type', 'name'])

const showDialog = defineModel()
const showDialog = defineModel('showDialog')
const resourceDraftMode = defineModel('resourceDraftMode')

watch(showDialog, (newVal) => {
if(!newVal) resourceDraftMode.value = false
})

</script>
2 changes: 1 addition & 1 deletion src/frontend/src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const router = createRouter({
component: () => import('../views/EntryPointsView.vue')
},
{
path: '/entrypoints/:id',
path: '/entrypoints/:id/:draftType?/:resourceDraftParentId?',
component: () => import('../views/CreateEntryPoint.vue')
},
{
Expand Down
46 changes: 40 additions & 6 deletions src/frontend/src/services/dataApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,17 +172,33 @@ export async function getItem<T extends ItemType>(type: T, id: number, isDraft:
return res
}

export async function getDraft<T extends ItemType>(type: T, id: number) {
const res = await axios.get(`/api/${type}/${id}/draft`)
export async function getNewDraft<T extends ItemType>(type: T, draftId: number) {
const res = await axios.get(`/api/${type}/drafts/${draftId}`)
if(res.data) {
console.log('res = ', res)
Object.assign(res.data, res.data.payload)
}
return res
}

export async function getResourceDraft<T extends ItemType>(type: T, parentResourceId: number) {
console.log('parentResourceId = ', parentResourceId)
const res = await axios.get(`/api/${type}/${parentResourceId}/draft`)
if(res.data) {
console.log('res = ', res)
Object.assign(res.data, res.data.payload)
}
return res
}

export async function updateItem<T extends ItemType>(type: T, id: number, params: UpdateParams[T]) {
return await axios.put(`/api/${type}/${id}`, params)
// update item or NEW draft
export async function updateItem<T extends ItemType>(type: T, id: number, params: UpdateParams[T], isDraft?: boolean) {
return await axios.put(`/api/${type}/${isDraft ? 'drafts/' : ''}${id}`, params)
}

export async function addItem<T extends keyof CreateParams>(type: T, params: CreateParams[T]) {
return await axios.post(`/api/${type}/`, params)
// add item or NEW draft
export async function addItem<T extends keyof CreateParams>(type: T, params: CreateParams[T], isDraft?: boolean) {
return await axios.post(`/api/${type}/${isDraft ? 'drafts/' : ''}`, params)
}

interface JobParams {
Expand All @@ -203,12 +219,30 @@ export async function deleteJob(id: number, jobId: number) {

export async function addDraft<T extends keyof CreateParams>(type: T, params: CreateParams[T], id: number) {
if(id) {
// add RESOURCE draft
return await axios.post(`/api/${type}/${id}/draft`, params)
} else {
// add NEW draft
return await axios.post(`/api/${type}/drafts/`, params)
}
}

export async function addNewDraft<T extends keyof CreateParams>(type: T, params: CreateParams[T]) {
return await axios.post(`/api/${type}/drafts/`, params)
}

export async function addResourceDraft<T extends keyof CreateParams>(type: T, params: CreateParams[T], id: number) {
return await axios.post(`/api/${type}/${id}/draft`, params)
}

export async function updateResourceDraft<T extends keyof CreateParams>(type: T, params: CreateParams[T], id: number) {
return await axios.put(`/api/${type}/${id}/draft`, params)
}

export async function deleteResourceDraft<T extends keyof CreateParams>(type: T, id: number) {
return await axios.delete(`/api/${type}/${id}/draft`)
}

export async function updateDraft<T extends ItemType>(type: T, draftId: string, params: UpdateParams[T]) {
return await axios.put(`/api/${type}/drafts/${draftId}`, params)
}
Expand Down
66 changes: 53 additions & 13 deletions src/frontend/src/views/CreateEntryPoint.vue
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,14 @@
</div>
</fieldset>
</div>

<div :class="`${isMobile ? '' : 'q-mx-xl'} float-right q-mb-lg`">
<div :class="`${isMobile ? '' : 'q-mx-xl'} q-mb-lg row`">
<q-btn
v-if="route.params.id === 'new' && !route.params.draftType"
color="secondary"
label="Save Draft"
@click="submit(true)"
/>
<q-space />
<q-btn
to="/entrypoints"
color="negative"
Expand Down Expand Up @@ -265,11 +271,22 @@
getEntrypoint()
async function getEntrypoint() {
if(route.params.id === 'new') {
title.value = 'Create Entrypoint'
if(route.params.draftType === 'resourceDraft') {
const res = await api.getItem('entrypoints', route.params.resourceDraftParentId)
entryPoint.value = res.data
}
title.value = `Create ${route.params.draftType === 'resourceDraft' ? `Draft for ${entryPoint.value.name}` : 'Entrypoint'}`
return
}
try {
const res = await api.getItem('entrypoints', route.params.id)
let res
if (route.params.draftType === 'newDraft') {
res = await api.getNewDraft('entrypoints', route.params.id)
} else if(route.params.draftType === 'resourceDraft') {
res = await api.getResourceDraft('entrypoints', route.params.resourceDraftParentId)
} else {
res = await api.getItem('entrypoints', route.params.id)
}
entryPoint.value = res.data
title.value = `Edit ${res.data.name}`
console.log('entryPoint = ', entryPoint.value)
Expand All @@ -294,36 +311,59 @@

const taskGraphError = ref('')

function submit() {
function submit(isNewDraft = false) {
basicInfoForm.value.validate().then(success => {
taskGraphError.value = entryPoint.value.taskGraph.length > 0 ? '' : 'This field is required'
if (success && taskGraphError.value === '') {
addOrModifyEntrypoint()
}
else {
// error
addOrModifyEntrypoint(isNewDraft)
}
})
}

async function addOrModifyEntrypoint() {
async function addOrModifyEntrypoint(isNewDraft) {
entryPoint.value.queues.forEach((queue, index, array) => {
if(typeof queue === 'object') {
array[index] = queue.id
}
})
entryPoint.value?.plugins?.forEach((plugins, index, array) => {
if(typeof plugins === 'object') {
array[index] = plugins.id
}
})
try {
// CREATE
const createParams = {
name: entryPoint.value.name,
description: entryPoint.value.description,
taskGraph: entryPoint.value.taskGraph,
parameters: entryPoint.value.parameters,
queues: entryPoint.value.queues,
plugins: entryPoint.value.plugins
}
if (route.params.id === 'new') {
await api.addItem('entrypoints', entryPoint.value)
if(isNewDraft) {
await api.addNewDraft('entrypoints', entryPoint.value)
} else if(route.params.draftType === 'resourceDraft') {
await api.addResourceDraft('entrypoints', createParams, route.params.resourceDraftParentId)
} else {
await api.addItem('entrypoints', entryPoint.value)
}
notify.success(`Sucessfully created '${entryPoint.value.name}'`)
} else {
await api.updateItem('entrypoints', route.params.id, {
// EDIT
const params = {
name: entryPoint.value.name,
description: entryPoint.value.description,
taskGraph: entryPoint.value.taskGraph,
parameters: entryPoint.value.parameters,
queues: entryPoint.value.queues,
})
}
if (route.params.draftType === 'resourceDraft') {
await api.updateResourceDraft('entrypoints', params, route.params.resourceDraftParentId)
} else {
await api.updateItem('entrypoints', route.params.id, params, route.params.draftType === 'newDraft')
}
notify.success(`Sucessfully updated '${entryPoint.value.name}'`)
}
} catch(err) {
Expand Down
Loading