Skip to content

Commit

Permalink
feat: Add task list to Sector Info page
Browse files Browse the repository at this point in the history
  • Loading branch information
strahe committed Sep 4, 2024
1 parent dcd665a commit e04cb3b
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 4 deletions.
16 changes: 16 additions & 0 deletions graph/loaders/sector.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,26 @@ type SectorLoader interface {
SectorLocations(ctx context.Context, actor types.ActorID, sectorNumber int) ([]*model.SectorLocation, error)
SectorPieces(ctx context.Context, actor types.ActorID, sectorNumber int) ([]*model.SectorMetaPiece, error)
SectorEvents(ctx context.Context, actor types.ActorID, sectorNumber int) ([]*model.TaskHistory, error)
SectorTasks(ctx context.Context, actor types.ActorID, sectorNumber int) ([]*model.Task, error)
}

var _ SectorLoader = &Loader{}

func (l *Loader) SectorTasks(ctx context.Context, actor types.ActorID, sectorNumber int) ([]*model.Task, error) {
var tasks []*model.Task
if err := l.db.Select(ctx, &tasks, `
WITH task_ids AS (
SELECT unnest(get_sdr_pipeline_tasks($1, $2)) AS task_id
)
SELECT ht.id, ht.name, ht.posted_time, ht.update_time, ht.initiated_by, ht.owner_id, ht.previous_task, ht.added_by
FROM task_ids
INNER JOIN harmony_task ht ON ht.id = task_id;
`, actor, sectorNumber); err != nil {
return nil, err
}
return tasks, nil
}

func (l *Loader) SectorMetas(ctx context.Context, actor *types.ActorID, offset int, limit int) ([]*model.SectorMeta, error) {
var m []*model.SectorMeta
if actor == nil {
Expand Down
3 changes: 2 additions & 1 deletion graph/resolvers/sector.go

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

15 changes: 14 additions & 1 deletion ui/src/views/query/sector.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import gql from 'graphql-tag'
import { taskHistoryFragment } from '@/views/query/task'
import { taskFragment, taskHistoryFragment } from '@/views/query/task'

const metaFragment = gql`
fragment MetaAll on SectorMeta {
Expand Down Expand Up @@ -114,3 +114,16 @@ export const GetSectorEvents = gql`
}
${taskHistoryFragment}
`

export const GetSectorTasks = gql`
query GetSectorTasks($miner: ActorID!, $sectorNumber: Int!) {
sector(actor: $miner, sectorNumber: $sectorNumber) {
spID
sectorNum
tasks {
...TaskAll
}
}
}
${taskFragment}
`
29 changes: 29 additions & 0 deletions ui/src/views/query/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,35 @@ export const taskHistoryFragment = gql`
}
`

export const taskFragment = gql`
fragment TaskAll on Task {
id
initiatedByID
initiatedBy {
id
hostAndPort
}
updateTime
postedTime
ownerId
owner {
id
hostAndPort
}
addedByID
addedBy {
id
hostAndPort
}
previousTaskID
previousTask {
id
name
}
name
}
`

export const SubscribeCompletedTask = gql`
subscription SubscribeCompletedTask($last: Int!) {
completedTask(last: $last) {
Expand Down
8 changes: 6 additions & 2 deletions ui/src/views/sectors/SectorDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import UiChildCard from '@/components/shared/UiChildCard.vue'
import PiecesInfo from '@/views/sectors/PiecesInfo.vue'
import SectorLocations from '@/views/sectors/SectorLocations.vue'
import SectorEvents from '@/views/sectors/SectorEvents.vue'
import SectorTasks from '@/views/sectors/SectorTasks.vue'
const page = ref({ title: 'Sector Details' })
const breadcrumbs = ref([
Expand Down Expand Up @@ -58,11 +59,11 @@ const meta: ComputedRef<SectorMeta> = computed(() => result.value?.sector.meta |
<div class="d-flex align-center flex-column flex-sm-row text-medium-emphasis ga-4">
<div class="d-flex align-center">
<UserIcon />
<span class="text-subtitle-1 font-weight-medium ml-2">Miner: {{ meta.spId }}</span>
<span class="text-subtitle-1 font-weight-medium ml-2">Miner: {{ miner }}</span>
</div>
<div class="d-flex align-center">
<BoxIcon />
<span class="text-subtitle-1 font-weight-medium ml-2">Sector: {{ meta.sectorNum }}</span>
<span class="text-subtitle-1 font-weight-medium ml-2">Sector: {{ sectorNumber }}</span>
</div>
<div class="d-flex align-center">
<TrashIcon />
Expand Down Expand Up @@ -140,6 +141,9 @@ const meta: ComputedRef<SectorMeta> = computed(() => result.value?.sector.meta |
<v-col cols="12">
<PiecesInfo :miner="miner" :sector-number="sectorNumber" />
</v-col>
<v-col cols="12">
<SectorTasks :miner="miner" :sector-number="sectorNumber" />
</v-col>
<v-col cols="8">
<SectorLocations :miner="miner" :sector-number="sectorNumber" />
</v-col>
Expand Down
82 changes: 82 additions & 0 deletions ui/src/views/sectors/SectorTasks.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<script setup lang="ts">
import moment from 'moment'
import UiChildCard from '@/components/shared/UiChildCard.vue'
import { useQuery } from '@vue/apollo-composable'
import { GetSectorTasks } from '@/views/query/sector'
import { computed, ComputedRef } from 'vue'
import { Task } from '@/typed-graph'
import type { Header } from 'vue3-easy-data-table'
const props = defineProps({
miner: {
type: String,
required: true,
},
sectorNumber: {
type: String,
required: true,
},
})
const { result, loading, refetch, error } = useQuery(GetSectorTasks, {
miner: props.miner,
sectorNumber: props.sectorNumber,
}, () => ({
fetchPolicy: 'cache-first',
}))
const tasks: ComputedRef<[Task]> = computed(() => result.value?.sector.tasks || [])
const headers :Header[] = [
{ text: 'ID', value: 'id' },
{ text: 'Name', value: 'name' },
{ text: 'Worker', value: 'owner' },
{ text: 'Update', value: 'updateTime' },
{ text: 'Posted', value: 'postedTime' },
{ text: 'previousTask', value: 'previousTask' },
]
</script>

<template>
<UiChildCard :loading="loading" title="Sector Tasks ">
<template #action>
<v-btn round :rounded="true" variant="text" @click="refetch">
<ReloadIcon />
</v-btn>
</template>
<EasyDataTable
:headers="headers"
hide-footer
:items="tasks"
:loading="loading"
:rows-per-page="100"
table-class-name="customize-table"
theme-color="primary"
>
<template #empty-message>
<p class="text-high-emphasis">{{ error?.message || 'No Data' }} </p>
</template>
<template #item-owner="{owner}">
<!-- todo: add router link to worker details-->
<p class="text-high-emphasis">{{ owner ? owner.hostAndPort: '' }} </p>
</template>
<template #item-name="{name}">
<v-chip color="primary" small>{{ name }}</v-chip>
</template>
<template #item-updateTime="{updateTime}">
{{ moment(updateTime).calendar() }}
</template>
<template #item-postedTime="{postedTime}">
{{ moment(postedTime).calendar() }}
</template>
<template #item-previousTask="{previousTask}">
<!-- todo: add router link to previous task details-->
{{ previousTask ? previousTask.name : '' }}
</template>
</EasyDataTable>
</UiChildCard>
</template>

<style scoped lang="scss">
</style>

0 comments on commit e04cb3b

Please sign in to comment.