Skip to content

Commit

Permalink
feat: feature complete implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilR8 committed Sep 24, 2024
1 parent 266cc7e commit 4cc791a
Showing 1 changed file with 27 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
COUNT_TYPES_MAP,
DOCUMENT_TYPES,
DOCUMENT_TYPES_MAP,
getRequestParams,
} from "utilities/utils";
const props = defineProps({
Expand Down Expand Up @@ -41,17 +42,32 @@ if (props.parent !== "search")
if (!isAuthenticated)
docTypesArr = docTypesArr.filter((type) => type !== "internal");
const counts = ref({});
const counts = ref({
results: {},
loading: true,
error: false,
});
const fetchCounts = async () => {
const response = await getGranularCounts({
apiUrl,
});
const fetchCounts = async ({ queryParams }) => {
counts.value.loading = true;
counts.value.error = false;
try {
const response = await getGranularCounts({
apiUrl,
requestParams: getRequestParams({ queryParams }),
});
counts.value = response;
counts.value.results = response;
} catch (error) {
counts.value.error = true;
counts.value.results = {};
} finally {
counts.value.loading = false;
}
};
fetchCounts();
fetchCounts({ queryParams: $route.query });
// v-model with a ref to control if the checkbox is displayed as checked or not
let boxesArr;
Expand Down Expand Up @@ -113,6 +129,8 @@ watch(
(newQuery) => {
const { type: typeParams } = newQuery;
fetchCounts({ queryParams: newQuery });
if (_isUndefined(typeParams) || typeParams.includes("all")) {
checkedBoxes.value = [];
} else {
Expand Down Expand Up @@ -144,9 +162,9 @@ const makeCount = ({ type }) => {
const mappedType = COUNT_TYPES_MAP[type];
return _isUndefined(counts.value[mappedType])
return _isUndefined(counts.value.results[mappedType])
? ""
: `(${counts.value[mappedType]})`;
: `(${counts.value.results[mappedType]})`;
};
onMounted(() => {
Expand Down

0 comments on commit 4cc791a

Please sign in to comment.