Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added 'exact-string' PropertyType #1597

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions src/backend/adapters/property/base-property.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,30 @@
const TITLE_COLUMN_NAMES = ['title', 'name', 'subject', 'email']

export type PropertyType =
'string' | 'float' | 'number' | 'boolean' |
'date' | 'datetime' | 'mixed' | 'reference' | 'key-value' |
'richtext' | 'textarea' | 'password' | 'currency' | 'phone' | 'uuid';
| 'string'
| 'float'
| 'number'
| 'boolean'
| 'date'
| 'datetime'
| 'mixed'
| 'reference'
| 'key-value'
| 'richtext'
| 'textarea'
| 'password'
| 'currency'
| 'phone'
| 'uuid'
| 'exact-string'

// description
type BasePropertyAttrs = {
path: string;
type?: PropertyType;
isId?: boolean;
isSortable?: boolean;
position?: number;
path: string
type?: PropertyType
isId?: boolean
isSortable?: boolean
position?: number
}

/**
Expand Down
71 changes: 33 additions & 38 deletions src/frontend/components/property-type/base-property-component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
date: datetime,
richtext,
string: defaultType,
'exact-string': defaultType,
number: defaultType,
float: defaultType,
uuid: defaultType,
Expand All @@ -59,28 +60,35 @@
const BasePropertyComponent: React.FC<BasePropertyComponentProps> = (props) => {
const { property: baseProperty, resource, record, filter, where, onChange } = props

const property: PropertyJSON = useMemo(() => ({
...baseProperty,
// we fill the path if it is not there. That is why all the actual Component Renderers are
// called with the path set to this root path. Next mixed and array components adds to this
// path either index (for array) or subProperty name.
path: (baseProperty as PropertyJSON).path || baseProperty.propertyPath,
}), [baseProperty])
const property: PropertyJSON = useMemo(
() => ({
...baseProperty,
// we fill the path if it is not there. That is why all the actual Component Renderers are
// called with the path set to this root path. Next mixed and array components adds to this
// path either index (for array) or subProperty name.
path: (baseProperty as PropertyJSON).path || baseProperty.propertyPath,
}),
[baseProperty],
)

const testId = `property-${where}-${property.path}`
const contentTag = getActionElementCss(resource.id, where, property.path)

let Component: ReactComponentLike = (types[property.type] && types[property.type][where])
|| defaultType[where]
let Component: ReactComponentLike =

Check failure on line 77 in src/frontend/components/property-type/base-property-component.tsx

View workflow job for this annotation

GitHub Actions / Test

There should be no line break before or after '='
(types[property.type] && types[property.type][where]) || defaultType[where]

if (property.components && property.components[where]) {
const component = property.components[where]
if (!component) {
throw new Error(`there is no "${property.path}.components.${where}"`)
}
Component = globalAny.AdminJS.UserComponents[component] ?? (() => {
throw new Error(`Component "${component}" has not been bundled, ensure it was added to your ComponentLoader instance (the one included in AdminJS options).`)
})
Component =

Check failure on line 85 in src/frontend/components/property-type/base-property-component.tsx

View workflow job for this annotation

GitHub Actions / Test

There should be no line break before or after '='
globalAny.AdminJS.UserComponents[component] ??

Check failure on line 86 in src/frontend/components/property-type/base-property-component.tsx

View workflow job for this annotation

GitHub Actions / Test

'??' should be placed at the beginning of the line
(() => {
throw new Error(
`Component "${component}" has not been bundled, ensure it was added to your ComponentLoader instance (the one included in AdminJS options).`,
)
})
return (
<ErrorBoundary>
<Box data-css={contentTag} data-testid={testId}>
Expand All @@ -102,37 +110,27 @@
const KeyValue = KeyValueType[where]

if (baseProperty.isArray) {
if (!Array) { return (<div />) }
if (!Array) {
return <div />
}
return (
<Array
{...props}
property={property}
ItemComponent={BasePropertyComponent}
testId={testId}
/>
<Array {...props} property={property} ItemComponent={BasePropertyComponent} testId={testId} />
)
}

if (baseProperty.type === 'key-value') {
if (!KeyValue) { return (<div />) }
return (
<KeyValue
{...props}
property={property}
testId={testId}
/>
)
if (!KeyValue) {
return <div />
}
return <KeyValue {...props} property={property} testId={testId} />
}

if (baseProperty.type === 'mixed') {
if (!Mixed) { return (<div />) }
if (!Mixed) {
return <div />
}
return (
<Mixed
{...props}
property={property}
ItemComponent={BasePropertyComponent}
testId={testId}
/>
<Mixed {...props} property={property} ItemComponent={BasePropertyComponent} testId={testId} />
)
}

Expand All @@ -151,7 +149,4 @@
</ErrorBoundary>
)
}
export {
BasePropertyComponent as default,
BasePropertyComponent,
}
export { BasePropertyComponent as default, BasePropertyComponent }
Loading