From 0b4b9250de151657cd6634f5e5eee24d5f761940 Mon Sep 17 00:00:00 2001 From: Matej Kubinec Date: Fri, 20 Jan 2023 13:13:12 +0100 Subject: [PATCH 01/32] PMM-1148 initial inventory management rework --- .../AddInstance/AddInstance.messages.ts | 2 + .../AddInstance/AddInstance.styles.ts | 52 ++---- .../AddInstance/AddInstance.test.tsx | 18 +- .../components/AddInstance/AddInstance.tsx | 52 +++--- .../AddInstance/AddInstance.types.ts | 18 +- .../AddRemoteInstance.messages.ts | 11 ++ .../AddRemoteInstance.styles.ts | 2 +- .../AddRemoteInstance.test.tsx | 6 +- .../AddRemoteInstance/AddRemoteInstance.tsx | 29 +--- .../AddRemoteInstance.types.ts | 1 + .../AdditionalOptions/AdditionalOptions.tsx | 41 +++-- .../ExternalServiceConnectionDetails.tsx | 162 +++++++++--------- .../FormParts/FormParts.messages.ts | 9 +- .../FormParts/FormParts.styles.tsx | 47 ++++- .../HAProxyConnectionDetails.tsx | 99 +++++------ .../FormParts/Labels/Labels.tsx | 93 ++++++---- .../FormParts/Labels/Labels.types.ts | 3 + .../FormParts/MainDetails/MainDetails.tsx | 92 +++++----- .../MongoDBConnectionDetails.tsx | 112 ++++++------ .../MySQLConnectionDetails.tsx | 113 ++++++------ .../PostgreSQLConnectionDetails.tsx | 129 +++++++------- .../AzureDiscovery/Discovery.test.tsx | 2 +- .../components/AzureDiscovery/Discovery.tsx | 2 +- .../AzureDiscovery/Discovery.types.ts | 1 + .../components/Credentials/Credentials.tsx | 8 +- .../components/Discovery/Discovery.test.tsx | 2 +- .../components/Discovery/Discovery.tsx | 4 +- .../components/Discovery/Discovery.types.ts | 1 + .../Credentials/Credentials.test.tsx | 4 +- .../components/Credentials/Credentials.tsx | 20 +-- .../Credentials/Credentials.types.ts | 3 - .../app/percona/add-instance/panel.styles.ts | 10 +- public/app/percona/add-instance/panel.tsx | 119 +++++++++---- .../app/percona/add-instance/panel.types.ts | 4 + .../edit-instance/EditInstance.messages.ts | 6 + .../edit-instance/EditInstance.test.tsx | 35 ++++ .../percona/edit-instance/EditInstance.tsx | 79 +++++++++ .../edit-instance/EditInstance.types.ts | 23 +++ .../edit-instance/EditInstance.utils.ts | 54 ++++++ .../ColumnRenderers/ColumnRenderers.tsx | 5 + .../percona/inventory/Inventory.constants.ts | 58 ++++++- .../percona/inventory/Inventory.service.ts | 6 + .../app/percona/inventory/Tabs/Services.tsx | 40 +++-- .../app/percona/inventory/Tabs/Tabs.styles.ts | 3 + .../inventory/__mocks__/Inventory.service.ts | 31 +++- .../inventory/__mocks__/Services.service.ts | 10 ++ .../DeleteServiceModal.messages.ts | 13 ++ .../DeleteServiceModal.styles.ts | 7 + .../DeleteServiceModal.test.tsx | 77 +++++++++ .../DeleteServiceModal/DeleteServiceModal.tsx | 69 ++++++++ .../ServicesOptions.messages.ts | 7 + .../ServicesOptions/ServicesOptions.styles.ts | 9 + .../ServicesOptions/ServicesOptions.test.tsx | 70 ++++++++ .../ServicesOptions/ServicesOptions.tsx | 50 ++++++ .../ServicesOptions/ServicesOptions.types.ts | 5 + .../PerconaNavigation.constants.ts | 8 + .../PerconaNavigation/PerconaNavigation.tsx | 2 + .../shared/core/reducers/services/services.ts | 17 +- public/app/routes/routes.tsx | 12 ++ 59 files changed, 1390 insertions(+), 577 deletions(-) create mode 100644 public/app/percona/add-instance/components/AddRemoteInstance/FormParts/Labels/Labels.types.ts create mode 100644 public/app/percona/edit-instance/EditInstance.messages.ts create mode 100644 public/app/percona/edit-instance/EditInstance.test.tsx create mode 100644 public/app/percona/edit-instance/EditInstance.tsx create mode 100644 public/app/percona/edit-instance/EditInstance.types.ts create mode 100644 public/app/percona/edit-instance/EditInstance.utils.ts create mode 100644 public/app/percona/inventory/__mocks__/Services.service.ts create mode 100644 public/app/percona/inventory/components/DeleteServiceModal/DeleteServiceModal.messages.ts create mode 100644 public/app/percona/inventory/components/DeleteServiceModal/DeleteServiceModal.styles.ts create mode 100644 public/app/percona/inventory/components/DeleteServiceModal/DeleteServiceModal.test.tsx create mode 100644 public/app/percona/inventory/components/DeleteServiceModal/DeleteServiceModal.tsx create mode 100644 public/app/percona/inventory/components/ServicesOptions/ServicesOptions.messages.ts create mode 100644 public/app/percona/inventory/components/ServicesOptions/ServicesOptions.styles.ts create mode 100644 public/app/percona/inventory/components/ServicesOptions/ServicesOptions.test.tsx create mode 100644 public/app/percona/inventory/components/ServicesOptions/ServicesOptions.tsx create mode 100644 public/app/percona/inventory/components/ServicesOptions/ServicesOptions.types.ts diff --git a/public/app/percona/add-instance/components/AddInstance/AddInstance.messages.ts b/public/app/percona/add-instance/components/AddInstance/AddInstance.messages.ts index 3f8b44e707235..10c8645b2f1cc 100644 --- a/public/app/percona/add-instance/components/AddInstance/AddInstance.messages.ts +++ b/public/app/percona/add-instance/components/AddInstance/AddInstance.messages.ts @@ -1,4 +1,6 @@ export const Messages = { + sectionTitle: 'Select service type', + description: 'Select the service type you want to configure and then add to your inventory.', titles: { rds: 'Amazon RDS', azure: 'Microsoft Azure MySQL or PostgreSQL', diff --git a/public/app/percona/add-instance/components/AddInstance/AddInstance.styles.ts b/public/app/percona/add-instance/components/AddInstance/AddInstance.styles.ts index 7a68c6d2aa1df..d53786ce51856 100644 --- a/public/app/percona/add-instance/components/AddInstance/AddInstance.styles.ts +++ b/public/app/percona/add-instance/components/AddInstance/AddInstance.styles.ts @@ -1,52 +1,30 @@ import { css } from '@emotion/css'; -import { GrafanaTheme } from '@grafana/data'; +import { GrafanaTheme2 } from '@grafana/data'; -export const getStyles = ({ border, colors, spacing, typography }: GrafanaTheme) => ({ - navigationButton: css` +export const getStyles = (theme: GrafanaTheme2) => ({ + Content: css` display: flex; flex-direction: column; - justify-content: flex-end; - align-items: center; - padding-bottom: 1.2em; - margin: ${spacing.sm}; - border-radius: ${border.radius.md}; - width: 230px; - height: 160px; - text-align: center; - background-color: transparent; - border: ${border.width.sm} dashed ${colors.border2}; - - :hover { - cursor: pointer; - background-color: ${colors.dropdownOptionHoverBg}; - border: ${border.width.sm} solid ${colors.border2}; - } + align-items: flex-start; `, - navigationPanel: css` + NavigationPanel: css` display: flex; flex-direction: row; - justify-content: center; + justify-content: flex-start; flex-wrap: wrap; - max-width: 800px; + max-width: 825px; width: 100%; overflow: hidden; + gap: ${theme.spacing(2)}; + padding: 3px; + margin: -3px; `, - content: css` - display: flex; - flex-direction: column; - align-items: center; - margin-top: 2em; + InstanceCard: css` + width: 375px; + margin: 0; `, - addInstance: css` - margin-top: ${spacing.sm}; - font-size: ${typography.size.sm}; - `, - addInstanceTitle: css` - margin-top: ${spacing.sm}; - overflow: hidden; - line-height: ${typography.lineHeight.md}; - width: 65%; - height: 3em; + Description: css` + color: ${theme.colors.text.secondary}; `, }); diff --git a/public/app/percona/add-instance/components/AddInstance/AddInstance.test.tsx b/public/app/percona/add-instance/components/AddInstance/AddInstance.test.tsx index 1b84d63c09f2e..b1f64f3acc96d 100644 --- a/public/app/percona/add-instance/components/AddInstance/AddInstance.test.tsx +++ b/public/app/percona/add-instance/components/AddInstance/AddInstance.test.tsx @@ -1,14 +1,22 @@ import { render, screen, waitFor, fireEvent } from '@testing-library/react'; import React from 'react'; +import { InstanceAvailable } from '../../panel.types'; + import { AddInstance } from './AddInstance'; import { instanceList } from './AddInstance.constants'; jest.mock('app/percona/settings/Settings.service'); +const selectedInstanceType: InstanceAvailable = { type: '' }; + describe('AddInstance page::', () => { it('should render a given number of links', async () => { - await waitFor(() => render( {}} />)); + await waitFor(() => + render( + {}} selectedInstanceType={selectedInstanceType} /> + ) + ); expect(screen.getAllByRole('button')).toHaveLength(instanceList.length); instanceList.forEach((item) => { @@ -17,7 +25,9 @@ describe('AddInstance page::', () => { }); it('should render azure option', async () => { - await waitFor(() => render( {}} />)); + await waitFor(() => + render( {}} selectedInstanceType={selectedInstanceType} />) + ); expect(screen.getAllByRole('button')).toHaveLength(instanceList.length + 1); instanceList.forEach((item) => { @@ -29,7 +39,9 @@ describe('AddInstance page::', () => { it('should invoke a callback with a proper instance type', async () => { const onSelectInstanceType = jest.fn(); - render(); + render( + + ); expect(onSelectInstanceType).toBeCalledTimes(0); diff --git a/public/app/percona/add-instance/components/AddInstance/AddInstance.tsx b/public/app/percona/add-instance/components/AddInstance/AddInstance.tsx index 12e228e18e4d4..06d8eb0613d29 100644 --- a/public/app/percona/add-instance/components/AddInstance/AddInstance.tsx +++ b/public/app/percona/add-instance/components/AddInstance/AddInstance.tsx @@ -1,59 +1,65 @@ import React, { FC, useMemo } from 'react'; -import { useStyles } from '@grafana/ui'; -import { Database } from 'app/percona/shared/components/Elements/Icons/Database'; +import { Card, Icon, useStyles2 } from '@grafana/ui'; import { Databases } from 'app/percona/shared/core'; import { InstanceTypesExtra, InstanceAvailableType } from '../../panel.types'; import { Messages } from './AddInstance.messages'; import { getStyles } from './AddInstance.styles'; -import { AddInstanceProps, SelectInstanceProps } from './AddInstance.types'; +import { AddInstanceProps, InstanceListItem, SelectInstanceProps } from './AddInstance.types'; -export const SelectInstance: FC = ({ type, selectInstanceType, title }) => { - const styles = useStyles(getStyles); +export const SelectInstance: FC = ({ type, isSelected, icon, selectInstanceType, title }) => { + const styles = useStyles2(getStyles); return ( - + {title} + {Messages.titles.addInstance} + + + + ); }; -export const AddInstance: FC = ({ onSelectInstanceType, showAzure }) => { - const styles = useStyles(getStyles); - const instanceList = useMemo( +export const AddInstance: FC = ({ selectedInstanceType, onSelectInstanceType, showAzure }) => { + const styles2 = useStyles2(getStyles); + const instanceList = useMemo( () => [ + { type: Databases.postgresql, title: Messages.titles.postgresql, icon: 'percona-database-postgresql' }, + { type: Databases.mysql, title: Messages.titles.mysql, icon: 'percona-database-mysql' }, + { type: Databases.mongodb, title: Messages.titles.mongodb, icon: 'percona-database-mongodb' }, + { type: Databases.proxysql, title: Messages.titles.proxysql, icon: 'percona-database-proxysql' }, + { type: Databases.haproxy, title: Messages.titles.haproxy, icon: 'percona-database-haproxy' }, { type: InstanceTypesExtra.rds, title: Messages.titles.rds }, - { type: InstanceTypesExtra.azure, title: Messages.titles.azure, isHidden: !showAzure }, - { type: Databases.postgresql, title: Messages.titles.postgresql }, - { type: Databases.mysql, title: Messages.titles.mysql }, - { type: Databases.mongodb, title: Messages.titles.mongodb }, - { type: Databases.proxysql, title: Messages.titles.proxysql }, { type: InstanceTypesExtra.external, title: Messages.titles.external }, - { type: Databases.haproxy, title: Messages.titles.haproxy }, + { type: InstanceTypesExtra.azure, title: Messages.titles.azure, isHidden: !showAzure }, ], [showAzure] ); + // eslint-disable-next-line @typescript-eslint/consistent-type-assertions const selectInstanceType = (type: string) => () => onSelectInstanceType({ type: type as InstanceAvailableType }); return ( -
-