Skip to content

Commit

Permalink
feat: support for jsonb fields
Browse files Browse the repository at this point in the history
Along with that
* deprecate property.name
* remove not needed array helpers in favour of flat module

It fixes: #631, #628, #491, #444
  • Loading branch information
wojtek-krysiak committed Oct 8, 2020
1 parent 34a10bc commit bb9de77
Show file tree
Hide file tree
Showing 60 changed files with 194 additions and 401 deletions.
2 changes: 1 addition & 1 deletion src/backend/adapters/resource/base-resource.ts
Expand Up @@ -171,7 +171,7 @@ class BaseResource {
*
* @return {Promise<Array<BaseRecord>>} records
*/
async findMany(ids: Array<string>): Promise<Array<BaseRecord>> {
async findMany(ids: Array<string | number>): Promise<Array<BaseRecord>> {
throw new NotImplementedError('BaseResource#findMany')
}

Expand Down
Expand Up @@ -3,7 +3,7 @@ import AdminBro from '../../../../admin-bro'
import { BaseProperty, BaseResource } from '../../../adapters'
import { PropertyDecorator } from '../../property'
import { getPropertyByKey } from './get-property-by-key'
import { pathToParts } from './path-to-parts'
import { pathToParts } from '../../../../utils/flat/path-to-parts'

export type DecoratedProperties = {[key: string]: PropertyDecorator}

Expand Down
2 changes: 1 addition & 1 deletion src/backend/decorators/resource/utils/find-sub-property.ts
@@ -1,5 +1,5 @@
import PropertyDecorator from '../../property/property-decorator'
import { PathParts } from './path-parts.type'
import { PathParts } from '../../../../utils/flat/path-parts.type'

/**
* @private
Expand Down
@@ -1,7 +1,7 @@
import { PropertyDecorator } from '../../property'
import { DecoratedProperties } from './decorate-properties'
import { findSubProperty } from './find-sub-property'
import { pathToParts } from './path-to-parts'
import { pathToParts } from '../../../../utils/flat/path-to-parts'


export const getPropertyByKey = (
Expand Down
2 changes: 0 additions & 2 deletions src/backend/decorators/resource/utils/index.ts
@@ -1,7 +1,5 @@
export * from './find-sub-property'
export * from './flat-sub-properties'
export * from './path-to-parts'
export * from './path-parts.type'
export * from './get-navigation'
export * from './decorate-properties'
export * from './decorate-actions'
Expand Down
6 changes: 3 additions & 3 deletions src/backend/utils/populator/populate-property.ts
Expand Up @@ -46,7 +46,7 @@ export const populateProperty = async (
if (property.isArray()) {
return (foreignKeyValue as Array<string | number>).reduce((arrayMemo, valueInArray) => ({
...arrayMemo,
...(isValueSearchable(valueInArray) ? { [valueInArray]: null } : {}),
...(isValueSearchable(valueInArray) ? { [valueInArray]: valueInArray } : {}),
}), memo)
}

Expand All @@ -55,11 +55,11 @@ export const populateProperty = async (
}
return {
...memo,
[foreignKeyValue]: null,
[foreignKeyValue]: foreignKeyValue,
}
}, {})

const uniqueExternalIds = Object.keys(externalIdsMap)
const uniqueExternalIds = Object.values<string | number>(externalIdsMap)

// when no record has `userId` filled = return input `records`
if (!uniqueExternalIds.length) {
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/components/actions/edit.tsx
Expand Up @@ -55,7 +55,7 @@ const Edit: FC<ActionProps> = (props) => {
/>
)) : resource.editProperties.map(property => (
<PropertyType
key={property.name}
key={property.path}
where="edit"
onChange={handleChange}
property={property}
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/components/actions/new.tsx
Expand Up @@ -59,7 +59,7 @@ const New: FC<ActionProps> = (props) => {
/>
)) : resource.editProperties.map(property => (
<PropertyType
key={property.name}
key={property.path}
where="edit"
onChange={handleChange}
property={property}
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/components/actions/show.tsx
Expand Up @@ -30,7 +30,7 @@ const Show: React.FC<ActionProps> = (props) => {
/>
)) : properties.map(property => (
<PropertyType
key={property.name}
key={property.path}
where="show"
property={property}
resource={resource}
Expand Down
Expand Up @@ -47,9 +47,9 @@ export const LayoutElementRenderer: React.FC<Props> = (props) => {
return (
<Component {...other as any}>
{properties.map(property => (
<DesignSystem.Box flexGrow={1} key={property.name}>
<DesignSystem.Box flexGrow={1} key={property.path}>
<PropertyType
key={property.name}
key={property.path}
where={where}
property={property}
resource={resource}
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/components/app/filter-drawer.tsx
Expand Up @@ -105,7 +105,7 @@ export const FilterDrawer: React.FC<FilterProps> = (props) => {
<Box my="x3">
{properties.map(property => (
<PropertyType
key={property.name}
key={property.path}
where="filter"
onChange={handleChange}
property={property}
Expand Down
Expand Up @@ -56,7 +56,7 @@ describe('<PropertyHeader />', function () {
const query = new URLSearchParams(href.replace('/?', ''))

expect(query.get('direction')).to.equal('asc')
expect(query.get('sortBy')).to.equal(property.name)
expect(query.get('sortBy')).to.equal(property.path)
})

it('doesn\'t render a sort indicator', function () {
Expand Down
Expand Up @@ -25,7 +25,7 @@ export type PropertyHeaderProps = {
export const PropertyHeader: React.FC<PropertyHeaderProps> = (props) => {
const { property, titleProperty, display } = props

const isMain = property.name === titleProperty.name
const isMain = property.path === titleProperty.path

return (
<TableCell
Expand Down
6 changes: 3 additions & 3 deletions src/frontend/components/app/records-table/record-in-list.tsx
Expand Up @@ -102,15 +102,15 @@ export const RecordInList: React.FC<RecordInListProps> = (props) => {
{resource.listProperties.map(property => (
<TableCell
style={{ cursor: 'pointer' }}
key={property.name}
data-property-name={property.name}
key={property.path}
data-property-name={property.path}
display={display(property.isTitle)}
>
{isLoading ? (
<Placeholder style={{ height: 14 }} />
) : (
<PropertyType
key={property.name}
key={property.path}
where="list"
property={property}
resource={resource}
Expand Down
Expand Up @@ -100,7 +100,7 @@ export const RecordsTableHeader: React.FC<RecordsTableHeaderProps> = (props) =>
{properties.map(property => (
<PropertyHeader
display={display(property.isTitle)}
key={property.name}
key={property.path}
titleProperty={titleProperty}
property={property}
sortBy={sortBy}
Expand Down
Expand Up @@ -48,11 +48,11 @@ describe('<RecordsTable />', function () {
let container: RenderResult['container']

beforeEach(async function () {
const name = await factory.build<PropertyJSON>('PropertyJSON', { name: 'name', isTitle: true })
const name = await factory.build<PropertyJSON>('PropertyJSON', { path: 'path', isTitle: true })
properties = [
await factory.build<PropertyJSON>('PropertyJSON', { name: 'id', isId: true }),
await factory.build<PropertyJSON>('PropertyJSON', { path: 'id', isId: true }),
name,
await factory.build<PropertyJSON>('PropertyJSON', { name: 'surname' }),
await factory.build<PropertyJSON>('PropertyJSON', { path: 'surname' }),
]
resource = await factory.build<ResourceJSON>('ResourceJSON', {
listProperties: properties,
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/components/app/sort-link.tsx
Expand Up @@ -21,7 +21,7 @@ class SortLink extends React.PureComponent<SortLinkProps & RouteComponentProps>

isActive(): boolean {
const { sortBy, property } = this.props
return sortBy === property.name
return sortBy === property.path
}

render(): ReactNode {
Expand All @@ -31,7 +31,7 @@ class SortLink extends React.PureComponent<SortLinkProps & RouteComponentProps>
const sortedByIcon = `Caret${direction === 'asc' ? 'Up' : 'Down'}`

query.set('direction', oppositeDirection)
query.set('sortBy', property.name)
query.set('sortBy', property.path)

return (
<NavLink to={{ search: query.toString() }} className={cssClass('SortLink')}>
Expand Down
Expand Up @@ -13,7 +13,7 @@ const AddNewItemButton: React.FC<AddNewItemButtonProps> = (props) => {
const { resource, property } = props
const { translateProperty, translateButton } = useTranslation()
const label = translateProperty(
`${property.name}.addNewItem`,
`${property.path}.addNewItem`,
resource.id, {
defaultValue: translateButton('addNewItem', resource.id),
},
Expand Down

This file was deleted.

This file was deleted.

0 comments on commit bb9de77

Please sign in to comment.