Skip to content

Commit

Permalink
Refactor filters and tags to work without objectstore
Browse files Browse the repository at this point in the history
  • Loading branch information
jatindersingh93 committed Feb 22, 2024
1 parent fd64478 commit 99a9f1c
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 27 deletions.
15 changes: 4 additions & 11 deletions frontend/src/components/object/ObjectFilters.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,7 @@ objectStore.$onAction(({ name, args }) => {
// Computed
const metadataValues = computed(() => {
// Filter out any tags that don't have an objectID that exist in getUnfilteredObjectIds
const filteredVals = getMetadataSearchResults.value.filter((searchRes) =>
getUnfilteredObjectIds.value.some((obj) => obj === searchRes.objectId)
);
const filteredVals = getMetadataSearchResults.value;
return (
filteredVals
// Take the metadata for the objects, and flatten them into a single array
Expand All @@ -76,10 +72,7 @@ const metadataValues = computed(() => {
});
const tagsetValues = computed(() => {
// 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)
);
const filteredVals = getTagSearchResults.value;
return (
filteredVals
Expand Down Expand Up @@ -137,13 +130,13 @@ const selectedFilterValuesChanged = () => {
const searchMetadata = async () => {
searching.value = true;
await metadataStore.searchMetadata();
await metadataStore.searchMetadata(props['bucketId']);
searching.value = false;
};
const searchTagging = async () => {
searching.value = true;
await tagStore.searchTagging();
await tagStore.searchTagging(props['bucketId']);
searching.value = false;
};
</script>
Expand Down
7 changes: 7 additions & 0 deletions frontend/src/components/object/ObjectList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const { getUserId } = storeToRefs(useAuthStore());
// State
const displayUpload = ref(false);
const objectInfoId: Ref<string | undefined> = ref(undefined);
const objectTable = ref();
const selectedObjectIds = computed(() => {
return getSelectedObjects.value.map((o) => o.id);
Expand All @@ -54,6 +55,10 @@ const showUpload = () => {
const closeUpload = () => {
displayUpload.value = false;
objectTable.value.updateDataTable();
};
const onDeletedSuccess = () => {
objectTable.value.updateDataTable();
};
</script>

Expand Down Expand Up @@ -92,6 +97,7 @@ const closeUpload = () => {
:disabled="displayUpload"
:ids="selectedObjectIds"
:mode="ButtonMode.BUTTON"
@on-deleted-success="onDeletedSuccess"
/>
</div>

Expand All @@ -101,6 +107,7 @@ const closeUpload = () => {
>
<div class="flex-grow-1">
<ObjectTable
ref="objectTable"
:bucket-id="props.bucketId"
:object-info-id="objectInfoId"
@show-object-info="showObjectInfo"
Expand Down
53 changes: 45 additions & 8 deletions frontend/src/components/object/ObjectTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { Permissions } from '@/utils/constants';
import { ButtonMode } from '@/utils/enums';
import { formatDateLong } from '@/utils/formatters';
import { objectService } from '@/services';
import type { Ref } from 'vue';
import type { COMSObject } from '@/types';
Expand Down Expand Up @@ -49,6 +50,7 @@ const permissionStore = usePermissionStore();
const { getUserId } = storeToRefs(useAuthStore());
// State
const selectAll = ref(false);
const permissionsVisible = ref(false);
const permissionsObjectId = ref('');
const permissionsObjectName: Ref<string | undefined> = ref('');
Expand All @@ -58,7 +60,6 @@ const loading = ref(false);
const lazyParams: Ref<DataTableObjectSource> = ref({});
const totalRecords = ref(0);
const first = ref(0);
const selectedObjects: any = ref();
const filters = ref({
name: { value: undefined, matchMode: 'contains' },
tags: { value: undefined, matchMode: 'contains' },
Expand All @@ -82,6 +83,7 @@ async function showPermissions(objectId: string) {
permissionsObjectId.value = objectId;
permissionsObjectName.value = objectStore.findObjectById(objectId)?.name;
}
onMounted(() => {
loading.value = true;
lazyParams.value = {
Expand Down Expand Up @@ -117,7 +119,6 @@ const loadLazyData = (event?: any) => {
tableData.value = r.data;
totalRecords.value = +r?.headers['x-total-rows'];
loading.value = false;
// add to object store
r.data.forEach((o: COMSObject) => {
objectStore.$patch((state) => {
Expand All @@ -131,20 +132,34 @@ const loadLazyData = (event?: any) => {
permissionStore.fetchObjectPermissions({ objectId: objects.map((o: COMSObject) => o.id) });
});
};
const onPage = (event?: any) => {
lazyParams.value = event;
loadLazyData(event);
};
const onSort = (event?: any) => {
lazyParams.value = event;
loadLazyData(event);
};
const onFilter = (event?: any) => {
lazyParams.value.filters = filters;
// Seems to be a bug as current page is not being reset when filter trigger
dt.value.resetPage();
loadLazyData(event);
};
function selectCurrentPage() {
objectStore.setSelectedObjects(
tableData.value.filter((object) => {
return Array.from(document.querySelectorAll('[data-objectId]'))
.map((x) => x.getAttribute('data-objectId'))
.includes(object.id);
})
);
}
// Clear selections when navigating away
onUnmounted(() => {
objectStore.setSelectedObjects([]);
Expand Down Expand Up @@ -173,34 +188,52 @@ const selectedFilters = (payload: any) => {
}, {});
lazyParams.value.filters = filters;
};
// Exposed to update datatable rows
function updateDataTable() {
loadLazyData();
}
defineExpose({
updateDataTable
});
</script>

<template>
<div class="object-table">
<DataTable
ref="dt"
v-model:value="tableData"
v-model:selection="selectedObjects"
v-model:selection="objectStore.selectedObjects"
v-model:filters="filters"
:select-all="selectAll"
lazy
paginator
:loading="loading"
:total-records="totalRecords"
data-key="id"
class="p-datatable-sm"
responsive-layout="scroll"
:rows="3"
:rows="10"
:rows-per-page-options="[10, 20, 50]"
sort-field="updatedAt"
:sort-order="-1"
filter-display="row"
:global-filter-fields="['name']"
:first="first"
update:filters
update:page
@page="onPage($event)"
@sort="onSort($event)"
@filter="onFilter($event)"
@select-all-change="
(e) => {
selectAll = e.checked;
if (e.checked) {
selectCurrentPage();
} else {
objectStore.setSelectedObjects([]);
}
}
"
>
<template #header>
<div class="flex justify-content-end">
Expand Down Expand Up @@ -232,9 +265,9 @@ const selectedFilters = (payload: any) => {
</span>

<Button
v-tooltip.bottom="'Refresh'"
v-tooltip.bottom="'Search'"
class="ml-2"
icon="pi pi-refresh"
icon="pi pi-search"
outlined
rounded
aria-label="Filter"
Expand All @@ -256,7 +289,11 @@ const selectedFilters = (payload: any) => {
<Column
selection-mode="multiple"
header-style="width: 3rem"
/>
>
<template selection-mode="multiple">
<div v-tooltip.bottom="selectAll">Select all</div>
</template>
</Column>
<Column
field="name"
sortable
Expand Down
12 changes: 8 additions & 4 deletions frontend/src/services/objectService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,13 @@ export default {
* @function searchMetadata
* Gets a list of tags matching the given parameters
* @param {Object} headers Optional request headers
* @param {bucketId} bucketId optional
* @returns {Promise} An axios response
*/
searchMetadata(headers: { metadata?: Array<MetadataPair> }) {
searchMetadata(headers: { metadata?: Array<MetadataPair> }, bucketId?: Array<string>) {
const config = {
headers: {}
headers: {},
params: { bucketId: bucketId }
};

// Map the metadata if required
Expand Down Expand Up @@ -226,14 +228,16 @@ export default {
* @function searchTagging
* Gets a list of tags matching the given parameters
* @param {Array<Tag>} tagset Query parameters to search on
* @param {bucketId} bucketId optional
* @returns {Promise} An axios response
*/
searchTagging(tagset: Array<Tag>) {
searchTagging(tagset: Array<Tag>, bucketId?: Array<string>) {
return (
comsAxios()
.get(`${PATH}/tagging`, {
params: {
tagset: Object.fromEntries(tagset.map((x: { key: string; value: string }) => [x.key, x.value]))
tagset: Object.fromEntries(tagset.map((x: { key: string; value: string }) => [x.key, x.value])),
bucketId: bucketId
}
})
// filter out a configured list of select tags
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/store/metadataStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ export const useMetadataStore = defineStore('metadata', () => {
}
}

async function searchMetadata(metadataSet: Array<MetadataPair> = []) {
async function searchMetadata(bucketId: string = '', metadataSet: Array<MetadataPair> = []) {
try {
state.metadataSearchResults.value = [];
const response = (await objectService.searchMetadata({ metadata: metadataSet })).data;
const response = (await objectService.searchMetadata({ metadata: metadataSet }, bucketId)).data;
state.metadataSearchResults.value = response;
} catch (error: any) {
toast.error('Searching metadata', error);
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/store/tagStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ export const useTagStore = defineStore('tag', () => {
}
}

async function searchTagging(tagset: Array<Tag> = []) {
async function searchTagging(bucketId: string = '', tagset: Array<Tag> = []) {
try {
state.tagSearchResults.value = [];
// await new Promise((resolve) => setTimeout(resolve, 4000));
const response = (await objectService.searchTagging(tagset)).data;
const response = (await objectService.searchTagging(tagset, bucketId)).data;
state.tagSearchResults.value = response;
} catch (error: any) {
toast.error('Searching tags', error);
Expand Down

0 comments on commit 99a9f1c

Please sign in to comment.