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

Allow re-enrollment in recipe #51

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Allow re-enrollment in recipe #51

wants to merge 1 commit into from

Conversation

RJAK11
Copy link
Collaborator

@RJAK11 RJAK11 commented Oct 7, 2024

This change checks for existing enrollments, and if present shows the user a modal asking whether they want to force enroll. If so, it unenrolls them from the previous one, and deletes it before proceeding with the new enrollment.

Fixes #50

src/apis/nimbus.js Outdated Show resolved Hide resolved
src/apis/nimbus.js Outdated Show resolved Hide resolved
src/types/global.d.ts Outdated Show resolved Hide resolved
src/ui/components/FeatureConfigPage.tsx Outdated Show resolved Hide resolved
src/ui/components/RecipeEnrollmentPage.tsx Outdated Show resolved Hide resolved
src/ui/components/RecipeEnrollmentPage.tsx Outdated Show resolved Hide resolved
src/ui/components/FeatureConfigPage.tsx Outdated Show resolved Hide resolved
This change checks for existing enrollments, and if present shows the user a modal asking whether they want to force enroll. If so, it unenrolls them from the previous one, and deletes it before proceeding with the new enrollment.

Fixes #50
const { addToast } = useToastsContext();

const recipe = useMemo<NimbusExperiment | null>(() => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

We don't actually know its a valid NimbusExperiment here, unfortunately. It should be unknown | null

setEnrollError(null);
}, [setEnrollError]);

function EnrollmentError(
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be a top level function, not nested inside the component fn

if its nested inside, it will always trigger a re-render because the function is redefined every time the component is called

<Modal.Header closeButton>
<Modal.Title>Force Enrollment</Modal.Title>
</Modal.Header>
<Modal.Body>{EnrollmentError(slug, enrollError)}</Modal.Body>
Copy link
Collaborator

Choose a reason for hiding this comment

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

EnrollmentError is a component:

Suggested change
<Modal.Body>{EnrollmentError(slug, enrollError)}</Modal.Body>
<Modal.Body><EnrollmentError slug{slug} enrollError={enrollError} /></Modal.Body>

if (activeEnrollment) {
return (
<p>
There is an active enrollment for the slug: <strong>{slug}</strong>.
Copy link
Collaborator

Choose a reason for hiding this comment

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

This actually might not be the same slug.

Suggested change
There is an active enrollment for the slug: <strong>{slug}</strong>.
There is an active enrollment for the slug: <strong>{activeEnrollment}</strong>.

if (activeEnrollment && slugExistsInStore) {
return (
<p>
There is already an enrollment for the slug: <strong>{slug}</strong>.
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is only true if slug == activeEnrollment

There are technically two cases, slug == activeEnrollment and slug !== activeEnrollment (ie there is already an active enrollment for this feature but the slug doesnt match this one)

Comment on lines +13 to +21
const recipe = useMemo<NimbusExperiment | null>(() => {
try {
return JSON.parse(jsonInput) as NimbusExperiment;
} catch {
return null;
}
}, [jsonInput]);

const slug = recipe?.slug || "";
Copy link
Collaborator

Choose a reason for hiding this comment

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

We're doing this all to get the slug. Instead, lets change this slightly:

type EnrollError = EnrollInExperimentResult["error"] & { slug: string; };
const [enrollError, setEnrollError] = useState<EnrollError | null>(null);

// line 63
setEnrollError({ slug: parsedRecipe.slug ?? "", ...result.error });

Since we're already parsing this to pass it off to the API, we may as well grab the slug there and only if we're parsing successfully and there is an error. otherwise, just wasted work and threading data through awkwardly.

return (
<p>
There is an active enrollment for the slug: <strong>{slug}</strong>.
Would you like to unenroll from the active enrollment and re-enroll
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
Would you like to unenroll from the active enrollment and re-enroll
Would you like to unenroll from the active enrollment and enroll

<p>
There is already an enrollment for the slug: <strong>{slug}</strong>.
Would you like to proceed with force enrollment by unenrolling,
deleting, and re-enrolling into the new configuration?
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
deleting, and re-enrolling into the new configuration?
deleting, and enrolling into the new configuration?

<p>
There is an inactive enrollment stored for the slug:{" "}
<strong>{slug}</strong>. Would you like to delete the inactive
enrollment and re-enroll into the new configuration?
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
enrollment and re-enroll into the new configuration?
enrollment and enroll into the new configuration?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot enroll in a recipe more than once
2 participants