-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dynamic-plugins): make mountpoints and layout declarative
Signed-off-by: Tomas Coufal <tcoufal@redhat.com>
- Loading branch information
Showing
8 changed files
with
167 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,74 @@ | ||
import { EntitySwitch, isKind } from '@backstage/plugin-catalog'; | ||
import React from 'react'; | ||
import getMountPointData from '../../../utils/dynamicUI/getMountPointData'; | ||
import { EntityLayout, EntitySwitch, isKind } from '@backstage/plugin-catalog'; | ||
import { ScalprumMountPointConfig } from '../../DynamicRoot/DynamicRootContext'; | ||
import { isType } from '../utils'; | ||
import { Entity } from '@backstage/catalog-model'; | ||
|
||
import { | ||
componentPage, | ||
defaultEntityPage, | ||
apiPage, | ||
groupPage, | ||
userPage, | ||
systemPage, | ||
domainPage, | ||
resourcePage, | ||
} from './Pages'; | ||
|
||
const createConditionsArray = (conditions: ScalprumMountPointConfig['if']['allOf']) => { | ||
return conditions.map(c => { | ||
if (typeof c === 'function') { | ||
return c | ||
} | ||
if (c.isKind) { | ||
return isKind(c.isKind) | ||
} | ||
if (c.isType) { | ||
return isType(c.isType) | ||
} | ||
return () => true | ||
}) | ||
} | ||
|
||
const entitySwitchCaseIf = (conditional: ScalprumMountPointConfig['if']) => (e: Entity) => { | ||
if (conditional?.allOf) { | ||
return createConditionsArray(conditional.allOf).every(f => f(e)) | ||
} | ||
if (conditional?.anyOf) { | ||
return createConditionsArray(conditional.anyOf).some(f => f(e)) | ||
} | ||
if (conditional?.oneOf) { | ||
return createConditionsArray(conditional.oneOf).filter(f => f(e)).length === 1 | ||
} | ||
return true | ||
} | ||
|
||
export const entityPage = ( | ||
<EntitySwitch> | ||
<EntitySwitch.Case if={isKind('component')} children={componentPage} /> | ||
<EntitySwitch.Case if={isKind('api')} children={apiPage} /> | ||
<EntitySwitch.Case if={isKind('group')} children={groupPage} /> | ||
<EntitySwitch.Case if={isKind('user')} children={userPage} /> | ||
<EntitySwitch.Case if={isKind('system')} children={systemPage} /> | ||
<EntitySwitch.Case if={isKind('domain')} children={domainPage} /> | ||
<EntitySwitch.Case if={isKind('resource')} children={resourcePage} /> | ||
<EntityLayout> | ||
<EntityLayout.Route path="/" title="Overview"> | ||
<> | ||
{getMountPointData<React.ComponentType>('entity.page.overview/context').reduce( | ||
(acc, { component: Component }) => ( | ||
<Component> | ||
{acc} | ||
</Component> | ||
), | ||
<> | ||
{getMountPointData<React.ComponentType>('entity.page.overview/cards').map( | ||
({ component: Component, config }, index) => ( | ||
<EntitySwitch key={index}> | ||
<EntitySwitch.Case if={entitySwitchCaseIf(config.if)}> | ||
<Component /> | ||
</EntitySwitch.Case> | ||
</EntitySwitch> | ||
) | ||
)} | ||
</>) | ||
} | ||
</> | ||
</EntityLayout.Route> | ||
</EntityLayout> | ||
// <EntitySwitch> | ||
// <EntitySwitch.Case if={isKind('component')} children={componentPage} /> | ||
// <EntitySwitch.Case if={isKind('api')} children={apiPage} /> | ||
// <EntitySwitch.Case if={isKind('group')} children={groupPage} /> | ||
// <EntitySwitch.Case if={isKind('user')} children={userPage} /> | ||
// <EntitySwitch.Case if={isKind('system')} children={systemPage} /> | ||
// <EntitySwitch.Case if={isKind('domain')} children={domainPage} /> | ||
// <EntitySwitch.Case if={isKind('resource')} children={resourcePage} /> | ||
|
||
// <EntitySwitch.Case>{defaultEntityPage}</EntitySwitch.Case> | ||
// </EntitySwitch> | ||
|
||
<EntitySwitch.Case>{defaultEntityPage}</EntitySwitch.Case> | ||
</EntitySwitch> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters