ContentPages.js.map 11 KB

1
  1. {"version":3,"sources":["../src/app/ContentPages.tsx"],"names":["React","Route","Switch","NavItem","NavExpandable","Msg","PageNotFound","ForbiddenPage","isModulePageDef","item","modulePath","undefined","isExpansion","contentItem","content","groupId","group","itemId","isChildOf","parent","child","createNavItems","activePage","contentParam","groupNum","links","map","navLinkId","id","localize","label","labelParams","page","path","makeNavItems","console","log","setIds","expansionGroupNum","i","length","initGroupAndItemIds","flattenContent","pageDefs","flat","push","makeRoutes","routes","node","createElement","module","componentName","pageDef","component"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA,OAAO,KAAKA,KAAZ;AACA,SAAQC,KAAR,EAAeC,MAAf;AACA,SAAQC,OAAR,EAAiBC,aAAjB;AACA,SAAQC,GAAR;AACA,SAAQC,YAAR;AACA,SAASC,aAAT;AASC;AAoBD,OAAO,SAASC,eAAT,CAAyBC,IAAzB,EAAmE;AACtE,SAAQA,IAAD,CAAwBC,UAAxB,KAAuCC,SAA9C;AACH;AAED,OAAO,SAASC,WAAT,CAAqBC,WAArB,EAAyE;AAC5E,SAAQA,WAAD,CAA2BC,OAA3B,KAAuCH,SAA9C;AACH;;AAID,SAASI,OAAT,CAAiBC,KAAjB,EAAwC;AACpC,SAAO,SAASA,KAAhB;AACH;;AAED,SAASC,MAAT,CAAgBD,KAAhB,EAA+BP,IAA/B,EAAqD;AACjD,SAAO,SAASO,KAAT,GAAiB,OAAjB,GAA2BP,IAAlC;AACH;;AAED,SAASS,SAAT,CAAmBC,MAAnB,EAAsCC,KAAtC,EAA+D;AAC3D,OAAK,IAAIX,IAAT,IAAiBU,MAAM,CAACL,OAAxB,EAAiC;AAC7B,QAAIF,WAAW,CAACH,IAAD,CAAX,IAAqBS,SAAS,CAACT,IAAD,EAAOW,KAAP,CAAlC,EAAiD,OAAO,IAAP;AACjD,QAAID,MAAM,CAACJ,OAAP,KAAmBK,KAAK,CAACL,OAA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AAG,EAAEA,IAAI,CAACf,MAAjB;AAAyB,QAAA,IAAI,EAAE,MAAMe,IAAI,CAACC,IAA1C;AAAgD,QAAA,KAAK,MAArD;AAAsD,QAAA,SAAS,EAAEmB,OAAO,CAACC;AAAzE,QAAP;AACH;AACJ,GAR2C,CAA5C;AAUA,SAAQ,oBAAC,MAAD,QACKN,MADL,EAEI,oBAAC,KAAD;AAAO,IAAA,IAAI,EAAC,YAAZ;AAAyB,IAAA,SAAS,EAAExC;AAApC,IAFJ,EAGI,oBAAC,KAAD;AAAO,IAAA,SAAS,EAAED;AAAlB,IAHJ,CAAR;AAKH","sourcesContent":["/*\n * Copyright 2019 Red Hat, Inc. and/or its affiliates.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport * as React from 'react';\nimport {Route, Switch} from 'react-router-dom';\nimport {NavItem, NavExpandable} from '@patternfly/react-core';\nimport {Msg} from './widgets/Msg';\nimport {PageNotFound} from './content/page-not-found/PageNotFound';\nimport { ForbiddenPage } from './content/forbidden-page/ForbiddenPage';\n\nexport interface ContentItem {\n id?: string;\n label: string;\n labelParams?: string[];\n hidden?: string;\n groupId: string; // computed value\n itemId: string; // computed value\n};\n\nexport interface Expansion extends ContentItem {\n content: ContentItem[];\n}\n\nexport interface PageDef extends ContentItem {\n path: string;\n}\n\nexport interface ComponentPageDef extends PageDef {\n component: React.ComponentType;\n}\n\nexport interface ModulePageDef extends PageDef {\n modulePath: string;\n componentName: string;\n module: React.Component; // computed value\n}\n\nexport function isModulePageDef(item: ContentItem): item is ModulePageDef {\n return (item as ModulePageDef).modulePath !== undefined;\n}\n\nexport function isExpansion(contentItem: ContentItem): contentItem is Expansion {\n return (contentItem as Expansion).content !== undefined;\n}\n\ndeclare const content: ContentItem[];\n\nfunction groupId(group: number): string {\n return 'grp-' + group;\n}\n\nfunction itemId(group: number, item: number): string {\n return 'grp-' + group + '_itm-' + item;\n}\n\nfunction isChildOf(parent: Expansion, child: PageDef): boolean {\n for (var item of parent.content) {\n if (isExpansion(item) && isChildOf(item, child)) return true;\n if (parent.groupId === child.groupId) return true;\n }\n\n return false;\n}\n\nfunction createNavItems(activePage: PageDef, contentParam: ContentItem[], groupNum: number): React.ReactNode {\n if (typeof content === 'undefined') return (<React.Fragment/>);\n\n const links: React.ReactElement[] = contentParam.map((item: ContentItem) => {\n const navLinkId = `nav-link-${item.id}`;\n if (isExpansion(item)) {\n return <NavExpandable id={navLinkId}\n groupId={item.groupId}\n key={item.groupId}\n title={Msg.localize(item.label, item.labelParams)}\n isExpanded={isChildOf(item, activePage)}>\n {createNavItems(activePage, item.content, groupNum + 1)}\n </NavExpandable>\n } else {\n const page: PageDef = item as PageDef;\n return <NavItem id={navLinkId}\n groupId={item.groupId}\n itemId={item.itemId}\n key={item.itemId}\n to={'#/' + page.path}\n isActive={activePage.itemId === item.itemId}\n type=\"button\">\n {Msg.localize(page.label, page.labelParams)}\n </NavItem>\n }\n });\n\n return (<React.Fragment>{links}</React.Fragment>);\n}\n\nexport function makeNavItems(activePage: PageDef): React.ReactNode {\n console.log({activePage});\n return createNavItems(activePage, content, 0);\n}\n\nfunction setIds(contentParam: ContentItem[], groupNum: number): number {\n if (typeof contentParam === 'undefined') return groupNum;\n let expansionGroupNum = groupNum;\n\n for (let i = 0; i < contentParam.length; i++) {\n const item: ContentItem = contentParam[i];\n if (isExpansion(item)) {\n item.itemId = itemId(groupNum, i);\n expansionGroupNum = expansionGroupNum + 1;\n item.groupId = groupId(expansionGroupNum);\n expansionGroupNum = setIds(item.content, expansionGroupNum);\n console.log('currentGroup=' + (expansionGroupNum));\n } else {\n item.groupId = groupId(groupNum);\n item.itemId = itemId(groupNum, i);\n }\n };\n\n return expansionGroupNum;\n}\n\nexport function initGroupAndItemIds(): void {\n setIds(content, 0);\n console.log({content});\n}\n\n// get rid of Expansions and put all PageDef items into a single array\nexport function flattenContent(pageDefs: ContentItem[]): PageDef[] {\n const flat: PageDef[] = [];\n\n for (let item of pageDefs) {\n if (isExpansion(item)) {\n flat.push(...flattenContent(item.content));\n } else {\n flat.push(item as PageDef);\n }\n }\n\n return flat;\n}\n\nexport function makeRoutes(): React.ReactNode {\n if (typeof content === 'undefined') return (<span/>);\n\n const pageDefs: PageDef[] = flattenContent(content);\n\n const routes: React.ReactElement<Route>[] = pageDefs.map((page: PageDef) => {\n if (isModulePageDef(page)) {\n const node: React.ReactNode = React.createElement(page.module[page.componentName], {'pageDef': page});\n return <Route key={page.itemId} path={'/' + page.path} exact render={() => node} />;\n } else {\n const pageDef: ComponentPageDef = page as ComponentPageDef;\n return <Route key={page.itemId} path={'/' + page.path} exact component={pageDef.component}/>;\n }\n });\n\n return (<Switch>\n {routes}\n <Route path=\"/forbidden\" component={ForbiddenPage}/>\n <Route component={PageNotFound}/>\n </Switch>);\n}\n"],"file":"ContentPages.js"}