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

Feature/select single questions #24

Merged
merged 13 commits into from
Aug 23, 2023
Merged

Conversation

barshathakuri
Copy link
Collaborator

@barshathakuri barshathakuri commented Aug 16, 2023

  • Detail Change
    • Add Single and Multiple question type
    • Add Pillars options in both questions type

@barshathakuri barshathakuri requested a review from subinasr August 16, 2023 05:04
@barshathakuri barshathakuri temporarily deployed to Test August 16, 2023 05:05 — with GitHub Actions Inactive
@barshathakuri barshathakuri temporarily deployed to Test August 16, 2023 08:09 — with GitHub Actions Inactive
@barshathakuri barshathakuri changed the base branch from develop to feature/project-list August 16, 2023 08:10
@subinasr subinasr force-pushed the feature/select-single-questions branch from 3d7623c to 20134c1 Compare August 16, 2023 08:53
Copy link
Collaborator

@subinasr subinasr left a comment

Choose a reason for hiding this comment

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

Also, let's fix the typecheck and lint issues.

Comment on lines 35 to 108
<MultiSelectInput
keySelector={keySelector}
label="Country"
labelSelector={labelSelector}
name="test"
onChange={function noRefCheck() { }}
options={[]}
value={[]}
/>
Copy link
Collaborator

Choose a reason for hiding this comment

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

The preview for this question type should be a list of options with a checkbox instead of MultiSelectInput.

Comment on lines 121 to 122
limit: PAGE_SIZE,
offset: 0,
Copy link
Collaborator

Choose a reason for hiding this comment

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

These variables are not called in query and hence is not required here.

},
);
const initialFormValue: FormType = {
type: 'SELECT_ONE' as QuestionTypeEnum,
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
type: 'SELECT_ONE' as QuestionTypeEnum,
type: 'SELECT_MULTIPLE' as QuestionTypeEnum,

} = useQuery<PillarsQuery, PillarsQueryVariables>(
PILLARS,
{
variables: pillarsVariables,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's add this:

Suggested change
variables: pillarsVariables,
skip: isNotDefined(pillarsVariables),
variables: pillarsVariables,

}
);

const pillarsOptions = pillarsResponse?.private?.projectScope?.groups.items || [];
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should also include the hierarchy of the options. For eg: For a nested group, let's say, 'Mammals' inside a group 'Animals', the option should say: 'Animals > Mammals'.
instead of currently shown options: 'Animals' and 'Mammals'.

error={fieldError?.hint}
onChange={setFieldValue}
/>
<>Options</>
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can remove this for now if it's not ready.

import styles from './index.module.css';
import SelectMultipleQuestionPreview from '#components/SelectMultipleQuestionsPreview';

const CREATE_TEXT_QUESTION = gql`
Copy link
Collaborator

Choose a reason for hiding this comment

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

The query should be named something else like CREATE_MULTIPLE_SELECTION_QUESTION. Let's not use misleading names.

triggerQuestionCreate,
{ loading: createQuestionPending },
] = useMutation<CreateTextQuestionMutation, CreateTextQuestionMutationVariables>(
CREATE_TEXT_QUESTION,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's change the mutation name.


import styles from './index.module.css';

const CREATE_TEXT_QUESTION = gql`
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's change the mutation names.

Comment on lines 255 to 291
<SelectInput
name="label"
label="Pillar and Sub pillar"
value={formValue.label}
error={fieldError?.label}
onChange={setFieldValue}
keySelector={pillarKeySelector}
labelSelector={pillarLabelSelector}
options={pillarsOptions}
/>
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we should make a separate component for this SelectInput. Also, let's make this a SearchSelectInput.

@barshathakuri barshathakuri requested a review from tnagorra August 17, 2023 11:11
@thenav56 thenav56 requested a review from shreeyash07 August 17, 2023 11:26
@barshathakuri barshathakuri force-pushed the feature/select-single-questions branch from 20134c1 to 5df9814 Compare August 18, 2023 11:59
@barshathakuri barshathakuri marked this pull request as draft August 18, 2023 12:00
@barshathakuri barshathakuri requested a review from subinasr August 21, 2023 08:11
@barshathakuri barshathakuri marked this pull request as ready for review August 21, 2023 08:12
@barshathakuri barshathakuri force-pushed the feature/select-single-questions branch from 4846faa to 4f70c3f Compare August 21, 2023 08:34
@barshathakuri barshathakuri temporarily deployed to Test August 21, 2023 08:38 — with GitHub Actions Inactive
@barshathakuri barshathakuri temporarily deployed to Test August 21, 2023 08:50 — with GitHub Actions Inactive
@barshathakuri barshathakuri temporarily deployed to Test August 21, 2023 10:06 — with GitHub Actions Inactive
@barshathakuri barshathakuri temporarily deployed to Test August 21, 2023 10:08 — with GitHub Actions Inactive
@barshathakuri barshathakuri temporarily deployed to Test August 21, 2023 12:03 — with GitHub Actions Inactive
@AdityaKhatri AdityaKhatri force-pushed the feature/select-single-questions branch from d61774d to 8793067 Compare August 22, 2023 02:17
@AdityaKhatri AdityaKhatri changed the base branch from feature/project-list to develop August 22, 2023 02:17
@barshathakuri barshathakuri force-pushed the feature/select-single-questions branch from 8793067 to d61774d Compare August 22, 2023 04:01
@barshathakuri barshathakuri temporarily deployed to Test August 22, 2023 04:01 — with GitHub Actions Inactive
Comment on lines 78 to 89
return (
<SelectInput
name={name}
label="Pillar and Sub pillar"
value={value}
error={error}
onChange={onChange}
keySelector={pillarKeySelector}
labelSelector={pillarLabelSelector}
options={pillarsOptions}
/>
);

Choose a reason for hiding this comment

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

please pass disable also

Comment on lines 91 to 109
return (
<div className={_cs(styles.preview, className)}>
<TextOutput
value={label ?? 'Which Country needs the assistance quickest?'}
description={hint ?? 'Choose One'}
spacing="none"
block
/>
<ListView
className={styles.questionList}
data={optionsListResponse?.private?.projectScope?.choiceCollection?.choices}
keySelector={checkboxKeySelector}
renderer={Checkbox}
rendererParams={checkboxListRendererParams}
filtered={false}
errored={false}
pending={false}
/>
</div>

Choose a reason for hiding this comment

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

Let's also handle case where choices are empty

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this is okay. The list won't be displayed in case of empty data which is exactly what we want.

Comment on lines 1 to 6
import {
_cs,
isNotDefined,
noOp,
} from '@togglecorp/fujs';
import { useMemo } from 'react';

Choose a reason for hiding this comment

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

maintain order

Comment on lines 99 to 108
<RadioInput
className={styles.questionList}
keySelector={choiceCollectionKeySelector}
label="Options"
labelSelector={choiceCollectionLabelSelector}
name="options"
onChange={noOp}
options={optionsList as QuestionChoiceCollectionType[]}
value={optionsListResponse?.private?.projectScope?.choiceCollection?.name}
/>

Choose a reason for hiding this comment

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

Let's pass disable here too

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 readOnly as we're only previewing the options, not letting users choose from the options. @barshathakuri Let's add a 'readOnly' everywhere in preview.

onQuestionClick: React.Dispatch<React.SetStateAction<string | undefined>>;
}

function QuestionTypeItem(props: Props) {

Choose a reason for hiding this comment

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

Let's rename to QuestionTypeButton, pass disable from props

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, this should be inside components/questionPreviews

@barshathakuri barshathakuri temporarily deployed to Test August 22, 2023 11:21 — with GitHub Actions Inactive
@barshathakuri barshathakuri temporarily deployed to Test August 22, 2023 11:22 — with GitHub Actions Inactive
@barshathakuri barshathakuri temporarily deployed to Test August 22, 2023 11:24 — with GitHub Actions Inactive
@barshathakuri barshathakuri temporarily deployed to Test August 22, 2023 11:28 — with GitHub Actions Inactive
@barshathakuri barshathakuri temporarily deployed to Test August 22, 2023 11:30 — with GitHub Actions Inactive
@barshathakuri barshathakuri temporarily deployed to Test August 22, 2023 11:38 — with GitHub Actions Inactive
@barshathakuri barshathakuri temporarily deployed to Test August 22, 2023 11:42 — with GitHub Actions Inactive
@barshathakuri barshathakuri temporarily deployed to Test August 22, 2023 11:44 — with GitHub Actions Inactive
Comment on lines 75 to 76
const pillarKeySelector = (data: Pillar) => data.id;
const pillarLabelSelector = (data: Pillar) => data.label;
Copy link
Member

Choose a reason for hiding this comment

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

define these outside

Comment on lines 267 to 278
name="choiceCollection"
keySelector={choiceCollectionKeySelector}
label="Options"
labelSelector={choiceCollectionLabelSelector}
onChange={setFieldValue}
onSearchValueChange={setSearch}
onOptionsChange={setChoiceCollectionOptions}
searchOptions={searchOption}
options={choiceCollectionOptions}
onShowDropdownChange={setOpened}
value={formValue.choiceCollection}
/>
Copy link
Member

Choose a reason for hiding this comment

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

reuse created component

return (
<div className={_cs(styles.preview, className)}>
<TextOutput
value={label ?? 'Which Country needs the assistance quickest?'}
Copy link
Member

Choose a reason for hiding this comment

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

replace dummy text with "Title"

labelSelector={choiceCollectionLabelSelector}
name="options"
onChange={noOp}
options={optionsList as QuestionChoiceCollectionType[]}
Copy link
Member

Choose a reason for hiding this comment

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

cast shouldn't be done

choiceCollections(
filters: {
questionnaire: {pk: $questionnaireId},
name: {iContains: $search }
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think if we want to filter the choiceCollections, we should do it through label instead of name.

]);

const {
data: choiceCollectionsResponse,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's fetch loading as well. We need to disable the SelectInput when the query is loading.

onShowDropdownChange={setOpened}
value={value}
label={label}
error={error}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's include disabled props.

]);

const {
data: pillarsResponse,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's fetch loading as well.

keySelector={pillarKeySelector}
labelSelector={pillarLabelSelector}
options={pillarsOptions}
disabled={false}
Copy link
Collaborator

Choose a reason for hiding this comment

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

The SelectInput is disabled when the query is loading. Let's include that as well.

options={optionsList}
value={optionsListResponse?.private?.projectScope?.choiceCollection?.name}
readOnly
disabled={false}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's add disabled when the query is loading.

const [
triggerQuestionCreate,
{ loading: createQuestionPending },
] = useMutation<CreateMultipleSelectionQuestionMutation, CreateTextQuestionMutationVariables>(
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
] = useMutation<CreateMultipleSelectionQuestionMutation, CreateTextQuestionMutationVariables>(
] = useMutation<CreateMultipleSelectionQuestionMutation, CreateMultipleSelectionQuestionMutationVariables>(

PartialForm,
} from '@togglecorp/toggle-form';
import {
CreateTextQuestionMutationVariables,
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
CreateTextQuestionMutationVariables,
CreateMultipleSelectionQuestionMutationVariables,

} from '@togglecorp/toggle-form';

import {
CreateTextQuestionMutationVariables,
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
CreateTextQuestionMutationVariables,
CreateSingleSelectQuestionMutationVariables,

{ loading: createQuestionPending },
] = useMutation<
CreateSingleSelectionQuestionMutation,
CreateTextQuestionMutationVariables
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
CreateTextQuestionMutationVariables
CreateSingleSelectionQuestionMutationVariables

@barshathakuri barshathakuri temporarily deployed to Test August 23, 2023 10:38 — with GitHub Actions Inactive
@barshathakuri barshathakuri temporarily deployed to Test August 23, 2023 10:43 — with GitHub Actions Inactive
@subinasr subinasr merged commit 9229091 into develop Aug 23, 2023
@subinasr subinasr deleted the feature/select-single-questions branch August 23, 2023 10:45
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.

4 participants