Skip to content

Commit

Permalink
Merge branch 'languageChoices'
Browse files Browse the repository at this point in the history
  • Loading branch information
hatton committed May 4, 2024
2 parents fc6a6ed + 68a876c commit 6ce9de1
Show file tree
Hide file tree
Showing 26 changed files with 886 additions and 232 deletions.
5 changes: 1 addition & 4 deletions archive-configurations/ELAR/fields.json5
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
{
project: [
{ key: "collectionSubjectLanguages", visibility: "always" },
{ key: "collectionWorkingLanguages", visibility: "always" },

{ key: "collectionName", visibility: "always" },
// { key: "collectionName", visibility: "always" },
{ key: "collectionTitle", visibility: "always" },
{ key: "collectionDescription", visibility: "always" },
{
Expand Down
6 changes: 4 additions & 2 deletions archive-configurations/lameta/fields.json5
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,22 @@
key: "vernacularIso3CodeAndName",
englishLabel: "Subject Language",
xmlTag: "VernacularISO3CodeAndName",
visibility: "never", // replaced by collectionWorkingLanguages
type: "language",
tabIndex: 1
},
{
key: "analysisIso3CodeAndName",
englishLabel: "Working Language",
xmlTag: "AnalysisISO3CodeAndName",
visibility: "never", // replaced by collectionSubjectLanguages
type: "language",
tabIndex: 2
},
{
key: "collectionSubjectLanguages",
englishLabel: "Subject Languages",
visibility: "never",
xmlTag: "CollectionSubjectLanguages",
form: "primary",
type: "languageChoices",
controlProps: {
Expand All @@ -40,8 +42,8 @@
},
{
key: "collectionWorkingLanguages",
xmlTag: "CollectionWorkingLanguages",
englishLabel: "Working Languages",
visibility: "never",
form: "primary",
type: "languageChoices",
tabIndex: 2
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"@typescript-eslint/eslint-plugin": "^6.12.0",
"@typescript-eslint/parser": "^6.12.0",
"@vitejs/plugin-react": "^4.2.1",
"@vitest/ui": "^0.34.6",
"@vitest/ui": "^1.6.0",
"babel-core": "^7.0.0-bridge.0",
"babel-eslint": "10.1.0",
"babel-loader": "^8.1.0",
Expand Down Expand Up @@ -122,7 +122,7 @@
"vite-plugin-electron-renderer": "^0.12.1",
"vite-plugin-environment": "^1.1.3",
"vite-plugin-time-reporter": "^2.1.0",
"vitest": "^0.34.6",
"vitest": "^1.6.0",
"webdriverio": "^4.14.0"
},
"dependencies": {
Expand Down Expand Up @@ -262,15 +262,15 @@
},
"//remember to match this with github actions in main.yml": "",
"engines": {
"node": "18.16.0"
"node": "20.12.2"
},
"debug": {
"env": {
"VITE_DEV_SERVER_URL": "http://127.0.0.1:7777"
}
},
"volta": {
"node": "18.16.0",
"node": "20.12.2",
"yarn": "1.22.19"
},
"packageManager": "[email protected]"
Expand Down
4 changes: 2 additions & 2 deletions src/components/FieldLabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import { translateFieldLabel, translateTip } from "../other/localization";
import { observer } from "mobx-react";
import { tooltipBackground } from "../containers/theme";
import { Project } from "../model/Project/Project";
import { GetOtherConfigurationSettings } from "../model/Project/OtherConfigurationSettings";

export const FieldLabel: React.FunctionComponent<{
fieldDef: FieldDefinition;
Expand Down Expand Up @@ -81,7 +81,7 @@ export const FieldInfoAffordances: React.FunctionComponent<{
</CommaSeparatedIndicator>
)}

{Project.OtherConfigurationSettings.showImdiPreview &&
{GetOtherConfigurationSettings().showImdiPreview &&
props.fieldDef.omitFromImdi && <NotConsumedByArchiveIndicator />}
</div>
);
Expand Down
5 changes: 3 additions & 2 deletions src/components/FolderPane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
import { useEffect } from "react";
import { ErrorBoundary } from "./ErrorBoundary";
import { useLingui } from "@lingui/react";
import { GetOtherConfigurationSettings } from "../model/Project/OtherConfigurationSettings";

export interface IProps {
folder: Folder;
Expand Down Expand Up @@ -152,7 +153,7 @@ const FileTabs: React.FunctionComponent<
/>
</TabPanel>
);
const imdiTab = Project.OtherConfigurationSettings.showImdiPreview ? (
const imdiTab = GetOtherConfigurationSettings().showImdiPreview ? (
<Tab>IMDI {/* don't translate */}</Tab>
) : (
<></>
Expand All @@ -164,7 +165,7 @@ const FileTabs: React.FunctionComponent<
<></>
);

const imdiPanel = Project.OtherConfigurationSettings.showImdiPreview ? (
const imdiPanel = GetOtherConfigurationSettings().showImdiPreview ? (
<TabPanel>
<ErrorBoundary>
<ImdiView
Expand Down
49 changes: 39 additions & 10 deletions src/components/LanguageChoicesEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,23 @@ export const LanguageChoicesEditor: React.FunctionComponent<
};

const currentValueArray = props.field.text
.split(";")
.split(";") // TODO: move this serialization logic into the Field class
.filter((c) => c.length > 0)
.map((c) => c.trim())
.map((code) => ({
value: code,
label: getName(props.languageFinder, code)
}));
.map((code) => {
if (code.indexOf("|") > 0) {
const parts = code.split("|");
console.log("parts: " + JSON.stringify(parts));
return {
value: parts[0],
label: parts[1]
};
}
return {
value: code,
label: getName(props.languageFinder, code)
};
});

const loadMatchingOptions = (inputValue, callback) => {
const matches =
Expand Down Expand Up @@ -107,10 +117,24 @@ export const LanguageChoicesEditor: React.FunctionComponent<
loadOptions: _.debounce(loadMatchingOptions, 100),
value: currentValueArray,
styles: customStyles,
onChange: (v: any[]) => {
// if you delete the last member, you get null instead of []
const newChoices = v ? v : [];
const s: string = newChoices.map((o) => o.value).join(";");
onChange: (
v: Array<{ value: string; label: string; __isNew__: boolean }>
) => {
console.log("onChange: " + JSON.stringify(v));
// if any are new, change the value to "new"
const newChoices = v
? v.map((o) =>
o.__isNew__ ? { label: o.label, value: `qaa-x-${o.label}` } : o
)
: []; // if you delete the last member, you get null instead of []

// TODO: move this serialization logic into the Field class
const s: string = newChoices
.map((o) => {
return o.value;
})
.join(";"); // why semicolong instead of comma? The particpants field as used semicolon for years.
console.log("saving: " + s);
props.field.setValueFromString(s);
},
isMulti: true
Expand All @@ -120,7 +144,12 @@ export const LanguageChoicesEditor: React.FunctionComponent<
<div className={"field " + (props.className ? props.className : "")}>
<label>{props.field.labelInUILanguage}</label>
{props.canCreateNew ? (
<CreatableAsyncSelect {...selectProps}></CreatableAsyncSelect>
<CreatableAsyncSelect
{...selectProps}
onCreatableOptionCreate={(newOption) => {
window.alert("You created " + newOption.label);
}}
></CreatableAsyncSelect>
) : (
<AsyncSelect {...selectProps} />
)}
Expand Down
4 changes: 2 additions & 2 deletions src/components/Notes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { TextFieldEdit } from "./TextFieldEdit";
import { InfoIndicator } from "./FieldIndicators";
import { css } from "@emotion/react";
import { Trans, t } from "@lingui/macro";
import { Project } from "../model/Project/Project";
import { GetOtherConfigurationSettings } from "../model/Project/OtherConfigurationSettings";

export const Notes: React.FunctionComponent<{
field: Field;
Expand All @@ -19,7 +19,7 @@ export const Notes: React.FunctionComponent<{
overflow: auto;
`}
>
{Project.OtherConfigurationSettings.showImdiPreview && (
{GetOtherConfigurationSettings().showImdiPreview && (
<InfoIndicator
css={css`
margin-left: auto;
Expand Down
59 changes: 59 additions & 0 deletions src/components/lametaXmlView.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import * as React from "react";
import { css } from "@emotion/react";
import { Folder } from "../model/Folder/Folder";
import { Project } from "../model/Project/Project";
import SyntaxHighlighter, {
registerLanguage
} from "react-syntax-highlighter/light";
import xmlLang from "react-syntax-highlighter/languages/hljs/xml";
import syntaxStyle from "./ImdiSyntaxStyle";
registerLanguage("xml", xmlLang);

export const LametaXmlView: React.FunctionComponent<{
target: any;

// note, folder will equal project if we're generating at the project level
// otherwise, folder will be a session or person
project: Project;

folder: Folder;
}> = (props) => {
const [xml, setXml] = React.useState<string>("");

React.useEffect(() => {
if (props.target instanceof Project) {
setXml(props.project.metadataFile?.getXml(false) || "");
}
}, [props.target, props.project, props.folder]);

return (
<div
css={css`
// Enhance: the size and scrolling of this got all messed up with the switch to electron 6
// (though it could have been anything). It's currently a hack.
height: 500px;
width: 100%;
display: flex;
flex-direction: column;
flex-grow: 1; // <-- grow to fit available space and then...
overflow: hidden; // <-- ... show scroll if too big, instead of just going off the screen.
code,
code * {
font-family: sans-serif;
white-space: pre-wrap;
}
pre {
flex: 1; // fill space
}
`}
>
<SyntaxHighlighter
language="xml"
style={{ ...syntaxStyle, marginTop: 0, paddingTop: 0 }}
>
{xml}
</SyntaxHighlighter>
</div>
);
};
32 changes: 27 additions & 5 deletions src/components/project/ProjectTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ import { AuthorityLists } from "../../model/Project/AuthorityLists/AuthorityList
import { ArchiveConfigurationForm } from "./ArchiveConfigurationForm";
import { ImdiView } from "../ImdiView";
import "./ProjectTab.scss";
import { ParadisecView } from "../ParadisecView";
import userSettings from "../../other/UserSettings";
import { ThemeProvider } from "@mui/material";
import { useState } from "react";
import { createProjectTheme } from "../../containers/theme";
import { ParadisecView } from "../ParadisecView";
import { LametaXmlView } from "../lametaXmlView";
import { GetOtherConfigurationSettings } from "../../model/Project/OtherConfigurationSettings";

interface IProps {
project: Project;
Expand Down Expand Up @@ -71,20 +74,27 @@ export const ProjectTab: React.FunctionComponent<IProps> = observer((props) => {
<Tab className={"tab-project-other-docs"}>
<Trans>Other Documents</Trans>
</Tab>
{Project.OtherConfigurationSettings.showImdiPreview ? (
{GetOtherConfigurationSettings().showImdiPreview ? (
<Tab className={"tab-project-imdi"}>
IMDI {/* don't translate */}
</Tab>
) : (
<></>
)}
{Project.OtherConfigurationSettings.showParadisec ? (
{GetOtherConfigurationSettings().showParadisec ? (
<Tab className={"tab-project-paradisec"}>
PARADISEC {/* don't translate */}
</Tab>
) : (
<></>
)}
{userSettings.DeveloperMode ? (
<Tab className={"tab-project-lameta"}>
LaMeta {/* don't translate */}
</Tab>
) : (
<></>
)}
</TabList>
<TabPanel>
<AutoForm
Expand Down Expand Up @@ -159,7 +169,7 @@ export const ProjectTab: React.FunctionComponent<IProps> = observer((props) => {
<br />
</FolderPane>
</TabPanel>
{Project.OtherConfigurationSettings.showImdiPreview ? (
{GetOtherConfigurationSettings().showImdiPreview ? (
<TabPanel>
<ImdiView
target={props.project}
Expand All @@ -170,7 +180,7 @@ export const ProjectTab: React.FunctionComponent<IProps> = observer((props) => {
) : (
<></>
)}
{Project.OtherConfigurationSettings.showParadisec ? (
{GetOtherConfigurationSettings().showParadisec ? (
<TabPanel>
<ParadisecView
target={props.project}
Expand All @@ -181,6 +191,18 @@ export const ProjectTab: React.FunctionComponent<IProps> = observer((props) => {
) : (
<></>
)}
{/* if in developer mode, show LametaXmlView */}
{userSettings.DeveloperMode ? (
<TabPanel>
<LametaXmlView
target={props.project}
project={props.project}
folder={props.project}
/>
</TabPanel>
) : (
<></>
)}
</Tabs>
</ThemeProvider>
);
Expand Down
6 changes: 3 additions & 3 deletions src/export/ImdiBundler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export default class ImdiBundler {
imdiMode === IMDIMode.OPEX
? Path.basename(session.directory)
: "", // with opex, the metadata file goes into the folder it describes. Else, on the level above.
sanitizeForArchive(imdiFileName, true)
sanitizeForArchive(imdiFileName, "ASCII")
),
sessionImdi
);
Expand Down Expand Up @@ -234,7 +234,7 @@ export default class ImdiBundler {
// that renames that change the link name are used.
sanitizeForArchive(
f.getNameToUseWhenExportingUsingTheActualFile(),
true
"ASCII"
)
),
(progressMessage) => {}
Expand Down Expand Up @@ -327,7 +327,7 @@ export default class ImdiBundler {
fs.writeFileSync(
Path.join(
directoryForMetadataXmlFile,
sanitizeForArchive(imdiFileName, true)
sanitizeForArchive(imdiFileName, "ASCII")
),
imdiXml
);
Expand Down
File renamed without changes.
Loading

0 comments on commit 6ce9de1

Please sign in to comment.