Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cb 5378 dm ability to use custom ssl certificate #2808

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,7 @@
display: none;
}
}

.uploadButton {
margin-top: 4px;
}
43 changes: 38 additions & 5 deletions webapp/packages/core-blocks/src/FormControls/Textarea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@
import { observer } from 'mobx-react-lite';
import { useCallback, useContext, useLayoutEffect, useRef } from 'react';

import { getTextFileReadingProcess } from '@cloudbeaver/core-utils';

import { Button } from '../Button';
import { filterLayoutFakeProps, getLayoutProps } from '../Containers/filterLayoutFakeProps';
import type { ILayoutSizeProps } from '../Containers/ILayoutSizeProps';
import { useTranslate } from '../localization/useTranslate';
import { s } from '../s';
import { UploadArea } from '../UploadArea';
import { useS } from '../useS';
import { Field } from './Field';
import { FieldDescription } from './FieldDescription';
Expand All @@ -24,6 +29,7 @@ type BaseProps = Omit<React.TextareaHTMLAttributes<HTMLTextAreaElement>, 'onChan
labelTooltip?: string;
embedded?: boolean;
cursorInitiallyAtEnd?: boolean;
uploadable?: boolean;
};

type ControlledProps = BaseProps & {
Expand Down Expand Up @@ -56,25 +62,27 @@ export const Textarea: TextareaType = observer(function Textarea({
labelTooltip,
embedded,
cursorInitiallyAtEnd,
uploadable,
onChange = () => {},
...rest
}: ControlledProps | ObjectProps<any, any>) {
const translate = useTranslate();
const textareaRef = useRef<HTMLTextAreaElement | null>(null);
const layoutProps = getLayoutProps(rest);
rest = filterLayoutFakeProps(rest);
const styles = useS(textareaStyle);
const context = useContext(FormContext);

const handleChange = useCallback(
(event: React.ChangeEvent<HTMLTextAreaElement>) => {
(value: string) => {
if (state) {
state[name] = event.target.value;
state[name] = value;
}
if (onChange) {
onChange(event.target.value, name);
onChange(value, name);
}
if (context) {
context.change(event.target.value, name);
context.change(value, name);
}
},
[state, name, onChange],
Expand Down Expand Up @@ -102,9 +110,34 @@ export const Textarea: TextareaType = observer(function Textarea({
value={value ?? ''}
name={name}
data-embedded={embedded}
onChange={handleChange}
onChange={event => handleChange(event.target.value)}
/>
{description && <FieldDescription>{description}</FieldDescription>}
{uploadable && (
<UploadArea
className={s(styles, { uploadButton: true })}
disabled={rest.disabled || rest.readOnly}
reset
onChange={async event => {
const file = event.target.files?.[0];

if (!file) {
throw new Error('File is not found');
}

const process = getTextFileReadingProcess(file);
const value = await process.promise;

if (value) {
handleChange(value);
}
}}
>
<Button tag="div" disabled={rest.disabled || rest.readOnly} mod={['outlined']}>
{translate('ui_file')}
</Button>
</UploadArea>
)}
</Field>
);
});
17 changes: 17 additions & 0 deletions webapp/packages/core-utils/src/getDomainFromUrl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* CloudBeaver - Cloud Database Manager
* Copyright (C) 2020-2024 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0.
* you may not use this file except in compliance with the License.
*/

export function getDomainFromUrl(url: string): string {
try {
const urlObject = new URL(url);
return urlObject.hostname;
} catch (e) {
console.error('Invalid URL:', e);
return '';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to return undefined if error appeared so we definatelly know outside of the scope that something can go wrong here

}
}
1 change: 1 addition & 0 deletions webapp/packages/core-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,4 @@ export * from './toSafeHtmlString';
export * from './getProgressPercent';
export * from './types/UndefinedToNull';
export * from './bindFunctions';
export * from './getDomainFromUrl';
Loading