SoftwareBrothers / adminjs

AdminJS is an admin panel for apps written in node.js
https://adminjs.co
MIT License
8.2k stars 662 forks source link

Enhancement: Unhandled type: Map #144

Closed trevex closed 2 years ago

trevex commented 5 years ago

Recently array support was implemented: https://github.com/SoftwareBrothers/admin-bro/issues/90

However currently Maps are not supported yet.

Apart from this feature request is there a way to work around this issue, e.g. representation as string (via its JSON form)?

wojtek-krysiak commented 5 years ago

can you write the example schema - maybe I will be able to help from there.

LucasLeandro1204 commented 4 years ago

@wojtek-krysiak

import Mongoose, { Schema } from 'mongoose';

const {
  Map,
  String,
  Boolean,
  ObjectId,
} = Schema.Types;

const schema = new Schema({
  config: Map,

  url: String,

  component: {
    type: String,
  },
}),
salvacnj commented 3 years ago

Hello @wojtek-krysiak, is this feature implemented?

I'm trying to use it but not working for me.

Here is my code and result:

 @Prop({ type: Map })
  @ApiProperty({
    example: { "1605689439": 30.32, "1605689445": 20.35 }
  })
  samples: Map<string, number>;

  @Prop(raw({
    firstName: { type: String },
    lastName: { type: String }
  }))
  details: Record<string, any>;

imagen imagen

marciondg commented 2 years ago

I have the same issue, any workaround? image image image image

krzysztofstudniarek commented 2 years ago

Currently we don't have plans to implement such type. It would be very hard considering current data model in AdminJS.

You could try to set type: 'mixed' for your Map property in resource options which will send the form data as an object, you'd have to parse it as Map by yourself before saving though.

Bilits commented 7 months ago

Hi @trevex @krzysztofstudniarek just wanted to check since its been around 2 years since the last update on this thread, is adminjs now supports mongoose maps? below is my schema structure:

import mongoose, { Schema } from "mongoose";

const scenarioSchema = new Schema({ scenario: { type: String }, status: { type: String }, minPlayer: { type: Number }, maxPlayer: { type: Number }, imagePath: { type: String }, wideImagePath: { type: String }, articlePath: { type: String }, youtubePath: { type: String }, aparatPath: { type: String }, isCustom: { type: Boolean, default: false }, abilities: { type: Map, of: [ { ability: { type: Schema.Types.ObjectId, ref: "Ability", }, count: { type: Number, required: true, min: 1, default: 1, }, }, ], }, });

export default mongoose.model("scenario", scenarioSchema);

and everytime i try to open this in adminJs i am getting the following error:

2024-03-07T01:12:50.935Z error: Error Handler Middleware - Error: {"method":"GET","path":"/admin/api/resources/scenario/actions/list","errorMessage":"There are no resources with given id: \"Ability\"\nThis is the list of all registered resources you can use:\nuser, ability, room, scenario, malicious","stack":"Error: There are no resources with given id: \"Ability\"\nThis is the list of all registered resources you can use:\nuser, ability, room, scenario, malicious\n at AdminJS.findResource (file:///Users/moe/Desktop/gorgine-backend/node_modules/adminjs/lib/adminjs.js:183:13)\n at PropertyDecorator.reference (file:///Users/moe/Desktop/gorgine-backend/node_modules/adminjs/lib/backend/decorators/property/property-decorator.js:77:36)\n at file:///Users/moe/Desktop/gorgine-backend/node_modules/adminjs/lib/backend/utils/populator/populator.js:14:52\n at Array.filter ()\n at populator (file:///Users/moe/Desktop/gorgine-backend/node_modules/adminjs/lib/backend/utils/populator/populator.js:14:36)\n at Object.handler (file:///Users/moe/Desktop/gorgine-backend/node_modules/adminjs/lib/backend/actions/list/list-action.js:71:36)\n at process.processTicksAndRejections (node:internal/process/task_queues:95:5)\n at async ActionDecorator.handler (file:///Users/moe/Desktop/gorgine-backend/node_modules/adminjs/lib/backend/decorators/action/action-decorator.js:56:19)\n at async file:///Users/moe/Desktop/gorgine-backend/node_modules/@adminjs/express/lib/buildRouter.js:24:22"}

codeit13 commented 5 months ago

Is Map implemented yet?

It's been almost 2.5 years, How do @adminJS team expect someone to use this in production.

To be honest, I love the admin JS, dashborad, but these kind of bugs just keeps arriving time to time in adminJS, Can't really use this in production setup now.

Bilits commented 5 months ago

@codeit13 Its very frustrating for us too - we are already in production and cant use 2 collection at all because of this issue