Skip to content
Draft
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
5 changes: 3 additions & 2 deletions app/graphql/mutations/ask_question.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
module Mutations
class AskQuestion < BaseMutation
argument :registration_id, ID, required: true, loads: Types::RegistrationType
argument :urgent, Boolean, required: false
argument :body, String, required: true

field :question, Types::QuestionType, null: false
Expand All @@ -15,8 +16,8 @@ def authorized?(registration:, **_args)
raise GraphQL::ExecutionError, 'You do not have permission.'
end

def resolve(registration:, body:)
q = Question.new(registration: registration, body: body)
def resolve(registration:, urgent:, body:)
q = Question.new(registration: registration, urgent: urgent, body: body)
saved = q.save
raise GraphQL::ExecutionError, q.errors.full_messages.to_sentence unless saved

Expand Down
1 change: 1 addition & 0 deletions app/graphql/types/question_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class QuestionType < Types::BaseObject
def registration
RecordLoader.for(Registration).load(object.registration_id)
end
field :urgent, Boolean, null: false
field :body, String, null: false
field :created_at, GraphQL::Types::ISO8601DateTime, null: false
end
Expand Down
9 changes: 9 additions & 0 deletions app/javascript/components/workflows/proctor/exams/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ interface Question {
type: MessageType.Question;
time: DateTime;
id: string;
urgent: boolean;
body: string;
registration: {
id: string;
Expand Down Expand Up @@ -152,6 +153,7 @@ export interface MessageProps {
iconClass?: string;
tooltip: string;
time: DateTime;
urgent: boolean;
body: React.ReactElement | string;
}

Expand All @@ -161,6 +163,7 @@ const ShowMessage: React.FC<MessageProps> = (props) => {
iconClass,
tooltip,
time,
urgent,
body,
children,
} = props;
Expand All @@ -174,6 +177,7 @@ const ShowMessage: React.FC<MessageProps> = (props) => {
<i className="text-muted">
{`${tooltip} (${time.toLocaleString(DateTime.TIME_SIMPLE)})`}
</i>
{urgent && <strong className="text-danger"> LOCKED OUT</strong>}
{children}
</p>
<p className="wrap-anywhere">{body}</p>
Expand Down Expand Up @@ -784,13 +788,15 @@ const ShowQuestion: React.FC<{
const {
registration,
body,
urgent,
time,
} = question;
const reply = useCallback(() => replyTo(registration.id), [registration.id]);
return (
<ShowMessage
icon={MdMessage}
tooltip={`Received from ${registration.user.displayName}`}
urgent={urgent}
body={body}
time={time}
>
Expand Down Expand Up @@ -1084,6 +1090,7 @@ const newQuestionSubscriptionSpec = graphql`
displayName
}
}
urgent
body
}
questionsEdge {
Expand Down Expand Up @@ -1371,6 +1378,7 @@ const ExamMessages: React.FC<{
displayName
}
}
urgent
body
}
}
Expand Down Expand Up @@ -1410,6 +1418,7 @@ const ExamMessages: React.FC<{
questions: res.questions.edges.map(({ node: question }) => ({
type: MessageType.Question,
id: question.id,
urgent: question.urgent,
body: question.body,
registration: question.registration,
time: DateTime.fromISO(question.createdAt),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const AnomalousMessaging: React.FC<{
<Card.Title>
<h2>Ask a question</h2>
</Card.Title>
<AskQuestion examKey={res} />
<AskQuestion examKey={res} urgent />
</Card.Body>
</Card>
</Col>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const ShowQuestion: React.FC<{
graphql`
fragment AskQuestion_single on Question {
createdAt
urgent
body
}
`,
Expand All @@ -54,9 +55,11 @@ const ShowQuestion: React.FC<{

const SendQuestion: React.FC<{
registrationId: string;
urgent: boolean;
}> = (props) => {
const {
registrationId,
urgent,
} = props;
const [val, setVal] = useState('');
const [inTimeout, setInTimeout] = useState(false);
Expand Down Expand Up @@ -151,6 +154,7 @@ const SendQuestion: React.FC<{
variables: {
input: {
registrationId,
urgent,
body: val,
},
},
Expand Down Expand Up @@ -186,11 +190,13 @@ const questionPaginationConfig = {

interface AskQuestionProps {
examKey: AskQuestion$key;
urgent: boolean;
}

const AskQuestion: React.FC<AskQuestionProps> = (props) => {
const {
examKey,
urgent,
} = props;
const { alert } = useContext(AlertContext);
const [res, { isLoading, hasMore, loadMore }] = usePagination(
Expand Down Expand Up @@ -222,7 +228,7 @@ const AskQuestion: React.FC<AskQuestionProps> = (props) => {
const { edges } = res.myRegistration.questions;
return (
<div>
<SendQuestion registrationId={res.myRegistration.id} />
<SendQuestion registrationId={res.myRegistration.id} urgent={urgent} />
<span className="clearfix" />
<hr className="my-2" />
{edges.length === 0 && (
Expand Down
5 changes: 3 additions & 2 deletions db/migrate/20200522182009_create_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def change
t.index [:user_id, :exam_version_id], unique: true
t.index [:room_id, :user_id], unique: true
t.index [:user_id, :room_id], unique: true

t.boolean :published, null: false, default: false

t.datetime :start_time
Expand Down Expand Up @@ -175,6 +175,7 @@ def change
create_table :questions do |t|
t.references :registration, null: false, foreign_key: true

t.boolean :urgent, null: false, default: false
t.text :body, null: false
t.timestamps
end
Expand Down Expand Up @@ -220,7 +221,7 @@ def change
t.string :student_feedback, null: true
t.float :points, null: false
t.integer :order, null: true
Copy link
Contributor Author

Choose a reason for hiding this comment

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

My IDE insisted...


t.timestamps
end

Expand Down
1 change: 1 addition & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@

create_table "questions", force: :cascade do |t|
t.bigint "registration_id", null: false
t.boolean "urgent", default: false, null: false
t.text "body", null: false
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
Expand Down