2021-09-15 02:50:55 +00:00
import React from 'react' ;
2021-11-17 17:59:00 +00:00
import cx from 'classnames' ;
2021-09-15 02:50:55 +00:00
import Input from '@/_ui/Input' ;
2021-10-25 09:16:46 +00:00
import Textarea from '@/_ui/Textarea' ;
2021-09-15 02:50:55 +00:00
import Select from '@/_ui/Select' ;
import Headers from '@/_ui/HttpHeaders' ;
import OAuth from '@/_ui/OAuth' ;
import Toggle from '@/_ui/Toggle' ;
2022-04-26 08:44:12 +00:00
import OpenApi from '@/_ui/OpenAPI' ;
2023-04-24 08:10:58 +00:00
import { Checkbox , CheckboxGroup } from '@/_ui/CheckBox' ;
2021-11-17 17:59:00 +00:00
import { CodeHinter } from '@/Editor/CodeBuilder/CodeHinter' ;
2021-09-15 07:40:11 +00:00
import GoogleSheets from '@/_components/Googlesheets' ;
2021-09-15 02:50:55 +00:00
import Slack from '@/_components/Slack' ;
2022-10-06 08:15:42 +00:00
import Zendesk from '@/_components/Zendesk' ;
2024-04-05 08:44:47 +00:00
import { ConditionFilter , CondtionSort , MultiColumn } from '@/_components/MultiConditions' ;
2024-03-22 11:18:52 +00:00
import Salesforce from '@/_components/Salesforce' ;
2022-12-22 20:39:57 +00:00
import ToolJetDbOperations from '@/Editor/QueryManager/QueryEditors/TooljetDatabase/ToolJetDbOperations' ;
2023-08-14 08:58:51 +00:00
import { orgEnvironmentVariableService , orgEnvironmentConstantService } from '../_services' ;
2021-09-15 02:50:55 +00:00
2021-11-17 17:59:00 +00:00
import { find , isEmpty } from 'lodash' ;
Feature Homepage and settings redesign (#5763)
* adding colors
* feat :: add button
* feat :: added typography
* feat: init storybook
* removes browserlist
* feat :: adding button styles and button component
* feat :: added sass addon
* stories update
* feat :: replacing with radix colors
* danger variants
* updates buttin story
* fix :: removing default items
* cleanup
* fix icons update
* feat :: folder list component
* fix :: naming
* icon and split button :: init
* intermediate save :: app card component
* renaming
* updates
* update for module imports
* updates icon
* update :: homepage design updates
* design changes dashboard
* updates :: apps section
* workspace stting new design upate
* updates dasboard design
* style :: fixes
* feat :: added context for sidebar nav breadcrumb
* added all solid icons
* intermediate update
* change: conditions for fetching users
* sorybook updates
* design updates :: workspace settings page
* manage users page
* lint fixes
* fix :: styling
* stle fixes :: workspace settings
* homepage redesign
* fix :: all drawer colors and position ,teplate page revamp , database page header fixes
* imported all bulk icons
* svg to jsx : bulk icons
* minor :: cleanup
* fix :: manage users drawer
* fix :: searchboxes , userspage fixes
* fix :: all inputs and minor ui fixes
* database page ui fixes
* fix :: database and folder search functionality and iconlist in homecard
* fixed some db functionality and edge cases for longer texts
* fix :: user addition manage user page
* self review cleanup and change in bulk icon fill state
* fix :: homepage seacbar
* merging develop and resolving conflicts
* remove unwanted stories
* reverting merge with develop
* Revert "reverting merge with develop"
This reverts commit 2150c8ec0ce9cedda4f4676211faa3321d4af7f8.
* clearing out warnings
* lint fixes
* feat :: added org modal in database page
* fix :: sso loader theme
* fix :: broken styles select
* fixed icon warning and select ui
* fix :: upload bulk and user select dark mode
* merge styles with develop
* feat :: integrated new ui for database
* removing storybook files
* fix :: all bugs related to users dropdown and cleanup
* fix: user search api for organization page
* cleanup and splitting dropzone component
* fix :: overflow issue in app card time
* fix for scrollbars in homepage
* PR review fixes
* updates :: fix d=global datasource design issues , homepage responsiveness
* tj db operations
* breadcrumb bug fixes
* lint fixes
* removing logs , removed fade in in datasource and database page
* marketplace page ui fix
* removing inital users table fetch
* Pr :: review changes
* remove logs
* fix :: popover bug
* minot style fix
* fix :: remove arrow from all popovers
* fix :: for loading states
* ux :: sidebar items reorder
* style :: fix
* style fix :: templates
* fix :: qa bugs
* fix :: Qa reported bugs
* removes :: folder fetch bug
* share link and datsource bg color fix
* fixes :: rename group ,
* removed logs
* pages popover background fix
* fix :: tj db table addition ui bug
* fix :: ui bug confirm modal password disable
* modal , revert name capitalize in lists, typos fix
* typos , users page route bugfix
* users page header bugfix
* workspace archive btn , datasources form style for select
* groups updated , delete, create flow updated
* avatar bug in profile page fix
* revert styles
* fix :: for create new table nav breadcrumb not being updated
* click state bug fix in avatar
* fix bug with appcard popover
* fix :: text capitalize issue
* fix :: lints and updated icon for filter delete
* fix warnings
---------
Co-authored-by: gandharv <gandharvkumargarg@gmail.com>
Co-authored-by: Vijaykant Yadav <vjy239@gmail.com>
2023-04-21 06:15:48 +00:00
import { ButtonSolid } from './AppButton' ;
2023-07-19 06:12:28 +00:00
import { useCurrentState } from '@/_stores/currentStateStore' ;
2023-07-24 11:04:26 +00:00
import { useEditorStore } from '@/_stores/editorStore' ;
import { shallow } from 'zustand/shallow' ;
2021-09-15 02:50:55 +00:00
2021-11-17 17:59:00 +00:00
const DynamicForm = ( {
schema ,
2023-07-04 10:02:45 +00:00
isGDS ,
2021-11-17 17:59:00 +00:00
optionchanged ,
createDataSource ,
options ,
isSaving ,
selectedDataSource ,
2021-11-22 08:22:32 +00:00
isEditMode ,
optionsChanged ,
2021-12-10 03:09:23 +00:00
queryName ,
2022-12-20 13:08:51 +00:00
computeSelectStyles = false ,
2023-08-14 08:58:51 +00:00
currentAppEnvironmentId ,
2023-08-09 12:31:48 +00:00
onBlur ,
layout = 'vertical' ,
2021-11-17 17:59:00 +00:00
} ) => {
2022-12-27 14:40:33 +00:00
const [ computedProps , setComputedProps ] = React . useState ( { } ) ;
2023-08-09 12:31:48 +00:00
const isHorizontalLayout = layout === 'horizontal' ;
2023-07-19 06:12:28 +00:00
const currentState = useCurrentState ( ) ;
2023-07-04 10:02:45 +00:00
2023-08-14 08:58:51 +00:00
const [ workspaceVariables , setWorkspaceVariables ] = React . useState ( [ ] ) ;
const [ currentOrgEnvironmentConstants , setCurrentOrgEnvironmentConstants ] = React . useState ( [ ] ) ;
2023-07-24 11:04:26 +00:00
const { isEditorActive } = useEditorStore (
( state ) => ( {
isEditorActive : state ? . isEditorActive ,
} ) ,
shallow
) ;
2021-09-15 02:50:55 +00:00
// if(schema.properties) todo add empty check
2022-01-17 07:08:17 +00:00
React . useLayoutEffect ( ( ) => {
2021-11-22 08:22:32 +00:00
if ( ! isEditMode || isEmpty ( options ) ) {
optionsChanged ( schema ? . defaults ? ? { } ) ;
}
2023-07-04 10:02:45 +00:00
// eslint-disable-next-line react-hooks/exhaustive-deps
} , [ ] ) ;
React . useEffect ( ( ) => {
if ( isGDS ) {
2023-08-14 08:58:51 +00:00
orgEnvironmentConstantService . getConstantsFromEnvironment ( currentAppEnvironmentId ) . then ( ( data ) => {
const constants = { } ;
data . constants . map ( ( constant ) => {
constants [ constant . name ] = constant . value ;
} ) ;
setCurrentOrgEnvironmentConstants ( constants ) ;
} ) ;
2023-07-04 10:02:45 +00:00
orgEnvironmentVariableService . getVariables ( ) . then ( ( data ) => {
const client _variables = { } ;
const server _variables = { } ;
data . variables . map ( ( variable ) => {
if ( variable . variable _type === 'server' ) {
server _variables [ variable . variable _name ] = 'HiddenEnvironmentVariable' ;
} else {
client _variables [ variable . variable _name ] = variable . value ;
}
} ) ;
setWorkspaceVariables ( { client : client _variables , server : server _variables } ) ;
} ) ;
}
return ( ) => {
setWorkspaceVariables ( [ ] ) ;
2023-08-14 08:58:51 +00:00
setCurrentOrgEnvironmentConstants ( [ ] ) ;
2023-07-04 10:02:45 +00:00
} ;
2021-12-02 06:55:40 +00:00
// eslint-disable-next-line react-hooks/exhaustive-deps
2023-08-14 08:58:51 +00:00
} , [ currentAppEnvironmentId ] ) ;
2021-11-22 08:22:32 +00:00
2022-12-27 14:40:33 +00:00
React . useEffect ( ( ) => {
const { properties } = schema ;
2023-03-24 11:35:08 +00:00
if ( ! isEmpty ( properties ) ) {
let fields = { } ;
let encrpytedFieldsProps = { } ;
const flipComponentDropdown = find ( properties , [ 'type' , 'dropdown-component-flip' ] ) ;
2022-12-27 14:40:33 +00:00
2023-03-24 11:35:08 +00:00
if ( flipComponentDropdown ) {
const selector = options ? . [ flipComponentDropdown ? . key ] ? . value ;
fields = { ... flipComponentDropdown ? . commonFields , ... properties [ selector ] } ;
} else {
fields = { ... properties } ;
}
2022-12-27 14:40:33 +00:00
2023-04-22 21:20:17 +00:00
Object . keys ( fields ) . length > 0 &&
Object . keys ( fields ) . map ( ( key ) => {
2023-12-22 11:46:10 +00:00
const { type , encrypted , key : propertyKey } = fields [ key ] ;
if ( ( type === 'password' || encrypted ) && ! ( propertyKey in computedProps ) ) {
2023-04-22 21:20:17 +00:00
//Editable encrypted fields only if datasource doesn't exists
2023-12-22 11:46:10 +00:00
encrpytedFieldsProps [ propertyKey ] = {
2023-04-22 21:20:17 +00:00
disabled : ! ! selectedDataSource ? . id ,
} ;
}
} ) ;
2023-03-24 11:35:08 +00:00
setComputedProps ( { ... computedProps , ... encrpytedFieldsProps } ) ;
2022-12-27 14:40:33 +00:00
}
// eslint-disable-next-line react-hooks/exhaustive-deps
} , [ options ] ) ;
2021-09-15 02:50:55 +00:00
const getElement = ( type ) => {
switch ( type ) {
case 'password' :
case 'text' :
return Input ;
2021-10-25 09:16:46 +00:00
case 'textarea' :
return Textarea ;
2021-09-15 02:50:55 +00:00
case 'dropdown' :
return Select ;
case 'toggle' :
return Toggle ;
2023-04-21 10:05:51 +00:00
case 'checkbox' :
return Checkbox ;
case 'checkbox-group' :
return CheckboxGroup ;
2022-12-22 20:39:57 +00:00
case 'tooljetdb-operations' :
return ToolJetDbOperations ;
2021-09-15 02:50:55 +00:00
case 'react-component-headers' :
return Headers ;
case 'react-component-oauth-authentication' :
return OAuth ;
case 'react-component-google-sheets' :
return GoogleSheets ;
case 'react-component-slack' :
return Slack ;
2021-11-17 17:59:00 +00:00
case 'codehinter' :
return CodeHinter ;
2022-04-26 08:44:12 +00:00
case 'react-component-openapi-validator' :
return OpenApi ;
2022-10-06 08:15:42 +00:00
case 'react-component-zendesk' :
return Zendesk ;
2024-04-17 10:25:37 +00:00
case 'react-component-salesforce' :
return Salesforce ;
2021-09-15 02:50:55 +00:00
default :
return < div > Type is invalid < / div > ;
}
} ;
2022-12-07 08:45:05 +00:00
const handleToggle = ( controller ) => {
if ( controller ) {
return ! options ? . [ controller ] ? . value ? ' d-none' : '' ;
} else {
return '' ;
}
} ;
2021-11-17 17:59:00 +00:00
const getElementProps = ( {
2022-01-17 07:08:17 +00:00
key ,
list ,
rows = 5 ,
2021-11-17 17:59:00 +00:00
helpText ,
description ,
type ,
placeholder = '' ,
mode = 'sql' ,
lineNumbers = true ,
initialValue ,
2021-11-21 04:14:26 +00:00
height = 'auto' ,
2022-02-02 16:59:57 +00:00
width ,
2021-12-02 06:55:40 +00:00
ignoreBraces = false ,
2022-02-02 16:59:57 +00:00
className ,
2022-12-07 08:45:05 +00:00
controller ,
2023-12-19 12:47:34 +00:00
encrypted ,
2024-04-01 06:20:15 +00:00
placeholders = { } ,
2021-11-17 17:59:00 +00:00
} ) => {
2023-05-01 23:50:33 +00:00
const source = schema ? . source ? . kind ;
2021-11-17 17:59:00 +00:00
const darkMode = localStorage . getItem ( 'darkMode' ) === 'true' ;
2023-01-25 06:39:02 +00:00
if ( ! options ) return ;
2021-09-15 02:50:55 +00:00
switch ( type ) {
case 'password' :
case 'text' :
2023-12-19 12:47:34 +00:00
case 'textarea' : {
const useEncrypted =
( options ? . [ key ] ? . encrypted !== undefined ? options ? . [ key ] . encrypted : encrypted ) || type === 'password' ;
2021-09-15 02:50:55 +00:00
return {
type ,
2023-12-19 12:47:34 +00:00
placeholder : useEncrypted ? '**************' : description ,
2022-12-07 08:45:05 +00:00
className : ` form-control ${ handleToggle ( controller ) } ` ,
2023-12-19 05:02:49 +00:00
value : options ? . [ key ] ? . value || '' ,
2022-01-17 07:08:17 +00:00
... ( type === 'textarea' && { rows : rows } ) ,
2021-09-15 02:50:55 +00:00
... ( helpText && { helpText } ) ,
2023-08-09 12:31:48 +00:00
onChange : ( e ) => optionchanged ( key , e . target . value , true ) , //shouldNotAutoSave is true because autosave should occur during onBlur, not after each character change (in optionchanged).
onblur : ( ) => onBlur ( ) ,
2023-07-04 10:02:45 +00:00
isGDS ,
workspaceVariables ,
2023-08-14 08:58:51 +00:00
workspaceConstants : currentOrgEnvironmentConstants ,
2023-12-19 12:47:34 +00:00
encrypted : useEncrypted ,
2021-09-15 02:50:55 +00:00
} ;
2023-12-19 12:47:34 +00:00
}
2021-09-15 02:50:55 +00:00
case 'toggle' :
return {
2022-06-06 01:28:04 +00:00
defaultChecked : options ? . [ key ] ,
checked : options ? . [ key ] ? . value ,
2022-01-17 07:08:17 +00:00
onChange : ( e ) => optionchanged ( key , e . target . checked ) ,
2021-09-15 02:50:55 +00:00
} ;
case 'dropdown' :
case 'dropdown-component-flip' :
return {
2022-01-17 07:08:17 +00:00
options : list ,
2022-06-06 01:28:04 +00:00
value : options ? . [ key ] ? . value || options ? . [ key ] ,
2022-01-17 07:08:17 +00:00
onChange : ( value ) => optionchanged ( key , value ) ,
2022-04-11 11:57:07 +00:00
width : width || '100%' ,
useMenuPortal : queryName ? true : false ,
2022-12-20 13:08:51 +00:00
styles : computeSelectStyles ? computeSelectStyles ( '100%' ) : { } ,
2023-01-03 11:42:43 +00:00
useCustomStyles : computeSelectStyles ? true : false ,
2023-12-19 12:47:34 +00:00
encrypted : options ? . [ key ] ? . encrypted ,
2021-09-15 02:50:55 +00:00
} ;
2023-04-21 10:05:51 +00:00
case 'checkbox-group' :
return {
options : list ,
2023-04-25 09:38:38 +00:00
values : options ? . [ key ] ? ? [ ] ,
onChange : ( value ) => {
optionchanged ( key , [ ... value ] ) ;
} ,
2023-04-21 10:05:51 +00:00
} ;
2023-01-16 09:34:12 +00:00
case 'react-component-headers' : {
2023-07-24 11:04:26 +00:00
let isRenderedAsQueryEditor ;
2023-08-28 11:44:26 +00:00
if ( ! isEditorActive || isGDS ) {
2023-07-24 11:04:26 +00:00
isRenderedAsQueryEditor = false ;
} else {
2023-07-31 17:16:04 +00:00
isRenderedAsQueryEditor = ! isGDS && currentState != null ;
2023-07-24 11:04:26 +00:00
}
2021-09-15 02:50:55 +00:00
return {
2022-01-17 07:08:17 +00:00
getter : key ,
2023-01-16 09:34:12 +00:00
options : isRenderedAsQueryEditor
? options ? . [ key ] ? ? schema ? . defaults ? . [ key ]
: options ? . [ key ] ? . value ? ? schema ? . defaults ? . [ key ] ? . value ,
2021-09-15 02:50:55 +00:00
optionchanged ,
2023-01-16 09:34:12 +00:00
currentState ,
isRenderedAsQueryEditor ,
2023-08-17 09:20:31 +00:00
workspaceConstants : currentOrgEnvironmentConstants ,
2023-12-19 12:47:34 +00:00
encrypted : options ? . [ key ] ? . encrypted ,
2021-09-15 02:50:55 +00:00
} ;
2023-01-16 09:34:12 +00:00
}
2021-09-15 02:50:55 +00:00
case 'react-component-oauth-authentication' :
return {
2023-05-01 23:50:33 +00:00
isGrpc : source === 'grpc' ,
2023-01-25 06:12:04 +00:00
grant _type : options ? . grant _type ? . value ,
auth _type : options ? . auth _type ? . value ,
add _token _to : options ? . add _token _to ? . value ,
header _prefix : options ? . header _prefix ? . value ,
access _token _url : options ? . access _token _url ? . value ,
access _token _custom _headers : options ? . access _token _custom _headers ? . value ,
client _id : options ? . client _id ? . value ,
client _secret : options ? . client _secret ? . value ,
client _auth : options ? . client _auth ? . value ,
scopes : options ? . scopes ? . value ,
username : options ? . username ? . value ,
password : options ? . password ? . value ,
2023-05-01 23:50:33 +00:00
grpc _apiKey _key : options ? . grpc _apikey _key ? . value ,
grpc _apiKey _value : options ? . grpc _apikey _value ? . value ,
2023-01-25 06:12:04 +00:00
bearer _token : options ? . bearer _token ? . value ,
auth _url : options ? . auth _url ? . value ,
auth _key : options ? . auth _key ? . value ,
custom _auth _params : options ? . custom _auth _params ? . value ,
custom _query _params : options ? . custom _query _params ? . value ,
multiple _auth _enabled : options ? . multiple _auth _enabled ? . value ,
2021-09-15 02:50:55 +00:00
optionchanged ,
2023-08-17 09:20:31 +00:00
workspaceConstants : currentOrgEnvironmentConstants ,
2023-12-19 12:47:34 +00:00
options ,
optionsChanged ,
selectedDataSource ,
2021-09-15 02:50:55 +00:00
} ;
case 'react-component-google-sheets' :
case 'react-component-slack' :
2022-10-06 08:15:42 +00:00
case 'react-component-zendesk' :
2024-03-22 11:18:52 +00:00
case 'react-component-salesforce' :
2022-12-22 20:39:57 +00:00
return {
optionchanged ,
createDataSource ,
options ,
isSaving ,
selectedDataSource ,
2023-08-17 09:20:31 +00:00
workspaceConstants : currentOrgEnvironmentConstants ,
2023-12-19 12:47:34 +00:00
optionsChanged ,
2022-12-22 20:39:57 +00:00
} ;
case 'tooljetdb-operations' :
return {
currentState ,
optionchanged ,
createDataSource ,
options ,
isSaving ,
selectedDataSource ,
darkMode ,
} ;
2021-11-17 17:59:00 +00:00
case 'codehinter' :
return {
currentState ,
2022-01-17 07:08:17 +00:00
initialValue : options [ key ]
? typeof options [ key ] === 'string'
? options [ key ]
: JSON . stringify ( options [ key ] )
2021-11-17 17:59:00 +00:00
: initialValue ,
mode ,
lineNumbers ,
2022-02-02 16:59:57 +00:00
className : className ? className : lineNumbers ? 'query-hinter' : 'codehinter-query-editor-input' ,
2022-01-17 07:08:17 +00:00
onChange : ( value ) => optionchanged ( key , value ) ,
2021-11-17 17:59:00 +00:00
theme : darkMode ? 'monokai' : lineNumbers ? 'duotone-light' : 'default' ,
placeholder ,
2021-11-21 04:14:26 +00:00
height ,
2022-02-02 16:59:57 +00:00
width ,
2022-01-17 07:08:17 +00:00
componentName : queryName ? ` ${ queryName } :: ${ key ? ? '' } ` : null ,
2021-12-02 06:55:40 +00:00
ignoreBraces ,
2022-11-11 05:45:12 +00:00
cyLabel : key ? ` ${ String ( key ) . toLocaleLowerCase ( ) . replace ( /\s+/g , '-' ) } ` : '' ,
2021-11-17 17:59:00 +00:00
} ;
2022-04-26 08:44:12 +00:00
case 'react-component-openapi-validator' :
return {
format : options . format ? . value ,
definition : options . definition ? . value ,
auth _type : options . auth _type ? . value ,
auth _key : options . auth _key ? . value ,
username : options . username ? . value ,
password : options . password ? . value ,
bearer _token : options . bearer _token ? . value ,
api _keys : options . api _keys ? . value ,
optionchanged ,
grant _type : options . grant _type ? . value ,
add _token _to : options . add _token _to ? . value ,
header _prefix : options . header _prefix ? . value ,
access _token _url : options . access _token _url ? . value ,
2023-07-21 10:08:56 +00:00
access _token _custom _headers : options . access _token _custom _headers ? . value ,
2022-04-26 08:44:12 +00:00
client _id : options . client _id ? . value ,
client _secret : options . client _secret ? . value ,
client _auth : options . client _auth ? . value ,
scopes : options . scopes ? . value ,
auth _url : options . auth _url ? . value ,
custom _auth _params : options . custom _auth _params ? . value ,
custom _query _params : options . custom _query _params ? . value ,
2023-03-24 16:11:21 +00:00
spec : options . spec ? . value ,
2023-08-17 09:20:31 +00:00
workspaceConstants : currentOrgEnvironmentConstants ,
2022-04-26 08:44:12 +00:00
} ;
2024-04-01 06:20:15 +00:00
case 'filters' :
return {
operators : list || [ ] ,
value : options ? . [ key ] ? ? { } ,
onChange : ( value ) => optionchanged ( key , value ) ,
placeholders ,
} ;
case 'sorts' :
return {
orders : list || [ ] ,
value : options ? . [ key ] ? ? { } ,
onChange : ( value ) => optionchanged ( key , value ) ,
placeholders ,
} ;
2024-04-05 08:44:47 +00:00
case 'columns' :
return {
value : options ? . [ key ] ? ? { } ,
onChange : ( value ) => optionchanged ( key , value ) ,
placeholders ,
} ;
2021-09-15 02:50:55 +00:00
default :
return { } ;
}
} ;
const getLayout = ( obj ) => {
2021-11-17 17:59:00 +00:00
if ( isEmpty ( obj ) ) return null ;
const flipComponentDropdown = isFlipComponentDropdown ( obj ) ;
if ( flipComponentDropdown ) {
return flipComponentDropdown ;
}
2022-12-27 14:40:33 +00:00
const handleEncryptedFieldsToggle = ( event , field ) => {
const isEditing = computedProps [ field ] [ 'disabled' ] ;
if ( isEditing ) {
optionchanged ( field , '' ) ;
} else {
//Send old field value if editing mode disabled for encrypted fields
const newOptions = { ... options } ;
const oldFieldValue = selectedDataSource ? . [ 'options' ] ? . [ field ] ;
2023-12-22 11:46:10 +00:00
if ( oldFieldValue ) {
optionsChanged ( { ... newOptions , [ field ] : oldFieldValue } ) ;
} else {
delete newOptions [ field ] ;
optionsChanged ( { ... newOptions } ) ;
}
2022-12-27 14:40:33 +00:00
}
2023-08-28 11:44:26 +00:00
setComputedProps ( {
... computedProps ,
[ field ] : {
... computedProps [ field ] ,
disabled : ! isEditing ,
} ,
} ) ;
2022-12-27 14:40:33 +00:00
} ;
2021-09-15 02:50:55 +00:00
return (
2023-08-09 12:31:48 +00:00
< div className = { ` ${ isHorizontalLayout ? '' : 'row' } ` } >
2021-09-15 02:50:55 +00:00
{ Object . keys ( obj ) . map ( ( key ) => {
2023-12-22 11:46:10 +00:00
const { label , type , encrypted , className , key : propertyKey } = obj [ key ] ;
2021-09-15 02:50:55 +00:00
const Element = getElement ( type ) ;
2023-08-09 12:31:48 +00:00
const isSpecificComponent = [ 'tooljetdb-operations' ] . includes ( type ) ;
2021-09-15 02:50:55 +00:00
return (
2023-08-09 12:31:48 +00:00
< div
className = { cx ( 'my-2' , {
'col-md-12' : ! className && ! isHorizontalLayout ,
[ className ] : ! ! className ,
'd-flex' : isHorizontalLayout ,
'dynamic-form-row' : isHorizontalLayout ,
} ) }
key = { key }
>
{ ! isSpecificComponent && (
< div
className = { cx ( 'd-flex' , {
'form-label' : isHorizontalLayout ,
'align-items-center' : ! isHorizontalLayout ,
} ) }
>
{ label && (
< label
className = "form-label"
data - cy = { ` label- ${ String ( label ) . toLocaleLowerCase ( ) . replace ( /\s+/g , '-' ) } ` }
2022-12-27 14:40:33 +00:00
>
2023-08-09 12:31:48 +00:00
{ label }
< / label >
) }
{ ( type === 'password' || encrypted ) && selectedDataSource ? . id && (
< div className = "mx-1 col" >
< ButtonSolid
className = "datasource-edit-btn mb-2"
type = "a"
variant = "tertiary"
target = "_blank"
rel = "noreferrer"
2023-12-22 11:46:10 +00:00
onClick = { ( event ) => handleEncryptedFieldsToggle ( event , propertyKey ) }
2023-08-09 12:31:48 +00:00
>
2023-12-22 11:46:10 +00:00
{ computedProps ? . [ propertyKey ] ? . [ 'disabled' ] ? 'Edit' : 'Cancel' }
2023-08-09 12:31:48 +00:00
< / ButtonSolid >
< / div >
) }
{ ( type === 'password' || encrypted ) && (
< div className = "col-auto mb-2" >
< small className = "text-green" >
< img
className = "mx-2 encrypted-icon"
src = "assets/images/icons/padlock.svg"
width = "12"
height = "12"
/ >
Encrypted
< / small >
< / div >
) }
< / div >
) }
< div
className = { cx ( {
'flex-grow-1' : isHorizontalLayout && ! isSpecificComponent ,
'w-100' : isHorizontalLayout && type !== 'codehinter' ,
} ) }
>
< Element
{ ... getElementProps ( obj [ key ] ) }
2023-12-22 11:46:10 +00:00
{ ... computedProps [ propertyKey ] }
2023-08-09 12:31:48 +00:00
data - cy = { ` ${ String ( label ) . toLocaleLowerCase ( ) . replace ( /\s+/g , '-' ) } -text-field ` }
2023-09-04 08:00:39 +00:00
//to be removed after whole ui is same
2023-08-09 12:31:48 +00:00
isHorizontalLayout = { isHorizontalLayout }
/ >
2022-12-27 14:40:33 +00:00
< / div >
2021-09-15 02:50:55 +00:00
< / div >
) ;
} ) }
< / div >
) ;
} ;
2021-11-17 17:59:00 +00:00
const isFlipComponentDropdown = ( obj ) => {
const flipComponentDropdown = find ( obj , [ 'type' , 'dropdown-component-flip' ] ) ;
if ( flipComponentDropdown ) {
// options[key].value for datasource
// options[key] for dataquery
2022-06-06 01:28:04 +00:00
const selector = options ? . [ flipComponentDropdown ? . key ] ? . value || options ? . [ flipComponentDropdown ? . key ] ;
2021-11-17 17:59:00 +00:00
return (
< >
2023-08-09 12:31:48 +00:00
< div className = { ` ${ isHorizontalLayout ? '' : 'row' } ` } >
2022-02-21 18:07:09 +00:00
{ flipComponentDropdown . commonFields && getLayout ( flipComponentDropdown . commonFields ) }
< div
className = { cx ( 'my-2' , {
2023-08-09 12:31:48 +00:00
'col-md-12' : ! flipComponentDropdown . className && ! isHorizontalLayout ,
'd-flex' : isHorizontalLayout ,
'dynamic-form-row' : isHorizontalLayout ,
2022-02-21 18:07:09 +00:00
[ flipComponentDropdown . className ] : ! ! flipComponentDropdown . className ,
} ) }
>
2023-08-09 12:31:48 +00:00
{ ( flipComponentDropdown . label || isHorizontalLayout ) && (
2022-11-11 05:45:12 +00:00
< label
2023-08-09 12:31:48 +00:00
className = { cx ( 'form-label' ) }
2022-11-11 05:45:12 +00:00
data - cy = { ` ${ String ( flipComponentDropdown . label )
. toLocaleLowerCase ( )
. replace ( /\s+/g , '-' ) } - dropdown - label ` }
>
{ flipComponentDropdown . label }
< / label >
) }
2023-08-09 12:31:48 +00:00
< div data - cy = { 'query-select-dropdown' } className = { cx ( { 'flex-grow-1' : isHorizontalLayout } ) } >
2022-12-20 13:08:51 +00:00
< Select
{ ... getElementProps ( flipComponentDropdown ) }
styles = { computeSelectStyles ? computeSelectStyles ( '100%' ) : { } }
2023-01-03 11:42:43 +00:00
useCustomStyles = { computeSelectStyles ? true : false }
2022-12-20 13:08:51 +00:00
/ >
2022-11-11 05:45:12 +00:00
< / div >
2022-02-21 18:07:09 +00:00
{ flipComponentDropdown . helpText && (
< span className = "flip-dropdown-help-text" > { flipComponentDropdown . helpText } < / span >
) }
2021-11-17 17:59:00 +00:00
< / div >
< / div >
{ getLayout ( obj [ selector ] ) }
< / >
) ;
}
} ;
const flipComponentDropdown = isFlipComponentDropdown ( schema . properties ) ;
2021-09-15 02:50:55 +00:00
if ( flipComponentDropdown ) {
2021-11-17 17:59:00 +00:00
return flipComponentDropdown ;
2021-09-15 02:50:55 +00:00
}
return getLayout ( schema . properties ) ;
} ;
export default DynamicForm ;