fix(my-joy-beta): validate tags and metadata
This commit is contained in:
parent
4593980883
commit
3bfc7bd14b
@ -18,6 +18,8 @@ const FORM_NAME_CREATE = 'CREATE-INSTANCE-METADATA-ADD';
|
|||||||
const FORM_NAME_EDIT = i => `CREATE-INSTANCE-METADATA-EDIT-${i}`;
|
const FORM_NAME_EDIT = i => `CREATE-INSTANCE-METADATA-EDIT-${i}`;
|
||||||
|
|
||||||
export const Metadata = ({
|
export const Metadata = ({
|
||||||
|
id,
|
||||||
|
step,
|
||||||
metadata = [],
|
metadata = [],
|
||||||
expanded,
|
expanded,
|
||||||
proceeded,
|
proceeded,
|
||||||
@ -30,8 +32,8 @@ export const Metadata = ({
|
|||||||
handleChangeAddOpen,
|
handleChangeAddOpen,
|
||||||
handleNext,
|
handleNext,
|
||||||
handleEdit,
|
handleEdit,
|
||||||
id,
|
shouldAsyncValidate,
|
||||||
step
|
asyncValidate
|
||||||
}) => (
|
}) => (
|
||||||
<Fragment>
|
<Fragment>
|
||||||
<Title
|
<Title
|
||||||
@ -71,6 +73,8 @@ export const Metadata = ({
|
|||||||
destroyOnUnmount={false}
|
destroyOnUnmount={false}
|
||||||
forceUnregisterOnUnmount={true}
|
forceUnregisterOnUnmount={true}
|
||||||
onSubmit={newValue => handleUpdateMetadata(index, newValue)}
|
onSubmit={newValue => handleUpdateMetadata(index, newValue)}
|
||||||
|
shouldAsyncValidate={shouldAsyncValidate}
|
||||||
|
asyncValidate={asyncValidate}
|
||||||
>
|
>
|
||||||
{props => (
|
{props => (
|
||||||
<Fragment>
|
<Fragment>
|
||||||
@ -102,6 +106,8 @@ export const Metadata = ({
|
|||||||
destroyOnUnmount={false}
|
destroyOnUnmount={false}
|
||||||
forceUnregisterOnUnmount={true}
|
forceUnregisterOnUnmount={true}
|
||||||
onSubmit={handleAddMetadata}
|
onSubmit={handleAddMetadata}
|
||||||
|
shouldAsyncValidate={shouldAsyncValidate}
|
||||||
|
asyncValidate={asyncValidate}
|
||||||
>
|
>
|
||||||
{props =>
|
{props =>
|
||||||
expanded && addOpen ? (
|
expanded && addOpen ? (
|
||||||
@ -166,6 +172,22 @@ export default compose(
|
|||||||
handleEdit: () => {
|
handleEdit: () => {
|
||||||
return history.push(`/~create/metadata${history.location.search}`);
|
return history.push(`/~create/metadata${history.location.search}`);
|
||||||
},
|
},
|
||||||
|
shouldAsyncValidate: ({ trigger }) => {
|
||||||
|
return trigger === 'submit';
|
||||||
|
},
|
||||||
|
asyncValidate: async ({ name = '', value = '' }) => {
|
||||||
|
const isNameInvalid = name.length === 0;
|
||||||
|
const isValueInvalid = value.length === 0;
|
||||||
|
|
||||||
|
if (!isNameInvalid && !isValueInvalid) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw {
|
||||||
|
name: isNameInvalid,
|
||||||
|
value: isValueInvalid
|
||||||
|
};
|
||||||
|
},
|
||||||
handleAddMetadata: value => {
|
handleAddMetadata: value => {
|
||||||
const toggleToClosed = set({
|
const toggleToClosed = set({
|
||||||
name: `create-instance-metadata-add-open`,
|
name: `create-instance-metadata-add-open`,
|
||||||
|
@ -26,6 +26,7 @@ const FORM_NAME_CREATE = 'CREATE-INSTANCE-TAGS-ADD';
|
|||||||
const FORM_NAME_EDIT = i => `CREATE-INSTANCE-TAGS-EDIT-${i}`;
|
const FORM_NAME_EDIT = i => `CREATE-INSTANCE-TAGS-EDIT-${i}`;
|
||||||
|
|
||||||
export const Tags = ({
|
export const Tags = ({
|
||||||
|
step,
|
||||||
tags = [],
|
tags = [],
|
||||||
expanded,
|
expanded,
|
||||||
proceeded,
|
proceeded,
|
||||||
@ -37,8 +38,9 @@ export const Tags = ({
|
|||||||
handleCancelEdit,
|
handleCancelEdit,
|
||||||
handleChangeAddOpen,
|
handleChangeAddOpen,
|
||||||
handleNext,
|
handleNext,
|
||||||
step,
|
handleEdit,
|
||||||
handleEdit
|
shouldAsyncValidate,
|
||||||
|
asyncValidate
|
||||||
}) => (
|
}) => (
|
||||||
<Fragment>
|
<Fragment>
|
||||||
<Title
|
<Title
|
||||||
@ -86,6 +88,8 @@ export const Tags = ({
|
|||||||
destroyOnUnmount={false}
|
destroyOnUnmount={false}
|
||||||
forceUnregisterOnUnmount={true}
|
forceUnregisterOnUnmount={true}
|
||||||
onSubmit={handleAddTag}
|
onSubmit={handleAddTag}
|
||||||
|
shouldAsyncValidate={shouldAsyncValidate}
|
||||||
|
asyncValidate={asyncValidate}
|
||||||
>
|
>
|
||||||
{props =>
|
{props =>
|
||||||
expanded && addOpen ? (
|
expanded && addOpen ? (
|
||||||
@ -147,6 +151,22 @@ export default compose(
|
|||||||
handleEdit: () => {
|
handleEdit: () => {
|
||||||
return history.push(`/~create/tags${history.location.search}`);
|
return history.push(`/~create/tags${history.location.search}`);
|
||||||
},
|
},
|
||||||
|
shouldAsyncValidate: ({ trigger }) => {
|
||||||
|
return trigger === 'submit';
|
||||||
|
},
|
||||||
|
asyncValidate: async ({ name = '', value = '' }) => {
|
||||||
|
const isNameInvalid = name.length === 0;
|
||||||
|
const isValueInvalid = value.length === 0;
|
||||||
|
|
||||||
|
if (!isNameInvalid && !isValueInvalid) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw {
|
||||||
|
name: isNameInvalid,
|
||||||
|
value: isValueInvalid
|
||||||
|
};
|
||||||
|
},
|
||||||
handleAddTag: value => {
|
handleAddTag: value => {
|
||||||
const toggleToClosed = set({
|
const toggleToClosed = set({
|
||||||
name: `create-instance-tags-add-open`,
|
name: `create-instance-tags-add-open`,
|
||||||
|
@ -47,12 +47,19 @@ export const Metadata = ({
|
|||||||
handleCancel,
|
handleCancel,
|
||||||
handleCreate,
|
handleCreate,
|
||||||
handleUpdate,
|
handleUpdate,
|
||||||
handleRemove
|
handleRemove,
|
||||||
|
shouldAsyncValidate,
|
||||||
|
asyncValidate
|
||||||
}) => {
|
}) => {
|
||||||
const _loading = !(loading && !metadata.length) ? null : <StatusLoader />;
|
const _loading = !(loading && !metadata.length) ? null : <StatusLoader />;
|
||||||
|
|
||||||
const _add = addOpen ? (
|
const _add = addOpen ? (
|
||||||
<ReduxForm form={ADD_FORM_NAME} onSubmit={handleCreate}>
|
<ReduxForm
|
||||||
|
form={ADD_FORM_NAME}
|
||||||
|
onSubmit={handleCreate}
|
||||||
|
shouldAsyncValidate={shouldAsyncValidate}
|
||||||
|
asyncValidate={asyncValidate}
|
||||||
|
>
|
||||||
{props => (
|
{props => (
|
||||||
<MetadataAddForm
|
<MetadataAddForm
|
||||||
{...props}
|
{...props}
|
||||||
@ -87,6 +94,8 @@ export const Metadata = ({
|
|||||||
initialValues={initialValues}
|
initialValues={initialValues}
|
||||||
destroyOnUnmount={false}
|
destroyOnUnmount={false}
|
||||||
onSubmit={handleUpdate}
|
onSubmit={handleUpdate}
|
||||||
|
shouldAsyncValidate={shouldAsyncValidate}
|
||||||
|
asyncValidate={asyncValidate}
|
||||||
>
|
>
|
||||||
{props => (
|
{props => (
|
||||||
<MetadataEditForm
|
<MetadataEditForm
|
||||||
@ -198,15 +207,34 @@ export default compose(
|
|||||||
} = ownProps;
|
} = ownProps;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
handleCancel: form =>
|
handleCancel: form => {
|
||||||
dispatch([
|
return dispatch([
|
||||||
set({ name: `${form}-expanded`, value: false }),
|
set({ name: `${form}-expanded`, value: false }),
|
||||||
dispatch(reset(form))
|
dispatch(reset(form))
|
||||||
]),
|
]);
|
||||||
handleToggleAddOpen: value =>
|
},
|
||||||
dispatch(set({ name: `add-metadata-open`, value })),
|
handleToggleAddOpen: value => {
|
||||||
handleUpdateExpanded: (form, expanded) =>
|
return dispatch(set({ name: `add-metadata-open`, value }));
|
||||||
dispatch(set({ name: `${form}-expanded`, value: expanded })),
|
},
|
||||||
|
handleUpdateExpanded: (form, expanded) => {
|
||||||
|
return dispatch(set({ name: `${form}-expanded`, value: expanded }));
|
||||||
|
},
|
||||||
|
shouldAsyncValidate: ({ trigger }) => {
|
||||||
|
return trigger === 'submit';
|
||||||
|
},
|
||||||
|
asyncValidate: async ({ name = '', value = '' }) => {
|
||||||
|
const isNameInvalid = name.length === 0;
|
||||||
|
const isValueInvalid = value.length === 0;
|
||||||
|
|
||||||
|
if (!isNameInvalid && !isValueInvalid) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw {
|
||||||
|
name: isNameInvalid,
|
||||||
|
value: isValueInvalid
|
||||||
|
};
|
||||||
|
},
|
||||||
handleCreate: async ({ name, value }) => {
|
handleCreate: async ({ name, value }) => {
|
||||||
// call mutation
|
// call mutation
|
||||||
const [err] = await intercept(
|
const [err] = await intercept(
|
||||||
|
@ -48,7 +48,9 @@ export const Tags = ({
|
|||||||
handleCancel,
|
handleCancel,
|
||||||
handleEdit,
|
handleEdit,
|
||||||
handleRemove,
|
handleRemove,
|
||||||
handleCreate
|
handleCreate,
|
||||||
|
shouldAsyncValidate,
|
||||||
|
asyncValidate
|
||||||
}) => {
|
}) => {
|
||||||
const _loading = !(loading && !tags.length) ? null : <StatusLoader />;
|
const _loading = !(loading && !tags.length) ? null : <StatusLoader />;
|
||||||
|
|
||||||
@ -57,6 +59,8 @@ export const Tags = ({
|
|||||||
form={ADD_FORM_NAME}
|
form={ADD_FORM_NAME}
|
||||||
onSubmit={handleCreate}
|
onSubmit={handleCreate}
|
||||||
onCancel={() => handleToggleAddOpen(false)}
|
onCancel={() => handleToggleAddOpen(false)}
|
||||||
|
shouldAsyncValidate={shouldAsyncValidate}
|
||||||
|
asyncValidate={asyncValidate}
|
||||||
>
|
>
|
||||||
{TagsAddForm}
|
{TagsAddForm}
|
||||||
</ReduxForm>
|
</ReduxForm>
|
||||||
@ -95,6 +99,8 @@ export const Tags = ({
|
|||||||
<ReduxForm
|
<ReduxForm
|
||||||
form={editing.form}
|
form={editing.form}
|
||||||
initialValues={{ name: editing.name, value: editing.value }}
|
initialValues={{ name: editing.name, value: editing.value }}
|
||||||
|
shouldAsyncValidate={shouldAsyncValidate}
|
||||||
|
asyncValidate={asyncValidate}
|
||||||
onSubmit={handleEdit}
|
onSubmit={handleEdit}
|
||||||
>
|
>
|
||||||
{props => (
|
{props => (
|
||||||
@ -197,10 +203,28 @@ export default compose(
|
|||||||
},
|
},
|
||||||
(dispatch, ownProps) => {
|
(dispatch, ownProps) => {
|
||||||
return {
|
return {
|
||||||
handleToggleAddOpen: value =>
|
handleToggleAddOpen: value => {
|
||||||
dispatch(set({ name: `add-tags-open`, value })),
|
return dispatch(set({ name: `add-tags-open`, value }));
|
||||||
handleToggleEditing: value =>
|
},
|
||||||
dispatch(set({ name: `editing-tag`, value })),
|
handleToggleEditing: value => {
|
||||||
|
return dispatch(set({ name: `editing-tag`, value }));
|
||||||
|
},
|
||||||
|
shouldAsyncValidate: ({ trigger }) => {
|
||||||
|
return trigger === 'submit';
|
||||||
|
},
|
||||||
|
asyncValidate: async ({ name = '', value = '' }) => {
|
||||||
|
const isNameInvalid = name.length === 0;
|
||||||
|
const isValueInvalid = value.length === 0;
|
||||||
|
|
||||||
|
if (!isNameInvalid && !isValueInvalid) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw {
|
||||||
|
name: isNameInvalid,
|
||||||
|
value: isValueInvalid
|
||||||
|
};
|
||||||
|
},
|
||||||
handleEdit: async ({ name, value }, _, { form, initialValues }) => {
|
handleEdit: async ({ name, value }, _, { form, initialValues }) => {
|
||||||
const { instance, deleteTag, updateTags, refetch } = ownProps;
|
const { instance, deleteTag, updateTags, refetch } = ownProps;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user