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

Convert historyItemsStore to ts+composition #16873

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
59 changes: 27 additions & 32 deletions client/src/components/History/CurrentHistory/HistoryPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
:scope-key="queryKey"
:get-item-key="(item) => item.type_id"
:filter-text="filterText"
:total-items-in-query="totalItemsInQuery"
:total-items-in-query="totalMatchesCount"
@query-selection-break="querySelectionBreak = true">
<section
class="history-layout d-flex flex-column w-100"
Expand All @@ -43,7 +43,7 @@
<HistoryCounter
:history="history"
:is-watching="isWatching"
:last-checked="lastChecked"
:last-checked="lastCheckedTime"
:show-controls="showControls"
:filter-text.sync="filterText"
@reloadContents="reloadContents" />
Expand All @@ -63,7 +63,7 @@
:content-selection="selectedItems"
:selection-size="selectionSize"
:is-query-selection="isQuerySelection"
:total-items-in-query="totalItemsInQuery"
:total-items-in-query="totalMatchesCount"
:operation-running.sync="operationRunning"
@update:show-selection="setShowSelection"
@operation-error="onOperationError"
Expand Down Expand Up @@ -156,7 +156,7 @@ import LoadingSpan from "components/LoadingSpan";
import { Toast } from "composables/toast";
import { mapActions, mapState, storeToRefs } from "pinia";
import { rewatchHistory } from "store/historyStore/model/watchHistory";
import { useHistoryItemsStore } from "stores/history/historyItemsStore";
import { useHistoryItemsStore } from "stores/historyItemsStore";
import { useHistoryStore } from "stores/historyStore";
import { getOperatorForAlias } from "utils/filtering";
import Vue from "vue";
Expand Down Expand Up @@ -199,6 +199,11 @@ export default {
showControls: { type: Boolean, default: true },
filterable: { type: Boolean, default: false },
},
setup() {
const { currentFilterText, currentHistoryId } = storeToRefs(useHistoryStore());
const { lastCheckedTime, totalMatchesCount, isWatching } = storeToRefs(useHistoryItemsStore());
return { currentFilterText, currentHistoryId, lastCheckedTime, totalMatchesCount, isWatching };
},
data() {
return {
filterText: "",
Expand Down Expand Up @@ -244,21 +249,6 @@ export default {
itemsLoaded() {
return this.getHistoryItems(this.historyId, this.filterText);
},
/** @returns {Date} */
lastChecked() {
const { getLastCheckedTime } = storeToRefs(useHistoryItemsStore());
return getLastCheckedTime.value;
},
/** @returns {Number} */
totalItemsInQuery() {
const { getTotalMatchesCount } = storeToRefs(useHistoryItemsStore());
return getTotalMatchesCount.value;
},
/** @returns {Boolean} */
isWatching() {
const { getWatchingVisibility } = storeToRefs(useHistoryItemsStore());
return getWatchingVisibility.value;
},
/** @returns {Object} */
formattedSearchError() {
if (this.searchError) {
Expand All @@ -278,9 +268,8 @@ export default {
},
/** @returns {String} */
storeFilterText() {
const { currentFilterText, currentHistoryId } = storeToRefs(useHistoryStore());
if (this.historyId === currentHistoryId.value) {
return currentFilterText.value || "";
if (this.historyId === this.currentHistoryId) {
return this.currentFilterText || "";
} else {
return "";
}
Expand Down Expand Up @@ -313,8 +302,8 @@ export default {
offset() {
this.loadHistoryItems();
},
historyUpdateTime() {
this.loadHistoryItems();
async historyUpdateTime() {
await this.loadHistoryItems();
},
},
async mounted() {
Expand Down Expand Up @@ -363,9 +352,11 @@ export default {
this.loading = false;
}
},
onDelete(item, recursive = false) {
async onDelete(item, recursive = false) {
this.loading = true;
this.setInvisible(item);
deleteContent(item, { recursive: recursive });
await deleteContent(item, { recursive: recursive });
this.loading = false;
},
onHideSelection(selectedItems) {
selectedItems.forEach((item) => {
Expand All @@ -375,13 +366,17 @@ export default {
onScroll(offset) {
this.offset = offset;
},
onUndelete(item) {
async onUndelete(item) {
this.setInvisible(item);
updateContentFields(item, { deleted: false });
this.loading = true;
await updateContentFields(item, { deleted: false });
this.loading = false;
},
onUnhide(item) {
async onUnhide(item) {
this.setInvisible(item);
updateContentFields(item, { visible: true });
this.loading = true;
await updateContentFields(item, { visible: true });
this.loading = false;
},
reloadContents() {
rewatchHistory();
Expand All @@ -405,7 +400,7 @@ export default {
this.showDropZone = false;
}
},
onDrop(evt) {
async onDrop(evt) {
this.showDropZone = false;
let data;
try {
Expand All @@ -416,7 +411,7 @@ export default {
if (data) {
const dataSource = data.history_content_type === "dataset" ? "hda" : "hdca";
if (data.history_id != this.historyId) {
copyDataset(data.id, this.historyId, data.history_content_type, dataSource)
await copyDataset(data.id, this.historyId, data.history_content_type, dataSource)
.then(() => {
if (data.history_content_type === "dataset") {
ahmedhamidawan marked this conversation as resolved.
Show resolved Hide resolved
Toast.info("Dataset copied to history");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import Backbone from "backbone";
import { createDatasetCollection } from "components/History/model/queries";
import { watchHistory } from "store/historyStore/model/watchHistory";
import { useHistoryItemsStore } from "stores/history/historyItemsStore";
import { useHistoryItemsStore } from "stores/historyItemsStore";
import { useHistoryStore } from "stores/historyStore";

import { buildCollectionModal } from "./buildCollectionModal";
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/Panels/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ export function searchToolsByKeys(
? keys.startsWith
: order;

const wordMatches = actualValueWords.filter((word) => queryWords.includes(word));
const wordMatches = Array.from(new Set(actualValueWords.filter((word) => queryWords.includes(word))));
if (!usesDL) {
if (actualValue.match(queryValue)) {
// if string.match() returns true, matching tool found
Expand Down
6 changes: 3 additions & 3 deletions client/src/components/Tool/ToolForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ import FormElement from "components/Form/FormElement";
import LoadingSpan from "components/LoadingSpan";
import ToolEntryPoints from "components/ToolEntryPoints/ToolEntryPoints";
import { mapActions, mapState } from "pinia";
import { useHistoryItemsStore } from "stores/history/historyItemsStore";
import { useHistoryItemsStore } from "stores/historyItemsStore";
import { useJobStore } from "stores/jobStore";
import { refreshContentsWrapper } from "utils/data";

Expand Down Expand Up @@ -187,7 +187,7 @@ export default {
computed: {
...mapState(useUserStore, ["currentUser"]),
...mapState(useHistoryStore, ["currentHistoryId"]),
...mapState(useHistoryItemsStore, ["getLastUpdateTime"]),
...mapState(useHistoryItemsStore, ["lastUpdateTime"]),
toolName() {
return this.formConfig.name;
},
Expand Down Expand Up @@ -225,7 +225,7 @@ export default {
currentHistoryId() {
this.onHistoryChange();
},
getLastUpdateTime() {
lastUpdateTime() {
this.onHistoryChange();
},
},
Expand Down
6 changes: 3 additions & 3 deletions client/src/components/Workflow/Run/WorkflowRun.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<script>
import LoadingSpan from "components/LoadingSpan";
import { mapState } from "pinia";
import { useHistoryItemsStore } from "stores/history/historyItemsStore";
import { useHistoryItemsStore } from "stores/historyItemsStore";
import { errorMessageAsString } from "utils/simple-error";

import { useHistoryStore } from "@/stores/historyStore";
Expand Down Expand Up @@ -98,9 +98,9 @@ export default {
},
computed: {
...mapState(useHistoryStore, ["currentHistoryId", "getHistoryById"]),
...mapState(useHistoryItemsStore, ["getLastUpdateTime"]),
...mapState(useHistoryItemsStore, ["lastUpdateTime"]),
historyStatusKey() {
return `${this.currentHistoryId}_${this.getLastUpdateTime}`;
return `${this.currentHistoryId}_${this.lastUpdateTime}`;
},
},
watch: {
Expand Down
6 changes: 3 additions & 3 deletions client/src/components/Workflow/Run/WorkflowRunDefaultStep.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import FormMessage from "components/Form/FormMessage";
import { visitInputs } from "components/Form/utilities";
import WorkflowIcons from "components/Workflow/icons";
import { mapState } from "pinia";
import { useHistoryItemsStore } from "stores/history/historyItemsStore";
import { useHistoryItemsStore } from "stores/historyItemsStore";

import { getTool } from "./services";

Expand Down Expand Up @@ -70,12 +70,12 @@ export default {
};
},
computed: {
...mapState(useHistoryItemsStore, ["getLastUpdateTime"]),
...mapState(useHistoryItemsStore, ["lastUpdateTime"]),
icon() {
return WorkflowIcons[this.model.step_type];
},
historyStatusKey() {
return `${this.historyId}_${this.getLastUpdateTime}`;
return `${this.historyId}_${this.lastUpdateTime}`;
},
},
watch: {
Expand Down
12 changes: 7 additions & 5 deletions client/src/store/historyStore/model/watchHistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
*/

import { getGalaxyInstance } from "app";
import { storeToRefs } from "pinia";
import defaultStore from "store/index";
import { useHistoryItemsStore } from "stores/history/historyItemsStore";
import { useHistoryItemsStore } from "stores/historyItemsStore";
import { useHistoryStore } from "stores/historyStore";
import { getCurrentHistoryFromServer } from "stores/services/history.services";
import { loadSet } from "utils/setCache";
Expand Down Expand Up @@ -51,7 +52,8 @@ export async function watchHistoryOnce(store) {
// get current history
const checkForUpdate = new Date();
const history = await getCurrentHistoryFromServer(lastUpdateTime);
historyItemsStore.setLastCheckedTime(checkForUpdate);
const { lastCheckedTime } = storeToRefs(historyItemsStore);
lastCheckedTime.value = checkForUpdate;
if (!history || !history.id) {
return;
}
Expand Down Expand Up @@ -96,11 +98,11 @@ export async function watchHistoryOnce(store) {
}

export async function watchHistory(store = defaultStore) {
const historyItemsStore = useHistoryItemsStore();
const { isWatching } = storeToRefs(useHistoryItemsStore());
// Only set up visibility listeners once, whenever a watch is first started
if (watchingVisibility === false) {
watchingVisibility = true;
historyItemsStore.setWatchingVisibility(watchingVisibility);
isWatching.value = watchingVisibility;
document.addEventListener("visibilitychange", setVisibilityThrottle);
}
try {
Expand All @@ -109,7 +111,7 @@ export async function watchHistory(store = defaultStore) {
// error alerting the user that watch history failed
console.warn(error);
watchingVisibility = false;
historyItemsStore.setWatchingVisibility(watchingVisibility);
isWatching.value = watchingVisibility;
} finally {
watchTimeout = setTimeout(() => {
watchHistory(store);
Expand Down
2 changes: 1 addition & 1 deletion client/src/store/historyStore/model/watchHistory.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createLocalVue, mount } from "@vue/test-utils";
import axios from "axios";
import MockAdapter from "axios-mock-adapter";
import { createPinia, mapState } from "pinia";
import { useHistoryItemsStore } from "stores/history/historyItemsStore";
import { useHistoryItemsStore } from "stores/historyItemsStore";
import { useHistoryStore } from "stores/historyStore";

import { watchHistoryOnce } from "./watchHistory";
Expand Down
102 changes: 0 additions & 102 deletions client/src/stores/history/historyItemsStore.js

This file was deleted.

Loading
Loading