Skip to content

Commit

Permalink
Merge pull request #517 from datagov-cz/issue-al-174
Browse files Browse the repository at this point in the history
Issue AL-174
  • Loading branch information
bindeali authored Dec 12, 2023
2 parents 25b3248 + eb65633 commit 6615c00
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 13 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ REACT_APP_COMPONENTS=YWwtc2dvdi1zZXJ2ZXI6CiAgbmFtZTogU0dvViBTZXJ2aWNlCiAgdXJsOiB
BROWSER=none
REACT_APP_DEBUG=false
REACT_APP_AUTHENTICATION=true
REACT_APP_TERM_LANGUAGE=cs
1 change: 0 additions & 1 deletion src/components/modals/CreationModals.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ export const CreationModals: React.FC<Props> = (props) => {
}}
/>
<NewElemModal
projectLanguage={props.projectLanguage}
modal={modalAddElem}
configuration={props.elemConfiguration}
close={(
Expand Down
14 changes: 7 additions & 7 deletions src/components/modals/NewElemForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import classNames from "classnames";
import { Flags } from "../LanguageSelector";
import * as _ from "lodash";
import { ListLanguageControls } from "../../panels/detail/components/items/ListLanguageControls";
import { Environment } from "../../config/Environment";

interface Props {
projectLanguage: string;
termName: LanguageObject;
selectedVocabulary: string;
errorText: string;
Expand All @@ -34,7 +34,7 @@ export const NewElemForm: React.FC<Props> = (props) => {
const [activatedInputs, setActivatedInputs] = useState<string[]>([]);

useEffect(() => {
setActivatedInputs([AppSettings.canvasLanguage]);
setActivatedInputs([Environment.language]);
}, []);

const checkExists: (scheme: string, name: string) => boolean = (
Expand Down Expand Up @@ -68,7 +68,7 @@ export const NewElemForm: React.FC<Props> = (props) => {
names: ReturnType<typeof initLanguageObject>
) => {
let errorText = "";
if (names[AppSettings.canvasLanguage] === "") {
if (names[Environment.language] === "") {
errorText = Locale[AppSettings.interfaceLanguage].modalNewElemError;
} else if (Object.values(names).find((name) => checkExists(scheme, name))) {
errorText = Locale[AppSettings.interfaceLanguage].modalNewElemExistsError;
Expand All @@ -79,7 +79,7 @@ export const NewElemForm: React.FC<Props> = (props) => {
) {
errorText = Locale[AppSettings.interfaceLanguage].modalNewElemLengthError;
} else if (
createNewElemIRI(scheme, names[AppSettings.canvasLanguage]) ===
createNewElemIRI(scheme, names[Environment.language]) ===
WorkspaceVocabularies[getVocabularyFromScheme(scheme)].namespace
) {
errorText =
Expand Down Expand Up @@ -118,7 +118,7 @@ export const NewElemForm: React.FC<Props> = (props) => {
src={`https://purecatamphetamine.github.io/country-flag-icons/3x2/${Flags[lang]}.svg`}
alt={Languages[lang]}
/>
{lang === AppSettings.canvasLanguage ? "*" : ""}
{lang === Environment.language && <strong>*</strong>}
</InputGroup.Text>
<Form.Control
value={props.termName[lang]}
Expand Down Expand Up @@ -175,7 +175,7 @@ export const NewElemForm: React.FC<Props> = (props) => {
<option key={i} value={vocab}>
{getLabelOrBlank(
WorkspaceVocabularies[vocab].labels,
props.projectLanguage
AppSettings.canvasLanguage
)}
</option>
))}
Expand All @@ -188,7 +188,7 @@ export const NewElemForm: React.FC<Props> = (props) => {
}
${createNewElemIRI(
WorkspaceVocabularies[props.selectedVocabulary].glossary,
props.termName[AppSettings.interfaceLanguage]
props.termName[Environment.language]
)}`}</Alert>
)}
{props.errorText && <Alert variant="danger">{props.errorText}</Alert>}
Expand Down
5 changes: 2 additions & 3 deletions src/components/modals/NewElemModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import { ElemCreationConfiguration } from "./CreationModals";
import { initLanguageObject } from "../../function/FunctionEditVars";
import { Locale } from "../../config/Locale";
import { NewElemForm } from "./NewElemForm";
import { Environment } from "../../config/Environment";

interface Props {
modal: boolean;
close: (names?: State["termName"], vocabulary?: string) => void;
projectLanguage: string;
configuration: ElemCreationConfiguration;
}

Expand Down Expand Up @@ -76,7 +76,7 @@ export default class NewElemModal extends React.Component<Props, State> {
Locale[AppSettings.interfaceLanguage].modalNewElemError,
});
const input = document.getElementById(
"newElemLabelInput" + this.props.projectLanguage
"newElemLabelInput" + Environment.language
);
if (input) input.focus();
}}
Expand All @@ -93,7 +93,6 @@ export default class NewElemModal extends React.Component<Props, State> {
<Modal.Body>
{this.state.selectedVocabulary && (
<NewElemForm
projectLanguage={this.props.projectLanguage}
termName={this.state.termName}
selectedVocabulary={this.state.selectedVocabulary}
errorText={this.state.errorText}
Expand Down
1 change: 0 additions & 1 deletion src/components/modals/NewLinkModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,6 @@ export default class NewLinkModal extends React.Component<Props, State> {
/>
{this.state.create && (
<NewElemForm
projectLanguage={this.props.projectLanguage}
termName={this.state.termName}
selectedVocabulary={this.state.selectedVocabulary}
errorText={this.state.errorText}
Expand Down
9 changes: 8 additions & 1 deletion src/config/Environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import {
} from "@opendata-mvcr/assembly-line-shared";
import { Components } from "@opendata-mvcr/assembly-line-shared/dist/env/types";

type LocalVars = "PUBLIC_URL" | "AUTHENTICATION" | "DEBUG_DATA";
type LocalVars =
| "PUBLIC_URL"
| "AUTHENTICATION"
| "DEBUG_DATA"
| "TERM_LANGUAGE";

setProcessEnv(process.env);
const ENV = getEnvInstance<LocalVars>();
Expand All @@ -22,11 +26,14 @@ export const Environment: {
auth: boolean;
// Load local debug data instead of fetching off a DB
debug: boolean;
// Default language
language: string;
} = {
components: ENV.getComponents(),
context: ENV.get("CONTEXT"),
id: ENV.get("ID"),
url: ENV.get("URL"),
auth: ENV.get("AUTHENTICATION", "true") === "true",
debug: ENV.get("DEBUG", "true") === "true",
language: ENV.get("TERM_LANGUAGE"),
};
6 changes: 6 additions & 0 deletions src/interface/ContextInterface.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { StoreSettings } from "../config/Store";
import {
AppSettings,
Diagrams,
Languages,
Links,
WorkspaceElements,
WorkspaceLinks,
Expand Down Expand Up @@ -51,8 +52,13 @@ import {
updateProjectLinkParallel,
} from "../queries/update/UpdateLinkQueries";
import { processQuery, processTransaction } from "./TransactionInterface";
import { Environment } from "../config/Environment";

export function retrieveInfoFromURLParameters(): boolean {
if (!(Environment.language in Languages))
throw new Error(
"TERM_LANGUAGE environment variable is not listed in the Languages.ts object."
);
const isURL = require("is-url");
const urlParams = new URLSearchParams(window.location.search);
const URIContexts = urlParams.getAll("vocabulary");
Expand Down

0 comments on commit 6615c00

Please sign in to comment.