change naming from widget to panel
Signed-off-by: Chongyang Adrian, Ke <ftt.adrian.ke@grabtaxi.com>
This commit is contained in:
@@ -90,7 +90,11 @@ export const DocsTable = ({
|
||||
<>
|
||||
{documents && documents.length > 0 ? (
|
||||
<Table
|
||||
options={{ paging: true, pageSize: 20, search: true }}
|
||||
options={{
|
||||
paging: true,
|
||||
pageSize: 20,
|
||||
search: true,
|
||||
}}
|
||||
data={documents}
|
||||
columns={columns}
|
||||
title={
|
||||
|
||||
@@ -19,7 +19,7 @@ import { CatalogApi, catalogApiRef } from '@backstage/plugin-catalog-react';
|
||||
import { renderInTestApp } from '@backstage/test-utils';
|
||||
import { screen } from '@testing-library/react';
|
||||
import React from 'react';
|
||||
import { TechDocsCustomHome, WidgetType } from './TechDocsCustomHome';
|
||||
import { TechDocsCustomHome, PanelType } from './TechDocsCustomHome';
|
||||
|
||||
describe('TechDocsCustomHome', () => {
|
||||
const catalogApi: Partial<CatalogApi> = {
|
||||
@@ -32,22 +32,22 @@ describe('TechDocsCustomHome', () => {
|
||||
const tabsConfig = [
|
||||
{
|
||||
label: 'First Tab',
|
||||
widgets: [
|
||||
panels: [
|
||||
{
|
||||
title: 'First Tab',
|
||||
description: 'First Tab Description',
|
||||
widgetType: 'DocsCardGrid' as WidgetType,
|
||||
panelType: 'DocsCardGrid' as PanelType,
|
||||
filterPredicate: () => true,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
label: 'Second Tab ',
|
||||
widgets: [
|
||||
panels: [
|
||||
{
|
||||
title: 'Second Tab',
|
||||
description: 'Second Tab Description',
|
||||
widgetType: 'DocsTable' as WidgetType,
|
||||
panelType: 'DocsTable' as PanelType,
|
||||
filterPredicate: () => true,
|
||||
},
|
||||
],
|
||||
|
||||
@@ -37,46 +37,46 @@ import {
|
||||
import { DocsTable } from './DocsTable';
|
||||
import { DocsCardGrid } from './DocsCardGrid';
|
||||
|
||||
const widgets = {
|
||||
const panels = {
|
||||
DocsTable: DocsTable,
|
||||
DocsCardGrid: DocsCardGrid,
|
||||
};
|
||||
|
||||
export type WidgetType = 'DocsCardGrid' | 'DocsTable';
|
||||
export type PanelType = 'DocsCardGrid' | 'DocsTable';
|
||||
|
||||
export interface WidgetConfig {
|
||||
export interface PanelConfig {
|
||||
title: string;
|
||||
description: string;
|
||||
widgetType: WidgetType;
|
||||
widgetMaxHeight?: string;
|
||||
panelType: PanelType;
|
||||
panelCSS?: {};
|
||||
filterPredicate: (entity: Entity) => boolean;
|
||||
}
|
||||
|
||||
export interface TabConfig {
|
||||
label: string;
|
||||
widgets: WidgetConfig[];
|
||||
panels: PanelConfig[];
|
||||
}
|
||||
|
||||
export type TabsConfig = TabConfig[];
|
||||
|
||||
const CustomWidget = ({
|
||||
const CustomPanel = ({
|
||||
config,
|
||||
entities,
|
||||
index,
|
||||
}: {
|
||||
config: WidgetConfig;
|
||||
config: PanelConfig;
|
||||
entities: Entity[];
|
||||
index: number;
|
||||
}) => {
|
||||
const useStyles = makeStyles({
|
||||
widgetContainer: {
|
||||
maxHeight: config.widgetMaxHeight || 'inherit',
|
||||
panelContainer: {
|
||||
marginBottom: '2rem',
|
||||
overflow: 'auto',
|
||||
...(config.panelCSS ? config.panelCSS : {}),
|
||||
},
|
||||
});
|
||||
const classes = useStyles();
|
||||
const Widget = widgets[config.widgetType];
|
||||
const Panel = panels[config.panelType];
|
||||
const shownEntities = entities.filter(config.filterPredicate);
|
||||
return (
|
||||
<>
|
||||
@@ -87,8 +87,8 @@ const CustomWidget = ({
|
||||
</SupportButton>
|
||||
) : null}
|
||||
</ContentHeader>
|
||||
<div className={classes.widgetContainer}>
|
||||
<Widget entities={shownEntities} />
|
||||
<div className={classes.panelContainer}>
|
||||
<Panel entities={shownEntities} />
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
@@ -155,8 +155,8 @@ export const TechDocsCustomHome = ({
|
||||
}))}
|
||||
/>
|
||||
<Content>
|
||||
{currentTabConfig.widgets.map((config, index) => (
|
||||
<CustomWidget
|
||||
{currentTabConfig.panels.map((config, index) => (
|
||||
<CustomPanel
|
||||
key={index}
|
||||
config={config}
|
||||
entities={!!entities ? entities : []}
|
||||
|
||||
@@ -18,7 +18,7 @@ import React from 'react';
|
||||
import { Entity } from '@backstage/catalog-model';
|
||||
import { useOwnUser } from '../hooks';
|
||||
import { isOwnerOf } from '@backstage/plugin-catalog-react';
|
||||
import { WidgetType, TechDocsCustomHome } from './TechDocsCustomHome';
|
||||
import { PanelType, TechDocsCustomHome } from './TechDocsCustomHome';
|
||||
|
||||
export const TechDocsHome = () => {
|
||||
const { value: user } = useOwnUser();
|
||||
@@ -26,23 +26,24 @@ export const TechDocsHome = () => {
|
||||
const tabsConfig = [
|
||||
{
|
||||
label: 'Overview',
|
||||
widgets: [
|
||||
panels: [
|
||||
{
|
||||
title: 'Overview',
|
||||
description:
|
||||
'Explore your internal technical ecosystem through documentation.',
|
||||
widgetType: 'DocsCardGrid' as WidgetType,
|
||||
panelType: 'DocsCardGrid' as PanelType,
|
||||
filterPredicate: () => true,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
label: 'Owned',
|
||||
widgets: [
|
||||
panels: [
|
||||
{
|
||||
title: 'Owned documents',
|
||||
description: 'Access your documentation.',
|
||||
widgetType: 'DocsTable' as WidgetType,
|
||||
panelType: 'DocsTable' as PanelType,
|
||||
paneCSS: { maxHeight: '200px' },
|
||||
filterPredicate: (entity: Entity) => {
|
||||
if (!user) {
|
||||
return false;
|
||||
|
||||
@@ -27,4 +27,4 @@ export {
|
||||
export { Router, EmbeddedDocsRouter } from './Router';
|
||||
export * from './reader';
|
||||
export * from './api';
|
||||
export type { WidgetType } from './home/components/TechDocsCustomHome';
|
||||
export type { PanelType } from './home/components/TechDocsCustomHome';
|
||||
|
||||
Reference in New Issue
Block a user