Skip to content

Commit

Permalink
Added support for the isMultiLine attribute metadata.
Browse files Browse the repository at this point in the history
  • Loading branch information
TPReal committed Oct 9, 2024
1 parent 59ccb01 commit f58f30c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
11 changes: 8 additions & 3 deletions resources/js/components/ui/form/AttributeFields.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,14 @@ export const AttributeFields: VoidComponent<Props> = (props) => {
function simpleAttributeField(type: SimpleAttributeType, fieldName = name()) {
switch (type) {
case "string":
return <TextField name={fieldName} label="" small />;
case "text":
return <MultilineTextField name={fieldName} label="" small />;
case "text": {
const {isMultiLine = type === "text"} = aProps.attribute.metadata;
return isMultiLine ? (
<MultilineTextField name={fieldName} label="" small />
) : (
<TextField name={fieldName} label="" small />
);
}
case "int":
return <TextField name={fieldName} type="number" label="" small />;
case "bool":
Expand Down
3 changes: 3 additions & 0 deletions resources/js/data-access/memo-api/attributes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ describe("Attributes", () => {
description: null,
apiName: "aa1ApiName",
type: "dict",
metadata: null,
typeModel: null,
dictionaryId: "dd",
isFixed: true,
Expand All @@ -41,6 +42,7 @@ describe("Attributes", () => {
description: null,
apiName: "aa2ApiName",
type: "string",
metadata: null,
typeModel: null,
dictionaryId: null,
isFixed: false,
Expand All @@ -56,6 +58,7 @@ describe("Attributes", () => {
description: null,
apiName: "aa5ApiName",
type: "int",
metadata: null,
typeModel: null,
dictionaryId: null,
isFixed: false,
Expand Down
3 changes: 3 additions & 0 deletions resources/js/data-access/memo-api/attributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {FacilityIdOrGlobal} from "state/activeFacilityId.state";
import {Attributable, getAttributeModel, makeAttributable, readAttribute} from "./attributable";
import {Dictionaries, Dictionary, dictionaryNameTranslationKey} from "./dictionaries";
import {
AttributeMetadataResource,
AttributeModel,
AttributeResource,
AttributeType,
Expand Down Expand Up @@ -108,6 +109,7 @@ export class Attribute<T = unknown> {
readonly label: string,
readonly apiName: string,
readonly type: AttributeType,
readonly metadata: AttributeMetadataResource,
readonly basicType: SimpleAttributeType | DictAttributeType | SeparatorAttributeType | undefined,
readonly typeModel: AttributeModel | undefined,
readonly dictionary: Dictionary | undefined,
Expand Down Expand Up @@ -152,6 +154,7 @@ export class Attribute<T = unknown> {
}),
resource.apiName,
resource.type,
resource.metadata || {},
resource.typeModel
? undefined
: (resource.type as SimpleAttributeType | DictAttributeType | SeparatorAttributeType),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export interface AttributeResource {
/** The field name in API communication. */
readonly apiName: string;
readonly type: AttributeType;
readonly metadata: AttributeMetadataResource | null;
/** The type of the attribute, filled in only if it is a model value (not simple value or dict). */
readonly typeModel: AttributeModel | null;
/** The dictionary type. Only filled in if type is dict. */
Expand All @@ -58,3 +59,8 @@ export interface AttributeResource {
readonly isMultiValue: boolean | null;
readonly requirementLevel: RequirementLevel;
}

export interface AttributeMetadataResource {
// For string and text:
readonly isMultiLine?: boolean;
}

0 comments on commit f58f30c

Please sign in to comment.