forked from allyoucanmap/geonode-mapstore-client
-
Notifications
You must be signed in to change notification settings - Fork 127
Multilang in metadata editor #2324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
stefanocudini
wants to merge
12
commits into
GeoNode:master
Choose a base branch
from
stefanocudini:metadata_editor_i18n
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
36403b5
new comp TextWidgetMultiLang
stefanocudini be05782
rm comments
stefanocudini 90f9af3
clean code rm console and comments
stefanocudini 704469d
rm style inline
stefanocudini 098cab4
rewrite func schemaToMultiLang
stefanocudini ec64ea5
lint pass
stefanocudini cfb6b34
fix hardcoded langs code
stefanocudini 2440a07
fix placeholder i18n
stefanocudini 28e7964
fix getLanguageName()
stefanocudini b98bc93
fix i18n metadata title
stefanocudini e77efba
fix scrolling on title input
stefanocudini a96c263
fix labels
stefanocudini File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
232 changes: 232 additions & 0 deletions
232
...store_client/client/js/plugins/MetadataEditor/components/_widgets/TextWidgetMultiLang.jsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,232 @@ | ||
| /* | ||
| * Copyright 2026, GeoSolutions Sas. | ||
| * All rights reserved. | ||
| * | ||
| * This source code is licensed under the BSD-style license found in the | ||
| * LICENSE file in the root directory of this source tree. | ||
| */ | ||
|
|
||
| import React, { useState } from "react"; | ||
| import Form from "@rjsf/core"; | ||
| import validator from "@rjsf/validator-ajv8"; | ||
| import isEmpty from 'lodash/isEmpty'; | ||
| import isString from 'lodash/isString'; | ||
|
|
||
| import DefaultTextWidget from "@rjsf/core/lib/components/widgets/TextWidget"; | ||
| import DefaultTextareaWidget from '@rjsf/core/lib/components/widgets/TextareaWidget'; | ||
| import FieldTemplate from "../_templates/FieldTemplate"; | ||
| import IconWithTooltip from '../IconWithTooltip'; | ||
| import { | ||
| getTemplate, | ||
| getUiOptions | ||
| } from '@rjsf/utils'; | ||
|
|
||
| const TextWidgetMultiLang = (props) => { | ||
|
|
||
| //console.log("TextWidgetMultiLang props:", props); | ||
stefanocudini marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| const { formData, onChange, schema, required, formContext, registry } = props; | ||
stefanocudini marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const id = props.id || Math.random().toString(36).substring(7); | ||
| const { title, description } = schema; | ||
|
|
||
| //TODO map langs from schema when iso lang is change to 2 chars https://github.com/GeoNode/geonode/issues/13643#issuecomment-3728578749 | ||
| const languages = ["en", "hy", "ru"]; | ||
| const languageLong = (langCode) => { | ||
| return { | ||
| en: "English", | ||
| hy: "Armenian", | ||
| ru: "Russian" | ||
| }[langCode] || langCode.toUpperCase(); | ||
| } | ||
stefanocudini marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| const isTextarea = schema?.['ui:options']?.widget === 'textarea'; | ||
|
|
||
| const [currentLang, setCurrentLang] = useState(languages[0]); | ||
| const values = formData || {}; | ||
|
|
||
| const handleInputChange = (ev) => { | ||
| const value = isString(ev) ? ev : ev?.target?.value; | ||
| const newValue = { | ||
| ...values, | ||
| [currentLang]: value, | ||
| }; | ||
| console.log("handleInputChange value:", value, newValue); | ||
| onChange(newValue); | ||
| }; | ||
|
|
||
| return ( | ||
| <div className="form-group field field-string multilang-widget"> | ||
| <label className={`control-label${formContext?.capitalizeTitle ? ' capitalize' : ''}`}> | ||
| {title} | ||
| {required && <span className="required">{' '}*</span>} | ||
| {!isEmpty(description) ? <>{' '} | ||
| <IconWithTooltip tooltip={description} tooltipPosition={"right"} /> | ||
| </> : null} | ||
| </label> | ||
| {isTextarea ? ( | ||
| <DefaultTextareaWidget | ||
| id={id} | ||
| value={values[currentLang] || ""} | ||
| onChange={handleInputChange} | ||
| onFocus={() => {}} | ||
| options={{ rows: 5 }} | ||
| placeholder={`Type textarea in ${languageLong(currentLang)}...`} | ||
| /> | ||
| ) : | ||
| <input | ||
| type="text" | ||
| className="form-control" | ||
| value={values[currentLang] || ""} | ||
| onChange={handleInputChange} | ||
| placeholder={`Type text in ${languageLong(currentLang)}...`} | ||
| /> | ||
| } | ||
|
|
||
| <div style={{ marginTop: "8px", display: "flex", gap: "5px" }}> | ||
stefanocudini marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| {languages.map((lang) => ( | ||
| <button | ||
| key={lang} | ||
| type="button" | ||
| className={`btn btn-xs ${currentLang === lang ? "btn-primary" : "btn-outline-secondary"}`} | ||
| onClick={() => setCurrentLang(lang)} | ||
| > | ||
| {languageLong(lang)} | ||
| </button> | ||
| ))} | ||
| </div> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
|
|
||
| export default TextWidgetMultiLang; | ||
|
|
||
|
|
||
| /** | ||
| * schema definition for multilang fields: | ||
| * https://github.com/GeoNode/geonode/issues/13643 | ||
| * | ||
| * loaded from backend as: http://localhost/api/v2/metadata/schema?format=json | ||
| * | ||
| * | ||
| * "title": { | ||
| "type": "string", | ||
| "title": "Title", | ||
| "description": "name by which the cited resource is known", | ||
| "maxLength": 255, | ||
| "geonode:handler": "base", | ||
| "geonode:required": true, | ||
| "geonode:multilang": true, | ||
| "readOnly": true, | ||
| "ui:widget": "hidden" | ||
| }, | ||
| "title_multilang_en": { | ||
| "type": [ | ||
| "string", | ||
| "null" | ||
| ], | ||
| "geonode:handler": "sparse", | ||
| "geonode:multilang-lang": "en", | ||
| "geonode:multilang-group": "title", | ||
| "title": "Title [EN] !", | ||
| "geonode:required": true, | ||
| "description": "name by which the cited resource is known" | ||
| }, | ||
| "title_multilang_hy": { | ||
| "type": [ | ||
| "string", | ||
| "null" | ||
| ], | ||
| "geonode:handler": "sparse", | ||
| "geonode:multilang-lang": "hy", | ||
| "geonode:multilang-group": "title", | ||
| "title": "Title [HY]" | ||
| }, | ||
| "title_multilang_ru": { | ||
| "type": [ | ||
| "string", | ||
| "null" | ||
| ], | ||
| "geonode:handler": "sparse", | ||
| "geonode:multilang-lang": "ru", | ||
| "geonode:multilang-group": "title", | ||
| "title": "Title [RU]" | ||
| }, | ||
| textarea widgets | ||
| "abstract": { | ||
| "type": "string", | ||
| "title": "Abstract", | ||
| "description": "brief narrative summary of the content of the resource(s)", | ||
| "maxLength": 2000, | ||
| "ui:options": { | ||
| "widget": "hidden", | ||
| "rows": 5 | ||
| }, | ||
| "geonode:handler": "base", | ||
| "geonode:required": true, | ||
| "geonode:multilang": true, | ||
| "readOnly": true | ||
| }, | ||
| "abstract_multilang_en": { | ||
| "type": [ | ||
| "string", | ||
| "null" | ||
| ], | ||
| "geonode:handler": "sparse", | ||
| "geonode:multilang-lang": "en", | ||
| "geonode:multilang-group": "abstract", | ||
| "title": "Abstract [EN] !", | ||
| "geonode:required": true, | ||
| "description": "brief narrative summary of the content of the resource(s)", | ||
| "ui:options": { | ||
| "widget": "textarea", | ||
| "rows": 5 | ||
| } | ||
| } | ||
| * | ||
| * | ||
| */ | ||
|
|
||
| // // schema of form | ||
| // const schema = { | ||
| // title: "Esempio Form Multilingua", | ||
| // type: "object", | ||
| // properties: { | ||
| // titolo_prodotto: { | ||
| // type: "object", | ||
| // title: "Nome Prodotto (Multilingua)", | ||
| // properties: { | ||
| // it: { type: "string" }, | ||
| // en: { type: "string" }, | ||
| // fr: { type: "string" }, | ||
| // }, | ||
| // }, | ||
| // }, | ||
| // }; | ||
|
|
||
| // // uiSchema of rjsf form | ||
| // const uiSchema = { | ||
| // titolo_prodotto: { | ||
| // "ui:widget": "MultiLangWidget", | ||
| // "ui:options": { | ||
| // languages: ["it", "en", "es"], // Personalizzabile qui | ||
| // }, | ||
| // }, | ||
| // }; | ||
|
|
||
| // USAGE EXAMPLE: | ||
| // register widget on Form | ||
| // const widgets = { | ||
| // MultiLangWidget: MultiLangWidget | ||
| // }; | ||
| // export const TextWidgetMultiLang = () => ( | ||
| // <Form | ||
| // schema={schema} | ||
| // uiSchema={uiSchema} | ||
| // widgets={widgets} | ||
| // validator={validator} | ||
| // onChange={(e) => console.log("Data:", e.formData)} | ||
| // /> | ||
| // ); | ||
stefanocudini marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.