Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Comments

fix: add skill show error if manifest url can not be accessed#2935

Merged
a-b-r-o-w-n merged 23 commits intomasterfrom
zhixzhan/skill-fix
May 13, 2020
Merged

fix: add skill show error if manifest url can not be accessed#2935
a-b-r-o-w-n merged 23 commits intomasterfrom
zhixzhan/skill-fix

Conversation

@zhixzhan
Copy link
Contributor

@zhixzhan zhixzhan commented May 7, 2020

Description

fix skill-add flow:

  1. check manifest url before save.
  2. check name should not contain special characters.

Task Item

close #2920

Screenshots

image

image

@github-actions
Copy link

github-actions bot commented May 7, 2020

Coverage Status

Coverage remained the same at 0.0% when pulling 0d0795c on zhixzhan/skill-fix into 398dbdf on master.

@cwhitten
Copy link
Member

cwhitten commented May 7, 2020

@zhixzhan instead of an alert modal can we render something a bit more subtle, like a text notification in the form itself?

Screen Shot 2020-05-07 at 12 58 19 PM
Screen Shot 2020-05-07 at 12 58 34 PM

@zhixzhan
Copy link
Contributor Author

zhixzhan commented May 8, 2020

@cwhitten updated. the url check result would be sent from server and display as a notification (with some lag)

@zhixzhan zhixzhan changed the title fix: add skill throw error if manifest url can not be accessed fix: add skill show error if manifest url can not be accessed May 8, 2020
Copy link
Contributor

@a-b-r-o-w-n a-b-r-o-w-n left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should separate the async validation from the sync validation and consolidate the skill validation logic into a utility used by both the skill form and skill modal. I'm also curious if the modal and form can share common components.

For the url validation, here is what I suggest:

useEffect(() => {
  httpClient('/projects/:projectId/skill/check', { url })
    .then(/* maybe clear error */)
    .catch(/* set validation error */)
}, [data.manifestUrl]);

Action creators should only be used to dispatch updates to the store (maybe as a result of an api call). They should not be used directly in components either to return a value or for a try/catch. It violates the uni-directional data flow model of the reducer pattern.

@a-b-r-o-w-n a-b-r-o-w-n self-assigned this May 8, 2020
@zhixzhan
Copy link
Contributor Author

zhixzhan commented May 9, 2020

I think we should separate the async validation from the sync validation and consolidate the skill validation logic into a utility used by both the skill form and skill modal. I'm also curious if the modal and form can share common components.

For the url validation, here is what I suggest:

useEffect(() => {
  httpClient('/projects/:projectId/skill/check', { url })
    .then(/* maybe clear error */)
    .catch(/* set validation error */)
}, [data.manifestUrl]);

Action creators should only be used to dispatch updates to the store (maybe as a result of an api call). They should not be used directly in components either to return a value or for a try/catch. It violates the uni-directional data flow model of the reducer pattern.

@a-b-r-o-w-n I moved two form into a component, and separate remote call to an async validation. but when I run jest ,meet a warning about useEffect, did you meet it before?

image

a-b-r-o-w-n
a-b-r-o-w-n previously approved these changes May 11, 2020
@a-b-r-o-w-n
Copy link
Contributor

@zhixzhan that error is probably due to the api call resolving after the component has unmounted. This may only be a problem with the test, but something to consider is adding some cancellation functionality so that the state update is not triggered.

useEffect(() => {
  let isCancelled = false;
  asyncValidation(formData).then((errors) => {
    setFormErrors(errors);
  });

  return () => {
    isCancelled = true;
  }
}, [formData.manifestUrl]);

I'm not sure if that would work.

@zhixzhan
Copy link
Contributor Author

@zhixzhan that error is probably due to the api call resolving after the component has unmounted. This may only be a problem with the test, but something to consider is adding some cancellation functionality so that the state update is not triggered.

useEffect(() => {
  let isCancelled = false;
  asyncValidation(formData).then((errors) => {
    setFormErrors(errors);
  });

  return () => {
    isCancelled = true;
  }
}, [formData.manifestUrl]);

I'm not sure if that would work.

I tried but no difference, ( anyway, it's only a test warning, wouldn't effect the feature. )

@a-b-r-o-w-n
Copy link
Contributor

Sorry @zhixzhan my code snippet was wrong.

useEffect(() => {
  let isCancelled = false;
  asyncValidation(formData).then((errors) => {
    if (!isCancelled) {
      setFormErrors(errors);
    }
  });

  return () => {
    isCancelled = true;
  }
}, [formData.manifestUrl]);

@a-b-r-o-w-n
Copy link
Contributor

@zhixzhan I pulled this and tried to fix the jest warning but didn't make any progress.

@a-b-r-o-w-n a-b-r-o-w-n merged commit 888f79a into master May 13, 2020
@a-b-r-o-w-n a-b-r-o-w-n deleted the zhixzhan/skill-fix branch May 13, 2020 18:16
lei9444 pushed a commit to lei9444/BotFramework-Composer-1 that referenced this pull request Jun 15, 2021
…oft#2935)

* throw error when skill manifest url can not be accessed

* check skill manifest url before commit

* update

* use createSkillModal component

* clean up

* separate async/sync validation

* clean up

* remove dead code

* check status code when fetching manifest

* extract manifest url validation

* clean up

Co-authored-by: Chris Whitten <christopher.whitten@microsoft.com>
Co-authored-by: Andy Brown <asbrown002@gmail.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants