Skip to content

Commit

Permalink
fix(sidebar): expanding custom ui sidebar groups was not working as e…
Browse files Browse the repository at this point in the history
…xpected
  • Loading branch information
SteKoe committed Jul 7, 2023
1 parent 37a41b9 commit 8a5266c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ const emitCustomRouteAddedEvent = debounce(() => {
export function useViewRegistry() {
return {
views: viewRegistry.views,
addView(view) {
viewRegistry.addView(view);
addView(viewToAdd) {
const view = viewRegistry.addView(viewToAdd)[0];

if (view.parent) {
viewRegistry.router.addRoute(view.parent, {
Expand Down
12 changes: 7 additions & 5 deletions spring-boot-admin-server-ui/src/main/frontend/viewRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/
import { remove } from 'lodash-es';
import { Text, VNode, h, markRaw, reactive, shallowRef } from 'vue';
import { Text, VNode, h, markRaw, reactive, shallowRef, toRaw } from 'vue';
import { Router, createRouter, createWebHistory } from 'vue-router';

import sbaConfig from './sba-config';
Expand Down Expand Up @@ -82,8 +82,8 @@ export default class ViewRegistry {
return Array.prototype.find.call(this._views, (v) => v.name === name);
}

addView(...views: View[]) {
views.forEach((view) => this._addView(view));
addView(...views: View[]): SbaView[] {
return views.map((view) => this._addView(view));
}

addRedirect(path: string, redirect: string | object) {
Expand All @@ -94,7 +94,7 @@ export default class ViewRegistry {
}
}

_addView(viewConfig: ViewConfig) {
_addView(viewConfig: ViewConfig): SbaView {
const view = { ...viewConfig } as SbaView;
view.hasChildren = !!viewConfig.children;

Expand Down Expand Up @@ -132,6 +132,8 @@ export default class ViewRegistry {

this._removeExistingView(view);
this._views.push(view);

return view;
}

_removeExistingView(view) {
Expand All @@ -151,7 +153,7 @@ export default class ViewRegistry {
name: view.name,
component: view.component,
props: view.props,
meta: { view: view },
meta: { view: toRaw(view) },
children,
};
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
</template>

<script lang="ts">
import { defineComponent } from 'vue';
import { defineComponent, toRaw } from 'vue';
import SbaButton from '@/components/sba-button.vue';
Expand Down Expand Up @@ -195,7 +195,7 @@ export default defineComponent({
return key === translated ? groupId : translated;
},
isActiveGroup(group) {
return group.views.includes(this.$route.meta.view);
return group.views.some((v) => toRaw(v) === this.$route.meta.view);
},
hasMultipleViews(group) {
return group.views.length > 1;
Expand All @@ -208,10 +208,12 @@ export default defineComponent({
.instance-info-block {
@apply bg-sba-50 bg-opacity-40 text-sba-900 flex items-center text-sm py-4 px-6 text-left overflow-hidden text-ellipsis rounded transition duration-300 ease-in-out cursor-pointer;
}
.navbar-link {
@apply cursor-pointer bg-sba-50 bg-opacity-40 duration-300 ease-in-out flex items-center overflow-hidden py-4 rounded text-sm transition whitespace-nowrap;
@apply text-gray-700;
}
.navbar-link:hover,
.navbar-link__active {
@apply bg-sba-50 bg-opacity-80 text-sba-900;
Expand Down

0 comments on commit 8a5266c

Please sign in to comment.