MainMenu ile entityeditor den seçilebilir hale getirildi.
This commit is contained in:
parent
35dfc600d6
commit
58d3e3c940
3 changed files with 50 additions and 30 deletions
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Dynamic.Core;
|
||||
using System.Threading.Tasks;
|
||||
using Erp.Languages.Entities;
|
||||
using Erp.Platform.Entities;
|
||||
|
|
@ -206,6 +207,19 @@ public class MenuAppService : CrudAppService<
|
|||
|
||||
await base.DeleteAsync(id);
|
||||
}
|
||||
|
||||
public async Task<List<MenuDto>> GetListMainMenuAsync()
|
||||
{
|
||||
await CheckGetPolicyAsync();
|
||||
|
||||
var query = await _menuRepository.GetQueryableAsync();
|
||||
query = query.Where(a => !a.IsDisabled && a.ShortName != null);
|
||||
|
||||
var entities = await AsyncExecuter.ToListAsync(query);
|
||||
var entityDtos = await MapToGetListOutputDtosAsync(entities);
|
||||
|
||||
return entityDtos;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,8 @@ import { Formik, Form, Field, FieldProps, FieldArray } from 'formik'
|
|||
import * as Yup from 'yup'
|
||||
import { FormItem, Input, Select, Checkbox, FormContainer, Button } from '@/components/ui'
|
||||
import { SelectBoxOption } from '@/types/shared'
|
||||
import { useStoreState } from '@/store/store'
|
||||
import { MenuService } from '@/services/menu.service'
|
||||
import { MenuDto } from '@/proxy/menus/models'
|
||||
|
||||
// Validation schema
|
||||
const validationSchema = Yup.object({
|
||||
|
|
@ -50,36 +51,34 @@ const EntityEditor: React.FC = () => {
|
|||
const { id } = useParams()
|
||||
const navigate = useNavigate()
|
||||
const { translate } = useLocalization()
|
||||
const { mainMenu } = useStoreState((state) => state.abpConfig.menu)
|
||||
const { getEntity, addEntity, updateEntity } = useEntities()
|
||||
|
||||
const isEditing = !!id
|
||||
|
||||
// Convert first level menu items to select options with prefix
|
||||
const menuOptions = useMemo(() => {
|
||||
if (!mainMenu || mainMenu.length === 0) return []
|
||||
|
||||
const prefixMap: Record<string, string> = {
|
||||
'Platform': 'Plat',
|
||||
'Saas': 'Sas',
|
||||
'Administration': 'Adm',
|
||||
'Crm': 'Crm',
|
||||
'Coordinator': 'Crd',
|
||||
'SupplyChain': 'Scp',
|
||||
'Maintenance': 'Mnt',
|
||||
'Warehouse': 'Str',
|
||||
'Project': 'Prj',
|
||||
'Hr': 'Hr',
|
||||
'Mrp': 'Mrp',
|
||||
'Accounting': 'Acc',
|
||||
// Menu options state
|
||||
const [menuOptions, setMenuOptions] = useState<SelectBoxOption[]>([])
|
||||
|
||||
// Fetch menu options on mount
|
||||
useEffect(() => {
|
||||
const fetchMenuOptions = async () => {
|
||||
try {
|
||||
const menuService = new MenuService()
|
||||
const response = await menuService.getListMainMenu()
|
||||
|
||||
if (response.data && Array.isArray(response.data)) {
|
||||
const options = response.data.map((menuItem: any) => ({
|
||||
value: menuItem.shortName || menuItem.code,
|
||||
label: menuItem.displayName || menuItem.code,
|
||||
}))
|
||||
setMenuOptions(options)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error fetching menu options:', error)
|
||||
}
|
||||
}
|
||||
|
||||
return mainMenu.map((menuItem) => ({
|
||||
value: menuItem.key,
|
||||
label: menuItem.title,
|
||||
prefix: menuItem.shortName || prefixMap[menuItem.key] || menuItem.key.substring(0, 3),
|
||||
}))
|
||||
}, [mainMenu])
|
||||
|
||||
fetchMenuOptions()
|
||||
}, [])
|
||||
|
||||
// Initial values for Formik
|
||||
const [initialValues, setInitialValues] = useState({
|
||||
|
|
@ -182,7 +181,7 @@ const EntityEditor: React.FC = () => {
|
|||
if (!menuValue || !entityName) return ''
|
||||
const selectedMenu = menuOptions.find((opt) => opt.value === menuValue)
|
||||
if (!selectedMenu) return ''
|
||||
return `${selectedMenu.prefix}_D_${entityName}`
|
||||
return `${selectedMenu.value}_D_${entityName}`
|
||||
}
|
||||
|
||||
const fieldTypes = [
|
||||
|
|
@ -365,7 +364,7 @@ const EntityEditor: React.FC = () => {
|
|||
<p className="text-xs text-slate-500 mt-1">
|
||||
Format:{' '}
|
||||
{values.menu
|
||||
? `${menuOptions.find((opt) => opt.value === values.menu)?.prefix || '[Prefix]'}_D_`
|
||||
? `${menuOptions.find((opt) => opt.value === values.menu)?.value || '[Prefix]'}_D_`
|
||||
: '[Prefix]_D_'}
|
||||
EntityName
|
||||
</p>
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
import { PagedAndSortedResultRequestDto, PagedResultDto } from '@/proxy/abp'
|
||||
import { MenuDto } from '@/proxy/menus/models'
|
||||
import apiService, { Config } from '@/services/api.service'
|
||||
import { useStoreState } from '@/store/store'
|
||||
import { useState } from 'react'
|
||||
|
||||
export class MenuService {
|
||||
apiName = 'Default'
|
||||
|
|
@ -68,6 +66,15 @@ export class MenuService {
|
|||
},
|
||||
{ apiName: this.apiName },
|
||||
)
|
||||
|
||||
getListMainMenu = () =>
|
||||
apiService.fetchData<MenuDto[]>(
|
||||
{
|
||||
method: 'GET',
|
||||
url: `/api/app/menu/main-menu`,
|
||||
},
|
||||
{ apiName: this.apiName },
|
||||
)
|
||||
}
|
||||
|
||||
export const getMenus = async (skipCount = 0, maxResultCount = 1000, sorting = 'order') => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue