-
-
Notifications
You must be signed in to change notification settings - Fork 306
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6a699fb
commit c57e9ec
Showing
12 changed files
with
237 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/renderer/components/modals/promise-new-record-modal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { Center, Icon, Spinner, Text } from '@chakra-ui/react'; | ||
import { FaQuoteLeft, FaQuoteRight } from 'react-icons/fa'; | ||
import { v4 } from 'uuid'; | ||
import { FilterBuilder } from 'renderer/containers/filter-builder'; | ||
|
||
import { PromiseModal } from './promise-modal'; | ||
import { ActionButtonType } from '@electrocrud/buttons'; | ||
import { ColumnWithMetadataAndTags } from 'renderer/defenitions/record-object'; | ||
import { Suspense } from 'react'; | ||
import { InlineSpinner } from '../icons'; | ||
import { RecordFormBuilder } from 'renderer/containers/record-editor'; | ||
|
||
export const PromiseNewRecordModal = ( | ||
columnViews: ColumnWithMetadataAndTags[] | ||
) => { | ||
return PromiseModal({ | ||
keyu: v4(), | ||
instanceId: v4(), | ||
size: '5xl', | ||
getValue: () => {}, | ||
actionButtons: [ActionButtonType.SAVE, ActionButtonType.CANCEL], | ||
title: ( | ||
<Text display="inline-flex" fontWeight="medium" textTransform="uppercase"> | ||
Add New Record Modal | ||
</Text> | ||
), | ||
children: (properties) => ( | ||
<Suspense fallback={<InlineSpinner />}> | ||
<RecordFormBuilder | ||
columns={columnViews} | ||
formRef={properties.formCtxRef} | ||
/> | ||
</Suspense> | ||
), | ||
}); | ||
}; |
28 changes: 28 additions & 0 deletions
28
src/renderer/containers/record-editor/form-inputs/form-input-datetime.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { Box, Icon, InputRightAddon } from '@chakra-ui/react'; | ||
import { Field } from '@saas-ui/forms'; | ||
import { FC } from 'react'; | ||
import { ColumnWithMetadataAndTags } from 'renderer/defenitions/record-object'; | ||
import { findType } from 'renderer/defenitions/record-object/data-types'; | ||
|
||
export type FormInputTypeDateTime = { | ||
column: ColumnWithMetadataAndTags; | ||
}; | ||
|
||
export const FormInputDateTime: FC<FormInputTypeDateTime> = ({ column }) => { | ||
const type = findType(column.data_type); | ||
return ( | ||
<Field | ||
variant="flushed" | ||
type="datetime-local" | ||
name={column.name} | ||
label={`${column.name} (${column.alias || column.name})`} | ||
defaultValue={column.default_value} | ||
isDisabled={column.has_auto_increment} | ||
isRequired={!column.is_nullable} | ||
help={column.comment} | ||
rules={{ | ||
required: column.is_nullable ? false : `${column.name} is required.`, | ||
}} | ||
/> | ||
); | ||
}; |
37 changes: 37 additions & 0 deletions
37
src/renderer/containers/record-editor/form-inputs/form-input-number.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { Box, Icon, InputRightAddon } from '@chakra-ui/react'; | ||
import { Field } from '@saas-ui/forms'; | ||
import { FC } from 'react'; | ||
import { ColumnWithMetadataAndTags } from 'renderer/defenitions/record-object'; | ||
import { findType } from 'renderer/defenitions/record-object/data-types'; | ||
|
||
export type FormInputTypeNumber = { | ||
column: ColumnWithMetadataAndTags; | ||
}; | ||
|
||
export const FormInputNumber: FC<FormInputTypeNumber> = ({ column }) => { | ||
const type = findType(column.data_type); | ||
return ( | ||
<Field | ||
variant="flushed" | ||
type="number" | ||
name={column.name} | ||
label={`${column.name} (${column.alias || column.name})`} | ||
defaultValue={column.default_value} | ||
isDisabled={column.has_auto_increment} | ||
isRequired={!column.is_nullable && !column.has_auto_increment} | ||
max={column.max_length || Number.POSITIVE_INFINITY} | ||
help={column.comment} | ||
rules={{ | ||
required: | ||
column.is_nullable || column.has_auto_increment | ||
? false | ||
: `${column.name} is required.`, | ||
}} | ||
rightAddon={ | ||
<Box flex={1} display="flex" alignItems="center"> | ||
<Icon as={type.icon} /> | ||
</Box> | ||
} | ||
/> | ||
); | ||
}; |
34 changes: 34 additions & 0 deletions
34
src/renderer/containers/record-editor/form-inputs/form-input-text.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Box, Icon, InputRightAddon } from '@chakra-ui/react'; | ||
import { Field } from '@saas-ui/forms'; | ||
import { FC } from 'react'; | ||
import { ColumnWithMetadataAndTags } from 'renderer/defenitions/record-object'; | ||
import { findType } from 'renderer/defenitions/record-object/data-types'; | ||
|
||
export type FormInputTypeText = { | ||
column: ColumnWithMetadataAndTags; | ||
}; | ||
|
||
export const FormInputText: FC<FormInputTypeText> = ({ column }) => { | ||
const type = findType(column.data_type); | ||
return ( | ||
<Field | ||
variant="flushed" | ||
type="text" | ||
name={column.name} | ||
label={`${column.name} (${column.alias || column.name})`} | ||
defaultValue={column.default_value} | ||
isDisabled={column.has_auto_increment} | ||
isRequired={!column.is_nullable} | ||
maxLength={column.max_length} | ||
help={column.comment} | ||
rules={{ | ||
required: column.is_nullable ? false : `${column.name} is required.`, | ||
}} | ||
rightAddon={ | ||
<Box flex={1} display="flex" alignItems="center"> | ||
<Icon as={type.icon} /> | ||
</Box> | ||
} | ||
/> | ||
); | ||
}; |
25 changes: 25 additions & 0 deletions
25
src/renderer/containers/record-editor/form-inputs/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { ColumnWithMetadataAndTags } from 'renderer/defenitions/record-object'; | ||
import { findType } from 'renderer/defenitions/record-object/data-types'; | ||
import { FormInputDateTime } from './form-input-datetime'; | ||
import { FormInputNumber } from './form-input-number'; | ||
import { FormInputText } from './form-input-text'; | ||
|
||
export * from './form-input-text'; | ||
|
||
export const InputFormFactory = (column: ColumnWithMetadataAndTags) => { | ||
switch (findType(column.data_type).name) { | ||
case 'string': { | ||
return FormInputText; | ||
break; | ||
} | ||
case 'number': { | ||
return FormInputNumber; | ||
break; | ||
} | ||
case 'datetime': { | ||
return FormInputDateTime; | ||
break; | ||
} | ||
} | ||
return FormInputText; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './record-form-builder'; |
25 changes: 25 additions & 0 deletions
25
src/renderer/containers/record-editor/record-form-builder.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Form, FormLayout } from '@saas-ui/forms'; | ||
import { FC } from 'react'; | ||
import { ColumnWithMetadataAndTags } from 'renderer/defenitions/record-object'; | ||
import { InputFormFactory } from './form-inputs'; | ||
|
||
export type RecordFormBuilderProperties = { | ||
columns: ColumnWithMetadataAndTags[]; | ||
formRef: any; | ||
}; | ||
export const RecordFormBuilder: FC<RecordFormBuilderProperties> = ({ | ||
columns, | ||
formRef, | ||
}) => { | ||
return ( | ||
// @ts-ignore | ||
<Form ref={formRef}> | ||
<FormLayout> | ||
{columns?.map((column: ColumnWithMetadataAndTags) => { | ||
const Component = InputFormFactory(column); | ||
return <Component key={column.name} column={column} />; | ||
})} | ||
</FormLayout> | ||
</Form> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { InsertRequest, InsertResponse } from '@electrocrud/shared'; | ||
import { useBaseRequest } from './base-request'; | ||
|
||
export const useIPCInsertData = (request: InsertRequest) => { | ||
return useBaseRequest<InsertResponse>(request); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters