-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
86c4c6a
commit 996730f
Showing
2 changed files
with
145 additions
and
1 deletion.
There are no files selected for viewing
138 changes: 138 additions & 0 deletions
138
lumigator/frontend/src/components/molecules/LExperimentTable.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
<template> | ||
<div class="l-experiment-table"> | ||
<transition name="transition-fade"> | ||
<DataTable | ||
v-if="tableVisible" | ||
:value="tableData" | ||
:tableStyle="style" | ||
columnResizeMode="expand" | ||
scrollable | ||
:pt="{table:'table-root'}" | ||
@row-click="emit('l-experiment-selected', $event.data)" | ||
> | ||
<Column | ||
field="name" | ||
header="experiment title" | ||
/> | ||
<Column | ||
field="created_at" | ||
header="created" | ||
> | ||
<template #body="slotProps"> | ||
{{ formatDate(slotProps.data.created_at) }} | ||
</template> | ||
</Column> | ||
<Column | ||
field="status" | ||
header="status" | ||
> | ||
<template #body="slotProps"> | ||
{{ retrieveStatus(slotProps.data.id) }} | ||
</template> | ||
</Column> | ||
<Column header="options"> | ||
<template #body="slotProps"> | ||
<span | ||
class="pi pi-fw pi-ellipsis-h l-experiment-table__options-trigger" | ||
aria-controls="optionsMenu" | ||
@click.stop="togglePopover($event, slotProps.data)" | ||
/> | ||
</template> | ||
</Column> | ||
</DataTable> | ||
</transition> | ||
</div> | ||
</template> | ||
|
||
<script setup> | ||
import { ref, computed, watch, onMounted, onUnmounted } from 'vue' | ||
import { storeToRefs } from 'pinia'; | ||
import DataTable from 'primevue/datatable'; | ||
import Column from 'primevue/column'; | ||
import { formatDate } from '@/helpers/index' | ||
import { useSlidePanel } from '@/composables/SlidingPanel'; | ||
import { useHealthStore } from '@/stores/health/store'; | ||
const props = defineProps({ | ||
tableData: { | ||
type: Array, | ||
required: true, | ||
} | ||
}); | ||
const isThrottled = ref(false); | ||
const { showSlidingPanel } = useSlidePanel(); | ||
const healthStore = useHealthStore(); | ||
const { runningJobs } = storeToRefs(healthStore); | ||
const tableVisible = ref(true) | ||
const style = computed(() => { | ||
return showSlidingPanel.value ? | ||
'min-width: min(40vw, 1200px)' : 'min-width: min(80vw, 1200px)' | ||
}) | ||
function retrieveStatus(jobID) { | ||
const job = runningJobs.value.find(job => job.id === jobID); | ||
return job ? job.status.toLowerCase() : null; | ||
} | ||
function updateJobStatuses() { | ||
runningJobs.value = props.tableData.map(experiment => ({ | ||
id: experiment.id, | ||
status: experiment.status | ||
})); | ||
console.log('props', props.tableData) | ||
console.log(runningJobs.value) | ||
} | ||
// Throttle ensures the function is invoked at most once every defined period. | ||
async function throttledUpdateAllJobs() { | ||
if (isThrottled.value) { return }; // Skip if throttle is active | ||
isThrottled.value = true; | ||
await healthStore.updateAllJobs(); | ||
setTimeout(() => { | ||
isThrottled.value = false; // Release throttle after delay | ||
}, 5000); // 5 seconds throttle | ||
} | ||
// This is a temporary solution until 'experiments/' endpoint | ||
// updates the status of each experiment | ||
let pollingId; | ||
onMounted(() => { | ||
updateJobStatuses(); | ||
pollingId = setInterval(() => { | ||
throttledUpdateAllJobs(); | ||
}, 1000); // Check every second, throttled to execute every 5 seconds | ||
}) | ||
onUnmounted(() => { | ||
clearInterval(pollingId); | ||
}); | ||
watch(showSlidingPanel, () => { | ||
tableVisible.value = false; | ||
setTimeout(() => { | ||
tableVisible.value = true; | ||
}, 100); | ||
}); | ||
watch(() => props.tableData.length, () => { | ||
updateJobStatuses(); | ||
}); | ||
</script> | ||
|
||
<style scoped lang="scss"> | ||
.l-experiment-table { | ||
$root: &; | ||
width: 100%; | ||
display: flex; | ||
place-content: center; | ||
&__options-trigger { | ||
padding: 0; | ||
margin-left: 20% !important; | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters