Skip to content

Commit

Permalink
feat(data-studio): add max length to attributes
Browse files Browse the repository at this point in the history
Co-authored-by: Renaud Amsellem <[email protected]>
test(data-studio): replace mock function
  • Loading branch information
philippechevieux and renaudAmsellem committed Mar 4, 2024
1 parent 5722efe commit 18048ba
Show file tree
Hide file tree
Showing 10 changed files with 2,139 additions and 5,666 deletions.
1 change: 1 addition & 0 deletions apps/admin/src/_gqlTypes/globalTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ export interface AttributeInput {
values_list?: ValuesListConfInput | null;
reverse_link?: string | null;
unique?: boolean | null;
maxLength?: number | null;
}

export interface DeleteTaskInput {
Expand Down
40 changes: 22 additions & 18 deletions apps/core/src/app/core/attributeApp/attributeApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ interface IDeps {
'core.utils'?: IUtils;
}

export default function (deps: IDeps = {}): ICoreAttributeApp {
export default function(deps: IDeps = {}): ICoreAttributeApp {
const {
'core.domain.attribute': attributeDomain = null,
'core.domain.record': recordDomain = null,
Expand Down Expand Up @@ -185,7 +185,8 @@ export default function (deps: IDeps = {}): ICoreAttributeApp {
${attributesInterfaceSchema}
embedded_fields: [EmbeddedAttribute],
values_list: StandardValuesListConf,
unique: Boolean
unique: Boolean,
maxLength: Int
}
type LinkAttribute implements Attribute{
Expand Down Expand Up @@ -218,7 +219,8 @@ export default function (deps: IDeps = {}): ICoreAttributeApp {
metadata_fields: [String!],
values_list: ValuesListConfInput,
reverse_link: String,
unique: Boolean
unique: Boolean,
maxLength: Int
}
type EmbeddedAttribute {
Expand Down Expand Up @@ -393,21 +395,23 @@ export default function (deps: IDeps = {}): ICoreAttributeApp {
// TODO: this could be optimized if find() would allow searching for multiple IDs at once
return {
...attributeData.values_list,
values: (attributeData.values_list.values as string[]) || []
.map(async recId => {
const record = await recordDomain.find({
params: {
library: attributeData.linked_library,
filters: [
{field: 'id', condition: AttributeCondition.EQUAL, value: recId}
]
},
ctx
});

return record.list.length ? record.list[0] : null;
})
.filter(r => r !== null) // Remove invalid values (unknown records)
values:
(attributeData.values_list.values as string[]) ||
[]
.map(async recId => {
const record = await recordDomain.find({
params: {
library: attributeData.linked_library,
filters: [
{field: 'id', condition: AttributeCondition.EQUAL, value: recId}
]
},
ctx
});

return record.list.length ? record.list[0] : null;
})
.filter(r => r !== null) // Remove invalid values (unknown records)
};
}
},
Expand Down
1 change: 1 addition & 0 deletions libs/ui/src/__mocks__/common/attribute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export const mockAttributeWithDetails: AttributeDetailsFragment = {
fr: 'Ma description',
en: 'My description'
},
maxLength: null,
unique: false,
readonly: false,
multiple_values: false
Expand Down
Loading

0 comments on commit 18048ba

Please sign in to comment.