From 63a8205a726590542fc02170ec666c0735527408 Mon Sep 17 00:00:00 2001 From: Matteo Barone Date: Fri, 18 Jun 2021 09:48:11 +0200 Subject: [PATCH] removed actions factories and define defaultActions in component itself Signed-off-by: Matteo Barone --- .../components/CatalogTable/CatalogTable.tsx | 50 +++++++++++--- .../src/components/CatalogTable/actions.tsx | 67 ------------------- plugins/catalog/src/index.ts | 1 - 3 files changed, 41 insertions(+), 77 deletions(-) delete mode 100644 plugins/catalog/src/components/CatalogTable/actions.tsx diff --git a/plugins/catalog/src/components/CatalogTable/CatalogTable.tsx b/plugins/catalog/src/components/CatalogTable/CatalogTable.tsx index f7049ead9d..6515211074 100644 --- a/plugins/catalog/src/components/CatalogTable/CatalogTable.tsx +++ b/plugins/catalog/src/components/CatalogTable/CatalogTable.tsx @@ -23,14 +23,21 @@ import { } from '@backstage/core'; import { formatEntityRefTitle, + getEntityMetadataEditUrl, + getEntityMetadataViewUrl, getEntityRelations, useEntityListProvider, useStarredEntities, } from '@backstage/plugin-catalog-react'; +import Edit from '@material-ui/icons/Edit'; +import OpenInNew from '@material-ui/icons/OpenInNew'; import { capitalize } from 'lodash'; import React from 'react'; +import { + favouriteEntityIcon, + favouriteEntityTooltip, +} from '../FavouriteEntity/FavouriteEntity'; import * as columnFactories from './columns'; -import * as actionFactories from './actions'; import { EntityRow } from './types'; const defaultColumns: TableColumn[] = [ @@ -70,14 +77,39 @@ export const CatalogTable = ({ columns, actions }: CatalogTableProps) => { } const defaultActions: TableProps['actions'] = [ - ({ entity }) => actionFactories.createViewUrlAction(entity), - ({ entity }) => actionFactories.createEditUrlAction(entity), - ({ entity }) => - actionFactories.createStarredAction( - entity, - isStarredEntity, - toggleStarredEntity, - ), + ({ entity }) => { + const url = getEntityMetadataViewUrl(entity); + return { + icon: () => , + tooltip: 'View', + disabled: !url, + onClick: () => { + if (!url) return; + window.open(url, '_blank'); + }, + }; + }, + ({ entity }) => { + const url = getEntityMetadataEditUrl(entity); + return { + icon: () => , + tooltip: 'Edit', + disabled: !url, + onClick: () => { + if (!url) return; + window.open(url, '_blank'); + }, + }; + }, + ({ entity }) => { + const isStarred = isStarredEntity(entity); + return { + cellStyle: { paddingLeft: '1em' }, + icon: () => favouriteEntityIcon(isStarred), + tooltip: favouriteEntityTooltip(isStarred), + onClick: () => toggleStarredEntity(entity), + }; + }, ]; const rows = entities.map(entity => { diff --git a/plugins/catalog/src/components/CatalogTable/actions.tsx b/plugins/catalog/src/components/CatalogTable/actions.tsx deleted file mode 100644 index dfbb0202ea..0000000000 --- a/plugins/catalog/src/components/CatalogTable/actions.tsx +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2021 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 from 'react'; -import { Entity } from '@backstage/catalog-model'; -import { - getEntityMetadataViewUrl, - getEntityMetadataEditUrl, -} from '@backstage/plugin-catalog-react'; -import OpenInNew from '@material-ui/icons/OpenInNew'; -import Edit from '@material-ui/icons/Edit'; -import { - favouriteEntityIcon, - favouriteEntityTooltip, -} from '../FavouriteEntity/FavouriteEntity'; - -export function createViewUrlAction(entity: Entity) { - const url = getEntityMetadataViewUrl(entity); - return { - icon: () => , - tooltip: 'View', - disabled: !url, - onClick: () => { - if (!url) return; - window.open(url, '_blank'); - }, - }; -} - -export function createEditUrlAction(entity: Entity) { - const url = getEntityMetadataEditUrl(entity); - return { - icon: () => , - tooltip: 'Edit', - disabled: !url, - onClick: () => { - if (!url) return; - window.open(url, '_blank'); - }, - }; -} - -export function createStarredAction( - entity: Entity, - isStarredEntity: (entity: Entity) => boolean, - toggleStarredEntity: (entity: Entity) => void, -) { - const isStarred = isStarredEntity(entity); - return { - cellStyle: { paddingLeft: '1em' }, - icon: () => favouriteEntityIcon(isStarred), - tooltip: favouriteEntityTooltip(isStarred), - onClick: () => toggleStarredEntity(entity), - }; -} diff --git a/plugins/catalog/src/index.ts b/plugins/catalog/src/index.ts index 3d5f932896..c6feb9c7c0 100644 --- a/plugins/catalog/src/index.ts +++ b/plugins/catalog/src/index.ts @@ -42,4 +42,3 @@ export { EntitySystemDiagramCard, } from './plugin'; export * from './components/CatalogTable/columns'; -export * from './components/CatalogTable/actions';