diff --git a/example-app/src/nested/value-trigger.component.tsx b/example-app/src/nested/value-trigger.component.tsx index 823bd198a..95055a751 100644 --- a/example-app/src/nested/value-trigger.component.tsx +++ b/example-app/src/nested/value-trigger.component.tsx @@ -1,10 +1,13 @@ import React from 'react' -import { EditPropertyProps } from 'admin-bro' +import { EditPropertyProps, unflatten } from 'admin-bro' import { Button, Box } from '@admin-bro/design-system' const ValueTrigger: React.FC = (props) => { const { onChange, record } = props + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const data = unflatten(record.params) + const handleClick = (): void => { onChange({ ...record, diff --git a/index.d.ts b/index.d.ts index 29ca08b14..caa174aab 100644 --- a/index.d.ts +++ b/index.d.ts @@ -3,6 +3,8 @@ import AdminBro from './types/src/admin-bro' import * as ACTIONS from './types/src/backend/actions/index' import { ReduxState } from './types/src/frontend/store/store' +export { flatten, unflatten } from './types/src/admin-bro' + export * from '@admin-bro/design-system' export * from './types/src/frontend/store/store' export * from './types/src/backend/utils/build-feature' diff --git a/index.js b/index.js index 1bdb9b24f..0d7a2e49e 100644 --- a/index.js +++ b/index.js @@ -17,6 +17,8 @@ const { buildFeature, mergeResourceOptions } = require('./lib/backend/utils/buil AdminBro.buildFeature = buildFeature AdminBro.mergeResourceOptions = mergeResourceOptions +AdminBro.flatten = require('./lib/admin-bro').flatten +AdminBro.unflatten = require('./lib/admin-bro').unflatten AdminBro.require = AdminBro.bundle Object.keys(constants).forEach((key) => { diff --git a/package.json b/package.json index 9c89b5c22..ed9073bb7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "admin-bro", - "version": "3.1.0-beta.5", + "version": "3.1.2", "description": "Admin panel for apps written in node.js", "main": "index.js", "types": "index.d.ts", diff --git a/src/admin-bro.ts b/src/admin-bro.ts index c2d495afc..81b3107b9 100644 --- a/src/admin-bro.ts +++ b/src/admin-bro.ts @@ -2,6 +2,7 @@ import * as _ from 'lodash' import * as path from 'path' import * as fs from 'fs' import i18n, { i18n as I18n } from 'i18next' +import { flatten, unflatten } from 'flat' import AdminBroOptions, { AdminBroOptionsWithDefault } from './admin-bro-options.interface' import BaseResource from './backend/adapters/base-resource' @@ -356,5 +357,6 @@ interface AdminBro extends TranslateFunctions {} export const { registerAdapter } = AdminBro export const { bundle } = AdminBro +export { flatten, unflatten } export default AdminBro diff --git a/src/backend/utils/request-parser.spec.ts b/src/backend/utils/request-parser.spec.ts index 0a02970b0..7277d691a 100644 --- a/src/backend/utils/request-parser.spec.ts +++ b/src/backend/utils/request-parser.spec.ts @@ -22,7 +22,6 @@ describe('RequestParser', function () { describe('boolean values', function () { beforeEach(function () { resource = buildResourceWithProperty('isHired', { - isDisabled: () => false, type: () => 'boolean', }) }) @@ -45,19 +44,4 @@ describe('RequestParser', function () { expect(requestParser(request, resource).payload?.isHired).to.be.false }) }) - - describe('disabled values', function () { - beforeEach(function () { - resource = buildResourceWithProperty('anyProperty', { - isDisabled: () => true, - type: () => 'number', - }) - }) - - it('strips payload from disabled properties', function () { - const request = { ...baseRequest, payload: { anyProperty: 'yeAaa' } } - - expect(requestParser(request, resource).payload?.anyProperty).to.be.undefined - }) - }) }) diff --git a/src/backend/utils/request-parser.ts b/src/backend/utils/request-parser.ts index c22130137..785fad5cf 100644 --- a/src/backend/utils/request-parser.ts +++ b/src/backend/utils/request-parser.ts @@ -24,11 +24,6 @@ const RequestParser = (originalRequest: ActionRequest, resource: BaseResource): if (formValue === FORM_VALUE_EMPTY_ARRAY) { value = [] } if (property) { - // Strip payload from disabled properties. - // isDisabled method has been added recently so this check is needed - // so adapters with older version of admin-bro will also work - if (property.isDisabled && property.isDisabled()) { return { ...memo } } - if (property.type() === 'boolean') { if (value === 'true') { return { ...memo, [path]: true } } if (value === 'false') { return { ...memo, [path]: false } } diff --git a/src/frontend/bundle-entry.jsx b/src/frontend/bundle-entry.jsx index 6feac283d..cff23f902 100644 --- a/src/frontend/bundle-entry.jsx +++ b/src/frontend/bundle-entry.jsx @@ -4,6 +4,7 @@ import { BrowserRouter } from 'react-router-dom' import { ThemeProvider } from 'styled-components' import { initReactI18next } from 'react-i18next' import i18n from 'i18next' +import flat from 'flat' import App from './components/application' import BasePropertyComponent from './components/property-type' @@ -58,6 +59,8 @@ export default { env, ...AppComponents, ...Hooks, + flatten: flat.flatten, + unflatten: flat.unflatten, // DEPRECATED: this should be removed in the next version // now it was added here to ensure backwards compatibility // window.AdminBroDesignSystem is set by design-system bundle