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

Esteban/feature/editable configs #111

Merged
merged 1 commit into from
Nov 19, 2022

Conversation

esteban-gs
Copy link
Member

@esteban-gs esteban-gs commented Apr 25, 2022

Changes:

Module for machete configs (called machete settings in ui) within the Configs module
  • Edit/read ui for machete user-configurable configs
    • JSON editor for multiple online hiring terms
  • List ui for machete configs

image

image

@esteban-gs esteban-gs self-assigned this May 5, 2022
@esteban-gs esteban-gs marked this pull request as ready for review June 23, 2022 20:13
first()
);
}

update(config: Config): Observable<Config> {
if (MS_NON_EDITABLE_CONFIGS_LOWER_CASE.includes(config.key.toLowerCase())) {
Copy link
Member

Choose a reason for hiding this comment

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

Does the backend make this same check ? You have to assume the UI is untrustworthy and check on the server-side too.

Copy link
Member Author

Choose a reason for hiding this comment

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

I added a PR on the back end to validate

/**
* Model for Machete Setting Terms
*/
export class Term {
Copy link
Member

Choose a reason for hiding this comment

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

We're using Term here and Confirm in the backend?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. I have updated it to be OnlineOrderTerm

@esteban-gs esteban-gs linked an issue Oct 17, 2022 that may be closed by this pull request
@jcii jcii force-pushed the esteban/feature/editable_configs branch 2 times, most recently from 1c0627e to 63d9fa6 Compare November 19, 2022 21:33
Comment on lines +11 to +41
beforeEach(() => {
cy.apiLogin(MACHETE_ADMIN.user, MACHETE_ADMIN.password);

// Stubbing the response from server here
cy.fixture("settings/settings.json");
cy.intercept(
{
method: "GET",
url: "/api/configs",
},
{ fixture: "settings/settings" }
).as("configs");
cy.visit(macheteSettingsRoutes.list);

cy.wait("@configs").then((i) => {
Cypress.env(STUBBED_CONFGIS_KEY, i.response.body.data);
const configs = Cypress.env(STUBBED_CONFGIS_KEY) as Config[];

userEditableConfigs = configs.filter(
(c: Config) =>
c.publicConfig &&
!MS_NON_EDITABLE_CONFIGS_LOWER_CASE.includes(c.key.toLowerCase())
);

privateConfigs = configs.filter(
(c: Config) =>
!c.publicConfig &&
MS_NON_EDITABLE_CONFIGS_LOWER_CASE.includes(c.key.toLowerCase())
);
});
});
Copy link
Member Author

Choose a reason for hiding this comment

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

This is injecting test config data from fixtures/settings into the http response

Comment on lines +28 to +34
cy.wait("@configs").then(() => {
configs = Cypress.env(ENV_KEY_MACHETE_CONFIGS) as Config[];
userEditableConfigs = configs.filter(
(c: Config) =>
c.publicConfig &&
!MS_NON_EDITABLE_CONFIGS_LOWER_CASE.includes(c.key.toLowerCase())
);
Copy link
Member Author

Choose a reason for hiding this comment

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

Also injecting test data in the http response

Comment on lines +23 to +28
path: "settings",
loadChildren: () =>
import("./machete-settings/machete-settings.module").then(
(m) => m.MacheteSettingsModule
),
},
Copy link
Member Author

Choose a reason for hiding this comment

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

this lazy-loads the module

Comment on lines +71 to +92
return this.http
.put(`${this.uriBase}/${config.id}`, config, { withCredentials: true })
.pipe(
catchError((error) => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
const errorAsText: string = error["statusText"] as string;
this.appMessages.showErrors({
Error: `${errorAsText}: Contact Machete support.`,
});
console.log(error);
return throwError(error);
}),
pluck("data"),
map((data) => data as Config),
tap(() => {
this.appMessages.showSuccess({
label: "Success",
message: "Record Saved",
});
})
);
}
Copy link
Member Author

Choose a reason for hiding this comment

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

catchError will break the stream and user will receive the feedback

remove unused

bootstrap routing for edit component

bootstrap edit component

handle confirm save and cancel

implement edit

configs service

Handle SAVE errors and return new reference on `getOne`

Include description in template

Exclude rows not editable by users

user-defined settings
- exclude from list
- validate against edits

Better titles

define user-defined settings

implement terms editor

e2e testing

stub settings reponses

edit component unit tests

fix confitional render

better type names

better file name

better online order term naming
@jcii jcii force-pushed the esteban/feature/editable_configs branch from 63d9fa6 to 2e41751 Compare November 19, 2022 22:55
Comment on lines +45 to +67
<div class="p-field p-col-12 p-input-filled" [hidden]="r.key === TERMS_KEY">
<span class="p-float-label">
<input
pInputText
[(ngModel)]="r.value"
id="value"
name="value"
required
ngModel
#value="ngModel"
/>
<label for="value">Value</label>
</span>
<small class="p-error" *ngIf="!r.value"
>Value is required</small
>
</div>
<div class="p-field p-col-12" *ngIf="r.key === TERMS_KEY">
<app-machete-settings-term-form [termsAsString]="r.value" (termChange)="onChildTermChange($event, r)"></app-machete-settings-term-form>
</div>
</div>
</form>
</div>
Copy link
Member Author

Choose a reason for hiding this comment

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

logic to determine if form will display an input field or the onlineTerms form. The terms form is in a child component: app-machete-settings-term-form

@@ -0,0 +1,119 @@
<ng-container *ngIf="record$ | async as r">
Copy link
Member Author

@esteban-gs esteban-gs Nov 19, 2022

Choose a reason for hiding this comment

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

foo$ | async as bar aka async pipe is a new ng feature that handles the subscribe/unsubscribe logic automatically

@esteban-gs esteban-gs merged commit de7d020 into master Nov 19, 2022
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.

Content to make configurable from the Configs endpoint
2 participants