Skip to content

Commit

Permalink
refactor: Update conditional logic for displaying forum link and test…
Browse files Browse the repository at this point in the history
… runner card visibility
  • Loading branch information
andy1li committed Dec 24, 2024
1 parent 22240bb commit 8ac358d
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
{{else if (eq stepList.expandedStep.id "submit-code")}}
<CoursePage::CourseStageStep::FirstStageTutorialCard::SubmitCodeStep
@isComplete={{this.submitCodeStepIsComplete}}
@shouldHideTestRunnerCardBeforeUserHasSubmitted={{@shouldHideTestRunnerCardBeforeUserHasSubmitted}}
@shouldHideTestRunnerCardRelatedCopy={{@shouldHideTestRunnerCardRelatedCopy}}
/>
{{/if}}
</ExpandableStepList>

{{#if @shouldHideTestRunnerCardBeforeUserHasSubmitted}}
{{#if @shouldShowLinkToForum}}
{{#if @shouldHideTestRunnerCardRelatedCopy}}
{{#if this.shouldShowLinkToForum}}
<div class="prose dark:prose-invert prose-sm prose-compact mt-6">
<p>Need help?</p>
<ul>
Expand All @@ -40,7 +40,7 @@
rel="noopener noreferrer"
>
Post your issue</a>
on the forumAndy is quick to reply, typically within 6 hours.
on the forumAndy usually replies within 6 hours.
</li>
</ul>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import CoursePageStateService from 'codecrafters-frontend/services/course-page-s
import FeatureFlagsService from 'codecrafters-frontend/services/feature-flags';
import Store from '@ember-data/store';
import type CourseStageModel from 'codecrafters-frontend/models/course-stage';
import type CourseStageStep from 'codecrafters-frontend/utils/course-page-step-list/course-stage-step';
import type RepositoryModel from 'codecrafters-frontend/models/repository';
import type { Step } from 'codecrafters-frontend/components/expandable-step-list';
import { action } from '@ember/object';
Expand All @@ -14,8 +15,8 @@ interface Signature {
Args: {
repository: RepositoryModel;
courseStage: CourseStageModel;
shouldHideTestRunnerCardBeforeUserHasSubmitted: boolean;
shouldShowLinkToForum: boolean;
currentStep: CourseStageStep;
shouldHideTestRunnerCardRelatedCopy: boolean;
};
}

Expand Down Expand Up @@ -84,6 +85,12 @@ export default class FirstStageTutorialCardComponent extends Component<Signature
return this.coursePageState.manuallyCompletedStepIdsInFirstStageInstructions.includes('navigate-to-file');
}

get shouldShowLinkToForum() {
const currentStep = this.args.currentStep;

return currentStep.testsStatus !== 'passed' && currentStep.status !== 'complete';
}

get steps() {
return [
new NavigateToFileStep(this.args.repository, this.navigateToFileStepIsComplete),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<div class="prose dark:prose-invert">
<p class={{if @isComplete "line-through"}}>
Once you run the commands above, our system will automatically run tests on your code.
Once you run the commands above, our system will automatically test your code.
</p>

{{#if @isComplete}}
Expand All @@ -20,7 +20,7 @@
</div>

{{#unless @isComplete}}
{{#unless @shouldHideTestRunnerCardBeforeUserHasSubmitted}}
{{#unless @shouldHideTestRunnerCardRelatedCopy}}
<p class="prose dark:prose-invert prose-sm mt-3">
<b>Note:</b>
If you're still seeing "Tests failed" after completing the steps above,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ interface Signature {

Args: {
isComplete: boolean;
shouldHideTestRunnerCardBeforeUserHasSubmitted: boolean;
shouldHideTestRunnerCardRelatedCopy: boolean;
};
}

Expand Down
30 changes: 16 additions & 14 deletions app/controllers/course/stage/instructions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,32 +48,34 @@ export default class CourseStageInstructionsController extends Controller {
return this.model.courseStage.prerequisiteInstructionsMarkdownFor(this.model.activeRepository);
}

get shouldHideTestRunnerCardBeforeUserHasSubmitted() {
return this.featureFlags.hideTestRunnerCardBeforeUserHasSubmitted;
get shouldHideTestRunnerCardBeforeStage1Submission() {
return this.featureFlags.cannotSeeTestRunnerCardBeforeStage1Submission;
}

get shouldShowFeedbackPrompt() {
return !this.currentStep.courseStage.isFirst && this.currentStep.status === 'complete';
}

get shouldShowLinkToForum() {
return (
this.isCurrentStage &&
this.currentStep.status !== 'complete' &&
this.currentStep.testsStatus !== 'passed' &&
this.shouldHideTestRunnerCardBeforeUserHasSubmitted
);
}

get shouldShowPrerequisites() {
return !!this.prerequisiteInstructionsMarkdown;
}

get shouldShowTestRunnerCard() {
const shouldHideTestRunnerCard =
this.model.courseStage.isFirst && this.model.activeRepository.submissions.length <= 1 && this.shouldHideTestRunnerCardBeforeUserHasSubmitted;
if (!this.isCurrentStage) {
return false;
}

return this.isCurrentStage && this.currentStep.status !== 'complete' && !shouldHideTestRunnerCard;
if (this.currentStep.status === 'complete') {
return false;
}

if (this.model.courseStage.isFirst) {
// For stage 1, we hide the test runner card until the user's submission.
return !(this.model.activeRepository.submissionsCount <= 1 && this.shouldHideTestRunnerCardBeforeStage1Submission);
} else {
// For other stages, we always show the test runner card
return true;
}
}

get shouldShowUpgradePrompt() {
Expand Down
8 changes: 4 additions & 4 deletions app/services/feature-flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ export default class FeatureFlagsService extends Service {
return this.currentUser?.isStaff || this.getFeatureFlagValue('can-see-short-instructions-for-stage-2') === 'test';
}

get currentUser() {
return this.authenticator.currentUser;
get cannotSeeTestRunnerCardBeforeStage1Submission() {
return this.currentUser?.isStaff || this.getFeatureFlagValue('cannot-see-test-runner-card-before-stage1-submission') === 'test';
}

get hideTestRunnerCardBeforeUserHasSubmitted() {
return this.currentUser?.isStaff || this.getFeatureFlagValue('hide-test-runner-card-before-user-has-submitted') === 'test';
get currentUser() {
return this.authenticator.currentUser;
}

getFeatureFlagValue(flagName) {
Expand Down
4 changes: 2 additions & 2 deletions app/templates/course/stage/instructions.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
<CoursePage::CourseStageStep::FirstStageTutorialCard
@repository={{@model.activeRepository}}
@courseStage={{@model.courseStage}}
@shouldHideTestRunnerCardBeforeUserHasSubmitted={{this.shouldHideTestRunnerCardBeforeUserHasSubmitted}}
@shouldShowLinkToForum={{this.shouldShowLinkToForum}}
@currentStep={{this.currentStep}}
@shouldHideTestRunnerCardRelatedCopy={{this.shouldHideTestRunnerCardBeforeStage1Submission}}
class="mb-6"
/>
{{/if}}
Expand Down

0 comments on commit 8ac358d

Please sign in to comment.