packages/core: remove old widget related things

This commit is contained in:
Patrik Oldsberg
2020-04-30 12:23:30 +02:00
parent 3ae7021d9c
commit ae0d3994e9
8 changed files with 0 additions and 205 deletions
-5
View File
@@ -16,7 +16,6 @@
import ApiRef, { ApiRefConfig } from './apis/ApiRef';
import AppBuilder from './app/AppBuilder';
import WidgetViewBuilder from './widgetView/WidgetViewBuilder';
import BackstagePlugin, { PluginConfig } from './plugin/Plugin';
export function createApp() {
@@ -27,10 +26,6 @@ export function createApiRef<T>(config: ApiRefConfig) {
return new ApiRef<T>(config);
}
export function createWidgetView() {
return new WidgetViewBuilder();
}
export function createPlugin(config: PluginConfig): BackstagePlugin {
return new BackstagePlugin(config);
}
-11
View File
@@ -22,7 +22,6 @@ import {
FeatureFlagName,
} from './types';
import { validateBrowserCompat, validateFlagName } from 'api/app/FeatureFlags';
import { Widget } from 'api/widgetView/types';
export type PluginConfig = {
id: string;
@@ -31,7 +30,6 @@ export type PluginConfig = {
export type PluginHooks = {
router: RouterHooks;
widgets: WidgetHooks;
featureFlags: FeatureFlagsHooks;
};
@@ -49,10 +47,6 @@ export type RouterHooks = {
): void;
};
export type WidgetHooks = {
add(widget: Widget): void;
};
export type FeatureFlagsHooks = {
register(name: FeatureFlagName): void;
};
@@ -88,11 +82,6 @@ export default class Plugin {
outputs.push({ type: 'redirect-route', path, target, options });
},
},
widgets: {
add(widget: Widget) {
outputs.push({ type: 'widget', widget });
},
},
featureFlags: {
register(name) {
validateBrowserCompat();
-7
View File
@@ -15,7 +15,6 @@
*/
import { ComponentType } from 'react';
import { Widget } from 'api/widgetView/types';
export type RouteOptions = {
// Whether the route path must match exactly, defaults to true.
@@ -38,11 +37,6 @@ export type RedirectRouteOutput = {
options?: RouteOptions;
};
export type WidgetOutput = {
type: 'widget';
widget: Widget;
};
export type FeatureFlagName = string;
export type FeatureFlagOutput = {
@@ -53,5 +47,4 @@ export type FeatureFlagOutput = {
export type PluginOutput =
| RouteOutput
| RedirectRouteOutput
| WidgetOutput
| FeatureFlagOutput;
@@ -1,83 +0,0 @@
/*
* Copyright 2020 Spotify AB
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import React, { ComponentType } from 'react';
import { AppComponentBuilder } from 'api/app/types';
import { Widget } from './types';
import BackstagePlugin from 'api/plugin/Plugin';
import DefaultWidgetView from 'components/DefaultWidgetView';
type WidgetViewRegistration =
| {
type: 'component';
widget: Widget;
}
| {
type: 'plugin';
plugin: BackstagePlugin;
};
export default class WidgetViewBuilder extends AppComponentBuilder {
private readonly registrations = new Array<WidgetViewRegistration>();
private output?: ComponentType<any>;
add(widget: Widget): WidgetViewBuilder {
this.registrations.push({ type: 'component', widget });
return this;
}
register(plugin: BackstagePlugin): WidgetViewBuilder {
this.registrations.push({ type: 'plugin', plugin });
return this;
}
build(): ComponentType<any> {
if (this.output) {
return this.output;
}
const widgets = new Array<Widget>();
for (const reg of this.registrations) {
switch (reg.type) {
case 'component':
widgets.push(reg.widget);
break;
case 'plugin':
{
let added = false;
for (const output of reg.plugin.output()) {
if (output.type === 'widget') {
widgets.push(output.widget);
added = true;
}
}
if (!added) {
throw new Error(
`Plugin ${reg.plugin} was registered as widget provider, but did not provide any widgets`,
);
}
}
break;
default:
throw new Error(`Unknown WidgetViewBuilder registration`);
}
}
this.output = () => <DefaultWidgetView widgets={widgets} />;
return this.output;
}
}
-26
View File
@@ -1,26 +0,0 @@
/*
* Copyright 2020 Spotify AB
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { ComponentType } from 'react';
export type Widget = {
size: 4 | 6 | 8 | 12;
component: ComponentType<any>;
};
export type WidgetViewProps = {
widgets: Widget[];
};
@@ -1,48 +0,0 @@
/*
* Copyright 2020 Spotify AB
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import React, { FC } from 'react';
import { Grid, Paper, makeStyles, Theme } from '@material-ui/core';
import { WidgetViewProps } from 'api/widgetView/types';
const useStyles = makeStyles<Theme>(theme => ({
root: {
padding: theme.spacing(2),
},
widgetWrapper: {
padding: theme.spacing(2),
},
}));
const WidgetViewComponent: FC<WidgetViewProps> = ({ widgets }) => {
const classes = useStyles();
return (
<div className={classes.root}>
<Grid container direction="row" spacing={2}>
{widgets.map(({ size, component: WidgetComponent }, index) => (
<Grid key={index} item xs={size}>
<Paper className={classes.widgetWrapper}>
<WidgetComponent />
</Paper>
</Grid>
))}
</Grid>
</div>
);
};
export default WidgetViewComponent;
@@ -1,17 +0,0 @@
/*
* Copyright 2020 Spotify AB
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export { default } from './DefaultWidgetView';
@@ -52,9 +52,6 @@ const VARIANT_STYLES = {
display: 'flex',
flexDirection: 'column',
},
widget: {
height: 430,
},
fullHeight: {
height: '100%',
},
@@ -79,11 +76,6 @@ const VARIANT_STYLES = {
},
},
cardContent: {
widget: {
overflowY: 'auto',
height: 332,
width: '100%',
},
fullHeight: {
height: 'calc(100% - 50px)',
},