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

Various fixes #314

Merged
merged 10 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend/app/models/launched_study.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class LaunchedStudy < ApplicationRecord
belongs_to :study
belongs_to :study, counter_cache: true
has_many :stages, through: :study

before_create { self.first_launched_at ||= Time.now }
Expand Down
7 changes: 6 additions & 1 deletion backend/app/models/stage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ def completed?
return true
end

!study.closes_at.nil? && study.closes_at < DateTime.now
days_until_close = previous_stages.count * available_after_days
!study.closes_at.nil? && study.closes_at.next_day(days_until_close) < DateTime.now
end

def scheduled?
Expand All @@ -63,6 +64,10 @@ def active?
study.opens_at.present? && study.opens_at < DateTime.now
end

def previous_stages
siblings.where(Stage.arel_table[:order].lt(order)).order(:order)
end

def previous_stage
siblings.where(Stage.arel_table[:order].lt(order)).order(:order).last
end
Expand Down
12 changes: 7 additions & 5 deletions backend/app/models/study.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Study < ApplicationRecord
# need the double quotes, order is a postgresql semi-reserved word
has_many :stages, -> { order('"order"') }, inverse_of: :study, dependent: :destroy
has_many :launched_stages, through: :stages
has_many :launched_studies, counter_cache: true
has_many :launched_studies

has_many :response_exports, through: :stages
has_many :study_analysis
Expand Down Expand Up @@ -141,8 +141,10 @@ def submit
end
end

def pause
stages.where.not(status: 'paused').first&.update!(status: 'paused')
def pause(stage_index=0)
stages.first(stage_index.to_i + 1).each do |stage|
stage.update!(status: 'paused')
end
end

def resume(stage_index=0)
Expand Down Expand Up @@ -171,9 +173,9 @@ def reopen_if_possible

# called from studies controller to update status using action and stage_index from params
def update_status!(action, stage_index)
if %w[pause end launch].include?(action)
if %w[end launch].include?(action)
send(action)
elsif %w[resume reopen].include?(action)
elsif %w[resume pause reopen].include?(action)
send(action, stage_index)
elsif action == 'submit'
submit
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddLaunchedStudiesCountToStudies < ActiveRecord::Migration[6.1]
def change
add_column :studies, :launched_studies_count, :integer
end
end
6 changes: 3 additions & 3 deletions backend/db/migrate/study_migration_data.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1077,7 +1077,7 @@
title_for_participants: "Are you online ready for studying?"
short_description_for_participants: "Are you ready for taking an online course/studying in an online context?"
long_description_for_participants: "Before enrolling in an online course, you should first assess your readiness for becoming an online learner. This survey will assess your online readiness, and if you need to improve upon it."
study_topic: "Others"
study_topic: "Other"
study_subject: null
benefits: "You will receive feedback based on your answers to the following questions that will help you think about yourself as a learner and determine what you need to do to be successful in an online learning environment."
opens_at: 2023-06-22 09:00:00
Expand All @@ -1100,7 +1100,7 @@
title_for_participants: "So what is financial aid, anyway?"
short_description_for_participants: "Student loans, anyone? Whether you're considering, own, or just want to know more, you can master financial aid by taking this mini course."
long_description_for_participants: "Try out this fun new lesson on student loans! You'll take a quiz so we can see what you already know, read a brief lesson on what financial aid is and how students can manage it, and then reflect on what you learned with a short writing prompt."
study_topic: "School & Future Career"
study_topic: "School & Career"
study_subject: null
benefits: "You'll learn how financial aid in the US works and how you can take advantage of student loans. Your responses will also help us understand how learners act on knowledge."
opens_at: 2023-10-23 09:00:00
Expand All @@ -1123,7 +1123,7 @@
title_for_participants: "OpenStax Syllabus Contest"
short_description_for_participants: "Is your course using an OpenStax textbook? Share your syllabus for a chance to win a pair of AirPods Pro!"
long_description_for_participants: "The more people who report using OpenStax, the greater our ability to secure future philanthropic support. Share your OpenStax syllabus to help us provide even more free educational resources to students and instructors everywhere."
study_topic: "Others"
study_topic: "Other"
study_subject: null
benefits: "The more people who report using OpenStax, the greater our ability to secure future philanthropic support to provide even more free educational resources for students and instructors everywhere."
opens_at: 2023-11-06 09:00:00
Expand Down
6 changes: 4 additions & 2 deletions backend/db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,8 @@ CREATE TABLE public.studies (
subject character varying,
internal_description character varying,
target_sample_size integer,
public_on timestamp with time zone
public_on timestamp with time zone,
launched_studies_count integer
);


Expand Down Expand Up @@ -1479,6 +1480,7 @@ INSERT INTO "schema_migrations" (version) VALUES
('20230712163112'),
('20230726142755'),
('20230808163159'),
('20230905121510');
('20230905121510'),
('20231113162430');


13 changes: 4 additions & 9 deletions backend/spec/models/study_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
it 'pauses first session of a study' do
study.launch
# Pause first session
study.pause
study.pause(0)
expect(study.status).to eq 'active'
expect(study.stages.first.status).to eq 'paused'
expect(study.stages.second.status).to eq 'active'
Expand All @@ -112,8 +112,7 @@
it 'pauses second session of a study' do
study.launch
# Pause first two sessions
study.pause
study.pause
study.pause(1)
expect(study.status).to eq 'active'
expect(study.stages.first.status).to eq 'paused'
expect(study.stages.second.status).to eq 'paused'
Expand All @@ -123,9 +122,7 @@
it 'pauses third session of a study' do
study.launch
# Pause all three sessions
study.pause
study.pause
study.pause
study.pause(2)
expect(study.status).to eq 'paused'
expect(study.stages.first.status).to eq 'paused'
expect(study.stages.second.status).to eq 'paused'
Expand All @@ -145,9 +142,7 @@

it 'resumes subsequent studies' do
study.launch
study.pause
study.pause
study.pause
study.pause(2)
expect(study.status).to eq 'paused'

# Resume first session, should resume all subsequent paused sessions
Expand Down
5 changes: 5 additions & 0 deletions frontend/specs/researcher-account.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ test('can update researcher account details', async({ browser }) => {

await researcherPage.fill('[name=labPage]', faker.internet.url())
await researcherPage.fill('[name=bio]', faker.name.jobDescriptor())
await researcherPage.locator('.select', {
has: researcherPage.locator(`input[name=institution]`),
}).click()
await researcherPage.waitForTimeout(100)
await researcherPage.keyboard.press('Enter')

await researcherPage.click('testId=form-save-btn')
await researcherPage.waitForLoadState('networkidle')
Expand Down
9 changes: 1 addition & 8 deletions frontend/src/components/manage-cookies.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from 'react';
import { css, Global } from '@emotion/react'

// documentation for this at https://docs.osano.com/hiding-the-cookie-widget
export const ManageCookiesLink = () => {
Expand All @@ -15,13 +14,7 @@ export const ManageCookiesLink = () => {
osano.cm.showDrawer('osano-cm-dom-info-dialog-open')
}


return (
<>
<Global
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

moved to main.scss

Copy link
Member

Choose a reason for hiding this comment

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

Hm, I slightly prefer it here because this way we only hide the osano cookie link if we're also rendering an alternative method. If the hiding is in the sass, it's possible that we hide it, but then don't render this on some screens

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I should have added another comment for context woops, we moved the manage cookies link into the user name/dropdown thing at the top right, with that being there it's not technically rendered until the dropdown is opened. This way every user should have access to it (ie before the researcher experience doesn't have a footer so the cookie was still rendering)

styles={css({ '.osano-cm-widget': { display: 'none' } })}
/>
<a href='#' onClick={showOsano}>Manage Cookies</a>
</>
<span onClick={showOsano}>Manage Cookies</span>
Copy link
Member

Choose a reason for hiding this comment

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

if you want to use a span, this needs to have cursor:hover and also a role="button" for a18y

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@nathanstitt the cursor portion is taken care of by the parent link

<StyledLink to='#'>
    <Menu.Item>
        <ManageCookiesLink />
    </Menu.Item>
</StyledLink>

the result:

Screenshot 2023-11-13 at 3 23 45 PM

Question is, would we still want the role on the span? or would this parent cover that case?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@nathanstitt the cursor portion is taken care of by the parent link

<StyledLink to='#'>
    <Menu.Item>
        <ManageCookiesLink />
    </Menu.Item>
</StyledLink>

the result:

Screenshot 2023-11-13 at 3 23 45 PM

Question is, would we still want the role on the span? or would this parent cover that case?

Copy link
Member

Choose a reason for hiding this comment

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

nah, sorry I'd left that comment before I realized it was being used in the menu

)
};
6 changes: 6 additions & 0 deletions frontend/src/components/navbar/account-links.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Menu } from '@mantine/core';
import { logout } from '@models';
import { React } from '@common';
import { StyledLink } from '@components';
import { ManageCookiesLink } from '../manage-cookies';

export default function AccountLinks() {
const user = useCurrentUser()
Expand All @@ -19,6 +20,11 @@ export default function AccountLinks() {
My Account
</Menu.Item>
</StyledLink>
<StyledLink to='#'>
<Menu.Item>
<ManageCookiesLink />
</Menu.Item>
</StyledLink>
{!env.isImpersonating &&
<StyledLink to={logoutURL} onClick={() => {
logout().then(() => refetch())
Expand Down
2 changes: 0 additions & 2 deletions frontend/src/components/resource-links.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { React } from '@common'
import { useCurrentUser } from '@lib';
import { ManageCookiesLink } from './manage-cookies'

export const ResourceLinks = () => {
return (
<>
<h4>Resources</h4>
<a target="_blank" href="https://help.openstax.org/s/article/Kinetic-Learner-Student-FAQs">FAQs</a>
<a target="_blank" href="https://openstax.org/privacy-policy">Privacy Policy</a>
<ManageCookiesLink />
</>
)
}
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/screens/learner/card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ const Card = styled(Box)({
color: 'inherit',
textDecoration: 'none',
cursor: 'pointer',
minHeight: 475,
maxHeight: 475,
minHeight: 500,
maxHeight: 500,
borderRadius: 8,
overflow: 'hidden',
'&:hover': {
Expand Down
26 changes: 13 additions & 13 deletions frontend/src/screens/researcher/account/researcher-account-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Researcher } from '@api';
import {
Box,
CharacterCount,
FieldErrorMessage,
Form,
FormSaveButton,
Icon,
Expand All @@ -21,8 +22,12 @@ export const ResearcherValidationSchema = Yup.object().shape({
researchInterest1: Yup.string().max(25),
researchInterest2: Yup.string().max(25),
researchInterest3: Yup.string().max(25),
labPage: Yup.string().matches(urlRegex, 'Enter a valid URL'),
bio: Yup.string().max(250),
institution: Yup.mixed().required('Required'),
labPage: Yup.string().matches(urlRegex, {
message: 'Please enter a valid URL',
excludeEmptyString: true,
}),
bio: Yup.string().max(250).required('Required'),
})

const institutionList = [
Expand Down Expand Up @@ -53,7 +58,6 @@ const StyledForm = styled(Form<Researcher>)(({ readOnly }) => ({
export const ResearcherAccountForm: React.FC<{className?: string}> = ({ className }) => {
const api = useApi()
const [researcher, setResearcher] = useState(useCurrentResearcher())
const [institution, setInstitution] = useState(researcher?.institution)
const { refetch: refetchEnv } = useFetchEnvironment()
const { data: userInfo, refetch: refetchUser } = useUserInfo()

Expand Down Expand Up @@ -104,17 +108,16 @@ export const ResearcherAccountForm: React.FC<{className?: string}> = ({ classNam

<div className='col-12 mt-1'>
<h6>Institution</h6>

<SelectField
name="institution"
isClearable={true}
placeholder={'Select Option'}
onChange={(value) => (typeof value == 'string' && setInstitution(value))}
value={institution}
defaultValue={institution}
defaultValue={researcher.institution}
options={institutionList}
/>
<FieldErrorMessage name='institution' />
</div>

<Box align='baseline' gap className='mt-1'>
<h6>Research Interests</h6>
<Tooltip tooltip='Examples: Multimedia Learning; AI in Education; Adaptive Tutoring Systems'>
Expand All @@ -139,17 +142,13 @@ export const ResearcherAccountForm: React.FC<{className?: string}> = ({ classNam
<div className='mt-1'>
<h6>Lab Page Link</h6>
<InputField placeholder='https://' name="labPage" />
<div className="invalid-feedback">
<Icon icon="warning" color='red' height={18}></Icon>
&nbsp;
Please enter a valid URL
</div>
<FieldErrorMessage name='labPage' />
</div>

<div className='mb-1 mt-1'>
<Box align='baseline' gap>
<h6 className='field-title'>Bio</h6>
<Tooltip tooltip='Simplify your research description for mass appeal'>
<Tooltip tooltip='This bio will be visible to learners, as a chance for them to know more about the researcher conducting the study'>
<Icon css={{ color: colors.blue50 }} icon='helpCircle' height={16}/>
</Tooltip>
</Box>
Expand All @@ -160,6 +159,7 @@ export const ResearcherAccountForm: React.FC<{className?: string}> = ({ classNam
placeholder='Please add a brief bio to share with learners'
/>
<CharacterCount max={250} name={'bio'} />
<FieldErrorMessage name='bio' />
</div>

<FormSave />
Expand Down
13 changes: 9 additions & 4 deletions frontend/src/screens/researcher/studies/create/action-footer.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { Box, React, useCallback, useState } from '@common';
import { Link } from 'react-router-dom';
import { Box, React, styled, useCallback, useState } from '@common';
import { Icon, ResearcherButton, Step } from '@components';

const FakeLink = styled.span({
cursor: 'pointer',
color: 'blue',
textDecoration: 'underline',
})

export const ActionFooter: FC<{ step: Step, }> = ({ step }) => {
const [busy, setBusy] = useState(false)
const triggerAnimation = useCallback(() => {
Expand All @@ -15,12 +20,12 @@ export const ActionFooter: FC<{ step: Step, }> = ({ step }) => {
return (
<Box className='fixed-bottom bg-white mt-auto' css={{ minHeight: 80, boxShadow: `0px -3px 10px rgba(219, 219, 219, 0.5)` }}>
<Box className='container-lg' align='center' justify='between'>
{step.backAction ? <Link to=''>
{step.backAction ? <FakeLink>
<Box align='center' gap='small' onClick={() => step.backAction?.()}>
<Icon icon='chevronLeft'></Icon>
<span>Back</span>
</Box>
</Link> : <span></span>}
</FakeLink> : <span></span>}
Copy link
Member

Choose a reason for hiding this comment

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

should add role="link" to the span for screenreader


<Box align='center' gap='large'>
{step.secondaryAction ?
Expand Down
Loading