@@ -20,56 +20,77 @@ import './style.css';
2020import sbaConfig from '@/sba-config' ;
2121import ViewRegistry from '@/viewRegistry' ;
2222
23+ function addExternalView (
24+ viewRegistry : ViewRegistry ,
25+ view : ExternalView ,
26+ parent ?: string ,
27+ ) {
28+ if ( view . iframe ) {
29+ addIframeView ( viewRegistry , view , parent ) ;
30+ } else {
31+ addExternalLink ( viewRegistry , view , parent ) ;
32+ }
33+ }
34+
35+ function getViewOpts ( view : ExternalView , parent ?: string ) {
36+ const safeLabel = view . label . replace ( / [ ^ a - z A - Z 0 - 9 - _ ] / g, '' ) ;
37+ const name = `/external/${ safeLabel } ` ;
38+
39+ return {
40+ name,
41+ path : name ,
42+ parent,
43+ label : view . label ,
44+ order : view . order ,
45+ } ;
46+ }
47+
2348export const addIframeView = (
2449 viewRegistry : ViewRegistry ,
25- { url, label, order } : Omit < ExternalView , 'children' > ,
50+ view : ExternalView ,
51+ parent ?: string ,
2652) => {
27- const urlWithoutScheme = url . replace ( / ^ h t t p s ? : [ / ] [ / ] / , '' ) ;
28- viewRegistry . addView ( {
29- name : `external/${ label } ` ,
30- path : `/external/${ encodeURIComponent ( urlWithoutScheme ) } ` ,
31- label,
32- order,
53+ const viewOpts = {
54+ ...getViewOpts ( view , parent ) ,
3355 component : {
3456 inheritAttrs : false ,
3557 render ( ) {
3658 return h ( 'div' , { class : 'external-view' } , [
37- h ( 'iframe' , { src : url } ) ,
59+ h ( 'iframe' , { src : view . url } ) ,
3860 ] ) ;
3961 } ,
4062 } ,
41- } as ComponentView ) ;
63+ } as ComponentView ;
64+
65+ viewRegistry . addView ( viewOpts ) ;
66+
67+ view . children ?. forEach ( ( view ) => {
68+ addExternalView ( viewRegistry , view , viewOpts . name ) ;
69+ } ) ;
4270} ;
4371
4472export const addExternalLink = (
4573 viewRegistry : ViewRegistry ,
46- { url , label , order , children } : Omit < ExternalView , 'iframe' > ,
74+ view : ExternalView ,
4775 parent ?: string ,
4876) => {
49- const name = `external/${ label } ` ;
77+ const viewOpts = {
78+ ...getViewOpts ( view , parent ) ,
79+ href : view . url ,
80+ } as LinkView ;
5081
51- viewRegistry . addView ( {
52- href : url ,
53- name,
54- parent,
55- label,
56- order,
57- } as LinkView ) ;
82+ viewRegistry . addView ( viewOpts ) ;
5883
59- children ?. forEach ( ( child ) => {
60- addExternalLink ( viewRegistry , child , name ) ;
84+ view . children ?. forEach ( ( view ) => {
85+ addExternalView ( viewRegistry , view , viewOpts . name ) ;
6186 } ) ;
6287} ;
6388
6489export default {
6590 install ( { viewRegistry } ) {
66- const externalViews = sbaConfig . uiSettings . externalViews ;
67- externalViews . forEach ( ( view ) => {
68- if ( view . iframe ) {
69- addIframeView ( viewRegistry , view ) ;
70- } else {
71- addExternalLink ( viewRegistry , view ) ;
72- }
91+ const views = sbaConfig . uiSettings . externalViews ;
92+ views . forEach ( ( view ) => {
93+ addExternalView ( viewRegistry , view ) ;
7394 } ) ;
7495 } ,
7596} ;
0 commit comments