chore: working through beginning API

Signed-off-by: blam <ben@blam.sh>
This commit is contained in:
blam
2021-06-09 17:00:12 +02:00
parent 794af0de8e
commit d7f0b0bed6
5 changed files with 57 additions and 22 deletions
@@ -108,6 +108,7 @@ import {
isTravisciAvailable,
} from '@roadiehq/backstage-plugin-travis-ci';
import { EntityCodeCoverageContent } from '@backstage/plugin-code-coverage';
import { FeatureFlagged } from '@backstage/core-app-api';
const EntityLayoutWrapper = (props: { children?: ReactNode }) => {
const [badgesDialogOpen, setBadgesDialogOpen] = useState(false);
@@ -282,9 +283,11 @@ const serviceEntityPage = (
{overviewContent}
</EntityLayout.Route>
<EntityLayout.Route path="/ci-cd" title="CI/CD">
{cicdContent}
</EntityLayout.Route>
<FeatureFlagged flag="show-graphiql-page">
<EntityLayout.Route path="/ci-cd" title="CI/CD">
{cicdContent}
</EntityLayout.Route>
</FeatureFlagged>
<EntityLayout.Route path="/errors" title="Errors">
{errorsContent}
@@ -303,9 +306,11 @@ const serviceEntityPage = (
<EntityLayout.Route path="/dependencies" title="Dependencies">
<Grid container spacing={3} alignItems="stretch">
<Grid item md={6}>
<EntityDependsOnComponentsCard variant="gridItem" />
</Grid>
<FeatureFlagged flag="show-graphiql-page">
<Grid item md={6}>
<EntityDependsOnComponentsCard variant="gridItem" />
</Grid>
</FeatureFlagged>
<Grid item md={6}>
<EntityDependsOnResourcesCard variant="gridItem" />
</Grid>
+1 -1
View File
@@ -244,7 +244,7 @@ export class PrivateAppImpl implements BackstageApp {
// Register feature flags that have been discovered
const featureFlagApi = apiHolder.get(featureFlagsApiRef)!;
for (const name of result.featureFlags) {
featureFlagApi.registerFlag({ name, pluginId: '<app>' });
featureFlagApi.registerFlag({ name, pluginId: '' });
}
return result;
@@ -14,8 +14,11 @@
* limitations under the License.
*/
import React from 'react';
import { featureFlagsApiRef, useApi } from '@backstage/core-plugin-api';
import {
featureFlagsApiRef,
useApi,
attachComponentData,
} from '@backstage/core-plugin-api';
export type FeatureFlaggedProps = {
flag: string;
@@ -25,5 +28,7 @@ export type FeatureFlaggedProps = {
export const FeatureFlagged = ({ children, flag }: FeatureFlaggedProps) => {
const featureFlagApi = useApi(featureFlagsApiRef);
const isEnabled = featureFlagApi.isActive(flag);
return isEnabled ? children : <div>NAT ENABLED</div>;
return isEnabled ? children : null;
};
attachComponentData(FeatureFlagged, 'core.featureFlagged', true);
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import React from 'react';
import React, { ReactNode } from 'react';
import { getComponentData } from './componentData';
/**
@@ -84,7 +84,7 @@ export const useCollectChildren = (
return found;
};
/**
/*
*
*
* TODO:
@@ -94,4 +94,17 @@ export const useCollectChildren = (
* - FlatRoutes
* - Respecting feature flags
*/
export function useElementCollection(children: ReactNode) {}
class ElementCollection {
constructor(private readonly children: ReactNode) {}
findByComponentData(query: { key: string; withStrictError?: string }) {
const next = applyFilterStuff(this.children);
return new ElementCollection(next);
}
listComponentData<T>(query: { key: string }): T[] {}
// listElements
}
export function useElementCollection(children: ReactNode) {
return new ElementCollection(children);
}
+21 -9
View File
@@ -32,16 +32,28 @@ import { collectComponentData, collectChildren } from '../extensions/helpers';
export const Router = () => {
const outlet = useOutlet();
const fieldExtensions = useMemo(() => {
const registeredExtensions = collectComponentData<FieldExtensionOptions>(
collectChildren(outlet, FIELD_EXTENSION_WRAPPER_KEY).flat(),
FIELD_EXTENSION_KEY,
);
const foundExtensions = useElementCollection(outlet)
.findByComponentData({
key: FIELD_EXTENSION_WRAPPER_KEY,
})
.findByComponentData({
key: FIELD_EXTENSION_KEY,
})
.listComponentData<FieldExtensionOptions>();
return registeredExtensions.length
? registeredExtensions
: DEFAULT_SCAFFOLDER_FIELD_EXTENSIONS;
}, [outlet]);
const fieldExtensions = foundExtensions.length
? foundExtensions
: DEFAULT_SCAFFOLDER_FIELD_EXTENSIONS;
// const fieldExtensions = useMemo(() => {
// const registeredExtensions = collectComponentData<FieldExtensionOptions>(
// collectChildren(outlet, FIELD_EXTENSION_WRAPPER_KEY).flat(),
// FIELD_EXTENSION_KEY,
// );
// return registeredExtensions.length
// ? registeredExtensions
// : DEFAULT_SCAFFOLDER_FIELD_EXTENSIONS;
// }, [outlet]);
return (
<Routes>