Skip to content

Commit d362c3b

Browse files
author
baylee-d
authored
[ENG-2276] Update add-new page to allow no project registration (#1140)
* Add to add-new page * Remove unecessary test code, update variable name, make conditionals in template more readable * Update logic in template
1 parent 884a9e5 commit d362c3b

File tree

11 files changed

+196
-75
lines changed

11 files changed

+196
-75
lines changed

app/adapters/draft-registration.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import OsfAdapter from './osf-adapter';
22

33
export default class DraftRegistrationAdapter extends OsfAdapter {
4-
parentRelationship = 'branchedFrom';
54
}
65

76
declare module 'ember-data/types/registries/adapter' {

app/models/node.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ export default class NodeModel extends BaseFileItem.extend(Validations, Collecta
152152
registrations!: DS.PromiseManyArray<RegistrationModel>;
153153

154154
@hasMany('draft-registration', { inverse: 'branchedFrom' })
155-
draftRegistrations!: DS.PromiseManyArray<DraftRegistrationModel>;
155+
draftRegistrations?: DS.PromiseManyArray<DraftRegistrationModel>;
156156

157157
@hasMany('node', { inverse: 'forkedFrom' })
158158
forks!: DS.PromiseManyArray<NodeModel>;

lib/registries/addon/branded/new/controller.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { timeout } from 'ember-concurrency';
66
import { task } from 'ember-concurrency-decorators';
77
import DS from 'ember-data';
88

9+
import DraftRegistrationModel from 'ember-osf-web/models/draft-registration';
910
import NodeModel from 'ember-osf-web/models/node';
1011
import { Permission } from 'ember-osf-web/models/osf-model';
1112
import RegistrationSchemaModel from 'ember-osf-web/models/registration-schema';
@@ -24,19 +25,27 @@ export default class BrandedRegistriesNewSubmissionController extends Controller
2425
@tracked selectedSchema?: RegistrationSchemaModel;
2526
@tracked schemaOptions: RegistrationSchemaModel[] = [];
2627
@tracked projectOptions: NodeModel[] = [];
28+
@tracked isBasedOnProject: boolean = false;
2729

2830
get disableCreateDraft(): boolean {
29-
return !(this.selectedSchema && this.selectedProject);
31+
return this.isBasedOnProject ? !(this.selectedSchema && this.selectedProject) : !this.selectedSchema;
3032
}
3133

3234
@task({ withTestWaiter: true })
3335
createNewDraftRegistration = task(function *(this: BrandedRegistriesNewSubmissionController) {
34-
const newRegistration = this.store.createRecord('draft-registration',
35-
{
36+
let newRegistration: DraftRegistrationModel;
37+
if (this.isBasedOnProject) {
38+
newRegistration = this.store.createRecord('draft-registration', {
3639
registrationSchema: this.selectedSchema,
3740
provider: this.model,
3841
branchedFrom: this.selectedProject,
3942
});
43+
} else {
44+
newRegistration = this.store.createRecord('draft-registration', {
45+
registrationSchema: this.selectedSchema,
46+
provider: this.model,
47+
});
48+
}
4049
try {
4150
yield newRegistration.save();
4251
this.transitionToRoute('drafts.draft', newRegistration.id);

lib/registries/addon/branded/new/styles.scss

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
.selectLabel {
1414
composes: SchemaBlockDropdown from '../../drafts/draft/metadata/styles.scss';
1515
display: block;
16+
17+
div {
18+
max-width: 361px;
19+
}
1620
}
1721

1822
.projectHeading {
@@ -25,9 +29,14 @@
2529
flex-direction: column;
2630
}
2731

28-
.newProjectHelpText {
29-
margin-top: 20px;
30-
max-width: 600px;
32+
.InformationText {
33+
margin: 20px 0 30px;
34+
text-align: center;
35+
font-style: italic;
36+
37+
&.ComponentHelpText {
38+
max-width: 390px;
39+
}
3140
}
3241

3342
.createDraftButton {
@@ -49,3 +58,47 @@
4958
.required {
5059
color: $brand-danger;
5160
}
61+
62+
.StepOneContainer {
63+
margin-bottom: 30px;
64+
}
65+
66+
.RadioFieldset {
67+
position: relative;
68+
text-align: center;
69+
}
70+
71+
.RadioLegend {
72+
border-bottom: 0;
73+
font-size: 24px;
74+
font-weight: 600;
75+
}
76+
77+
.RadioElement {
78+
width: 80px;
79+
height: 40px;
80+
margin: 0;
81+
}
82+
83+
.RadioInput {
84+
position: absolute;
85+
opacity: 0;
86+
87+
&:hover {
88+
cursor: pointer;
89+
}
90+
}
91+
92+
.RadioLabel {
93+
text-align: center;
94+
line-height: 40px;
95+
border: 1px solid $color-border-gray;
96+
color: $color-text-blue-dark;
97+
text-transform: uppercase;
98+
}
99+
100+
.IsChecked {
101+
color: $color-osf-secondary;
102+
background-color: $color-bg-gray-blue-light;
103+
border: 1px solid $color-bg-gray-blue-light;
104+
}

lib/registries/addon/branded/new/template.hbs

Lines changed: 70 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -16,50 +16,83 @@
1616
</HeroOverlay>
1717
</layout.heading>
1818
<layout.main local-class='main'>
19+
<p local-class='InformationText'>
20+
{{t 'registries.new.provider_info' provider=this.model.name htmlSafe=true}}
21+
</p>
1922
<form data-test-new-registration-form local-class='registrationForm'>
20-
<label
21-
data-test-project-select
22-
local-class='selectLabel'
23-
>
23+
<label local-class='selectLabel StepOneContainer'>
2424
<p local-class='stepLabel'>
2525
{{t 'registries.new.step_one'}}
2626
</p>
27-
<h2
28-
data-test-project-select-title
29-
local-class='projectHeading'
30-
>
31-
{{t 'registries.new.select_project'}}
32-
<span local-class='required' aria-label={{t 'registries.new.required'}}>*</span>
33-
</h2>
34-
<PowerSelect
35-
@ariaLabel={{this.selectedProject.title}}
36-
@placeholder={{t 'registries.new.select_project_placeholder'}}
37-
@options={{this.projectOptions}}
38-
@search={{perform this.projectSearch}}
39-
@selected={{this.selectedProject}}
40-
@onchange={{this.updateSelectedProject}}
41-
as |option|
42-
>
43-
{{option.title}}
44-
</PowerSelect>
27+
<fieldset local-class='RadioFieldset'>
28+
<legend local-class='RadioLegend'>
29+
{{t 'registries.new.step_one_project_heading'}}
30+
</legend>
31+
<input
32+
data-test-has-project-button
33+
local-class='RadioElement RadioInput'
34+
type='radio'
35+
name='HasProject'
36+
value='yes'
37+
onclick={{fn (mut this.isBasedOnProject) true}}
38+
checked={{this.isBasedOnProject}}
39+
>
40+
<label
41+
local-class='RadioElement RadioLabel {{if this.isBasedOnProject 'IsChecked'}}'
42+
for='HasProject'
43+
>
44+
{{t 'registries.new.yes'}}
45+
</label>
46+
<input
47+
data-test-no-project-button
48+
local-class='RadioElement RadioInput'
49+
type='radio'
50+
name='no-project'
51+
value='no'
52+
onclick={{fn (mut this.isBasedOnProject) false}}
53+
checked={{not this.isBasedOnProject}}
54+
>
55+
<label
56+
local-class='RadioElement RadioLabel {{unless this.isBasedOnProject 'IsChecked'}}'
57+
for='NoProject'
58+
>
59+
{{t 'registries.new.no'}}
60+
</label>
61+
</fieldset>
4562
</label>
63+
{{#if this.isBasedOnProject}}
64+
<label data-test-project-select local-class='selectLabel'>
65+
<p local-class='stepLabel'>
66+
{{t 'registries.new.step_two'}}
67+
</p>
68+
<h3 data-test-project-select-title local-class='projectHeading'>
69+
{{t 'registries.new.select_project'}}
70+
<span local-class='required' aria-label={{t 'registries.new.required'}}>*</span>
71+
</h3>
72+
<PowerSelect
73+
@ariaLabel={{this.selectedProject.title}}
74+
@placeholder={{t 'registries.new.select_project_placeholder'}}
75+
@options={{this.projectOptions}}
76+
@search={{perform this.projectSearch}}
77+
@selected={{this.selectedProject}}
78+
@onchange={{this.updateSelectedProject}}
79+
as |option|
80+
>
81+
{{option.title}}
82+
</PowerSelect>
83+
</label>
84+
<p local-class='InformationText ComponentHelpText'>
85+
{{t 'registries.new.component_help_text'}}
86+
</p>
87+
{{/if}}
4688

47-
<p local-class='newProjectHelpText'>
48-
{{t 'registries.new.new_project_help_fragment1'}}
49-
<OsfLink
50-
@route='dashboard'
51-
>
52-
{{t 'registries.new.go_to_dashboard'}}
53-
</OsfLink>
54-
{{t 'registries.new.new_project_help_fragment2' htmlSafe=true}}
55-
</p>
56-
57-
<label
58-
data-test-schema-select
59-
local-class='selectLabel'
60-
>
89+
<label data-test-schema-select local-class='selectLabel'>
6190
<p local-class='stepLabel'>
62-
{{t 'registries.new.step_two'}}
91+
{{#if this.isBasedOnProject}}
92+
{{t 'registries.new.step_three'}}
93+
{{else}}
94+
{{t 'registries.new.step_two'}}
95+
{{/if}}
6396
</p>
6497
<h2 data-test-schema-select-title>
6598
{{t 'registries.new.select_schema'}}

lib/registries/addon/drafts/draft/draft-registration-manager.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import buildChangeset from 'ember-osf-web/utils/build-changeset';
2424

2525
type LoadDraftModelTask = TaskInstance<{
2626
draftRegistration: DraftRegistration,
27-
node: NodeModel,
27+
node?: NodeModel,
2828
provider: ProviderModel,
2929
}>;
3030

@@ -52,7 +52,7 @@ export default class DraftRegistrationManager {
5252
@notEmpty('visitedPages') hasVisitedPages!: boolean;
5353

5454
draftRegistration!: DraftRegistration;
55-
node!: NodeModel;
55+
node?: NodeModel;
5656
provider!: ProviderModel;
5757

5858
@computed('pageManagers.{[],@each.pageIsValid}')

lib/registries/addon/drafts/draft/template.hbs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,16 @@
1616
<layout.heading>
1717
<HeroOverlay @align='left' local-class='DraftHeroOverlay'>
1818
<div local-class='Title'>
19-
<OsfLink
20-
data-analytics-name='Go to project'
21-
local-class='BreadCrumb'
22-
@route='guid-node'
23-
@models={{array draftManager.node.id}}
24-
>
25-
{{draftManager.node.title}} >
26-
</OsfLink>
19+
{{#if draftManager.node}}
20+
<OsfLink
21+
data-analytics-name='Go to project'
22+
local-class='BreadCrumb'
23+
@route='guid-node'
24+
@models={{array draftManager.node.id}}
25+
>
26+
{{draftManager.node.title}} >
27+
</OsfLink>
28+
{{/if}}
2729
<h1>
2830
{{t 'registries.drafts.draft.form.new_registration'}}
2931
</h1>

mirage/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ export default function(this: Server) {
129129
only: ['index', 'show', 'update'],
130130
path: '/draft_registrations',
131131
});
132+
this.post('/draft_registrations', createDraftRegistration);
132133
osfToManyRelationship(this, 'draft-registration', 'subjects');
133134
osfToManyRelationship(this, 'draft-registration', 'affiliatedInstitutions', {
134135
only: ['related', 'update', 'add', 'remove'],

mirage/serializers/draft-registration.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,6 @@ const { OSF: { apiUrl } } = config;
88
export default class DraftRegistrationSerializer extends ApplicationSerializer<DraftRegistration> {
99
buildRelationships(model: ModelInstance<DraftRegistration>) {
1010
const returnValue: SerializedRelationships<DraftRegistration> = {
11-
branchedFrom: {
12-
data: {
13-
id: model.branchedFrom.id,
14-
type: 'nodes',
15-
},
16-
links: {
17-
related: {
18-
href: `${apiUrl}/v2/nodes/${model.branchedFrom.id}`,
19-
meta: {},
20-
},
21-
},
22-
},
2311
initiator: {
2412
data: {
2513
id: model.initiator.id,
@@ -81,6 +69,20 @@ export default class DraftRegistrationSerializer extends ApplicationSerializer<D
8169
},
8270
},
8371
};
72+
if (model.branchedFrom) {
73+
returnValue.branchedFrom = {
74+
data: {
75+
id: model.branchedFrom.id,
76+
type: 'nodes',
77+
},
78+
links: {
79+
related: {
80+
href: `${apiUrl}/v2/nodes/${model.branchedFrom.id}`,
81+
meta: {},
82+
},
83+
},
84+
};
85+
}
8486
if (model.license) {
8587
returnValue.license = {
8688
data: {

tests/engines/registries/acceptance/branded/new-test.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ module('Registries | Acceptance | branded.new', hooks => {
6060
assert.equal(currentRouteName(), 'registries.page-not-found', 'At the correct route: page-not-found');
6161
});
6262

63-
test('users are prevented from submitting incomplete form', async assert => {
63+
test('users are prevented from submitting incomplete form with project', async assert => {
6464
server.loadFixtures('registration-schemas');
6565
server.loadFixtures('schema-blocks');
6666
const currentUser = server.create('user', 'loggedIn');
@@ -72,7 +72,11 @@ module('Registries | Acceptance | branded.new', hooks => {
7272
await visit(`/registries/${brandedProvider.id}/new`);
7373

7474
assert.dom('[data-test-start-registration-button]')
75-
.isDisabled('Start registration button is disabled on first load');
75+
.isNotDisabled('Start registration button is enabled on first load with schema selected');
76+
await click('[data-test-has-project-button]');
77+
assert.dom('[data-test-project-select]').exists();
78+
assert.dom('[data-test-start-registration-button]')
79+
.isDisabled('Start button is disabled without project selected');
7680
await click('[data-test-project-select] .ember-power-select-trigger');
7781
assert.dom('.ember-power-select-options > li.ember-power-select-option:first-of-type')
7882
.hasText('This is your project', 'Project dropdown shows project title');
@@ -87,4 +91,19 @@ module('Registries | Acceptance | branded.new', hooks => {
8791
assert.equal(currentRouteName(), 'registries.drafts.draft.metadata',
8892
'Go to draft registration metadata page on start');
8993
});
94+
test('users are prevented from submitting incomplete form no project', async assert => {
95+
server.loadFixtures('registration-schemas');
96+
server.loadFixtures('schema-blocks');
97+
const brandedProvider = server.create('registration-provider', 'withBrand', 'withSchemas');
98+
await visit(`/registries/${brandedProvider.id}/new`);
99+
100+
assert.dom('[data-test-start-registration-button]')
101+
.isNotDisabled('Start registration button is enabled on first load with schema selected');
102+
assert.dom('[data-test-project-select]').doesNotExist();
103+
assert.dom('[data-test-schema-select] .ember-power-select-trigger')
104+
.hasText('This is a Test Schema', 'Schema dropdown is autopopulated with first schema available');
105+
await click('[data-test-start-registration-button]');
106+
assert.equal(currentRouteName(), 'registries.drafts.draft.metadata',
107+
'Go to draft registration metadata page on start');
108+
});
90109
});

0 commit comments

Comments
 (0)