Skip to content
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

Correct catalog name validation in details form store #974

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/inputs/PrefixedName/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const validateCatalogName = (
): PrefixedName_Errors => {
const isBlank = !hasLength(value);

// See iff this field is allowed to be blank
// See if this field is allowed to be blank
if (!allowBlank && isBlank) {
return ['missing'];
}
Expand Down
1 change: 1 addition & 0 deletions src/lang/en-US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1311,6 +1311,7 @@ const PrefixedName: ResolvedIntlConfig['messages'] = {
const CustomErrors: ResolvedIntlConfig['messages'] = {
'custom.prefixedName.noAccessGrants': `You do not have the necessary ${CommonMessages['terms.permissions']}. Please contact an administrator.`,
'custom.prefixedName.prefix.missing': `please select an organization`,
'custom.prefixedName.prefix.invalid': `may only include ${CommonMessages['catalogName.limitations']} separated by forward slashes`,
'custom.prefixedName.name.missing': `please provide a name`,
'custom.prefixedName.name.unclean': `cannot contain ./ or ../`,
'custom.prefixedName.name.endingSlash': `cannot end with /`,
Expand Down
14 changes: 10 additions & 4 deletions src/stores/DetailsForm/Store.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { getConnectors_detailsForm } from 'api/connectors';
import { getLiveSpecs_detailsForm } from 'api/liveSpecsExt';
import { validateCatalogName } from 'components/inputs/PrefixedName/shared';
import { GlobalSearchParams } from 'hooks/searchParams/useGlobalSearchParams';
import produce from 'immer';
import { isEmpty, isEqual } from 'lodash';
Expand All @@ -19,6 +18,7 @@ import {
getStoreWithHydrationSettings,
} from 'stores/extensions/Hydration';
import { DetailsFormStoreNames } from 'stores/names';
import { PREFIX_NAME_PATTERN } from 'utils/misc-utils';
import { devtoolsOptions } from 'utils/store-utils';
import {
ConnectorVersionEvaluationOptions,
Expand Down Expand Up @@ -115,12 +115,18 @@ export const getInitialState = (
// Run validation on the name. This is done inside the input but
// having the input set custom errors causes issues as we basically
// make two near identical calls to the store and that causes problems.
const nameValidation = validateCatalogName(
state.details.data.entityName
const NAME_RE = new RegExp(
`^(${PREFIX_NAME_PATTERN}/)+${PREFIX_NAME_PATTERN}$`
);

const nameValidation = NAME_RE.test(
state.details.data.entityName
)
? null
: ['invalid'];

// We only have custom errors to handle name validation so it is okay
// to totally clear out customErrors and not inteligently update it
// to totally clear out customErrors and not intelligently update it
// As of Q3 2023
// TODO (intl) need to get a way for this kind of error to be translated
// and passed into the store
Expand Down