Skip to content

Commit

Permalink
Merge branch 'devel' into feat/cb-3456/form-template
Browse files Browse the repository at this point in the history
  • Loading branch information
EvgeniaBzzz authored Sep 26, 2023
2 parents dfb635e + 0d941b6 commit e6530a1
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export class UserInfoResource extends CachedDataResource<UserInfo | null, void,

if (authInfo.userTokens && authInfo.authStatus === AuthStatus.Success) {
this.resetIncludes();
this.markOutdated();
this.setData(await this.loader());
this.sessionDataResource.markOutdated();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ interface ObjectPropertyFormProps extends ILayoutSizeProps {
hideEmptyPlaceholder?: boolean;
canShowPassword?: boolean;
isSaved?: (property: ObjectPropertyInfo) => boolean;
geLayoutSize?: (property: ObjectPropertyInfo) => ILayoutSizeProps;
onFocus?: (name: string) => void;
}

Expand All @@ -49,6 +50,7 @@ export const ObjectPropertyInfoForm = observer<ObjectPropertyFormProps>(function
hideEmptyPlaceholder,
canShowPassword,
isSaved,
geLayoutSize,
onFocus,
...rest
}) {
Expand Down Expand Up @@ -77,7 +79,7 @@ export const ObjectPropertyInfoForm = observer<ObjectPropertyFormProps>(function
return (
<RenderField
key={property.id}
className={s(sizeStyles, { ...layoutProps }, className)}
className={s(sizeStyles, { ...(geLayoutSize ? geLayoutSize(property) : layoutProps) }, className)}
property={property}
state={state}
editable={editable}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { isControlPresented } from '../../FormControls/isControlPresented';
import { Textarea } from '../../FormControls/Textarea';
import { Link } from '../../Link';
import { useTranslate } from '../../localization/useTranslate';
import { type ControlType, getPropertyControlType } from './getPropertyControlType';

const RESERVED_KEYWORDS = ['no', 'off', 'new-password'];

Expand All @@ -37,26 +38,6 @@ interface RenderFieldProps {
onFocus?: (event: React.FocusEvent<HTMLInputElement>) => void;
}

type ControlType = 'checkbox' | 'combobox' | 'link' | 'input' | 'textarea' | 'file';

function getControlTypeFor(property: ObjectPropertyInfo): ControlType {
const dataType = property.dataType?.toLowerCase();

if (dataType === 'boolean') {
return 'checkbox';
} else if (property.validValues && property.validValues.length > 0) {
return 'combobox';
} else if (property.features.includes('href')) {
return 'link';
} else if (dataType === 'string' && property.length === 'MULTILINE') {
return 'textarea';
} else if (property.features.includes('file')) {
return 'file';
}

return 'input';
}

function getValue(value: any, controlType: ControlType) {
const checkbox = controlType === 'checkbox';

Expand Down Expand Up @@ -87,15 +68,15 @@ export const RenderField = observer<RenderFieldProps>(function RenderField({
}) {
const translate = useTranslate();

const controltype = getControlTypeFor(property);
const controlType = getPropertyControlType(property);
const password = property.features.includes('password');

const value = getValue(property.value, controltype);
const defaultValue = getValue(property.defaultValue, controltype);
const value = getValue(property.value, controlType);
const defaultValue = getValue(property.defaultValue, controlType);
const passwordSaved = showRememberTip && ((password && !!property.value) || saved);
const description = passwordSaved ? translate('ui_processing_saved') : undefined;

if (controltype === 'file' && state) {
if (controlType === 'file' && state) {
return (
<InputFileTextContent
tooltip={property.description}
Expand All @@ -112,7 +93,7 @@ export const RenderField = observer<RenderFieldProps>(function RenderField({
);
}

if (controltype === 'link') {
if (controlType === 'link') {
return (
<FormFieldDescription label={property.displayName} className={className}>
<Link href={state?.[property.id!]} target="_blank" rel="noopener noreferrer">
Expand All @@ -133,7 +114,7 @@ export const RenderField = observer<RenderFieldProps>(function RenderField({
);
}

if (controltype === 'checkbox') {
if (controlType === 'checkbox') {
if (state !== undefined) {
return (
<FieldCheckbox
Expand Down Expand Up @@ -164,7 +145,7 @@ export const RenderField = observer<RenderFieldProps>(function RenderField({
);
}

if (controltype === 'combobox') {
if (controlType === 'combobox') {
if (state !== undefined) {
return (
<Combobox
Expand Down Expand Up @@ -201,7 +182,7 @@ export const RenderField = observer<RenderFieldProps>(function RenderField({
);
}

if (controltype === 'textarea') {
if (controlType === 'textarea') {
if (state !== undefined) {
return (
<Textarea
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* CloudBeaver - Cloud Database Manager
* Copyright (C) 2020-2023 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0.
* you may not use this file except in compliance with the License.
*/
import type { ObjectPropertyInfo } from '@cloudbeaver/core-sdk';

export type ControlType = 'checkbox' | 'combobox' | 'link' | 'input' | 'textarea' | 'file';

export function getPropertyControlType(property: ObjectPropertyInfo): ControlType {
const dataType = property.dataType?.toLowerCase();

if (dataType === 'boolean') {
return 'checkbox';
} else if (property.validValues && property.validValues.length > 0) {
return 'combobox';
} else if (property.features.includes('href')) {
return 'link';
} else if (dataType === 'string' && property.length === 'MULTILINE') {
return 'textarea';
} else if (property.features.includes('file')) {
return 'file';
}

return 'input';
}
1 change: 1 addition & 0 deletions webapp/packages/core-blocks/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export * from './Menu/useMouseContextMenu';

export * from './ObjectPropertyInfo/ObjectPropertyInfoForm/ObjectPropertyInfoForm';
export * from './ObjectPropertyInfo/useObjectPropertyCategories';
export * from './ObjectPropertyInfo/ObjectPropertyInfoForm/getPropertyControlType';

export * from './Overlay/Overlay';
export * from './Overlay/OverlayActions';
Expand Down
5 changes: 1 addition & 4 deletions webapp/packages/plugin-administration/src/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ export default [

['administration_configuration_wizard_configuration_plugins', 'Configuration'],
['administration_configuration_wizard_configuration_custom_connections', 'Enable private connections'],
[
'administration_configuration_wizard_configuration_custom_connections_description',
'Allows users to create private connections. Otherwise, all new connections can be created from the administration part only',
],
['administration_configuration_wizard_configuration_custom_connections_description', 'Allows users to create private connections'],
['administration_configuration_wizard_configuration_navigation_tree_view', 'Navigator simple view'],
[
'administration_configuration_wizard_configuration_navigation_tree_view_description',
Expand Down
5 changes: 1 addition & 4 deletions webapp/packages/plugin-administration/src/locales/it.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,7 @@ export default [

['administration_configuration_wizard_configuration_plugins', 'Configurazione'],
['administration_configuration_wizard_configuration_custom_connections', 'Abilita connessioni custom'],
[
'administration_configuration_wizard_configuration_custom_connections_description',
"Permette agli utenti di creare connessioni custom. Altrimenti tutte le nuvoe connessioni saranno create solo dall'amministratore",
],
['administration_configuration_wizard_configuration_custom_connections_description', 'Permette agli utenti di creare connessioni custom'],
['administration_configuration_wizard_configuration_navigation_tree_view', 'Vista semplice del navigatore'],
[
'administration_configuration_wizard_configuration_navigation_tree_view_description',
Expand Down
5 changes: 1 addition & 4 deletions webapp/packages/plugin-administration/src/locales/ru.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ export default [

['administration_configuration_wizard_configuration_plugins', 'Настройки'],
['administration_configuration_wizard_configuration_custom_connections', 'Разрешить пользовательские подключения'],
[
'administration_configuration_wizard_configuration_custom_connections_description',
'Позволяет пользователям создавать собственные подключения. Иначе, любые подключения могут быть добавлены только со страницы администрирования',
],
['administration_configuration_wizard_configuration_custom_connections_description', 'Позволяет пользователям создавать собственные подключения'],
['administration_configuration_wizard_configuration_navigation_tree_view', 'Упрощенная версия дерева навигации'],
[
'administration_configuration_wizard_configuration_navigation_tree_view_description',
Expand Down
2 changes: 1 addition & 1 deletion webapp/packages/plugin-administration/src/locales/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default [

['administration_configuration_wizard_configuration_plugins', '配置'],
['administration_configuration_wizard_configuration_custom_connections', '允许自定义连接'],
['administration_configuration_wizard_configuration_custom_connections_description', '允许用户创建自定义连接。否则,只能从管理部分创建所有新连接'],
['administration_configuration_wizard_configuration_custom_connections_description', '允许用户创建自定义连接'],
['administration_configuration_wizard_configuration_navigation_tree_view', '导航器简单视图'],
['administration_configuration_wizard_configuration_navigation_tree_view_description', '默认情况下,所有用户的新连接在导航树中将仅包含基本信息'],

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
Container,
Expandable,
EXPANDABLE_FORM_STYLES,
getPropertyControlType,
Group,
GroupTitle,
ObjectPropertyInfoForm,
Expand Down Expand Up @@ -54,7 +55,7 @@ export const ProviderPropertiesForm = observer<Props>(function ProviderPropertie
state={config.providerProperties}
disabled={disabled}
readOnly={readonly}
medium
maximum
hideEmptyPlaceholder
/>
</Container>
Expand Down Expand Up @@ -84,8 +85,7 @@ export const ProviderPropertiesForm = observer<Props>(function ProviderPropertie
category={category}
disabled={disabled}
readOnly={readonly}
small
noGrow
geLayoutSize={property => (getPropertyControlType(property) === 'checkbox' ? { maximum: true } : { small: true, noGrow: true })}
hideEmptyPlaceholder
/>
</Container>
Expand Down

0 comments on commit e6530a1

Please sign in to comment.