-
Notifications
You must be signed in to change notification settings - Fork 34
feat(POC): implement live frontend config editing UI #2143
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
Open
Junjiequan
wants to merge
17
commits into
master
Choose a base branch
from
SWAP-5087-scicat-fe-poc-render-frontend-config-with-json-fo
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
282e0b4
chore(deps-dev): bump the types group with 2 updates
dependabot[bot] 463ab53
chore(deps-dev): bump cypress from 15.6.0 to 15.7.0
dependabot[bot] 545d1ab
chore(deps-dev): bump js-yaml from 3.14.1 to 3.14.2
dependabot[bot] 51cdc85
first commit
Junjiequan b6ac54d
Merge branch 'master' into SWAP-5087-scicat-fe-poc-render-frontend-co…
Junjiequan 8ed2781
set admin guard to check isLogging status
Junjiequan 1b700c6
improve frontend config jsonForms UI
Junjiequan 6ae4e38
improve jsonForms UI
Junjiequan d0edf7d
created shared json preview dialog
Junjiequan 59fe4f8
improve frontend config jsonforms uiSchema
Junjiequan c5bd66a
include json preview & export
Junjiequan 504b83e
eslint fix
Junjiequan 8b360d2
change naming of admin state to runtimeConfig state
Junjiequan ef084be
Merge branch 'master' into SWAP-5087-scicat-fe-poc-render-frontend-co…
Junjiequan ea319ab
fix es lint
Junjiequan 34d61fb
update comments for temporary conversion functions
Junjiequan fd95985
show admin settings button only to admin user
Junjiequan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/app/admin/admin-config-edit/admin-config-edit.component.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| <div style="display: flex; justify-content: space-between; margin-bottom: 10px"> | ||
| <!-- LEFT --> | ||
| <div> | ||
| <button mat-button color="primary" (click)="jsonPreview()"> | ||
| Json Preview | ||
| </button> | ||
| </div> | ||
|
|
||
| <!-- RIGHT --> | ||
| <div> | ||
| <button mat-button color="primary" (click)="export()">Export</button> | ||
| <button mat-button color="primary" (click)="save()">Save</button> | ||
| </div> | ||
| </div> | ||
| <div> | ||
| <jsonforms | ||
| [data]="data$ | async" | ||
| [schema]="schema" | ||
| [uischema]="uiSchema" | ||
| [renderers]="renderers" | ||
| (dataChange)="onChange($event)" | ||
| ></jsonforms> | ||
| <div style="display: flex; justify-content: space-between; margin-top: 10px"> | ||
| <!-- LEFT --> | ||
| <div> | ||
| <button mat-button color="primary" (click)="jsonPreview()"> | ||
| Json Preview | ||
| </button> | ||
| </div> | ||
|
|
||
| <!-- RIGHT --> | ||
| <div> | ||
| <button mat-button color="primary" (click)="export()">Export</button> | ||
| <button mat-button color="primary" (click)="save()">Save</button> | ||
| </div> | ||
| </div> | ||
| </div> |
Empty file.
187 changes: 187 additions & 0 deletions
187
src/app/admin/admin-config-edit/admin-config-edit.component.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,187 @@ | ||
| import { Component, OnInit } from "@angular/core"; | ||
| import { Store } from "@ngrx/store"; | ||
| import { updateConfiguration } from "state-management/actions/runtime-config.action"; | ||
| import { selectConfig } from "state-management/selectors/runtime-config.selectors"; | ||
| import schema from "../schema/frontend.config.jsonforms.json"; | ||
| import { angularMaterialRenderers } from "@jsonforms/angular-material"; | ||
| import { | ||
| accordionArrayLayoutRendererTester, | ||
| AccordionArrayLayoutRendererComponent, | ||
| } from "shared/modules/jsonforms-custom-renderers/expand-panel-renderer/accordion-array-layout-renderer.component"; | ||
| import { map, Subscription, take } from "rxjs"; | ||
| import { | ||
| expandGroupTester, | ||
| ExpandGroupRendererComponent, | ||
| } from "shared/modules/jsonforms-custom-renderers/expand-group-renderer/expand-group-renderer"; | ||
| import { | ||
| ArrayLayoutRendererCustom, | ||
| arrayLayoutRendererTester, | ||
| } from "shared/modules/jsonforms-custom-renderers/ingestor-renderer/array-renderer"; | ||
| import { MatDialog } from "@angular/material/dialog"; | ||
| import { JsonPreviewDialogComponent } from "shared/modules/json-preview-dialog/json-preview-dialog.component"; | ||
| import { JsonSchema, UISchemaElement } from "@jsonforms/core"; | ||
| import { AppConfigInterface } from "app-config.service"; | ||
|
|
||
| @Component({ | ||
| selector: "admin-config-edit", | ||
| templateUrl: "./admin-config-edit.component.html", | ||
| styleUrls: ["./admin-config-edit.component.scss"], | ||
| standalone: false, | ||
| }) | ||
| export class AdminConfigEditComponent implements OnInit { | ||
| private subscriptions: Subscription[] = []; | ||
| config$ = this.store.select(selectConfig); | ||
| data$ = this.config$.pipe( | ||
| map((cfg) => (cfg.data ? this.toFormData(cfg.data) : null)), | ||
| ); | ||
|
|
||
| currentData: AppConfigInterface; | ||
| schema: JsonSchema = schema.schema || {}; | ||
| uiSchema: UISchemaElement = schema.uiSchema; | ||
| renderers = [ | ||
| ...angularMaterialRenderers, | ||
| { | ||
| tester: accordionArrayLayoutRendererTester, | ||
| renderer: AccordionArrayLayoutRendererComponent, | ||
| }, | ||
| { | ||
| tester: expandGroupTester, | ||
| renderer: ExpandGroupRendererComponent, | ||
| }, | ||
| { | ||
| tester: arrayLayoutRendererTester, | ||
| renderer: ArrayLayoutRendererCustom, | ||
| }, | ||
| ]; | ||
| constructor( | ||
| private store: Store, | ||
| private dialog: MatDialog, | ||
| ) {} | ||
|
|
||
| ngOnInit(): void { | ||
| this.subscriptions.push( | ||
| this.data$.pipe(take(1)).subscribe((d) => (this.currentData = d)), | ||
| ); | ||
| } | ||
|
|
||
| onChange(event: any) { | ||
| this.currentData = event; | ||
| } | ||
|
|
||
| save() { | ||
| const apiData = this.toApiData(this.currentData); | ||
|
|
||
| this.store.dispatch( | ||
| updateConfiguration({ id: "frontendConfig", config: apiData }), | ||
| ); | ||
| } | ||
|
|
||
| jsonPreview() { | ||
| const apiData = this.toApiData(this.currentData); | ||
|
|
||
| this.dialog.open(JsonPreviewDialogComponent, { | ||
| width: "90vw", | ||
| maxHeight: "90vh", | ||
| data: apiData, | ||
| }); | ||
| } | ||
|
|
||
| export() { | ||
| const apiData = this.toApiData(this.currentData); | ||
| const json = JSON.stringify(apiData, null, 2); | ||
|
|
||
| const blob = new Blob([json], { type: "application/json;charset=utf-8" }); | ||
| const url = URL.createObjectURL(blob); | ||
|
|
||
| const a = document.createElement("a"); | ||
| a.href = url; | ||
| a.download = `frontend-config-${new Date().toLocaleString("sv-SE")}.json`; | ||
| a.click(); | ||
|
|
||
| URL.revokeObjectURL(url); | ||
| } | ||
|
|
||
| /////////////////////////////////////////////////////// | ||
| // NOTE: below are temporary conversion functions | ||
| // it converts dynamic object to array with key and value properties | ||
| // and vice versa for jsonforms compatibility | ||
| // Should be removed when config values are fixed to use only arrays | ||
| /////////////////////////////////////////////////////// | ||
|
|
||
| toArray(obj: any) { | ||
| if (!obj) return []; | ||
| return Object.entries(obj).map(([key, value]) => ({ key, value })); | ||
| } | ||
| // TODO: to be removed | ||
| toObject(arr: any) { | ||
| if (!arr?.length) return {}; | ||
|
|
||
| return Object.fromEntries(arr.map((i) => [i.key, i.value])); | ||
| } | ||
|
|
||
| // TODO: to be removed | ||
| toFormData(data: any) { | ||
| const d = structuredClone(data); | ||
|
|
||
| if (d.labelsLocalization.dataset) { | ||
| d.labelsLocalization.dataset = this.toArray(d.labelsLocalization.dataset); | ||
| } | ||
| if (d.labelsLocalization.proposal) { | ||
| d.labelsLocalization.proposal = this.toArray( | ||
| d.labelsLocalization.proposal, | ||
| ); | ||
| } | ||
| if (d.datafilesActions) { | ||
| d.datafilesActions = d.datafilesActions.map((a: any) => ({ | ||
| ...a, | ||
| variables: | ||
| a.variables && !Array.isArray(a.variables) | ||
| ? this.toArray(a.variables) | ||
| : a.variables, | ||
| inputs: | ||
| a.inputs && !Array.isArray(a.inputs) | ||
| ? this.toArray(a.inputs) | ||
| : a.inputs, | ||
| })); | ||
| } | ||
|
|
||
| return d; | ||
| } | ||
|
|
||
| // TODO: to be removed | ||
| toApiData(data: any) { | ||
| const d = structuredClone(data); | ||
|
|
||
| d.labelsLocalization = d.labelsLocalization ?? { | ||
| dataset: {}, | ||
| proposal: {}, | ||
| }; | ||
| if (Array.isArray(d.labelsLocalization.dataset)) { | ||
| d.labelsLocalization.dataset = this.toObject( | ||
| d.labelsLocalization.dataset, | ||
| ); | ||
| } | ||
| if (Array.isArray(d.labelsLocalization.proposal)) { | ||
| d.labelsLocalization.proposal = this.toObject( | ||
| d.labelsLocalization.proposal, | ||
| ); | ||
| } | ||
| if (Array.isArray(d.datafilesActions)) { | ||
| d.datafilesActions = d.datafilesActions.map((a: any) => ({ | ||
| ...a, | ||
| variables: Array.isArray(a.variables) | ||
| ? this.toObject(a.variables) | ||
| : a.variables, | ||
| inputs: Array.isArray(a.inputs) ? this.toObject(a.inputs) : a.inputs, | ||
| })); | ||
| } | ||
|
|
||
| return d; | ||
| } | ||
|
|
||
| ngOnDestroy() { | ||
| this.subscriptions.forEach((subscription) => { | ||
| subscription.unsubscribe(); | ||
| }); | ||
| } | ||
| } | ||
23 changes: 23 additions & 0 deletions
23
src/app/admin/admin-dashboard/admin-dashboard.component.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| <!-- src/app/admin/admin-dashboard/admin-dashboard.component.html --> | ||
|
|
||
| <nav mat-tab-nav-bar [tabPanel]="tabPanel"> | ||
| <ng-container *ngFor="let link of navLinks"> | ||
| <a | ||
| mat-tab-link | ||
| *ngIf="link.enabled" | ||
| routerLink="{{ link.location }}" | ||
| routerLinkActive | ||
| #rla="routerLinkActive" | ||
| [routerLinkActiveOptions]="routerLinkActiveOptions" | ||
| [active]="rla.isActive" | ||
| [replaceUrl]="true" | ||
| (click)="onTabSelected(link.label)" | ||
| > | ||
| <mat-icon>{{ link.icon }}</mat-icon> | ||
| <span>{{ link.label }}</span> | ||
| </a> | ||
| </ng-container> | ||
| </nav> | ||
| <mat-tab-nav-panel #tabPanel> | ||
| <router-outlet></router-outlet> | ||
| </mat-tab-nav-panel> |
Empty file.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.