From c046cbc85d516295cdb1fed8175e6724e9de3aa8 Mon Sep 17 00:00:00 2001 From: N00bG1rl <403helen@gmail.com> Date: Fri, 29 Sep 2023 12:24:17 +0300 Subject: [PATCH 1/3] Delete redundant code --- .../SelfService/Web/admin/CreateCustomer.tsx | 145 ------------- Source/SelfService/Web/admin/index.tsx | 2 - .../microservice/components/headDataRow.tsx | 39 ---- .../components/liveIngressView.tsx | 52 ----- .../microservice/rawDataLog/config/config.tsx | 81 ------- .../rawDataLog/config/configView.tsx | 50 ----- .../microservice/rawDataLog/config/edit.tsx | 32 --- .../rawDataLog/config/editConfig.tsx | 47 ----- .../microservice/rawDataLog/view.tsx | 94 --------- .../microservice/rawDataLog/webhook/edit.tsx | 197 ------------------ .../microservice/rawDataLog/webhooks.tsx | 148 ------------- .../Web/components/basicAuthComponent.tsx | 58 ------ .../Web/components/bearerAuthComponent.tsx | 36 ---- .../Web/components/breadCrumbWithRedirect.tsx | 22 -- .../SelfService/Web/components/buttonLink.tsx | 22 -- .../Web/components/layout/breadcrumbs.tsx | 57 ----- .../Web/components/theme-legacy/textField.tsx | 86 -------- 17 files changed, 1168 deletions(-) delete mode 100644 Source/SelfService/Web/admin/CreateCustomer.tsx delete mode 100644 Source/SelfService/Web/applications/microservice/components/headDataRow.tsx delete mode 100644 Source/SelfService/Web/applications/microservice/components/liveIngressView.tsx delete mode 100644 Source/SelfService/Web/applications/microservice/rawDataLog/config/config.tsx delete mode 100644 Source/SelfService/Web/applications/microservice/rawDataLog/config/configView.tsx delete mode 100644 Source/SelfService/Web/applications/microservice/rawDataLog/config/edit.tsx delete mode 100644 Source/SelfService/Web/applications/microservice/rawDataLog/config/editConfig.tsx delete mode 100644 Source/SelfService/Web/applications/microservice/rawDataLog/view.tsx delete mode 100644 Source/SelfService/Web/applications/microservice/rawDataLog/webhook/edit.tsx delete mode 100644 Source/SelfService/Web/applications/microservice/rawDataLog/webhooks.tsx delete mode 100644 Source/SelfService/Web/components/basicAuthComponent.tsx delete mode 100644 Source/SelfService/Web/components/bearerAuthComponent.tsx delete mode 100644 Source/SelfService/Web/components/breadCrumbWithRedirect.tsx delete mode 100644 Source/SelfService/Web/components/buttonLink.tsx delete mode 100644 Source/SelfService/Web/components/layout/breadcrumbs.tsx delete mode 100644 Source/SelfService/Web/components/theme-legacy/textField.tsx diff --git a/Source/SelfService/Web/admin/CreateCustomer.tsx b/Source/SelfService/Web/admin/CreateCustomer.tsx deleted file mode 100644 index 592879ec4..000000000 --- a/Source/SelfService/Web/admin/CreateCustomer.tsx +++ /dev/null @@ -1,145 +0,0 @@ -// Copyright (c) Dolittle. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -import React from 'react'; - -import { useNavigate } from 'react-router-dom'; -import { useSnackbar } from 'notistack'; - -import { Box, Grid, Step, Stepper, StepContent, StepLabel, Typography } from '@mui/material'; - -import { TextField as ThemedTextField } from '../components/theme-legacy/textField'; -import { Button } from '@dolittle/design-system'; - -import { createCustomer, HttpCustomerRequest } from '../apis/solutions/customer'; - -const styles = { - root: { - width: '100%', - }, - button: { - marginTop: 1, - marginRight: 1, - }, - actionsContainer: { - marginBottom: 2, - }, - resetContainer: { - padding: 3, - }, - inactiveText: { - color: '#93959F', - }, - progressBar: { - color: '#ff9366', - }, - stepIcon: { - 'color': '#3B3D48', - '&.MuiStepIcon-root.Mui-active': { - color: '#6678F6' - }, - '&.MuiStepIcon-root.Mui-completed': { - color: '#6678F6' - }, - '&.MuiStepIcon-root.Mui-active .MuiStepIcon-text': { - fill: '#B3BBFB' - }, - '&.MuiStepIcon-root .MuiStepIcon-text': { - fill: '#93959F' - } - } -}; - -export const CreateCustomer = () => { - const navigate = useNavigate(); - const { enqueueSnackbar } = useSnackbar(); - - const steps = [ - 'Provide a name', - ]; - - const [activeStep, setActiveStep] = React.useState(0); - const [customerName, setCustomerName] = React.useState(''); - - const [activeNextButton, setActiveNextButton] = React.useState(false); - - const stepsContent = [ - <> - Customer Name - - - ) => { - setCustomerName(event.target.value!); - setActiveNextButton(true); - }} - /> - - > - ]; - - const handleNext = async () => { - const input: HttpCustomerRequest = { - name: customerName, - }; - - try { - const data = await createCustomer(input); - enqueueSnackbar('Customer created', { variant: 'info' }); - } catch (error) { - enqueueSnackbar('Error creating customer.', { variant: 'error' }); - } - - return; - }; - - return ( - <> - Create Customer Screen - - - - {steps.map((label, index) => ( - - - = index ? {} : styles.inactiveText}>{label} - - - {stepsContent[index]} - - - - { - const href = `/admin/customers`; - navigate(href); - }} - /> - - - - - - - ))} - - - > - ); -}; diff --git a/Source/SelfService/Web/admin/index.tsx b/Source/SelfService/Web/admin/index.tsx index c8faae1e0..6d9175459 100644 --- a/Source/SelfService/Web/admin/index.tsx +++ b/Source/SelfService/Web/admin/index.tsx @@ -7,7 +7,6 @@ import { Route, Routes } from 'react-router-dom'; import { WorkSpaceLayoutWithSidePanel } from '../components/layout/workSpaceLayout'; import { Welcome } from './Welcome'; -import { CreateCustomer } from './CreateCustomer'; import { AllCustomersView } from './AllCustomersView'; import { CustomerView } from './CustomerView'; import { ApplicationAccessView } from './ApplicationAccessView'; @@ -17,7 +16,6 @@ export const AdminIndex = () => } /> } /> - } /> } /> } /> diff --git a/Source/SelfService/Web/applications/microservice/components/headDataRow.tsx b/Source/SelfService/Web/applications/microservice/components/headDataRow.tsx deleted file mode 100644 index 0275097ef..000000000 --- a/Source/SelfService/Web/applications/microservice/components/headDataRow.tsx +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (c) Dolittle. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. -import React from 'react'; - -import { Box, Typography } from '@mui/material'; - -const styles = { - - label: { - paddingBottom: 2, - color: theme => theme.palette.text.primary - }, - data: { - color: theme => theme.palette.text.secondary - }, - -}; - -export interface HeaderDataRowProps { - head: string - data: string -} - -export const HeaderDataRow: React.FunctionComponent = (props) => { - const head = props!.head; - const data = props!.data; - - return ( - - - {head} - - - - {data} - - - ); -}; diff --git a/Source/SelfService/Web/applications/microservice/components/liveIngressView.tsx b/Source/SelfService/Web/applications/microservice/components/liveIngressView.tsx deleted file mode 100644 index e50839ebb..000000000 --- a/Source/SelfService/Web/applications/microservice/components/liveIngressView.tsx +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright (c) Dolittle. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. -import React from 'react'; - -import { Grid, Typography } from '@mui/material'; - -import { HeaderDataRow } from './headDataRow'; -import { IngressURLWithCustomerTenantID, SimpleIngressPath } from '../../../apis/solutions/api'; - -type Props = { - urls: IngressURLWithCustomerTenantID[]; - paths: SimpleIngressPath[]; -}; - -export const LiveIngressView: React.FunctionComponent = (props) => { - const _props = props!; - const urls = _props.urls; - const paths = _props.paths; - - const tenantEndpoints = urls.map(info => { - const data = `${info.url} (${info.customerTenantID})`; - // React is unhappy when customTenantID is empty multiple times - const key = `${info.url}-${info.customerTenantID}`; - return ; - }); - - // Showing unique paths - const microservicePaths = [...new Set(paths.map(info => info.path))].map(infoPath => { - return ; - }); - - - return ( - - - {tenantEndpoints.length > 0 && - <> - Tenant Endpoints - {tenantEndpoints} - > - } - - Microservice Paths - {microservicePaths} - - ); -}; diff --git a/Source/SelfService/Web/applications/microservice/rawDataLog/config/config.tsx b/Source/SelfService/Web/applications/microservice/rawDataLog/config/config.tsx deleted file mode 100644 index fb6c992d4..000000000 --- a/Source/SelfService/Web/applications/microservice/rawDataLog/config/config.tsx +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright (c) Dolittle. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. -import React from 'react'; - -import { Label } from '@fluentui/react/lib/Label'; -import { TextField, ITextFieldStyles } from '@fluentui/react/lib/TextField'; -import { Stack } from '@fluentui/react/lib/Stack'; -import { PrimaryButton } from '@fluentui/react/lib/Button'; - -import { MicroserviceRawDataLogIngestor } from '../../../../apis/solutions/index'; - -const textFieldStyles: Partial = { fieldGroup: { width: 300 } }; -const stackTokens = { childrenGap: 15 }; - - -type WebhooksConfigProps = { - domain: string - action: string - ms: MicroserviceRawDataLogIngestor - onSave?: (ms: MicroserviceRawDataLogIngestor) => Promise; -}; -// TODO how to pass in - -export const Config: React.FunctionComponent = (props) => { - const domain = props!.domain; - const onSave = props!.onSave!; - const action = props!.action!; - const ms = props!.ms!; - let actionText = 'Create'; - - switch (action) { - case 'insert': - actionText = 'Create'; - break; - case 'upsert': - actionText = 'Save'; - break; - - } - - return ( - - - Webhook name - { - ms.name = v!; - }} - /> - - - - Endpoint - - / - { - ms.extra.ingress.path = `/${v!}`; - }} - /> - - - - { - (async () => { - await onSave(ms); - })(); - }} /> - - - ); -}; - diff --git a/Source/SelfService/Web/applications/microservice/rawDataLog/config/configView.tsx b/Source/SelfService/Web/applications/microservice/rawDataLog/config/configView.tsx deleted file mode 100644 index 6c3cc2463..000000000 --- a/Source/SelfService/Web/applications/microservice/rawDataLog/config/configView.tsx +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright (c) Dolittle. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. -import React from 'react'; - -import { Label } from '@fluentui/react/lib/Label'; -import { TextField, ITextFieldStyles } from '@fluentui/react/lib/TextField'; -import { Stack } from '@fluentui/react/lib/Stack'; - -import { MicroserviceRawDataLogIngestor } from '../../../../apis/solutions/index'; - -const textFieldStyles: Partial = { fieldGroup: { width: 300 } }; -const stackTokens = { childrenGap: 15 }; - -type WebhooksConfigProps = { - microservice: MicroserviceRawDataLogIngestor -}; - -export const ConfigView: React.FunctionComponent = (props) => { - const ms = props!.microservice; - const domain = 'TODO'; - - return ( - - - Webhook name - - - - - Endpoint - - / - - - - ); -}; - diff --git a/Source/SelfService/Web/applications/microservice/rawDataLog/config/edit.tsx b/Source/SelfService/Web/applications/microservice/rawDataLog/config/edit.tsx deleted file mode 100644 index 2f52744e5..000000000 --- a/Source/SelfService/Web/applications/microservice/rawDataLog/config/edit.tsx +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) Dolittle. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - - -// TODO how to load the logs? -// TODO validate the data -// TODO change action button from create to save - -import React from 'react'; - -import { MicroserviceRawDataLogIngestor } from '../../../../apis/solutions/index'; -import { HttpResponseApplication } from '../../../../apis/solutions/application'; -import { EditConfig } from './editConfig'; - -type Props = { - application: HttpResponseApplication - environment: string - ms: MicroserviceRawDataLogIngestor -}; - -export const Edit: React.FunctionComponent = (props) => { - const _props = props!; - const application = _props.application; - const environment = _props.environment; - const ms = _props.ms; - - return ( - <> - - > - ); -}; diff --git a/Source/SelfService/Web/applications/microservice/rawDataLog/config/editConfig.tsx b/Source/SelfService/Web/applications/microservice/rawDataLog/config/editConfig.tsx deleted file mode 100644 index 2eab793a7..000000000 --- a/Source/SelfService/Web/applications/microservice/rawDataLog/config/editConfig.tsx +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright (c) Dolittle. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - - -// TODO how to load the logs? -// TODO validate the data -// TODO change action button from create to save - -import React from 'react'; -import { useNavigate } from 'react-router-dom'; - -import { Stack } from '@fluentui/react/lib/Stack'; -import { Config } from './config'; -import { saveRawDataLogIngestorMicroservice } from '../../../stores/microservice'; -import { MicroserviceRawDataLogIngestor } from '../../../../apis/solutions/index'; - -import { HttpResponseApplication } from '../../../../apis/solutions/application'; - -const stackTokens = { childrenGap: 15 }; - -type Props = { - application: HttpResponseApplication - environment: string - ms: MicroserviceRawDataLogIngestor -}; - -export const EditConfig: React.FunctionComponent = (props) => { - const navigate = useNavigate(); - const _props = props!; - const application = _props.application; - const environment = _props.environment; - const ms = _props.ms; - - const onSave = async (ms: MicroserviceRawDataLogIngestor): Promise => { - const data = await saveRawDataLogIngestorMicroservice(ms); - const href = `/microservices/application/${application.id}/${environment}/overview`; - navigate(href); - }; - - return ( - <> - - - - > - ); -}; diff --git a/Source/SelfService/Web/applications/microservice/rawDataLog/view.tsx b/Source/SelfService/Web/applications/microservice/rawDataLog/view.tsx deleted file mode 100644 index e44d6dda6..000000000 --- a/Source/SelfService/Web/applications/microservice/rawDataLog/view.tsx +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright (c) Dolittle. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -import React, { useState } from 'react'; - -import { useNavigate } from 'react-router-dom'; -import { useReadable } from 'use-svelte-store'; - -import { microservices, MicroserviceStore } from '../../stores/microservice'; - -import { Stack } from '@fluentui/react/lib/Stack'; -import { Pivot, PivotItem } from '@fluentui/react'; - -import { Typography } from '@mui/material'; - -import { HttpResponsePodStatus } from '../../../apis/solutions/api'; - -import { Webhooks } from './webhooks'; -import { ConfigView } from './config/configView'; - -import { HealthStatusIndex } from '../microserviceDetails/microserviceView/healthStatus'; - -const stackTokens = { childrenGap: 15 }; - -type Props = { - applicationId: string - environment: string - microserviceId: string - podsData: HttpResponsePodStatus -}; - -export const View: React.FunctionComponent = (props) => { - const navigate = useNavigate(); - const $microservices = useReadable(microservices) as any; - - const _props = props!; - const applicationId = _props.applicationId; - const microserviceId = _props.microserviceId; - const environment = _props.environment; - const podsData = _props.podsData; - const [selectedKey, setSelectedKey] = useState('healthStatus'); - - // TODO ENV - const currentMicroservice: MicroserviceStore = $microservices.find(ms => ms.id === microserviceId && ms.environment === environment); - - if (!currentMicroservice) { - const href = `/microservices/application/${applicationId}/overview`; - navigate(href); - return null; - } - - return ( - <> - - {currentMicroservice.name} - - ) => { - const key = item?.props.itemKey as string; - if (selectedKey !== key) { - setSelectedKey(key); - } - }} - > - { - setSelectedKey('config'); - }} - > - {/* */} - - - { - setSelectedKey('webhooks'); - }} - > - {/* */} - - - - - - - - > - ); -}; diff --git a/Source/SelfService/Web/applications/microservice/rawDataLog/webhook/edit.tsx b/Source/SelfService/Web/applications/microservice/rawDataLog/webhook/edit.tsx deleted file mode 100644 index 5deb8bbbe..000000000 --- a/Source/SelfService/Web/applications/microservice/rawDataLog/webhook/edit.tsx +++ /dev/null @@ -1,197 +0,0 @@ -// Copyright (c) Dolittle. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -import React, { useState } from 'react'; - -import { Label } from '@fluentui/react/lib/Label'; -import { TextField, ITextFieldStyles } from '@fluentui/react/lib/TextField'; -import { Stack } from '@fluentui/react/lib/Stack'; -import { Dropdown } from '@fluentui/react/lib/Dropdown'; -import { IDropdownOption } from '@fluentui/react'; - -import { Button } from '@dolittle/design-system'; - -import { MicroserviceRawDataLogIngestorWebhookConfig, ConnectorWebhookConfigBasic } from '../../../../apis/solutions/index'; -import { BasicAuthComponent } from '../../../../components/basicAuthComponent'; -import { BearerAuthComponent } from '../../../../components/bearerAuthComponent'; - -import { trimPrefix, trimSuffix } from '../../../../utils/helpers'; -import { makeBasicAuth, makeBearer } from '../../../../utils/httpCredentials'; - -const textFieldStyles: Partial = { fieldGroup: { width: 300 } }; -const stackTokens = { childrenGap: 15 }; - -export type EditProps = { - domain: string; - ingressPath: string; - webhook: MicroserviceRawDataLogIngestorWebhookConfig; - onAfterSave: (webhooks: MicroserviceRawDataLogIngestorWebhookConfig) => Promise; -}; - -const defaultAuthType = 'Basic'; - -export const Edit = (props: EditProps) => { - const currentWebhook = props!.webhook; - let domain = props!.domain; - let ingressPath = props!.ingressPath; - const onAfterSave = props!.onAfterSave; - - domain = trimSuffix(domain, '/'); - ingressPath = trimPrefix(ingressPath, '/'); - ingressPath = trimSuffix(ingressPath, '/'); - - const urlPrefix = `${domain}/${ingressPath}`; - const actionText = 'Save'; - const authInfo = getAuthInfo(currentWebhook.authorization); - - const [authOptionState, setAuthOptionState] = useState(authInfo[0]); - const [config, setConfig] = useState(authInfo); - const [webhook, setWebhook] = useState(currentWebhook); - - const authenticationOptions: IDropdownOption[] = [ - { key: 'Bearer', text: 'Bearer Token' }, - { key: 'Basic', text: 'Basic (username and password)' } - ]; - - const authTypeChanged = (event: React.FormEvent, option?: IDropdownOption, index?: number) => { - // TODO Need to update the config for this kind as well - switch (option!.key) { - case 'Basic': - setConfig(['Basic', '']); - break; - case 'Bearer': - setConfig(['Bearer', '']); - break; - } - - setWebhook({ - ...webhook, - authorization: '', - }); - setAuthOptionState(option!.key as string); - }; - - const onUpdateConfig = (data: any) => { - switch (authOptionState) { - case 'Bearer': - setWebhook({ - ...webhook, - authorization: makeBearer(data), - }); - return; - case 'Basic': - setWebhook({ - ...webhook, - authorization: makeBasicAuth(data as ConnectorWebhookConfigBasic), - }); - return; - } - }; - - return ( - <> - - Entity type / Kind - , newValue?: string) => { - let kind = newValue!; - if (kind === '') { - kind = webhook.uriSuffix; - } - - setWebhook({ - ...webhook, - kind, - }); - }} - /> - - - - Endpoint - - / - , newValue?: string) => { - const uriSuffix = newValue!; - let kind = webhook.kind; - if (kind === '' || kind === webhook.uriSuffix) { - kind = uriSuffix; - } - - setWebhook({ - ...webhook, - uriSuffix, - kind, - }); - }} - /> - - - - Authentication - - - - - {authOptionState === 'Basic' && ( - - )} - - {authOptionState === 'Bearer' && ( - - )} - - - onAfterSave(webhook)} /> - - > - ); -}; - -function getAuthInfo(data: string): string[] { - try { - const parts = data.split(' '); - const authType = parts[0].toLowerCase(); - parts.shift(); - const authData = parts.join(' '); - if (authType === 'basic') { - return ['Basic', authData]; - } - - if (authType === 'bearer') { - return ['Bearer', authData]; - } - throw Error(); - } catch (e) { - return [defaultAuthType, '']; - } -}; - -function getUsernameAndPasswordFromBasicAuth(data: string): ConnectorWebhookConfigBasic { - try { - const parts = atob(data).split(':'); - return { - username: parts[0], - password: parts[1], - } as ConnectorWebhookConfigBasic; - } catch (e) { - return { - username: '', - password: '', - } as ConnectorWebhookConfigBasic; - } -}; diff --git a/Source/SelfService/Web/applications/microservice/rawDataLog/webhooks.tsx b/Source/SelfService/Web/applications/microservice/rawDataLog/webhooks.tsx deleted file mode 100644 index 82578d180..000000000 --- a/Source/SelfService/Web/applications/microservice/rawDataLog/webhooks.tsx +++ /dev/null @@ -1,148 +0,0 @@ -// Copyright (c) Dolittle. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -import React, { useState } from 'react'; -import { useNavigate } from 'react-router-dom'; - -import { Stack } from '@fluentui/react/lib/Stack'; -import { DetailsList, DetailsListLayoutMode, IColumn, CheckboxVisibility } from '@fluentui/react/lib/DetailsList'; -import { MicroserviceRawDataLogIngestor, MicroserviceRawDataLogIngestorWebhookConfig } from '../../../apis/solutions/index'; -import { Edit } from './webhook/edit'; -import { PrimaryButton } from '@fluentui/react/lib/Button'; -import { saveRawDataLogIngestorMicroservice } from '../../stores/microservice'; - - -const stackTokens = { childrenGap: 15 }; - -// TODO this might not be right, in terms of webhook data (from the log) -type Props = { - microservice: MicroserviceRawDataLogIngestor -}; - -type Item = { - kind: string - uriSuffix: string - authorization: string - lastMessage: string -}; - -const defaultWebhook = { - kind: '', - authorization: '', - uriSuffix: '', -} as MicroserviceRawDataLogIngestorWebhookConfig; - -export const Webhooks: React.FunctionComponent = (props) => { - // TODO update microservice - // TODO bubble up changes here - const navigate = useNavigate(); - const _props = props!; - const microservice = _props.microservice; - const [showWebhookEditor, setShowWebhookEditor] = useState(false); - const [webhookToEdit, setWebhookToEdit] = useState(defaultWebhook); - - const renderAction = (item?: Item, index?: number, column?: IColumn) => { - return ( - - <> - { - alert('TODO: View Sample'); - }}> - View Sample - - - { - setWebhookToEdit(item as MicroserviceRawDataLogIngestorWebhookConfig); - setShowWebhookEditor(true); - }}> - Edit - - - { - if (confirm('Delete webhook will stop future data arriving, are you sure? (will take upto a minute to take effect)')) { - const newWebhooks = microservice.extra.webhooks.filter(webhook => webhook.uriSuffix !== item!.uriSuffix); - microservice.extra.webhooks = newWebhooks; - await onSave(microservice); - } - - }}> - Delete - - - > - - ); - }; - - const columns: IColumn[] = [ - { key: 'kind', name: 'Kind', fieldName: 'kind', minWidth: 100, maxWidth: 200, isResizable: true }, - { key: 'uriSuffix', name: 'Suffix', fieldName: 'uriSuffix', minWidth: 100, maxWidth: 200, isResizable: true }, - { key: 'lastMessage', name: 'Last Message', fieldName: 'lastMessage', minWidth: 100, maxWidth: 200, isResizable: true }, - { key: 'action', name: 'Action', minWidth: 50, maxWidth: 50, isResizable: true, onRender: renderAction }, - ]; - - //const items: Item[] = fakeData; - const webhooks = _props.microservice.extra.webhooks; - const items: Item[] = webhooks.map(webhookConfig => { - return { - ...webhookConfig, - lastMessage: '2021-06-01 13:05:30', // TODO - } as Item; - }); - - - const onSave = async (ms: MicroserviceRawDataLogIngestor): Promise => { - const data = await saveRawDataLogIngestorMicroservice(ms); - }; - - return ( - <> - - { - setShowWebhookEditor(showWebhookEditor ? false : true); - setWebhookToEdit(defaultWebhook); - }} /> - - - {showWebhookEditor && ( - { - const index = microservice.extra.webhooks.findIndex(webhook => webhook.uriSuffix === newWebhook.uriSuffix); - const newWebhooks = [...microservice.extra.webhooks]; - if (index === -1) { - newWebhooks.push(newWebhook); - } else { - newWebhooks[index] = newWebhook; - } - - try { - microservice.extra.webhooks = newWebhooks; - console.log(microservice.extra.webhooks); - await onSave(microservice); - setWebhookToEdit(defaultWebhook); - setShowWebhookEditor(false); - } catch (e) { - alert('Failed to add webhook'); - } - }} - /> - )} - - - > - ); -}; diff --git a/Source/SelfService/Web/components/basicAuthComponent.tsx b/Source/SelfService/Web/components/basicAuthComponent.tsx deleted file mode 100644 index 28d6b44d8..000000000 --- a/Source/SelfService/Web/components/basicAuthComponent.tsx +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright (c) Dolittle. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. -import React from 'react'; -import { TextField, ITextFieldStyles } from '@fluentui/react/lib/TextField'; -import { Label } from '@fluentui/react/lib/Label'; -import { Stack } from '@fluentui/react/lib/Stack'; - -const textFieldStyles: Partial = { fieldGroup: { width: 300 } }; -const stackTokens = { childrenGap: 15 }; - -type Props = { - username?: string - password?: string - onUpdate?: (data: any) => void; -}; - -export const BasicAuthComponent: React.FunctionComponent = (props) => { - const username = props!.username!; - const password = props!.password!; - const onUpdate = props!.onUpdate!; - - const [usernameState, setUsernameState] = React.useState(username); - const [passwordState, setPasswordState] = React.useState(password); - - return ( - <> - - Username - , newValue?: string) => { - setUsernameState(newValue as string); - onUpdate({ - username: newValue, - password: passwordState - }); - }} - /> - - - - Password - , newValue?: string) => { - setPasswordState(newValue as string); - onUpdate({ - username: usernameState, - password: newValue - }); - }} - /> - - > - ); -}; diff --git a/Source/SelfService/Web/components/bearerAuthComponent.tsx b/Source/SelfService/Web/components/bearerAuthComponent.tsx deleted file mode 100644 index c58754582..000000000 --- a/Source/SelfService/Web/components/bearerAuthComponent.tsx +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (c) Dolittle. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. -import React from 'react'; -import { TextField } from '@fluentui/react/lib/TextField'; -import { Stack } from '@fluentui/react/lib/Stack'; -import { Label } from '@fluentui/react/lib/Label'; - -const stackTokens = { childrenGap: 15 }; - -type Props = { - token: string - onUpdate: (data: any) => void; -}; - -export const BearerAuthComponent: React.FunctionComponent = (props) => { - const token = props!.token; - const onUpdate = props!.onUpdate!; - const [tokenState, setTokenState] = React.useState(token); - - return ( - <> - - Token - , newValue?: string) => { - setTokenState(newValue as string); - onUpdate({ - token: newValue - }); - }} - /> - - > - ); -}; diff --git a/Source/SelfService/Web/components/breadCrumbWithRedirect.tsx b/Source/SelfService/Web/components/breadCrumbWithRedirect.tsx deleted file mode 100644 index 649b94e55..000000000 --- a/Source/SelfService/Web/components/breadCrumbWithRedirect.tsx +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (c) Dolittle. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -import React from 'react'; - -import { useNavigate } from 'react-router-dom'; - -export type BreadcrumbWithRedirectProps = { - url: string; - name: string; -}; - -export const BreadcrumbWithRedirect: React.FunctionComponent = (props) => { - const navigate = useNavigate(); - return ( - ) => { - event.stopPropagation(); - console.log('Redirect', props!.url); - navigate(props!.url); - }}> {props!.name} - ); -}; diff --git a/Source/SelfService/Web/components/buttonLink.tsx b/Source/SelfService/Web/components/buttonLink.tsx deleted file mode 100644 index f47b10831..000000000 --- a/Source/SelfService/Web/components/buttonLink.tsx +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (c) Dolittle. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -import React from 'react'; -import { Link as RouterLink } from 'react-router-dom'; -import { Button, ButtonProps } from '@dolittle/design-system'; - -export type ButtonLinkProps = ButtonProps & { - href: string -}; - -export const ButtonLink = ({ href, ...props }: ButtonLinkProps) => { - return ( - - ); -}; diff --git a/Source/SelfService/Web/components/layout/breadcrumbs.tsx b/Source/SelfService/Web/components/layout/breadcrumbs.tsx deleted file mode 100644 index 542976c98..000000000 --- a/Source/SelfService/Web/components/layout/breadcrumbs.tsx +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright (c) Dolittle. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -import React from 'react'; - -import { useMatch, Link as RouterLink } from 'react-router-dom'; - -import { Link, Breadcrumbs, Toolbar } from '@mui/material'; -import { ChevronRight } from '@mui/icons-material'; - -const styles = { - fontWeight: 400, - fontSize: 16, - lineHeight: '1.25rem', - color: 'text.primary', - textDecoration: 'none', -}; - -type Props = { - routes: BreadcrumbsRoute[]; -}; - -export type BreadcrumbsRoute = { - path: string; - to: string; - name: string; -}; - -export const BreadCrumbContainer = (props: Props) => { - const crumbs = props!.routes.filter((route) => useMatch({ path: route.path, end: false }) ? route : false); - - const breadcrumbs = crumbs.map((item, index) => { - const links = [ - - {item.name} - - ]; - - return links; - }); - - return ( - - } - aria-label="breadcrumb" - > - {breadcrumbs} - - - ); -}; diff --git a/Source/SelfService/Web/components/theme-legacy/textField.tsx b/Source/SelfService/Web/components/theme-legacy/textField.tsx deleted file mode 100644 index 85a9f4bac..000000000 --- a/Source/SelfService/Web/components/theme-legacy/textField.tsx +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright (c) Dolittle. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -import React from 'react'; - -import { SxProps } from '@mui/material/styles'; -import { InputAdornment, TextField as MuiTextField } from '@mui/material'; - -type Props = { - id: string; - label: string; - value: string; - type?: string; // input type https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#input_types - required?: boolean; - disabled?: boolean; - placeholder?: string; - readOnly?: boolean; - onChange?: (event: React.ChangeEvent) => void; - onKeyDown?: (event: React.KeyboardEvent) => void; - size?: 'small' | 'medium' | undefined; - autoComplete?: string; - fullWidth?: boolean; - startIcon?: React.ReactNode; -}; - -const styles = { - '& .MuiOutlinedInput-input': { - color: 'white' - }, - '& .MuiInputLabel-root': { - color: 'white' - }, - '& .MuiOutlinedInput-root .MuiOutlinedInput-notchedOutline': { - color: 'white', - borderColor: 'white' - }, - '&:hover .MuiOutlinedInput-input': { - color: 'white' - }, -} as SxProps; - -export const TextField: React.FunctionComponent = (props) => { - const _props = props!; - const onChange = _props.onChange ?? undefined; - const onKeyDown = _props.onKeyDown ?? undefined; - const disabled = _props.disabled ?? false; - const required = _props.required ?? true; - const type = _props.type ?? 'text'; - const value = _props.value; - const label = _props.label; - const id = _props.id; - const placeholder = _props.placeholder ?? ''; - const readOnly = _props.readOnly ?? false; - const size = _props.size ?? 'medium'; - const autoComplete = _props.autoComplete ?? undefined; - const fullWidth = _props.fullWidth ?? undefined; - const startIcon = _props.startIcon - ? ( - - {_props.startIcon} - - ) : undefined; - - return ( - - ); -}; From 9ec9db6ac4dc58ff543d3bc4fabc9b6ca5cda5a9 Mon Sep 17 00:00:00 2001 From: N00bG1rl <403helen@gmail.com> Date: Fri, 29 Sep 2023 12:42:12 +0300 Subject: [PATCH 2/3] Delete redundant code --- .../SelfService/Web/utils/httpCredentials.ts | 32 ------------------- 1 file changed, 32 deletions(-) delete mode 100644 Source/SelfService/Web/utils/httpCredentials.ts diff --git a/Source/SelfService/Web/utils/httpCredentials.ts b/Source/SelfService/Web/utils/httpCredentials.ts deleted file mode 100644 index 0a6eac059..000000000 --- a/Source/SelfService/Web/utils/httpCredentials.ts +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) Dolittle. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -import { ConnectorWebhookConfigBasic, ConnectorWebhookConfigBearer } from '../apis/solutions/index'; - -export const makeBasicAuth = (data: ConnectorWebhookConfigBasic): string => { - const suffix = btoa(`${data.username}:${data.password}`); - return `Basic ${suffix}`; -}; - -export const makeBearer = (data: ConnectorWebhookConfigBearer): string => { - return `Bearer ${data.token}`; -}; - -// getCredentialsFromBasicAuth assumes the data is in format of "Basic dXNlcjE6aGVsbG93b3JsZA==" where -// dXNlcjE6aGVsbG93b3JsZA== decoded is user1:helloworld -export const getCredentialsFromBasicAuth = (data: string): ConnectorWebhookConfigBasic => { - if (data === '') { - return { - username: '', - password: '', - }; - } - - const dataWithoutBase64 = atob(data.split(' ')[1]); - const rawCredentials = dataWithoutBase64.split(':'); - - return { - username: rawCredentials[0], - password: rawCredentials[1], - }; -}; From 96aa044fea6724a393df58b0b4ef05afd5505bbb Mon Sep 17 00:00:00 2001 From: N00bG1rl <403helen@gmail.com> Date: Fri, 29 Sep 2023 12:49:26 +0300 Subject: [PATCH 3/3] Delete redundant types --- .../Web/apis/solutions/customer.ts | 20 +----- .../SelfService/Web/apis/solutions/index.ts | 71 ------------------- .../Web/applications/stores/microservice.ts | 5 +- 3 files changed, 4 insertions(+), 92 deletions(-) diff --git a/Source/SelfService/Web/apis/solutions/customer.ts b/Source/SelfService/Web/apis/solutions/customer.ts index 10bfd7d49..baecac2f9 100644 --- a/Source/SelfService/Web/apis/solutions/customer.ts +++ b/Source/SelfService/Web/apis/solutions/customer.ts @@ -1,7 +1,7 @@ // Copyright (c) Dolittle. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -import { getServerUrlPrefix, JobInfo, parseJSONResponse, ShortInfo, ShortInfoWithEnvironment } from './api'; +import { getServerUrlPrefix, parseJSONResponse, ShortInfo, ShortInfoWithEnvironment } from './api'; import { Studio } from './studio'; export type CustomerDetailed = { @@ -45,21 +45,3 @@ export async function getCustomers(): Promise { const data = await parseJSONResponse(response); return data; }; - -export async function createCustomer(input: HttpCustomerRequest): Promise { - const url = `${getServerUrlPrefix()}/customer`; - - const response = await fetch( - url, - { - method: 'POST', - body: JSON.stringify(input), - mode: 'cors', - headers: { - 'content-type': 'application/json' - } - }); - - const data = await parseJSONResponse(response); - return data; -}; diff --git a/Source/SelfService/Web/apis/solutions/index.ts b/Source/SelfService/Web/apis/solutions/index.ts index 330871546..07aa838e2 100644 --- a/Source/SelfService/Web/apis/solutions/index.ts +++ b/Source/SelfService/Web/apis/solutions/index.ts @@ -3,32 +3,6 @@ import { HttpEnvironmentConnections } from './application'; -export type ConnectorWebhookConfigBearer = { - token: string; -}; - -export type ConnectorWebhookConfigBasic = { - username: string; - password: string; -}; - -export type ConnectorWebhookConfig = { - domain?: string; - uriPrefix?: string; - kind: string; - - // ConnectorWebhookConfigBasic - // ConnectorWebhookConfigBearer - config: any; -}; - -export type Connector = { - id: string; - name: string; - kind: string; - config: ConnectorWebhookConfig; -}; - export type MicroserviceDolittle = { applicationId: string; customerId: string; @@ -75,48 +49,3 @@ export type MicroserviceFormParameters = { ingressPath: string; hasM3Connector: boolean; }; - -export type MicroserviceRawDataLogIngestor = { - dolittle: MicroserviceDolittle; - name: string; - kind: string; - environment: string; - extra: MicroserviceRawDataLogIngestorExtra; -}; - -export type MicroserviceRawDataLogIngestorExtra = { - headImage: string; - runtimeImage: string; - ingress: MicroserviceIngressPath; - webhooks: MicroserviceRawDataLogIngestorWebhookConfig[]; - webhookStatsAuthorization: string; - writeTo: string; -}; - -export type MicroserviceRawDataLogIngestorWebhookConfig = { - kind: string; - uriSuffix: string; - authorization: string; - // TODO should we add the microservice that created it? - // It could be optional -}; - -// We want to know the state when in this microservice. -// When in rawdatlog we want to know the webhooks. -// We want to be able to update the webhooks, to update the webhooks, we need to know which rawDatelog to update the webhooks. - -/* Purchase Order API - Input - LOG_LEVEL: debug - DATABASE_READMODELS_URL: "mongodb://dev-mongo.application-1649ad53-5200-4a42-bcd5-7d559e0eefd4.svc.cluster.local" - DATABASE_READMODELS_NAME: "supplier_portal_dev_poapi_readmodels" - NODE_ENV: "development" - TENANT: "4d9bb23e-aa88-4be2-9dbd-f0bb3932e9d6" - SERVER_PORT: "8080" - NATS_CLUSTER_URL: "dev-rawdatalogv1-nats.application-1649ad53-5200-4a42-bcd5-7d559e0eefd4.svc.cluster.local:4222" - NATS_START_FROM_BEGINNING: "false" - LOG_OUTPUT_FORMAT: json - - https://github.com/dolittle/platform-api/blob/main/pkg/platform/doc.go - https://github.com/dolittle/platform-api/blob/main/pkg/platform/doc.go#L197-L204 copy and paste to reflect the above - -*/ diff --git a/Source/SelfService/Web/applications/stores/microservice.ts b/Source/SelfService/Web/applications/stores/microservice.ts index 778a6b9da..d4c032406 100644 --- a/Source/SelfService/Web/applications/stores/microservice.ts +++ b/Source/SelfService/Web/applications/stores/microservice.ts @@ -11,7 +11,7 @@ import { HttpResponseMicroservices, } from '../../apis/solutions/api'; -import { MicroserviceSimple, MicroserviceDolittle, MicroserviceRawDataLogIngestor } from '../../apis/solutions/index'; +import { MicroserviceSimple, MicroserviceDolittle } from '../../apis/solutions/index'; import { getApplication, HttpInputApplicationEnvironment } from '../../apis/solutions/application'; export type MicroserviceStore = { @@ -150,7 +150,8 @@ const saveMicroservice = async (kind: string, input: any): Promise => { }; export const saveSimpleMicroservice = (input: MicroserviceSimple) => saveMicroservice(input.kind, input); -export const saveRawDataLogIngestorMicroservice = (input: MicroserviceRawDataLogIngestor) => saveMicroservice(input.kind, input); + +//export const saveRawDataLogIngestorMicroservice = (input: MicroserviceRawDataLogIngestor) => saveMicroservice(input.kind, input); export const canEditMicroservices = (environments: HttpInputApplicationEnvironment[], environment: string): boolean => environments.some(info => info.name === environment && info.automationEnabled);