Skip to content

Commit

Permalink
Merge branch 'main' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
acoffman committed Aug 29, 2023
2 parents 10e42e8 + 866d792 commit 7894ab2
Show file tree
Hide file tree
Showing 30 changed files with 2,283 additions and 131 deletions.
7 changes: 6 additions & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
"generate-icon-ts": "svg-to-ts-constants",
"generate-icons": "yarn run optimize-icon-svg && yarn run generate-icon-ts",
"generate-apollo": "graphql-codegen",
"generate-apollo:start": "graphql-codegen --watch"
"generate-apollo:start": "graphql-codegen --watch",
"generate-icon-data": "scripts/generate-icon-data.js",
"generate-icon-rst": "scripts/generate-icon-rst.js",
"generate-docs-rst": "yarn run generate-icon-data && yarn run generate-icon-rst"
},
"private": true,
"resolutions": {
Expand Down Expand Up @@ -57,7 +60,9 @@
"@graphql-codegen/typescript-apollo-client-helpers": "^2.2.6",
"@graphql-codegen/typescript-operations": "^2.5.12",
"@types/node": "^12.11.1",
"directory-tree": "^3.5.1",
"graphql": "^16.7.1",
"mustache": "^4.2.0",
"ngx-json-viewer": "^3.0.2",
"prettier": "^2.5.1",
"svg-to-ts": "^9.0.0",
Expand Down
64 changes: 64 additions & 0 deletions client/scripts/generate-icon-data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/usr/bin/env node
const directoryTree = require('directory-tree')
const path = require('path')
const fs = require('fs')

const iconsDirectory = path.join(__dirname, '..', 'src', 'assets', 'icons')
const validSubdirectories = ['attribute', 'outline', 'twotone', 'fullcolor']

// Utility to remove redundant parent directory name from the filename
function removeRedundantName(type, filename) {
const pattern =
type === 'attribute' ? /-outline$/ : new RegExp(`-${type}$`, 'i')
return filename.replace(pattern, '')
}

function generateIconObject(tree) {
if (!tree || !tree.children) return []

return tree.children
.filter((child) => validSubdirectories.includes(child.name))
.flatMap((subdir) => {
return subdir.children.map((file) => {
const cleanName = removeRedundantName(
subdir.name,
path.basename(file.name, '.svg')
)
return {
type: subdir.name,
filepath: `${subdir.name}/${file.name}`,
name: cleanName,
alias: `${subdir.name}-${cleanName}`,
}
})
})
}

const tree = directoryTree(iconsDirectory, { extensions: /\.svg$/ })

if (!tree) {
console.error(
`Error: The icon assets folder ${iconsDirectory} does not exist or could not be accessed.`
)
process.exit(1)
}

const icons = generateIconObject(tree)
const output = {
icons: icons,
}

// Define the path to the output file
const outputPath = path.join(
__dirname,
'..',
'src',
'app',
'generated',
'civic.icons.data.json'
)

// Write the JSON data to the file
fs.writeFileSync(outputPath, JSON.stringify(output, null, 2))

console.log(`Icon data written to ${outputPath}`)
46 changes: 46 additions & 0 deletions client/scripts/generate-icon-rst.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env node
const fs = require('fs')
const path = require('path')
const mustache = require('mustache')

// Load the generated icon data JSON
const jsonDataPath = path.join(
__dirname,
'..',
'src',
'app',
'generated',
'civic.icons.data.json'
)
const iconData = JSON.parse(fs.readFileSync(jsonDataPath, 'utf-8'))

// Define the mustache template
const template = `
.. |{{alias}}| image:: /images/icons/{{{filepath}}}
:class: 'cvc-icon'
`

// Render the RST using mustache
const renderedRst =
'..\n ' +
'GENERATED BY CiVIC CLIENT DEV SCRIPT, DO NOT EDIT\n ' +
'(unless you know what you are doing)\n ' +
'Produced by `generate-icon-rst` script in civic-v2/client/scripts\n' +
iconData.icons.map((icon) => mustache.render(template, icon)).join('\n')

// Define the path to the output RST file
const outputPath = path.join(
__dirname,
'..',
'src',
'app',
'generated',
'civic.docs-aliases.rst'
)

// Write the rendered RST to the file
fs.writeFileSync(outputPath, renderedRst)

console.log(
`RST written to ${outputPath}, copy to civic-docs/docs/generated to update docs aliases.`
)
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ fragment RevisableMolecularProfileFields on MolecularProfile {
citationId
}
molecularProfileAliases
isComplex
}

mutation SuggestMolecularProfileRevision(
Expand Down
46 changes: 29 additions & 17 deletions client/src/app/forms/user-profile/user-profile.form.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,13 @@
</nz-form-item>
<nz-form-item>
<nz-form-label>ORCID Identifier</nz-form-label>
<input
nz-input
[(ngModel)]="this.orcid"
style="width: 100%" />
<nz-input-group nzAddOnBefore="https://orcid.org/">
<input
nz-input
placeholder="0000-0000-0000-0000"
[(ngModel)]="this.orcid"
style="width: 100%" />
</nz-input-group>
</nz-form-item>
<nz-form-item>
<nz-form-label>Personal Website</nz-form-label>
Expand All @@ -84,25 +87,34 @@
style="width: 100%" />
</nz-form-item>
<nz-form-item>
<nz-form-label>Twitter Handle</nz-form-label>
<input
nz-input
[(ngModel)]="this.twitterHandle"
style="width: 100%" />
<nz-form-label>X/Twitter Handle</nz-form-label>
<nz-input-group nzAddOnBefore="https://twitter.com/">
<input
nz-input
placeholder="username"
[(ngModel)]="this.twitterHandle"
style="width: 100%" />
</nz-input-group>
</nz-form-item>
<nz-form-item>
<nz-form-label>Facebook Profile</nz-form-label>
<input
nz-input
[(ngModel)]="this.facebookProfile"
style="width: 100%" />
<nz-input-group nzAddOnBefore="https://www.facebook.com/">
<input
nz-input
placeholder="username"
[(ngModel)]="this.facebookProfile"
style="width: 100%" />
</nz-input-group>
</nz-form-item>
<nz-form-item>
<nz-form-label>LinkedIn Profile</nz-form-label>
<input
nz-input
[(ngModel)]="this.linkedinProfile"
style="width: 100%" />
<nz-input-group nzAddOnBefore="https://www.linkedin.com/in/">
<input
nz-input
placeholder="username"
[(ngModel)]="this.linkedinProfile"
style="width: 100%" />
</nz-input-group>
</nz-form-item>
<nz-form-item>
<button
Expand Down
2 changes: 2 additions & 0 deletions client/src/app/forms/user-profile/user-profile.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { NzRadioModule } from 'ng-zorro-antd/radio'
import { NzSpinModule } from 'ng-zorro-antd/spin'
import { NzButtonModule } from 'ng-zorro-antd/button'
import { NzSelectModule } from 'ng-zorro-antd/select'
import { NzInputModule } from 'ng-zorro-antd/input'

@NgModule({
declarations: [CvcUserProfileForm],
Expand All @@ -27,6 +28,7 @@ import { NzSelectModule } from 'ng-zorro-antd/select'
NzButtonModule,
NzSpinModule,
NzSelectModule,
NzInputModule,
CvcFormErrorsAlertModule,
],
exports: [CvcUserProfileForm],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
[form]="form"
[fields]="fields"
[model]="model"
[options]="{}"
[options]="options"
(modelChange)="model = $event">
</formly-form>
</form>
Expand All @@ -29,5 +29,5 @@ <h4>Form</h4>
touched: {{ form.touched }}
</pre>
</nz-col>
</nz-row>
-->
</nz-row>
-->
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ import {
ChangeDetectorRef,
Component,
Input,
OnInit,
} from '@angular/core'
OnInit, } from '@angular/core'
import { UntypedFormGroup } from '@angular/forms'
import { MolecularProfileRevisableFieldsGQL, SuggestMolecularProfileRevisionGQL, SuggestMolecularProfileRevisionMutation, SuggestMolecularProfileRevisionMutationVariables } from '@app/generated/civic.apollo'
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy'
import { FormlyFieldConfig } from '@ngx-formly/core'
import { FormlyFieldConfig, FormlyFormOptions } from '@ngx-formly/core'
import { MutationState, MutatorWithState } from '@app/core/utilities/mutation-state-wrapper'
import { NetworkErrorsService } from '@app/core/services/network-errors.service'
import { MolecularProfileReviseModel } from '@app/forms2/models/molecular-profile-revise.model'
Expand All @@ -27,6 +26,7 @@ export class CvcMolecularProfileReviseForm implements OnInit, AfterViewInit {
model?: MolecularProfileReviseModel
form: UntypedFormGroup
fields: FormlyFieldConfig[]
options: FormlyFormOptions

reviseEvidenceMutator: MutatorWithState<
SuggestMolecularProfileRevisionGQL,
Expand All @@ -40,10 +40,28 @@ export class CvcMolecularProfileReviseForm implements OnInit, AfterViewInit {
constructor(
private revisableFieldsGQL: MolecularProfileRevisableFieldsGQL,
private submitRevisionsGQL: SuggestMolecularProfileRevisionGQL,
private networkErrorService: NetworkErrorsService,
private cdr: ChangeDetectorRef
private cdr: ChangeDetectorRef,
networkErrorService: NetworkErrorsService
) {
this.form = new UntypedFormGroup({})
this.options = { formState: { isSimpleMp: undefined } }

const aliasField = molecularProfileReviseFields[0]?.fieldGroup?.find(f => f.key == 'fields')?.fieldGroup?.find(f => f.key == "aliases")
if (aliasField) {
const originalDescription = aliasField.props?.description
aliasField.expressions = {
'props.disabled': (field: FormlyFieldConfig) => {
return field.options?.formState.isSimpleMp
},
'props.description': (field: FormlyFieldConfig) => {
if(field.options?.formState.isSimpleMp) {
return 'Simple Molecular Profiles inherit their Aliases from the corresponding Variant.'
} else {
return originalDescription
}
},
}
}
this.fields = molecularProfileReviseFields
this.reviseEvidenceMutator = new MutatorWithState(networkErrorService)
}
Expand All @@ -59,6 +77,9 @@ export class CvcMolecularProfileReviseForm implements OnInit, AfterViewInit {
.subscribe({
next: ({ data: { molecularProfile } }) => {
if (molecularProfile) {

this.options.formState.isSimpleMp = !molecularProfile.isComplex

this.model = {
id: molecularProfile.id,
fields: molecularProfileToModelFields(molecularProfile),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ fragment RevisableMolecularProfileFields on MolecularProfile {
citationId
}
molecularProfileAliases
isComplex
}

mutation SuggestMolecularProfileRevision(
Expand Down
9 changes: 5 additions & 4 deletions client/src/app/forms2/types/tag-input/tag-input.type.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<div>
<cvc-string-tag
*ngFor="let tag of tags$ | ngrxPush"
[cvcMode]="'closeable'"
[cvcMode]="this.props.disabled ? 'default' : 'closeable'"
[cvcLabel]="tag"
(cvcOnClose)="tagClosed(tag)"></cvc-string-tag>
<input nz-input
(keydown.enter)="onEnter($event)"
<input nz-input
[disabled]="this.props.disabled"
(keydown.enter)="onEnter($event)"
[placeholder]="this.props.placeholder" />
</div>

<input hidden nz-input [formControl]="formControl" [formlyAttributes]="field"/>
<input hidden nz-input [formControl]="formControl" [formlyAttributes]="field"/>
4 changes: 2 additions & 2 deletions client/src/app/forms2/types/tag-input/tag-input.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class CvcBaseInputField extends BaseInputMixin implements AfterViewInit {
placeholder: 'Enter value and hit Return'
},
}

tags$ = new Subject<string[]>()
values = new Set<string>()

Expand All @@ -73,7 +73,7 @@ export class CvcBaseInputField extends BaseInputMixin implements AfterViewInit {
this.tags$.next(arr)
this.formControl.setValue(arr)
}

tagClosed(tag: string) {
this.values.delete(tag)
let arr = Array.from(this.values)
Expand Down
Loading

0 comments on commit 7894ab2

Please sign in to comment.