Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: define reference in PropertyOptions
By omiting the ORM we can now define relationship between resources fixes - Referenced field is displayed as raw id instead of a link #583 - Custom Reference #416
- Loading branch information
1 parent
7cc68da
commit 052661d
Showing
19 changed files
with
201 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export const ContentParent = { | ||
name: 'Content', | ||
icon: 'Blog', | ||
} | ||
|
||
export const ProductsParent = { | ||
name: 'Store Management', | ||
icon: 'InventoryManagement', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import { ResourceOptions } from 'admin-bro' | ||
import { ContentParent } from '../../parents' | ||
|
||
export const BlogPostResource: ResourceOptions = { | ||
|
||
parent: ContentParent, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { ResourceOptions } from 'admin-bro' | ||
import { ProductsParent } from '../../parents' | ||
|
||
export const BrandResource: ResourceOptions = { | ||
parent: ProductsParent, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { BrandResource as options } from './brand-resource' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { ProductResource as options } from './product-resource' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { ResourceOptions } from 'admin-bro' | ||
import { ProductsParent } from '../../parents' | ||
|
||
export const ProductResource: ResourceOptions = { | ||
parent: ProductsParent, | ||
properties: { | ||
brandId: { | ||
reference: 'Brands', | ||
position: 10, | ||
}, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export type AvailableModels = 'User' | 'BlogPost' | ||
export type AvailableModels = 'User' | 'BlogPost' | 'Brand' | 'Product' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { DataTypes, Model, UUIDV4 } from 'sequelize' | ||
import { sequelize } from './connect' | ||
|
||
export interface BrandInterface extends Model { | ||
id: string; | ||
name: string; | ||
} | ||
|
||
export const BrandModel = sequelize.define<BrandInterface>('Brands', { | ||
// Model attributes are defined here | ||
id: { | ||
primaryKey: true, | ||
type: DataTypes.UUID, | ||
defaultValue: UUIDV4, | ||
}, | ||
name: { | ||
allowNull: false, | ||
type: DataTypes.STRING, | ||
}, | ||
}, { | ||
// Other model options go here | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
import { AvailableModels } from '../models.type' | ||
import { UserModel } from './user-model' | ||
import { BlogPostModel } from './blog-post-model' | ||
import { BrandModel } from './brand-model' | ||
import { ProductModel } from './product-model' | ||
|
||
export const models: Record<AvailableModels, any> = { | ||
User: UserModel, | ||
BlogPost: BlogPostModel, | ||
Brand: BrandModel, | ||
Product: ProductModel, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { DataTypes, Model, UUIDV4 } from 'sequelize' | ||
import { sequelize } from './connect' | ||
|
||
export interface ProductInterface extends Model { | ||
id: string; | ||
name: string; | ||
description?: string; | ||
} | ||
|
||
export const ProductModel = sequelize.define<ProductInterface>('Products', { | ||
// Model attributes are defined here | ||
id: { | ||
primaryKey: true, | ||
type: DataTypes.UUID, | ||
defaultValue: UUIDV4, | ||
}, | ||
name: { | ||
allowNull: false, | ||
type: DataTypes.STRING, | ||
}, | ||
description: { | ||
type: DataTypes.TEXT, | ||
}, | ||
brandId: { | ||
type: DataTypes.STRING, | ||
}, | ||
}, { | ||
// Other model options go here | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
import { number } from 'prop-types' | ||
|
||
/** | ||
* @alias ParamsTypeValue | ||
* @memberof BaseRecord | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.