ExtraFilterDto ControlType eklendi
This commit is contained in:
parent
fef0623349
commit
6ae74813e0
10 changed files with 103 additions and 38 deletions
|
|
@ -8,6 +8,7 @@ public class ExtraFilterDto
|
|||
public string Caption { get; set; }
|
||||
public string Operator { get; set; }
|
||||
public string DefaultValue { get; set; }
|
||||
public string ControlType { get; set; }
|
||||
public List<ExtraFilterItemsDto> Items { get; set; }
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12292,6 +12292,12 @@
|
|||
"en": "Default Value",
|
||||
"tr": "Varsayılan Değer"
|
||||
},
|
||||
{
|
||||
"resourceName": "Platform",
|
||||
"key": "ListForms.ListFormEdit.ExtraControlType",
|
||||
"en": "Control Type",
|
||||
"tr": "Kontrol Türü"
|
||||
},
|
||||
{
|
||||
"resourceName": "Platform",
|
||||
"key": "ListForms.ListFormEdit.ExtraSqlQuery",
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ public class ExtraFilter : ValueObject
|
|||
public string Caption { get; set; }
|
||||
public string Operator { get; set; }
|
||||
public string DefaultValue { get; set; }
|
||||
public string ControlType { get; set; }
|
||||
public string SqlQuery { get; set; }
|
||||
|
||||
protected override IEnumerable<object> GetAtomicValues()
|
||||
|
|
|
|||
|
|
@ -82,3 +82,8 @@ export const ListFormEditTabs = {
|
|||
Customization: 'customization',
|
||||
ExtraFilter: 'extraFilter',
|
||||
} as const
|
||||
|
||||
export const extraFilterControlTypeOptions = [
|
||||
{ value: 'Select', label: 'Select' },
|
||||
{ value: 'TextBox', label: 'TextBox' },
|
||||
]
|
||||
|
|
|
|||
|
|
@ -731,6 +731,7 @@ export interface ExtraFilterDto {
|
|||
caption: string
|
||||
operator: string
|
||||
defaultValue?: string
|
||||
controlType: string
|
||||
items?: ExtraFilterItemsDto[]
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -58,6 +58,7 @@ function FormTabExtraFilters(props: { listFormCode: string }) {
|
|||
<Th>{translate('::ListForms.ListFormEdit.ExtraCaption')}</Th>
|
||||
<Th>{translate('::ListForms.ListFormEdit.ExtraOperator')}</Th>
|
||||
<Th>{translate('::ListForms.ListFormEdit.ExtraDefaultValue')}</Th>
|
||||
<Th>{translate('::ListForms.ListFormEdit.ExtraControlType')}</Th>
|
||||
<Th>{translate('::ListForms.ListFormEdit.ExtraSqlQuery')}</Th>
|
||||
</Tr>
|
||||
</THead>
|
||||
|
|
@ -107,6 +108,7 @@ function FormTabExtraFilters(props: { listFormCode: string }) {
|
|||
<Td>{row.caption}</Td>
|
||||
<Td>{row.operator}</Td>
|
||||
<Td>{row.defaultValue}</Td>
|
||||
<Td>{row.controlType}</Td>
|
||||
<Td>{row.sqlQuery}</Td>
|
||||
</Tr>
|
||||
))}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import {
|
|||
Select,
|
||||
toast,
|
||||
} from '@/components/ui'
|
||||
import { ListFormJsonRowDto } from '@/proxy/admin/list-form/models'
|
||||
import { extraFilterControlTypeOptions, ListFormJsonRowDto } from '@/proxy/admin/list-form/models'
|
||||
import { SelectBoxOption } from '@/shared/types'
|
||||
import { useStoreActions, useStoreState } from '@/store'
|
||||
import { useLocalization } from '@/utils/hooks/useLocalization'
|
||||
|
|
@ -32,7 +32,12 @@ const schema = object().shape({
|
|||
caption: string().required('Caption Required'),
|
||||
operator: string().required('Operator Required'),
|
||||
defaultValue: string(),
|
||||
sqlQuery: string().required('SQL Query Required'),
|
||||
controlType: string().required('Control Type Required'),
|
||||
sqlQuery: string().when('controlType', {
|
||||
is: (val: string) => val === 'Select',
|
||||
then: (schema) => schema.required('SQL Query Required'),
|
||||
otherwise: (schema) => schema.notRequired(),
|
||||
}),
|
||||
})
|
||||
|
||||
function JsonRowOpDialogExtraFilter({
|
||||
|
|
@ -48,27 +53,9 @@ function JsonRowOpDialogExtraFilter({
|
|||
data: JsonRowDialogData | undefined
|
||||
setData: Dispatch<SetStateAction<JsonRowDialogData | undefined>>
|
||||
}) {
|
||||
const [permissionOptions, setPermissionOptions] = useState<SelectBoxOption[]>([])
|
||||
const { translate } = useLocalization()
|
||||
|
||||
const permissions: Record<string, boolean> | undefined = useStoreState(
|
||||
(state) => state.abpConfig.config?.auth.grantedPolicies,
|
||||
)
|
||||
const [fieldList, setFieldList] = useState<SelectBoxOption[]>([])
|
||||
|
||||
useEffect(() => {
|
||||
if (permissions) {
|
||||
setPermissionOptions(
|
||||
Object.keys(permissions).map((key) => {
|
||||
return {
|
||||
value: key,
|
||||
label: key,
|
||||
}
|
||||
}),
|
||||
)
|
||||
}
|
||||
}, [permissions])
|
||||
|
||||
const { setJsonValue } = useStoreActions((a) => a.admin)
|
||||
|
||||
const handleClose = async (e?: any) => {
|
||||
|
|
@ -147,6 +134,7 @@ function JsonRowOpDialogExtraFilter({
|
|||
caption: '',
|
||||
operator: '=',
|
||||
defaultValue: '',
|
||||
controlType: 'Select',
|
||||
sqlQuery: '',
|
||||
}
|
||||
}
|
||||
|
|
@ -260,6 +248,26 @@ function JsonRowOpDialogExtraFilter({
|
|||
/>
|
||||
</FormItem>
|
||||
|
||||
<FormItem
|
||||
label="Control Type"
|
||||
invalid={errors.fieldName && touched.fieldName}
|
||||
errorMessage={errors.fieldName}
|
||||
>
|
||||
<Field name="controlType">
|
||||
{({ field, form }: FieldProps<SelectBoxOption>) => (
|
||||
<Select
|
||||
field={field}
|
||||
form={form}
|
||||
options={extraFilterControlTypeOptions}
|
||||
value={extraFilterControlTypeOptions.find(
|
||||
(option: any) => option.value === values.controlType,
|
||||
)}
|
||||
onChange={(option) => form.setFieldValue(field.name, option?.value)}
|
||||
/>
|
||||
)}
|
||||
</Field>
|
||||
</FormItem>
|
||||
|
||||
<FormItem
|
||||
label="Sql Query (Key, Value)"
|
||||
invalid={errors.sqlQuery && touched.sqlQuery}
|
||||
|
|
|
|||
|
|
@ -533,6 +533,7 @@ const Grid = (props: GridProps) => {
|
|||
gridDto.gridOptions.extraFilterDto.map((f) => ({
|
||||
fieldName: f.fieldName,
|
||||
operator: f.operator,
|
||||
controlType: f.controlType,
|
||||
value: f.defaultValue ?? '',
|
||||
})),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import { ColumnFormatDto, GridBoxOptionsDto, TagBoxOptionsDto } from '../../prox
|
|||
export interface GridExtraFilterState {
|
||||
fieldName: string
|
||||
operator: string
|
||||
controlType: string
|
||||
value: string
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { GridExtraFilterState } from './GridColumnData'
|
||||
import { useState } from 'react'
|
||||
|
||||
export function GridExtraFilterToolbar({
|
||||
filters,
|
||||
|
|
@ -9,31 +10,69 @@ export function GridExtraFilterToolbar({
|
|||
extraFilters: GridExtraFilterState[]
|
||||
setExtraFilters: React.Dispatch<React.SetStateAction<GridExtraFilterState[]>>
|
||||
}) {
|
||||
// input için geçici state tutuyoruz
|
||||
const [inputValues, setInputValues] = useState<Record<string, string>>({})
|
||||
|
||||
return (
|
||||
<div className="flex gap-4">
|
||||
{filters.map((fs) => {
|
||||
const current = extraFilters.find((f) => f.fieldName === fs.fieldName)
|
||||
|
||||
const handleSave = (value: string) => {
|
||||
setExtraFilters((prev) => {
|
||||
const exists = prev.find((f) => f.fieldName === fs.fieldName)
|
||||
if (exists) {
|
||||
return prev.map((f) => (f.fieldName === fs.fieldName ? { ...f, value } : f))
|
||||
}
|
||||
return [
|
||||
...prev,
|
||||
{
|
||||
fieldName: fs.fieldName,
|
||||
operator: fs.operator,
|
||||
controlType: fs.controlType,
|
||||
value,
|
||||
},
|
||||
]
|
||||
})
|
||||
}
|
||||
|
||||
return (
|
||||
<div key={fs.fieldName} className="flex items-center gap-2">
|
||||
<label>{fs.caption}</label>
|
||||
<select
|
||||
className="border rounded px-0.5 py-0.5"
|
||||
value={current?.value ?? ''}
|
||||
onChange={(e) =>
|
||||
setExtraFilters((prev) =>
|
||||
prev.map((f) =>
|
||||
f.fieldName === fs.fieldName ? { ...f, value: e.target.value } : f,
|
||||
),
|
||||
)
|
||||
}
|
||||
>
|
||||
{!fs.defaultValue && <option value="">Seçiniz</option>}
|
||||
{fs.items.map((item: any) => (
|
||||
<option key={item.key} value={item.key}>
|
||||
{item.value}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
|
||||
{fs.controlType === 'Select' ? (
|
||||
<select
|
||||
className="border rounded px-0.5 py-0.5"
|
||||
value={current?.value ?? ''}
|
||||
onChange={(e) => handleSave(e.target.value)}
|
||||
>
|
||||
{!fs.defaultValue && <option value="">Seçiniz</option>}
|
||||
{fs.items?.map((item: any) => (
|
||||
<option key={item.key} value={item.key}>
|
||||
{item.value}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
) : (
|
||||
<input
|
||||
type="text"
|
||||
className="border rounded px-1 py-0.5"
|
||||
value={inputValues[fs.fieldName] ?? current?.value ?? ''}
|
||||
placeholder={fs.caption}
|
||||
onChange={(e) =>
|
||||
setInputValues((prev) => ({
|
||||
...prev,
|
||||
[fs.fieldName]: e.target.value,
|
||||
}))
|
||||
}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter') {
|
||||
handleSave(inputValues[fs.fieldName] ?? '')
|
||||
}
|
||||
}}
|
||||
onBlur={(e) => handleSave(e.target.value)}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
|
|
|
|||
Loading…
Reference in a new issue