Skip to content

Commit

Permalink
Add missing validation messages
Browse files Browse the repository at this point in the history
  • Loading branch information
nizetic committed Feb 5, 2024
1 parent 543ec33 commit 961854c
Show file tree
Hide file tree
Showing 19 changed files with 359 additions and 392 deletions.
9 changes: 9 additions & 0 deletions src/common/store/progress-bar-steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,12 @@ export const useCompletedSteps = () => {

return completedSteps;
};

const progressBarSelector = s => s.isMissingDataErrorShown;
export const useValidationStatus = () => {
const isProgressBarErrorShown = useProgressBarStore(progressBarSelector);

return {
failed: isProgressBarErrorShown,
};
};
4 changes: 3 additions & 1 deletion src/common/translations/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const en = {
'error.file.size.exceeded': 'The file is too big.',
'error.file.type.incorrect': 'Please upload a {{type}} file.',
'error.invalid.facility.name': 'Facility name cannot exceed 100 characters.',
'error.invalid.building.name': 'Building name cannot exceed 100 characters.',
'error.invalid.level.name': 'Level name cannot exceed 100 characters.',
'error.invalid.feature.class.name': 'Feature class name contains restricted characters.',
'error.invalid.property.name': 'Property name contains restricted characters.',
Expand Down Expand Up @@ -77,7 +78,8 @@ const en = {
'error.upload.file.processing': 'Processing your package has failed. Please try again.',
'error.validation.failed.missing.info': 'Validation failed. Required information is missing or not valid.',
'error.vertical.extent.not.valid': 'Vertical extent must be a valid number greater than 0 and less than 100.',
'exterior.layer.not.selected.error': "Please select 'exterior' layer(s) to georeference your Facility",
'exterior.layer.not.selected.error': "Please select 'Exterior' layer(s) to georeference your Facility",
'footprint.layer.not.selected.error': "Please select 'Footprint' layer to georeference your Building",
exterior: 'Exterior',
footprint: 'Footprint',
'facility.levels': 'Facility Levels',
Expand Down
3 changes: 3 additions & 0 deletions src/components/dropdown/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { cx } from '@emotion/css';
import { Dropdown, Option, OptionGroup } from '@fluentui/react-components';
import FieldError from 'components/field-error';
import { useMemo, useRef, useState } from 'react';
import {
dropdownButton,
dropdownOption,
dropdownStyleObj,
dropdownWithError,
errorContainer,
filterInputStyle,
hackInputStyle,
Expand Down Expand Up @@ -73,6 +75,7 @@ const DropdownComponent = props => {
<div className={className}>
<Dropdown
size="small"
className={cx({ [dropdownWithError]: showError && message })}
style={dropdownStyleObj}
button={<div className={dropdownButton}>{children}</div>}
onOpenChange={onOpenChangeCallback}
Expand Down
4 changes: 4 additions & 0 deletions src/components/dropdown/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,7 @@ export const errorContainer = css`
align-items: center;
color: ${color.redError};
`;

export const dropdownWithError = css`
border-color: ${color.redError} !important;
`;
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ exports[`Field Error should render component when text is provided 1`] = `
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
font-size: 0.813rem;
color: #A80000;
}
.emotion-1 {
Expand Down
5 changes: 3 additions & 2 deletions src/components/field-error/field-error.style.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { css } from '@emotion/css';

import { fontSize } from 'common/styles';
import { color, fontSize } from 'common/styles';

export const errorContainer = css`
display: flex;
align-items: center;
font-size: ${fontSize.sm};
color: ${color.redError};
`;

export const fieldErrorIconStyle = css`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,15 @@ Object {
<div
class="emotion-0"
>
<div
class="emotion-1"
>
<div>
<div
class="emotion-2"
class="emotion-1"
>
foobar
<div
class="emotion-2"
>
foobar
</div>
</div>
</div>
<div
Expand Down Expand Up @@ -303,13 +305,15 @@ Object {
<div
class="emotion-0"
>
<div
class="emotion-1"
>
<div>
<div
class="emotion-2"
class="emotion-1"
>
foobar
<div
class="emotion-2"
>
foobar
</div>
</div>
</div>
<div
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { cx } from '@emotion/css';
import { TextField } from '@fluentui/react';
import FieldError from 'components/field-error';
import FieldLabel from 'components/field-label';
import DeleteIcon from 'pages/layers/delete-icon';
import PropTypes from 'prop-types';
import { useCallback, useEffect, useState } from 'react';
import { useCallback, useEffect, useMemo, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { TEST_ID } from './create-manifest';
import { TEST_ID } from '../../pages/create-manifest/create-manifest';
import {
browseButtonContentStyle,
browseButtonStyle,
Expand All @@ -14,7 +15,7 @@ import {
formRowStyle,
inputStyles,
textFieldStyle,
} from './create-manifest.style';
} from '../../pages/create-manifest/create-manifest.style';

const errors = {
fileSizeExceeded: 'error.file.size.exceeded',
Expand All @@ -39,6 +40,8 @@ const FileField = props => {
required = true,
file,
allowClear,
showError = true,
errorMessage,
} = props;

const { t } = useTranslation();
Expand Down Expand Up @@ -93,16 +96,23 @@ const FileField = props => {
// eslint-disable-next-line
}, []);

const message = useMemo(() => {
if (typeof errorMessage === 'string') return errorMessage;
if (typeof errorMessage === 'function') return errorMessage();
}, [errorMessage]);

const handleRemoveFile = () => {
setFilename('');
onFileSelect(null);
};

return (
<div className={formRowStyle}>
<FieldLabel required={required} tooltip={tooltip}>
{label}
</FieldLabel>
<div>
<FieldLabel required={required} tooltip={tooltip}>
{label}
</FieldLabel>
</div>
<div className={cx(fieldStyle, fieldClassName)}>
<TextField
value={filename}
Expand All @@ -114,6 +124,7 @@ const FileField = props => {
styles={inputStyles}
onClick={onTextFieldClick}
onKeyPress={onTextFieldKeyPress}
errorMessage={showError && message && <FieldError text={message} />}
/>
{allowClear && filename && <DeleteIcon onDelete={handleRemoveFile} />}
<label htmlFor={id} className={browseButtonStyle}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { render, screen, fireEvent } from '@testing-library/react';
import { fireEvent, render, screen } from '@testing-library/react';

import FileField from './file-field';
import FileField from '../../components/file-field/file-field';

const defaultProps = {
id: 'wootwoot',
Expand Down
Loading

0 comments on commit 961854c

Please sign in to comment.