Skip to content

Commit

Permalink
Need to track unfiltered objects
Browse files Browse the repository at this point in the history
Signed-off-by: Lucas ONeil <[email protected]>
  • Loading branch information
loneil committed Jul 18, 2023
1 parent 6ee6be9 commit 33e0d83
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
14 changes: 8 additions & 6 deletions frontend/src/components/object/ObjectFilters.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const metadataStore = useMetadataStore();
const objectStore = useObjectStore();
const tagStore = useTagStore();
const { getMetadataSearchResults } = storeToRefs(useMetadataStore());
const { getObjects } = storeToRefs(useObjectStore());
const { getUnfilteredObjectIds } = storeToRefs(useObjectStore());
const { getTagSearchResults } = storeToRefs(useTagStore());
// State
Expand All @@ -49,9 +49,10 @@ objectStore.$onAction(
// Computed
const metadataValues = computed(() => {
// Filter out any tags that don't have an objectID that exist in getObjects
const filteredVals = getMetadataSearchResults.value.filter((val) =>
getObjects.value.some((obj) => obj.id === val.objectId)
const filteredVals = getMetadataSearchResults.value.filter((searchRes) =>
getUnfilteredObjectIds.value.some((obj) => obj === searchRes.objectId)
);
// Take the metadata for the objects, and flatten them into a single array
const metadataVals = [
...new Set(filteredVals.flatMap((obj) => obj.metadata)),
Expand All @@ -68,10 +69,11 @@ const metadataValues = computed(() => {
});
const tagsetValues = computed(() => {
// Filter out any tags that don't have an objectID that exist in getObjects
const filteredVals = getTagSearchResults.value.filter((val) =>
getObjects.value.some((obj) => obj.id === val.objectId)
// Filter out any tags that don't have an objectID that exist in getUnfilteredObjectIds
const filteredVals = getTagSearchResults.value.filter((searchRes) =>
getUnfilteredObjectIds.value.some((obj) => obj === searchRes.objectId)
);
// Take the tags for the objects, and flatten them into a single array
const taggingVals = [
...new Set(filteredVals.flatMap((obj) => obj.tagset)),
Expand Down
10 changes: 9 additions & 1 deletion frontend/src/store/objectStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import type { COMSObject, MetadataPair, ObjectSearchPermissionsOptions, Tag } fr
export type ObjectStoreState = {
objects: Ref<Array<COMSObject>>;
selectedObjects: Ref<Array<COMSObject>>; // All selected table row items
unfilteredObjectIds: Ref<Array<string>>;
}

export const useObjectStore = defineStore('object', () => {
Expand All @@ -27,12 +28,14 @@ export const useObjectStore = defineStore('object', () => {
const state: ObjectStoreState = {
objects: ref([]),
selectedObjects: ref([]),
unfilteredObjectIds: ref([]),
};

// Getters
const getters = {
getObjects: computed(() => state.objects.value),
getSelectedObjects: computed(() => state.selectedObjects.value)
getSelectedObjects: computed(() => state.selectedObjects.value),
getUnfilteredObjectIds: computed(() => state.unfilteredObjectIds.value),
};

// Actions
Expand Down Expand Up @@ -155,9 +158,14 @@ export const useObjectStore = defineStore('object', () => {

// Merge and assign
state.objects.value = difference.concat(response);
// Track all the object IDs that the user would have access to in the table (even if filters are applied)
if(!tagset && !metadata) {
state.unfilteredObjectIds.value = state.objects.value.map((o) => o.id);
}
}
else {
state.objects.value = response;
state.unfilteredObjectIds.value = [];
}
}
}
Expand Down

0 comments on commit 33e0d83

Please sign in to comment.