forked from geosolutions-it/geonode-mapstore-client
-
Notifications
You must be signed in to change notification settings - Fork 124
#2157: Refactor of the create dataset page and attribute table validation #2164
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
dsuren1
wants to merge
6
commits into
master
Choose a base branch
from
issue_2157
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 all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c19641e
#2157: Refactor of the create dataset page and attribute table valida…
dsuren1 7d99243
#2158: JSONSchema file upload for create dataset page
dsuren1 37b48e6
Merge commit '795df1bbdc255e06638ecf457ee694be7b9f7152' into issue_2157
dsuren1 b845783
json schema jsdoc
dsuren1 b655a2f
Merge commit '40d7a34654914d8f945dcd28c4ac92ba37a345b9' into issue_2157
dsuren1 782829d
update async upload process
dsuren1 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
185 changes: 185 additions & 0 deletions
185
..._mapstore_client/client/js/plugins/CreateDataset/components/CreateDatasetAttributeRow.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,185 @@ | ||
/* | ||
* Copyright 2025, 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 from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { FormGroup, FormControl, Checkbox, HelpBlock } from 'react-bootstrap'; | ||
|
||
import FlexBox from '@mapstore/framework/components/layout/FlexBox'; | ||
import Message from '@mapstore/framework/components/I18N/Message'; | ||
import { getMessageById } from '@mapstore/framework/utils/LocaleUtils'; | ||
|
||
import { AttributeTypes, getAttributeControlId, RestrictionsTypes } from '../utils/CreateDatasetUtils'; | ||
import RangeRestriction from './RangeRestriction'; | ||
import EnumRestriction from './EnumRestriction'; | ||
|
||
const CreateDatasetAttributeRow = ({ | ||
data, | ||
geometryAttribute, | ||
disabled, | ||
tools, | ||
onChange, | ||
getErrorByPath = () => undefined, | ||
index | ||
}, context) => { | ||
|
||
const errors = { | ||
name: getErrorByPath(`/attributes/${index}/name`), | ||
restrictionsType: getErrorByPath(`/attributes/${index}/restrictionsType`), | ||
restrictionsRangeMin: getErrorByPath(`/attributes/${index}/restrictionsRangeMin`), | ||
restrictionsRangeMax: getErrorByPath(`/attributes/${index}/restrictionsRangeMax`) | ||
}; | ||
|
||
const typesOptions = geometryAttribute | ||
? [ | ||
{ value: AttributeTypes.Point, labelId: 'gnviewer.points' }, | ||
{ value: AttributeTypes.LineString, labelId: 'gnviewer.lines' }, | ||
{ value: AttributeTypes.Polygon, labelId: 'gnviewer.polygons' }] | ||
: [ | ||
{ value: AttributeTypes.String, labelId: 'gnviewer.string' }, | ||
{ value: AttributeTypes.Integer, labelId: 'gnviewer.integer' }, | ||
{ value: AttributeTypes.Float, labelId: 'gnviewer.float' }, | ||
{ value: AttributeTypes.Date, labelId: 'gnviewer.date' } | ||
]; | ||
|
||
const restrictionsOptions = [ | ||
AttributeTypes.Integer, | ||
AttributeTypes.Float, | ||
AttributeTypes.String | ||
].includes(data?.type) | ||
? [ | ||
{ value: RestrictionsTypes.None, labelId: 'gnviewer.none' }, | ||
...(data?.type !== AttributeTypes.String | ||
? [{ value: RestrictionsTypes.Range, labelId: 'gnviewer.range' }] | ||
: [] | ||
), | ||
{ value: RestrictionsTypes.Options, labelId: 'gnviewer.options' } | ||
] | ||
: [{ value: RestrictionsTypes.None, labelId: 'gnviewer.none' }]; | ||
|
||
function handleOnChange(properties) { | ||
onChange({ | ||
...data, | ||
...properties | ||
}); | ||
} | ||
|
||
function handleTypeChange(event) { | ||
const newType = event.target.value; | ||
const currentType = data?.type; | ||
|
||
// If type is changing, clear restrictions and set to default | ||
if (newType !== currentType) { | ||
onChange({ | ||
...data, | ||
type: newType, | ||
restrictionsType: RestrictionsTypes.None, | ||
restrictionsRangeMin: null, | ||
restrictionsRangeMax: null, | ||
restrictionsOptions: [] | ||
}); | ||
} else { | ||
handleOnChange({ type: newType }); | ||
} | ||
} | ||
|
||
return ( | ||
<tr className="gn-dataset-attribute"> | ||
<td className="gn-attribute-name"> | ||
<FormGroup | ||
controlId={getAttributeControlId(data, 'name')} | ||
validationState={errors?.name ? 'error' : undefined} | ||
> | ||
<FormControl | ||
type="text" | ||
value={data?.name || ''} | ||
disabled={!!geometryAttribute || disabled} | ||
onChange={(event) => handleOnChange({ name: event.target.value })} | ||
/> | ||
{errors?.name ? <HelpBlock><Message msgId={errors.name} /></HelpBlock> : null} | ||
</FormGroup> | ||
</td> | ||
<td className="gn-attribute-type"> | ||
<FormGroup controlId={getAttributeControlId(data, 'type')}> | ||
<FormControl | ||
value={data?.type || ''} | ||
componentClass="select" | ||
placeholder="select" | ||
onChange={handleTypeChange} | ||
disabled={disabled} | ||
> | ||
{typesOptions.map(({ labelId, value }) => | ||
<option key={value} value={value}> | ||
{getMessageById(context.messages, labelId)} | ||
</option> | ||
)} | ||
</FormControl> | ||
</FormGroup> | ||
</td> | ||
<td className="gn-attribute-nillable"> | ||
<FormGroup controlId={getAttributeControlId(data, 'nillable')}> | ||
<Checkbox | ||
style={{ paddingTop: 6 }} | ||
checked={!!data?.nillable} | ||
disabled={!!geometryAttribute || disabled} | ||
onChange={(event) => | ||
handleOnChange({ nillable: event.target.checked }) | ||
} | ||
/> | ||
</FormGroup> | ||
</td> | ||
<td> | ||
<FlexBox column gap="sm"> | ||
<FormGroup | ||
controlId={getAttributeControlId(data, 'restrictions')} | ||
validationState={errors?.restrictionsType ? 'error' : undefined}> | ||
<FormControl | ||
value={data?.restrictionsType} | ||
componentClass="select" | ||
placeholder="select" | ||
disabled={!!geometryAttribute || disabled} | ||
onChange={(event) => | ||
handleOnChange({ restrictionsType: event.target.value }) | ||
} | ||
> | ||
{restrictionsOptions.map(({ labelId, value }) => | ||
<option key={value} value={value}> | ||
{getMessageById(context.messages, labelId)} | ||
</option> | ||
)} | ||
</FormControl> | ||
{errors?.restrictionsType ? <HelpBlock>{errors.restrictionsType}</HelpBlock> : null} | ||
</FormGroup> | ||
{data?.restrictionsType === RestrictionsTypes.Range ? | ||
<RangeRestriction | ||
errors={errors} | ||
data={data} | ||
handleOnChange={handleOnChange} | ||
disabled={disabled} | ||
/> : null} | ||
{data?.restrictionsType === RestrictionsTypes.Options | ||
? <EnumRestriction | ||
index={index} | ||
data={data} | ||
handleOnChange={handleOnChange} | ||
getErrorByPath={getErrorByPath} | ||
disabled={disabled} | ||
/> : null} | ||
</FlexBox> | ||
</td> | ||
<td className="gn-attribute-tools"> | ||
{tools} | ||
</td> | ||
</tr> | ||
); | ||
}; | ||
|
||
CreateDatasetAttributeRow.contextTypes = { | ||
messages: PropTypes.object | ||
}; | ||
|
||
export default CreateDatasetAttributeRow; |
94 changes: 94 additions & 0 deletions
94
geonode_mapstore_client/client/js/plugins/CreateDataset/components/EnumRestriction.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,94 @@ | ||
/* | ||
* Copyright 2025, 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 from "react"; | ||
import { v4 as uuid } from 'uuid'; | ||
import { FormGroup, FormControl, HelpBlock, Glyphicon } from "react-bootstrap"; | ||
|
||
import FlexBox from "@mapstore/framework/components/layout/FlexBox"; | ||
import Message from "@mapstore/framework/components/I18N/Message"; | ||
import Button from "@mapstore/framework/components/layout/Button"; | ||
import Text from "@mapstore/framework/components/layout/Text"; | ||
|
||
import { AttributeTypes, getAttributeControlId, parseNumber } from "../utils/CreateDatasetUtils"; | ||
|
||
const EnumRestriction = ({ | ||
index, | ||
data = {}, | ||
handleOnChange = () => {}, | ||
getErrorByPath = () => {}, | ||
disabled | ||
}) => { | ||
return ( | ||
<FlexBox column wrap gap="sm"> | ||
<FlexBox gap="sm" column component="ul"> | ||
{(data?.restrictionsOptions || []).map((option, idx) => { | ||
const optionsError = { | ||
value: getErrorByPath(`/attributes/${index}/restrictionsOptions/${idx}/value`) | ||
}; | ||
return ( | ||
<FlexBox component="li" gap="sm" key={option.id}> | ||
<Text style={{ paddingTop: 6 }}>●</Text> | ||
<FlexBox.Fill | ||
component={FormGroup} | ||
key={option.id} | ||
validationState={optionsError?.value ? 'error' : undefined} | ||
controlId={getAttributeControlId(data, `option-${option.id}`)} | ||
> | ||
<FormControl | ||
type={data?.type === AttributeTypes.String ? "text" : "number"} | ||
value={option.value} | ||
disabled={disabled} | ||
onChange={(event) => handleOnChange({ | ||
restrictionsOptions: (data?.restrictionsOptions || []) | ||
.map((opt) => { | ||
return opt.id !== option.id | ||
? opt : { | ||
...option, | ||
value: data?.type === AttributeTypes.String | ||
? event.target.value | ||
: parseNumber(event.target.value) | ||
}; | ||
}) | ||
})} | ||
/> | ||
{optionsError?.value ? <HelpBlock> | ||
<Message msgId={optionsError.value} /> | ||
</HelpBlock> : null} | ||
</FlexBox.Fill> | ||
<Button square | ||
onClick={() => handleOnChange({ | ||
restrictionsOptions: (data?.restrictionsOptions || []) | ||
.filter(opt => opt.id !== option.id) | ||
})} | ||
disabled={disabled}> | ||
<Glyphicon glyph="trash" /> | ||
</Button> | ||
</FlexBox> | ||
); | ||
})} | ||
<div> | ||
<Button size="sm" onClick={() => handleOnChange({ | ||
restrictionsOptions: [ | ||
...(data?.restrictionsOptions || []), | ||
{ | ||
id: uuid(), | ||
value: '' | ||
} | ||
] | ||
})} | ||
disabled={disabled}> | ||
<Glyphicon glyph="plus" /> | ||
{' '}<Message msgId="gnviewer.addOption" /> | ||
</Button> | ||
</div> | ||
</FlexBox> | ||
</FlexBox> | ||
); | ||
}; | ||
|
||
export default EnumRestriction; |
72 changes: 72 additions & 0 deletions
72
geonode_mapstore_client/client/js/plugins/CreateDataset/components/RangeRestriction.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,72 @@ | ||
/* | ||
* Copyright 2025, 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 from "react"; | ||
import { FormGroup, FormControl, ControlLabel, HelpBlock } from "react-bootstrap"; | ||
|
||
import FlexBox from "@mapstore/framework/components/layout/FlexBox"; | ||
import Message from "@mapstore/framework/components/I18N/Message"; | ||
|
||
import { getAttributeControlId, parseNumber } from "../utils/CreateDatasetUtils"; | ||
|
||
const RangeRestriction = ({ | ||
errors = {}, | ||
data = {}, | ||
handleOnChange = () => {}, | ||
disabled | ||
}) => { | ||
return ( | ||
<FlexBox centerChildrenVertically wrap gap="sm"> | ||
<FlexBox.Fill | ||
flexBox | ||
component={FormGroup} | ||
validationState={errors?.restrictionsRangeMin ? 'error' : undefined} | ||
controlId={getAttributeControlId(data, 'restrictions-min')} | ||
centerChildrenVertically | ||
gap="sm" | ||
> | ||
<ControlLabel><Message msgId="gnviewer.min" /></ControlLabel> | ||
<FormControl | ||
type="number" | ||
value={data?.restrictionsRangeMin} | ||
disabled={disabled} | ||
onChange={(event) => handleOnChange({ | ||
restrictionsRangeMin: parseNumber(event.target.value) | ||
})} | ||
/> | ||
{errors?.restrictionsRangeMin ? | ||
<HelpBlock> | ||
<Message msgId={errors.restrictionsRangeMin} /> | ||
</HelpBlock> : null} | ||
</FlexBox.Fill> | ||
<FlexBox.Fill | ||
flexBox | ||
component={FormGroup} | ||
validationState={errors?.restrictionsRangeMax ? 'error' : undefined} | ||
controlId={getAttributeControlId(data, 'restrictions-max')} | ||
gap="sm" | ||
centerChildrenVertically | ||
> | ||
<ControlLabel><Message msgId="gnviewer.max" /></ControlLabel> | ||
<FormControl | ||
type="number" | ||
value={data?.restrictionsRangeMax} | ||
disabled={disabled} | ||
onChange={(event) => handleOnChange({ | ||
restrictionsRangeMax: parseNumber(event.target.value) | ||
})} | ||
/> | ||
{errors?.restrictionsRangeMax | ||
? <HelpBlock> | ||
<Message msgId={errors.restrictionsRangeMax} /> | ||
</HelpBlock> : null} | ||
</FlexBox.Fill> | ||
</FlexBox> | ||
); | ||
}; | ||
|
||
export default RangeRestriction; |
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.