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

Fix: Use local venue data for development instead of prod data #3810

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

kavishsathia
Copy link
Contributor

Context

Closes #3803

Implementation

The solution checks if the user is on localhost, and if they are, it will opt to use the local venue data instead of the production data by default. To override this behavior, the user can add a query parameter prodVenue to their URL, which will enable them to use production data instead.

Other Information

Copy link

vercel bot commented Aug 24, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
nusmods-export ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 11, 2024 6:41am
nusmods-website ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 11, 2024 6:41am

Copy link

vercel bot commented Aug 24, 2024

@kavishsathia is attempting to deploy a commit to the modsbot's projects Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

codecov bot commented Aug 28, 2024

Codecov Report

Attention: Patch coverage is 25.00000% with 3 lines in your changes missing coverage. Please review.

Project coverage is 54.57%. Comparing base (2d4743d) to head (c536886).
Report is 25 commits behind head on master.

Files with missing lines Patch % Lines
website/src/utils/debug.ts 25.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3810      +/-   ##
==========================================
+ Coverage   53.87%   54.57%   +0.69%     
==========================================
  Files         274      274              
  Lines        6032     6056      +24     
  Branches     1449     1449              
==========================================
+ Hits         3250     3305      +55     
+ Misses       2782     2751      -31     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@zwliew
Copy link
Member

zwliew commented Sep 10, 2024

May I know what's the motivation behind changing this default?

Copy link
Member

@ravern ravern left a comment

Choose a reason for hiding this comment

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

Thank you for this contribution! Sorry it took me this long to get to it.

I like the idea of flipping the venue fetching such that it uses local by default and global in production.

Was there a specific reason you used a window.location.hostname check instead of the current environment string? If there wasn't, I'm thinking it might be better to use the existing config than the use the hostname.

Comment on lines +11 to +14
function isLocalhost() {
return window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1';
}

Copy link
Member

Choose a reason for hiding this comment

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

Would it be make sense to use NUSMODS_ENV instead?

// Snippet from src/types/global.d.ts

/**
 * NUSMods deployment environment.
 *
 * **Note:** although these environments may share the same name as
 * `NODE_ENV` and other envs, there are subtle differences. Definitions:
 *
 * - `production`: a production deployment of NUSMods, i.e. a deployment meant to
 *   be used by the general public.
 * - `staging`: a deployment of NUSMods's main development branch, which is
 *   not meant to be used by the general public but which may be promoted to
 *   production at any point.
 * - `preview`: a deployment of work-in-progress branches, e.g. PR deploy
 *   previews.
 * - `test`: we are in a test environment, e.g. a jest test run.
 * - `development`: all other situations.
 */
declare const NUSMODS_ENV: 'development' | 'production' | 'staging' | 'preview' | 'test';

export function preferRepoVenues() {
return getParams().localVenue === '1';
// Don't use repo data in jest tests
if (process.env.JEST_WORKER_ID !== undefined) return false;
Copy link
Member

Choose a reason for hiding this comment

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

Using NUSMODS_ENV would allow checking for NUSMODS_ENV === 'test' as well.

Copy link
Member

@ravern ravern left a comment

Choose a reason for hiding this comment

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

Sorry, meant to request changes.

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.

Use local venue data for development instead of prod data
3 participants