Skip to content

Commit 3898979

Browse files
authored
feat: Optional Clear (#109)
* Can have the clear field be optional on study creation
1 parent c7aad45 commit 3898979

File tree

8 files changed

+57
-4
lines changed

8 files changed

+57
-4
lines changed

packages/client/public/locales/en/translation.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
"newStudy": {
101101
"completed": "All steps completed - your new study is created",
102102
"createStudy": "Create New Study",
103+
"disableClear": "Disable Clear Button",
103104
"disableSameUserTagging": "Disable users tagging entries they recorded",
104105
"formTitle": "Study Information",
105106
"noDatasets": "No datasets available, create a dataset and grant the project access under Datasets > Project Access",

packages/client/public/locales/es/translation.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
"newStudy": {
101101
"completed": "All steps completed - your new study is created",
102102
"createStudy": "Create New Study",
103+
"disableClear": "",
103104
"disableSameUserTagging": "Disable users tagging entries they recorded",
104105
"formTitle": "Study Information",
105106
"noDatasets": "No datasets available, create a dataset and grant the project access under Datasets > Project Access",

packages/client/src/components/NewStudyJsonForm.component.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ export const NewStudyJsonForm: React.FC<NewStudyFormProps> = (props) => {
4545
sortByEntryID: {
4646
type: 'boolean',
4747
default: false
48+
},
49+
disableClear: {
50+
type: 'boolean',
51+
default: 'false'
4852
}
4953
}
5054
}
@@ -85,6 +89,11 @@ export const NewStudyJsonForm: React.FC<NewStudyFormProps> = (props) => {
8589
type: 'Control',
8690
label: t('components.newStudy.sortByEntryID'),
8791
scope: '#/properties/studyConfig/properties/sortByEntryID'
92+
},
93+
{
94+
type: 'Control',
95+
label: t('components.newStudy.disableClear'),
96+
scope: '#/properties/studyConfig/properties/disableClear'
8897
}
8998
]
9099
};

packages/client/src/components/contribute/TagForm.component.tsx

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,26 @@ export const TagForm: React.FC<TagFormProps> = (props) => {
2020
const [dataValid, setDataValid] = useState<boolean>(false);
2121
const { t } = useTranslation();
2222

23+
// Controls if a clear button should be present
24+
const [hasClearButton, setHasClearButton] = useState<boolean>(false);
25+
26+
useEffect(() => {
27+
// If the study config is not present, by default have a clear button
28+
if (!props.study.studyConfig) {
29+
setHasClearButton(true);
30+
return;
31+
}
32+
33+
// If the "disableClear" field isn't present, default have a clear button
34+
if (props.study.studyConfig.disableClear === undefined || props.study.studyConfig.disableClear === null) {
35+
setHasClearButton(true);
36+
return;
37+
}
38+
39+
// Otherwise use the field
40+
setHasClearButton(!props.study.studyConfig.disableClear);
41+
}, [props.study]);
42+
2343
const handleFormChange = (data: any, errors: ErrorObject[] | undefined) => {
2444
setData(data);
2545

@@ -81,9 +101,12 @@ export const TagForm: React.FC<TagFormProps> = (props) => {
81101
<Button variant="outlined" onClick={handleSubmit} disabled={!dataValid}>
82102
{t('common.submit')}
83103
</Button>
84-
<Button variant="outlined" onClick={handleClear}>
85-
{t('common.clear')}
86-
</Button>
104+
105+
{hasClearButton && (
106+
<Button variant="outlined" onClick={handleClear}>
107+
{t('common.clear')}
108+
</Button>
109+
)}
87110
</Stack>
88111
</Stack>
89112
</Box>

packages/client/src/graphql/graphql.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,11 +646,13 @@ export type Study = {
646646

647647
export type StudyConfig = {
648648
__typename?: 'StudyConfig';
649+
disableClear?: Maybe<Scalars['Boolean']['output']>;
649650
disableSameUserEntryTagging?: Maybe<Scalars['Boolean']['output']>;
650651
sortByEntryID?: Maybe<Scalars['Boolean']['output']>;
651652
};
652653

653654
export type StudyConfigInput = {
655+
disableClear?: InputMaybe<Scalars['Boolean']['input']>;
654656
disableSameUserEntryTagging?: InputMaybe<Scalars['Boolean']['input']>;
655657
sortByEntryID?: InputMaybe<Scalars['Boolean']['input']>;
656658
};

packages/client/src/graphql/study/study.graphql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ query findStudies($project: ID!) {
1010
dataSchema
1111
uiSchema
1212
}
13+
studyConfig {
14+
disableSameUserEntryTagging
15+
sortByEntryID
16+
disableClear
17+
}
1318
}
1419
}
1520

packages/client/src/graphql/study/study.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export type FindStudiesQueryVariables = Types.Exact<{
1010
}>;
1111

1212

13-
export type FindStudiesQuery = { __typename?: 'Query', findStudies: Array<{ __typename?: 'Study', _id: string, name: string, description: string, instructions: string, project: string, tagsPerEntry: number, tagSchema: { __typename?: 'TagSchema', dataSchema: any, uiSchema: any } }> };
13+
export type FindStudiesQuery = { __typename?: 'Query', findStudies: Array<{ __typename?: 'Study', _id: string, name: string, description: string, instructions: string, project: string, tagsPerEntry: number, tagSchema: { __typename?: 'TagSchema', dataSchema: any, uiSchema: any }, studyConfig?: { __typename?: 'StudyConfig', disableSameUserEntryTagging?: boolean | null, sortByEntryID?: boolean | null, disableClear?: boolean | null } | null }> };
1414

1515
export type DeleteStudyMutationVariables = Types.Exact<{
1616
study: Types.Scalars['ID']['input'];
@@ -62,6 +62,11 @@ export const FindStudiesDocument = gql`
6262
dataSchema
6363
uiSchema
6464
}
65+
studyConfig {
66+
disableSameUserEntryTagging
67+
sortByEntryID
68+
disableClear
69+
}
6570
}
6671
}
6772
`;

packages/server/src/study/study.model.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ export class StudyConfig {
3636
@Prop({ required: false })
3737
@Field({ nullable: true })
3838
sortByEntryID?: boolean;
39+
40+
/**
41+
* If set, clear button will not be present in the UI of the study
42+
*/
43+
@Prop({ required: false })
44+
@Field({ nullable: true })
45+
disableClear?: boolean;
3946
}
4047

4148
const StudyConfigSchema = SchemaFactory.createForClass(StudyConfig);

0 commit comments

Comments
 (0)