From 5b2b3f37acd6b8f8563040c4b658635c0b35807e Mon Sep 17 00:00:00 2001 From: Egor Zalenski Date: Thu, 12 Dec 2024 09:27:00 +0100 Subject: [PATCH] #RIVS-299 - Add the changes from the main project --- l10n/bundle.l10n.json | 5 +- package.json | 3 +- .../components/database-form/TlsDetails.tsx | 103 ++++++++----- src/webviews/src/components/index.ts | 4 + .../popover-delete/PopoverDelete.tsx | 1 + .../super-select/SuperSelect.spec.tsx | 43 ++++++ .../components/super-select/SuperSelect.tsx | 51 +++++++ .../removable-option/RemovableOption.spec.tsx | 13 ++ .../removable-option/RemovableOption.tsx | 63 ++++++++ .../super-select/styles.module.scss | 38 +++++ src/webviews/src/constants/database/form.ts | 6 +- src/webviews/src/interfaces/database/form.ts | 2 +- .../rejson-details/RejsonDetailsWrapper.tsx | 7 +- .../EditEntireItemAction.tsx | 1 + .../rejson-details/hooks/useRejsonStore.ts | 6 +- .../components/rejson-details/interfaces.ts | 2 +- .../rejson-object/RejsonObject.tsx | 6 +- .../rejson-scalar/RejsonScalar.spec.tsx | 40 +++++ .../rejson-scalar/RejsonScalar.tsx | 5 +- .../rejson-details/utils/utils.spec.ts | 143 +++++++++++++++++- .../components/rejson-details/utils/utils.ts | 114 +++++++++++++- .../database-wrapper/DatabaseWrapper.tsx | 2 +- .../manual-connection/ManualConnection.tsx | 23 ++- .../ManualConnectionFrom.spec.tsx | 15 +- .../useCertificatesStore.spec.ts | 24 ++- .../useCertificatesStore.ts | 20 +++ src/webviews/src/ui/button/RiButton.tsx | 1 + src/webviews/src/utils/comparisons/diff.ts | 2 +- .../src/utils/comparisons/tests/diff.spec.ts | 2 +- src/webviews/src/utils/database/form.tsx | 29 ++-- .../src/utils/formatters/bufferFormatters.ts | 7 + src/webviews/src/utils/formatters/javaDate.ts | 42 +++++ .../formatters/tests/bufferFormatters.spec.ts | 8 + .../formatters/tests/valueFormatters.spec.ts | 4 +- .../src/utils/formatters/valueFormatters.ts | 4 +- src/webviews/src/utils/telemetry/events.ts | 1 + .../handlers/database/certificatesHandlers.ts | 4 + src/webviews/test/helpers/constants.ts | 9 ++ yarn.lock | 8 +- 39 files changed, 769 insertions(+), 92 deletions(-) create mode 100644 src/webviews/src/components/super-select/SuperSelect.spec.tsx create mode 100644 src/webviews/src/components/super-select/SuperSelect.tsx create mode 100644 src/webviews/src/components/super-select/components/removable-option/RemovableOption.spec.tsx create mode 100644 src/webviews/src/components/super-select/components/removable-option/RemovableOption.tsx create mode 100644 src/webviews/src/components/super-select/styles.module.scss create mode 100644 src/webviews/src/utils/formatters/javaDate.ts diff --git a/l10n/bundle.l10n.json b/l10n/bundle.l10n.json index 2d2ba56d..2d260197 100644 --- a/l10n/bundle.l10n.json +++ b/l10n/bundle.l10n.json @@ -41,7 +41,7 @@ "Key Name": "Key Name", " will be deleted.": " will be deleted.", "Delete": "Delete", - "will be deleted from Redis for VS Code.": "will be deleted from Redis for VS Code.", + "will be removed from Redis for VS Code.": "will be removed from Redis for VS Code.", "Key Size": "Key Size", "Key Size: ": "Key Size: ", "Length": "Length", @@ -295,9 +295,6 @@ "Host:": "Host:", "Database Index:": "Database Index:", "Modules:": "Modules:", - "Select Logical Database": "Select Logical Database", - "Database Index": "Database Index", - "Enter Database Index": "Enter Database Index", "No decompression": "No decompression", "Enable automatic data decompression": "Enable automatic data decompression", "Decompression format": "Decompression format", diff --git a/package.json b/package.json index d829405c..00c17e55 100644 --- a/package.json +++ b/package.json @@ -143,6 +143,7 @@ "download:backend": "tsc ./scripts/downloadBackend.ts && node ./scripts/downloadBackend.js", "dev": "vite dev", "dev:key": "cross-env RI_DATA_ROUTE=main/key vite dev", + "dev:database": "cross-env RI_DATA_ROUTE=main/add_database vite dev", "dev:sidebar": "cross-env RI_DATA_ROUTE=sidebar vite dev", "l10n:collect": "npx @vscode/l10n-dev export -o ./l10n ./src", "watch": "tsc -watch -p ./", @@ -286,7 +287,7 @@ "react-inlinesvg": "^4.1.1", "react-monaco-editor": "^0.55.0", "react-router-dom": "^6.17.0", - "react-select": "^5.8.0", + "react-select": "^5.8.3", "react-spinners": "^0.13.8", "react-virtualized": "^9.22.5", "react-virtualized-auto-sizer": "^1.0.20", diff --git a/src/webviews/src/components/database-form/TlsDetails.tsx b/src/webviews/src/components/database-form/TlsDetails.tsx index ddd70cd6..d4398d89 100644 --- a/src/webviews/src/components/database-form/TlsDetails.tsx +++ b/src/webviews/src/components/database-form/TlsDetails.tsx @@ -2,40 +2,61 @@ import React, { ChangeEvent, useId } from 'react' import cx from 'classnames' import { FormikProps } from 'formik' import * as l10n from '@vscode/l10n' -import { VSCodeDivider } from '@vscode/webview-ui-toolkit/react' import { CheckboxChangeEvent } from 'rc-checkbox' +import { find } from 'lodash' +import { MenuListProps } from 'react-select' -import { validateCertName, validateField } from 'uiSrc/utils' +import { sendEventTelemetry, TelemetryEvent, validateCertName, validateField } from 'uiSrc/utils' import { ADD_NEW, ADD_NEW_CA_CERT, - ADD_NEW_CA_CERT_LABEL, - ADD_NEW_LABEL, + ApiEndpoints, NO_CA_CERT, - NO_CA_CERT_LABEL, } from 'uiSrc/constants' -import { DbConnectionInfo } from 'uiSrc/interfaces' -import { Checkbox, InputText, Select, TextArea } from 'uiSrc/ui' +import { DbConnectionInfo, RedisString } from 'uiSrc/interfaces' +import { Checkbox, InputText, TextArea } from 'uiSrc/ui' +import { removeCertAction } from 'uiSrc/store' +import { SuperSelectRemovableOption, SuperSelect, SuperSelectOption } from 'uiSrc/components' import styles from './styles.module.scss' +const suffix = '_tls_details' + export interface Props { formik: FormikProps caCertificates?: { id: string, name: string }[] certificates?: { id: string, name: string }[] } + const TlsDetails = (props: Props) => { const { formik, caCertificates, certificates } = props const id = useId() - const optionsCertsCA = [ - { - value: NO_CA_CERT, - label: NO_CA_CERT_LABEL, - }, - { - value: ADD_NEW_CA_CERT, - label: ADD_NEW_CA_CERT_LABEL, - }, + const handleDeleteCaCert = (id: RedisString, onSuccess?: () => void) => { + removeCertAction(id, ApiEndpoints.CA_CERTIFICATES, () => { + onSuccess?.() + handleClickDeleteCert('CA') + }) + } + + const handleDeleteClientCert = (id: RedisString, onSuccess?: () => void) => { + removeCertAction(id, ApiEndpoints.CLIENT_CERTIFICATES, () => { + onSuccess?.() + handleClickDeleteCert('Client') + }) + } + + const handleClickDeleteCert = (certificateType: 'Client' | 'CA') => { + sendEventTelemetry({ + event: TelemetryEvent.CONFIG_DATABASES_CERTIFICATE_REMOVED, + eventData: { + certificateType, + }, + }) + } + + const optionsCertsCA: SuperSelectOption[] = [ + NO_CA_CERT, + ADD_NEW_CA_CERT, ] caCertificates?.forEach((cert) => { @@ -45,12 +66,7 @@ const TlsDetails = (props: Props) => { }) }) - const optionsCertsClient = [ - { - value: ADD_NEW, - label: ADD_NEW_LABEL, - }, - ] + const optionsCertsClient: SuperSelectOption[] = [ADD_NEW] certificates?.forEach((cert) => { optionsCertsClient.push({ @@ -130,17 +146,22 @@ const TlsDetails = (props: Props) => {
{`${l10n.t('CA Certificate')}${formik.values.verifyServerTlsCert ? '*' : ''}`}
-