adminjs icon indicating copy to clipboard operation
adminjs copied to clipboard

Enhancement: Unhandled type: Map

Open trevex opened this issue 4 years ago • 4 comments

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)?

trevex avatar Sep 09 '19 09:09 trevex

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

wojtek-krysiak avatar Sep 20 '19 08:09 wojtek-krysiak

@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,
  },
}),

LucasLeandro1204 avatar Oct 23 '19 03:10 LucasLeandro1204

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

salvacnj avatar May 21 '21 14:05 salvacnj

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

marciondg avatar Mar 09 '22 16:03 marciondg

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.

krzysztofstudniarek avatar Aug 16 '22 08:08 krzysztofstudniarek

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"}

Bilits avatar Mar 07 '24 01:03 Bilits