Skip to content

Commit

Permalink
feat(ui): Hide category if there is no comp. WF-42
Browse files Browse the repository at this point in the history
  • Loading branch information
madeindjs committed Aug 15, 2024
1 parent 71106c3 commit 5ea5866
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/ui/src/builder/BuilderSidebarToolbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
v-for="(categoryData, category) in categoriesData"
:key="category"
>
<div v-if="categoryData.isVisible !== false" class="category">
<div v-if="shouldDisplayCategory(category)" class="category">
<div class="title">
<i class="material-symbols-outlined">{{
categoryData.icon ?? "question_mark"
Expand Down Expand Up @@ -70,6 +70,8 @@ const wf = inject(injectionKeys.core);
const ssbm = inject(injectionKeys.builderManager);
const { removeInsertionCandidacy } = useDragDropComponent(wf);
type CategoryId = "Root" | "Layout" | "Content" | "Input" | "Embed" | "Other";
type CategoryData = {
isVisible?: boolean;
isCollapsed?: boolean;
Expand All @@ -78,7 +80,7 @@ type CategoryData = {
const searchQuery = ref("");
const categoriesData: Ref<Record<string, CategoryData>> = ref({
const categoriesData: Ref<Record<CategoryId, CategoryData>> = ref({
Root: {
isVisible: false,
},
Expand All @@ -104,16 +106,24 @@ const categoriesData: Ref<Record<string, CategoryData>> = ref({
},
});
function shouldDisplayCategory(categoryId: CategoryId): boolean {
if (categoriesData.value[categoryId]?.isVisible === false) return false;
return (
Object.keys(definitionsByDisplayCategory.value[categoryId] ?? {})
.length > 0
);
}
function toggleCollapseCategory(categoryId: string) {
const categoryData = categoriesData.value[categoryId];
categoryData.isCollapsed = !categoryData.isCollapsed;
}
const definitionsByDisplayCategory = computed(() => {
const types = wf.getSupportedComponentTypes();
const result: Record<
string,
Record<string, WriterComponentDefinition>
const result: Partial<
Record<CategoryId, Record<string, WriterComponentDefinition>>
> = {};
types.map((type) => {
Expand Down Expand Up @@ -142,6 +152,8 @@ const definitionsByDisplayCategory = computed(() => {
result[displayCategory][type] = definition;
});
console.log(result);

Check failure on line 155 in src/ui/src/builder/BuilderSidebarToolbar.vue

View workflow job for this annotation

GitHub Actions / build (3.11)

Unexpected console statement

Check failure on line 155 in src/ui/src/builder/BuilderSidebarToolbar.vue

View workflow job for this annotation

GitHub Actions / build (3.9)

Unexpected console statement

Check failure on line 155 in src/ui/src/builder/BuilderSidebarToolbar.vue

View workflow job for this annotation

GitHub Actions / build (3.10)

Unexpected console statement

Check failure on line 155 in src/ui/src/builder/BuilderSidebarToolbar.vue

View workflow job for this annotation

GitHub Actions / build (3.12)

Unexpected console statement

Check failure on line 155 in src/ui/src/builder/BuilderSidebarToolbar.vue

View workflow job for this annotation

GitHub Actions / build (3.10)

Unexpected console statement

Check failure on line 155 in src/ui/src/builder/BuilderSidebarToolbar.vue

View workflow job for this annotation

GitHub Actions / build (3.12)

Unexpected console statement

Check failure on line 155 in src/ui/src/builder/BuilderSidebarToolbar.vue

View workflow job for this annotation

GitHub Actions / build (3.11)

Unexpected console statement

Check failure on line 155 in src/ui/src/builder/BuilderSidebarToolbar.vue

View workflow job for this annotation

GitHub Actions / build (3.10)

Unexpected console statement
return result;
});
Expand Down

0 comments on commit 5ea5866

Please sign in to comment.