Skip to content

Commit

Permalink
Merge pull request #55 from simonsobs/dev
Browse files Browse the repository at this point in the history
Display the order on the queue item view dialog
  • Loading branch information
TaiSakuma authored May 28, 2024
2 parents 72a1c58 + 8d72ca9 commit 48418e4
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 15 deletions.
6 changes: 3 additions & 3 deletions src/components/queue/TableFrame.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
</p>
</div>
</template>
<template #item.index="{ index }">
<span class="text-primary font-weight-medium"> {{ index + 1 }} </span>
<template #item.order="{ item }">
<span class="text-primary font-weight-medium"> {{ item.order }} </span>
</template>
<template #item.script="{ item }">
<div class="item-script">
Expand Down Expand Up @@ -53,7 +53,7 @@ const headersMobile = [
];
const headersNotMobile = [
{ title: "Order", key: "index", sortable: false },
{ title: "Order", key: "order", sortable: false },
{ title: "Name", key: "name", sortable: false },
{ title: "Created at", key: "createdAt", sortable: false },
{ title: "Python script", key: "script", sortable: false },
Expand Down
53 changes: 41 additions & 12 deletions src/components/queue/items.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { computed } from "vue";
import type { Ref, ComputedRef } from "vue";
import { ref, watchEffect } from "vue";
import type { Ref } from "vue";
import type { OperationResult, AnyVariables } from "@urql/vue";
import { formatDateTime } from "@/utils/format-date-time";
import { useSubscribeScheduleQueueItems } from "@/api/use-schedule-queue-items-subscription";
Expand All @@ -10,10 +10,11 @@ import {
import type {
ScheduleQueuePushInput,
ScheduleQueuePushMutation,
ScheduleQueueRemoveMutation
ScheduleQueueRemoveMutation,
} from "@/graphql/codegen/generated";

export interface Item {
order: number;
id: number;
name: string;
createdAt?: string;
Expand All @@ -24,7 +25,7 @@ type AddItemResult = OperationResult<ScheduleQueuePushMutation, AnyVariables>;
type DeleteItemResult = OperationResult<ScheduleQueueRemoveMutation, AnyVariables>;

interface _UseItemsResponse {
items: ComputedRef<Item[] | undefined>;
items: Ref<Item[]>;
loading: Ref<boolean>;
addItem: (item: ScheduleQueuePushInput) => Promise<AddItemResult>;
deleteItem: (item: Item) => Promise<DeleteItemResult>;
Expand All @@ -36,14 +37,42 @@ export function useItems(): UseItemsResponse {
const subscription = useSubscribeScheduleQueueItems();
const { items: items_, loading } = subscription;

const items = computed<Item[] | undefined>(() =>
items_.value?.map((item) => ({
id: item.id,
name: item.name,
createdAt: formatDateTime(item.createdAt),
script: item.script,
}))
);
const items = ref<Item[]>([]);
const itemMap = ref<Map<number, Item>>(new Map());
watchEffect(() => {
// Update the list of items as the subscription updates.
// Keep the same Item objects in the list.
// itemMap is used to keep track of the Item objects.

// Remove items from itemMap that are no longer in the subscription.
items_.value
?.map((item) => item.id)
.forEach((id) => {
if (!itemMap.value.has(id)) itemMap.value.delete(id);
});

// Empty the items list.
items.value.splice(0, items.value.length);

// Update
items_.value?.forEach((item, index) => {
const update = {
order: index + 1,
id: item.id,
name: item.name,
createdAt: formatDateTime(item.createdAt),
script: item.script,
};
const item_ = itemMap.value.get(item.id);
if (item_) {
Object.assign(item_, update); // Update the existing item object.
items.value.push(item_);
} else {
itemMap.value.set(item.id, update); // new item object.
items.value.push(update);
}
});
});

const { addItem } = useAddItem();
const { deleteItem } = useDeleteItem();
Expand Down
1 change: 1 addition & 0 deletions src/components/queue/view/ItemView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<div style="block-size: 100%; inline-size: 100%">
<div class="g-container">
<div class="g-top">
<div><span class="font-weight-bold">Order:</span> {{ item.order }}</div>
<div><span class="font-weight-bold">Name:</span> {{ item?.name }}</div>
<div>
<span class="font-weight-bold">Created at:</span> {{ item?.createdAt }}
Expand Down

0 comments on commit 48418e4

Please sign in to comment.