This pull request enhances the entity column generation logic in the admin views by adding support for including fields from additional GraphQL types, specifically for the `orders` entity. The changes allow more flexible and comprehensive column definitions by pulling in fields from related types (like `OrderDetail`) and updating the filtering and type resolution logic accordingly. **This adding payment_status & fulfillment_status from OrderDetail in view configuration feature** **Entity column generation enhancements:** * Added the `ADDITIONAL_ENTITY_TYPES` mapping to specify extra GraphQL types whose fields should be included for certain entities (currently, `OrderDetail` for `orders`). ([packages/medusa/src/api/admin/views/[entity]/columns/helpers.tsR260-R263](diffhunk://#diff-ce197feb4e4d1273d9ee19126e284b65fdb4367f0871774a75add5c8cd749d02R260-R263)) * Updated the column generation process to collect fields from both the main entity type and any additional types, while properly filtering out arrays and excluded fields. ([packages/medusa/src/api/admin/views/[entity]/columns/helpers.tsR340-R345](diffhunk://#diff-ce197feb4e4d1273d9ee19126e284b65fdb4367f0871774a75add5c8cd749d02R340-R345), [packages/medusa/src/api/admin/views/[entity]/columns/helpers.tsR373-R414](diffhunk://#diff-ce197feb4e4d1273d9ee19126e284b65fdb4367f0871774a75add5c8cd749d02R373-R414)) * Changed field lookup logic to use a unified `entityFields` object and a new `additionalFieldDefinitions` map for extra fields, ensuring correct type info resolution for all columns. ([packages/medusa/src/api/admin/views/[entity]/columns/helpers.tsL344-R354](diffhunk://#diff-ce197feb4e4d1273d9ee19126e284b65fdb4367f0871774a75add5c8cd749d02L344-R354), [packages/medusa/src/api/admin/views/[entity]/columns/helpers.tsL411-R463](diffhunk://#diff-ce197feb4e4d1273d9ee19126e284b65fdb4367f0871774a75add5c8cd749d02L411-R463))
46 lines
936 B
TypeScript
46 lines
936 B
TypeScript
/**
|
|
* Pick properties from an object and copy them to a new object
|
|
* @param obj
|
|
* @param keys
|
|
*/
|
|
export function pick(obj: Record<string, any>, keys: string[]) {
|
|
const ret: Record<string, any> = {}
|
|
|
|
keys.forEach((k) => {
|
|
if (k in obj) {
|
|
ret[k] = obj[k]
|
|
}
|
|
})
|
|
|
|
return ret
|
|
}
|
|
|
|
/**
|
|
* Remove properties that are `null` or `undefined` from the object.
|
|
* @param obj
|
|
*/
|
|
export function cleanNonValues(obj: Record<string, any>) {
|
|
const ret: Record<string, any> = {}
|
|
|
|
for (const key in obj) {
|
|
if (obj[key] !== null && typeof obj[key] !== "undefined") {
|
|
ret[key] = obj[key]
|
|
}
|
|
}
|
|
|
|
return ret
|
|
}
|
|
|
|
/**
|
|
* Convert a string to camel case
|
|
* @param str
|
|
* @returns camel case string
|
|
*/
|
|
export function toCamelCase(str: string): string {
|
|
return /^([a-zA-Z]+)(([A-Z]([a-z]+))+)$/.test(str)
|
|
? str
|
|
: str
|
|
.toLowerCase()
|
|
.replace(/[^a-zA-Z0-9]+(.)/g, (_, chr) => chr.toUpperCase())
|
|
}
|