Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

grfiltermenubyid

0.0.4 • Public • Published

grFilterMenuById

Recebe um JSON para menu e um array de ID, retorna o JSON aplicando o filtro e mantendo toda a estrutura para menu.

Instalação

npm install grfiltermenubyid

Teste

const grFilterMenuById = require('grfiltermenubyid')
 
const menuFull = [
    {
        id: 1,
        title: 'Sistema',
        icon: 'gear',
        text: 'Sistema',
        subItem: [
            {
                id: 2,
                link: '/usuario',
                title: 'Usuários',
                icon: 'user',
                text: 'Usuários',
                subItem: [],
            },
            {
                id: 3,
                link: '/grupo',
                title: 'Grupos',
                icon: 'group',
                text: 'Grupos',
                subItem: [],
                subItem: [
                    {
                        id: 222,
                        link: '/usuario',
                        title: 'xxxxxx',
                        icon: 'user',
                        text: 'xxxxxx',
                        subItem: [],
                    },
                    {
                        id: 223,
                        link: '/aaaaa',
                        title: 'xx',
                        icon: 'user',
                        text: 'xxxxxx',
                        subItem: [],
                    }
                ]
            }
        ]
    },
 
    {
        id: 5,
        title: 'Cadastros',
        icon: 'pencil-square-o',
        text: 'Cadastros',
        subItem: [
            {
                id: 6,
                link: '/pessoa',
                title: 'Pessoas',
                icon: 'user',
                text: 'Pessoas',
                subItem: [],
            },
            {
                id: 7,
                link: '/teste',
                title: 'teste',
                icon: 'user',
                text: 'Teste',
                subItem: [],
            }
        ]
    }
]
 
const permissions = [222]
 
let result = grFilterMenuById(menuFull, permissions)
 
console.log(JSON.stringify(result, 0, 3))
 
// Resultado:
 
[
   {
      "id": 1,
      "title": "Sistema",
      "icon": "gear",
      "text": "Sistema",
      "subItem": [
         null,
         {
            "id": 3,
            "link": "/grupo",
            "title": "Grupos",
            "icon": "group",
            "text": "Grupos",
            "subItem": [
               {
                  "id": 222,
                  "link": "/usuario",
                  "title": "xxxxxx",
                  "icon": "user",
                  "text": "xxxxxx",
                  "subItem": []
               },
               null
            ]
         }
      ]
   },
   {
      "id": 5,
      "title": "Cadastros",
      "icon": "pencil-square-o",
      "text": "Cadastros",
      "subItem": [
         {
            "id": 6,
            "link": "/pessoa",
            "title": "Pessoas",
            "icon": "user",
            "text": "Pessoas",
            "subItem": []
         },
         null
      ]
   }
]

Install

npm i grfiltermenubyid

DownloadsWeekly Downloads

6

Version

0.0.4

License

ISC

Unpacked Size

13.7 kB

Total Files

4

Last publish

Collaborators

  • avatar