Skip to content

A continuation of HomeBox the inventory and organization system built for the Home User

implement show/hide items for locations tree (#1328)

Ell74a509270083
diff --git a/frontend/components/Location/Tree/Node.vue b/frontend/components/Location/Tree/Node.vue
index f5ac6e3f..a60c609c 100644
--- a/frontend/components/Location/Tree/Node.vue
+++ b/frontend/components/Location/Tree/Node.vue
@@ -9,8 +9,11 @@
type Props = {
treeId: string;
item: TreeItem;
+ showItems?: boolean;
};
- const props = withDefaults(defineProps<Props>(), {});
+ const props = withDefaults(defineProps<Props>(), {
+ showItems: true,
+ });
const link = computed(() => {
return props.item.type === "location" ? `/location/${props.item.id}` : `/item/${props.item.id}`;
@@ -26,7 +29,13 @@
const sortedChildren = computed(() => {
const children = props.item.children ?? [];
- return [...children].sort((a, b) => collator.compare(a.name, b.name));
+ let filtered = [...children];
+
+ if (!props.showItems) {
+ filtered = filtered.filter(child => child.type === "location");
+ }
+
+ return filtered.sort((a, b) => collator.compare(a.name, b.name));
});
const openRef = computed({
@@ -73,7 +82,13 @@
<NuxtLink class="text-lg hover:underline" :to="link" @click.stop>{{ item.name }} </NuxtLink>
</div>
<div v-if="openRef" class="ml-4">
- <LocationTreeNode v-for="child in sortedChildren" :key="child.id" :item="child" :tree-id="treeId" />
+ <LocationTreeNode
+ v-for="child in sortedChildren"
+ :key="child.id"
+ :item="child"
+ :tree-id="treeId"
+ :show-items="showItems"
+ />
</div>
</div>
</template>
diff --git a/frontend/components/Location/Tree/Root.vue b/frontend/components/Location/Tree/Root.vue
index b61f86fb..fd0ac6e4 100644
--- a/frontend/components/Location/Tree/Root.vue
+++ b/frontend/components/Location/Tree/Root.vue
@@ -8,6 +8,7 @@
type Props = {
locs: TreeItem[];
treeId: string;
+ showItems?: boolean;
};
const { openDialog } = useDialog();
@@ -47,7 +48,7 @@
<ul role="tree" :aria-labelledby="treeId" class="space-y-1">
<li v-for="item in sortedLocs" :key="item.id" role="treeitem">
- <LocationTreeNode :item="item" :tree-id="treeId" />
+ <LocationTreeNode :item="item" :tree-id="treeId" :show-items="props.showItems ?? true" />
</li>
</ul>
</div>
diff --git a/frontend/locales/en.json b/frontend/locales/en.json
index 8706273d..4dc8e97f 100644
--- a/frontend/locales/en.json
+++ b/frontend/locales/en.json
@@ -645,6 +645,8 @@
"child_locations": "Child Locations",
"collapse_tree": "Collapse Tree",
"expand_tree": "Expand Tree",
+ "hide_items": "Hide Items",
+ "show_items": "Show Items",
"location_items_delete_confirm": "Are you sure you want to delete this location and all of its items? This action cannot be undone.",
"no_results": "No Locations Found",
"toast": {
diff --git a/frontend/pages/locations.vue b/frontend/pages/locations.vue
index 07cb252e..c4fabcac 100644
--- a/frontend/pages/locations.vue
+++ b/frontend/pages/locations.vue
@@ -3,6 +3,7 @@
import { useTreeState } from "~~/components/Location/Tree/tree-state";
import MdiCollapseAllOutline from "~icons/mdi/collapse-all-outline";
import MdiExpandAllOutline from "~icons/mdi/expand-all-outline";
+ import MdiPackageVariant from "~icons/mdi/package-variant";
import { Button, ButtonGroup } from "@/components/ui/button";
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip";
@@ -39,8 +40,10 @@
});
const locationTreeId = "locationTree";
+ const showItemsKey = "showItems";
const treeState = useTreeState(locationTreeId);
+ const showItems = ref(true);
const route = useRouter();
@@ -56,17 +59,35 @@
treeState.value[key] = data[key];
}
}
+
+ if (query && query[showItemsKey] !== undefined) {
+ showItems.value = query[showItemsKey] === "true";
+ }
});
watch(
treeState,
() => {
// Push the current state to the URL
- route.replace({ query: { [locationTreeId]: JSON.stringify(treeState.value) } });
+ route.replace({
+ query: {
+ [locationTreeId]: JSON.stringify(treeState.value),
+ [showItemsKey]: showItems.value.toString(),
+ },
+ });
},
{ deep: true }
);
+ watch(showItems, () => {
+ route.replace({
+ query: {
+ [locationTreeId]: JSON.stringify(treeState.value),
+ [showItemsKey]: showItems.value.toString(),
+ },
+ });
+ });
+
function closeAll() {
for (const key in treeState.value) {
treeState.value[key] = false;
@@ -108,7 +129,7 @@
</Tooltip>
<Tooltip>
<TooltipTrigger>
- <Button size="icon" variant="outline" data-pos="end" @click="closeAll">
+ <Button size="icon" variant="outline" data-pos="middle" @click="closeAll">
<MdiCollapseAllOutline />
</Button>
</TooltipTrigger>
@@ -116,13 +137,33 @@
<p>{{ $t("locations.collapse_tree") }}</p>
</TooltipContent>
</Tooltip>
+ <Tooltip>
+ <TooltipTrigger>
+ <Button
+ size="icon"
+ :variant="showItems ? 'default' : 'outline'"
+ data-pos="end"
+ @click="showItems = !showItems"
+ >
+ <MdiPackageVariant />
+ </Button>
+ </TooltipTrigger>
+ <TooltipContent>
+ <p>{{ showItems ? $t("locations.hide_items") : $t("locations.show_items") }}</p>
+ </TooltipContent>
+ </Tooltip>
</ButtonGroup>
</TooltipProvider>
</div>
</div>
<BaseCard>
<div class="p-2">
- <LocationTreeRoot v-if="tree" :locs="tree" :tree-id="locationTreeId" />
+ <LocationTreeRoot
+ v-if="tree && Array.isArray(tree)"
+ :locs="tree"
+ :tree-id="locationTreeId"
+ :show-items="showItems"
+ />
</div>
</BaseCard>
</BaseContainer>