Skip to content

Commit

Permalink
Add multilingual property to field definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
hatton committed Feb 5, 2024
1 parent 8705048 commit 774f502
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 20 deletions.
6 changes: 6 additions & 0 deletions configurations/ELAR/fields.json5
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,11 @@
visibility: "always",
description: "This is usually the same person as the Collection Steward."
}
],
session: [
{
key: "description",
multilingual: false
}
]
}
Binary file removed src/.yarn/install-state.gz
Binary file not shown.
16 changes: 9 additions & 7 deletions src/components/TextFieldEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface IProps {
validate?: (value: string) => boolean;
tooltip?: string;
showAffordancesAfter?: boolean;
LanguageAxes?: LanguageAxis[];
//LanguageAxes?: LanguageAxis[];
}

export const TextFieldEdit: React.FunctionComponent<
Expand Down Expand Up @@ -53,9 +53,10 @@ export const TextFieldEdit: React.FunctionComponent<
css={css`
background-color: white;
border: 1px solid black;
height: -webkit-fill-available;
`}
>
{["title", "description"].includes(props.field.key) ? (
{props.field.definition.multilingual ? (
testAxes.map((axis) => (
<>
<SingleLanguageTextFieldEdit {...props} axis={axis} />
Expand All @@ -74,10 +75,10 @@ const SingleLanguageTextFieldEdit: React.FunctionComponent<
> = mobx.observer((props) => {
const [invalid, setInvalid] = React.useState(false);
const [previous, setPrevious] = useState(props.field.text);
const { current: fieldId } = useRef(
"textfield-" +
(Math.random().toString(36) + "00000000000000000").slice(2, 7)
);
// const { current: fieldId } = useRef(
// "textfield-" +
// (Math.random().toString(36) + "00000000000000000").slice(2, 7)
// );

function onChange(event: React.FormEvent<HTMLTextAreaElement>, field: Field) {
// NB: Don't trim value here. It is tempting, because at the end of the day we'd
Expand Down Expand Up @@ -109,6 +110,7 @@ const SingleLanguageTextFieldEdit: React.FunctionComponent<
{props.axis && (
<span
css={css`
width: 2em; // it's important to nail down the width so that the following text blocks are aligned
color: #81c21e; // todo use theme with colors to match the form
`}
>
Expand All @@ -120,7 +122,7 @@ const SingleLanguageTextFieldEdit: React.FunctionComponent<
border: none;
padding-top: 0;
`}
id={fieldId}
id={props.field.key}
tabIndex={props.tabIndex}
autoFocus={props.autoFocus}
className={invalid ? "invalid" : ""}
Expand Down
2 changes: 1 addition & 1 deletion src/components/session/SessionForm.scss
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ $dateWidth: 148px; // enhance: why is it 148px?
textarea {
height: 100%;
// height: 8em;
overflow-y: scroll;
overflow-y: auto;
}
}
}
Expand Down
13 changes: 11 additions & 2 deletions src/model/field/ConfiguredFieldDefinitions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ describe("computeMergedCatalog", () => {
{
key: "title",
tabIndex: 99,
tooltip: "My special tooltip"
tooltip: "My special tooltip",
multilingual: true
},
{ key: "region", show: "never" }
]
Expand All @@ -24,7 +25,8 @@ describe("computeMergedCatalog", () => {
englishLabel: "Project ID", // changed to Project ID at ELAR request Dec 2019
tagInSayMoreClassic: "Title",
tabIndex: 99, // configuration changed
tooltip: "My special tooltip" // configuration added this
tooltip: "My special tooltip", // configuration added this
multilingual: true // configuration added this
});
});

Expand Down Expand Up @@ -63,4 +65,11 @@ describe("prepareFieldDefinitionCatalog", () => {
expect(catalog.person.find((f) => f.key == "name")).toBeDefined();
expect(catalog.person.find((f) => f.key == "howToContact")).toBeDefined();
});

it("desfault session description is monolingual", () => {
const catalog = makeFieldDefinitionCatalog("default");
expect(
catalog.session.find((f) => f.key == "description")!.multilingual
).toBe(false);
});
});
28 changes: 19 additions & 9 deletions src/model/field/ConfiguredFieldDefinitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,26 @@ import fs from "fs";
import { IFolderType } from "../Folder/Folder";
import { FieldDefinition } from "./FieldDefinition";
import JSON5 from "json5";
import raw from "../../../configurations/lameta/fields.json5?raw";
import jsonOfDefaultFieldConfig from "../../../configurations/lameta/fields.json5?raw";
import { locateDependencyForFilesystemCall } from "../../other/locateDependency";
import { NotifyError, NotifyNoBigDeal } from "../../components/Notify";
const catalogOfAllAvailableKnownFields = JSON5.parse(raw);

type FieldDefinitionCatalog = {
project: FieldDefinition[];
session: FieldDefinition[];
person: FieldDefinition[];
};
const catalogOfAllAvailableKnownFields: FieldDefinitionCatalog = JSON5.parse(
jsonOfDefaultFieldConfig
);
// for each field definition, if does not explicity set multilingual, set it to false
for (const area of ["project", "session", "person"]) {
for (const field of catalogOfAllAvailableKnownFields[area]) {
if (field.multilingual === undefined) {
field.multilingual = false;
}
}
}
export function getFieldDefinition(
folderType: IFolderType,
key: string
Expand Down Expand Up @@ -281,16 +296,11 @@ const countries = [

catalogOfAllAvailableKnownFields.project.find(
(d) => d.imdiRange === "http://www.mpi.nl/IMDI/Schema/Countries.xml"
).choices = countries;
)!.choices = countries;
catalogOfAllAvailableKnownFields.session.find(
(d) => d.imdiRange === "http://www.mpi.nl/IMDI/Schema/Countries.xml"
).choices = countries;
)!.choices = countries;

type FieldDefinitionCatalog = {
project: FieldDefinition[];
session: FieldDefinition[];
person: FieldDefinition[];
};
// we can't use the full definition becuase we want every field to be optional
type FieldDefinitionCustomization = {
key: string;
Expand Down
2 changes: 1 addition & 1 deletion src/model/field/FieldDefinition.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { CapitalCase } from "../../other/case";
import { IChoice } from "./Field";

export class FieldDefinition {
Expand All @@ -24,6 +23,7 @@ export class FieldDefinition {
//reconstitute when we load the files again.
public complexChoices?: IChoice[];
public multipleLines?: boolean;
public multilingual: boolean = false;
public tabIndex?: number = 99;
public markAsNotImdi?: boolean;
public imdiRange?: string;
Expand Down

0 comments on commit 774f502

Please sign in to comment.