@adminforth/quick-filters 1.1.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/dist/index.js +9 -12
  2. package/index.ts +9 -14
  3. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -8,6 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { AdminForthPlugin } from "adminforth";
11
+ import { suggestIfTypo } from "adminforth";
11
12
  export default class extends AdminForthPlugin {
12
13
  constructor(options) {
13
14
  super(options, import.meta.url);
@@ -33,21 +34,17 @@ export default class extends AdminForthPlugin {
33
34
  });
34
35
  }
35
36
  validateConfigAfterDiscover(adminforth, resourceConfig) {
36
- // optional method where you can safely check field types after database discovery was performed
37
+ for (const colOpt of this.options.columns) {
38
+ const column = resourceConfig.columns.find(c => c.name === colOpt.column);
39
+ if (!column) {
40
+ const similar = suggestIfTypo(resourceConfig.columns.map((column) => column.name), colOpt.column);
41
+ throw new Error(`QuickFilters plugin: column '${colOpt.column}' not found in resource '${resourceConfig.resourceId}'. Did you mean '${similar}'?`);
42
+ }
43
+ }
37
44
  }
38
45
  instanceUniqueRepresentation(pluginOptions) {
39
46
  // optional method to return unique string representation of plugin instance.
40
47
  // Needed if plugin can have multiple instances on one resource
41
- return `single`;
42
- }
43
- setupEndpoints(server) {
44
- server.endpoint({
45
- method: 'POST',
46
- path: `/plugin/${this.pluginInstanceId}/example`,
47
- handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body }) {
48
- const { name } = body;
49
- return { hey: `Hello ${name}` };
50
- })
51
- });
48
+ return `${this.resourceConfig.resourceId}-quick-filters`;
52
49
  }
53
50
  }
package/index.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { AdminForthPlugin } from "adminforth";
2
2
  import type { IAdminForth, IHttpServer, AdminForthResourcePages, AdminForthResourceColumn, AdminForthDataTypes, AdminForthResource, AdminForthComponentDeclaration } from "adminforth";
3
3
  import type { PluginOptions } from './types.js';
4
-
4
+ import { suggestIfTypo } from "adminforth";
5
5
 
6
6
  export default class extends AdminForthPlugin {
7
7
  options: PluginOptions;
@@ -30,24 +30,19 @@ export default class extends AdminForthPlugin {
30
30
  }
31
31
 
32
32
  validateConfigAfterDiscover(adminforth: IAdminForth, resourceConfig: AdminForthResource) {
33
- // optional method where you can safely check field types after database discovery was performed
33
+ for ( const colOpt of this.options.columns ) {
34
+ const column = resourceConfig.columns.find(c => c.name === colOpt.column);
35
+ if ( !column ) {
36
+ const similar = suggestIfTypo(resourceConfig.columns.map((column: any) => column.name), colOpt.column);
37
+ throw new Error(`QuickFilters plugin: column '${colOpt.column}' not found in resource '${resourceConfig.resourceId}'. Did you mean '${similar}'?`);
38
+ }
39
+ }
34
40
  }
35
41
 
36
42
  instanceUniqueRepresentation(pluginOptions: any) : string {
37
43
  // optional method to return unique string representation of plugin instance.
38
44
  // Needed if plugin can have multiple instances on one resource
39
- return `single`;
40
- }
41
-
42
- setupEndpoints(server: IHttpServer) {
43
- server.endpoint({
44
- method: 'POST',
45
- path: `/plugin/${this.pluginInstanceId}/example`,
46
- handler: async ({ body }) => {
47
- const { name } = body;
48
- return { hey: `Hello ${name}` };
49
- }
50
- });
45
+ return `${this.resourceConfig.resourceId}-quick-filters`;
51
46
  }
52
47
 
53
48
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adminforth/quick-filters",
3
- "version": "1.1.0",
3
+ "version": "1.2.1",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",