Skip to content

Commit

Permalink
Merge branch 'master' into feat/dynamic-data-partial-cache
Browse files Browse the repository at this point in the history
  • Loading branch information
esmeetewinkel authored Feb 27, 2025
2 parents 77f5221 + a99064b commit 9584d64
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 45 deletions.
23 changes: 16 additions & 7 deletions src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,18 @@ import { TourComponent } from "./feature/tour/tour.component";
* Additional home template redirects and fallback routes will be specified
* from deployment config via the AppConfigService
**/
export const APP_FEATURE_ROUTES: Routes = [
const featureRoutes: Routes = [
{
path: "campaigns",
loadChildren: () => import("./feature/campaign/campaign.module").then((m) => m.CampaignModule),
},
{
path: "component",
loadChildren: () =>
import("./feature/template/pages/component/component.module").then(
(m) => m.TemplateComponentModule
),
},
{
path: "notifications",
loadChildren: () =>
Expand All @@ -38,7 +45,9 @@ export const APP_FEATURE_ROUTES: Routes = [
path: "user",
loadChildren: () => import("./feature/user/user.module").then((m) => m.UserModule),
},
// Routes to show in sidebar routing
];
// Routes available for display in sidebar routing
const sidebarRoutes: Routes = [
{
path: "feedback",
loadChildren: () => import("./feature/feedback/feedback.module").then((m) => m.FeedbackModule),
Expand All @@ -51,14 +60,14 @@ export const APP_FEATURE_ROUTES: Routes = [
outlet: "sidebar",
},
{
path: "component",
loadChildren: () =>
import("./feature/template/pages/component/component.module").then(
(m) => m.TemplateComponentModule
),
path: "user",
loadChildren: () => import("./feature/user/user.module").then((m) => m.UserModule),
outlet: "sidebar",
},
];

export const APP_FEATURE_ROUTES = [...featureRoutes, ...sidebarRoutes];

@NgModule({
imports: [
RouterModule.forRoot(APP_FEATURE_ROUTES, {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
@if (variant === "modal") {
@if (params().variant === "modal") {
<button
class="open-combobox margin-t-regular"
(click)="openModal()"
[ngClass]="{
disabled: disabled(),
'placeholder-style': (!_row.value && placeholder) || prioritisePlaceholder,
'placeholder-style': (!_row.value && params().placeholder) || params().prioritisePlaceholder,
'with-value': _row.value,
'no-value': !_row.value
}"
[disabled]="disabled()"
>
{{ displayText() | translate }}
</button>
} @else if (variant === "dropdown") {
} @else if (params().variant === "dropdown") {
<div class="combo-box-container dropdown">
<ion-select
[class.hasValue]="!!_row.value"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, computed, effect, OnDestroy, signal } from "@angular/core";
import { Component, computed, effect, OnDestroy, Signal, signal } from "@angular/core";
import { ModalController } from "@ionic/angular";
import { ComboBoxModalComponent } from "./combo-box-modal/combo-box-modal.component";
import {
Expand All @@ -8,11 +8,20 @@ import {
getStringParamFromTemplateRow,
} from "src/app/shared/utils";
import { TemplateBaseComponent } from "../base";
import { ITemplateRowProps } from "../../models";
import { FlowTypes, ITemplateRowProps } from "../../models";
import { ReplaySubject, map, filter, switchMap } from "rxjs";
import { DataItemsService } from "../data-items/data-items.service";
import { toObservable, toSignal } from "@angular/core/rxjs-interop";

interface IComboBoxParams {
disabled: boolean;
disabledText: string;
placeholder: string;
prioritisePlaceholder: boolean;
style: string;
variant: "modal" | "dropdown";
}

@Component({
selector: "plh-combo-box",
templateUrl: "./combo-box.component.html",
Expand All @@ -22,13 +31,9 @@ export class TmplComboBoxComponent
extends TemplateBaseComponent
implements ITemplateRowProps, OnDestroy
{
public variant: "modal" | "dropdown";
public placeholder: string;
public prioritisePlaceholder: boolean;
public disabledText: string;
private style: string;
public params: Signal<IComboBoxParams> = computed(() => this.getParams(this.parameterList()));

public answerText = signal("");
private authorDisabled = false;
private customAnswerSelected = signal(false);
private customAnswerText: string;
private componentDestroyed$ = new ReplaySubject(1);
Expand All @@ -50,12 +55,14 @@ export class TmplComboBoxComponent
return getAnswerListParamFromTemplateRow(this.rowSignal(), "answer_list", []);
});

public disabled = computed(() => this.authorDisabled || this.answerOptions().length === 0);
public disabled = computed(() => this.params().disabled || this.answerOptions().length === 0);

public displayText = computed(() => {
if (this.disabled()) return this.disabledText;
if (this.disabled()) return this.params().disabledText;
if (this.customAnswerSelected()) return this.customAnswerText;
return this.answerText() && !this.prioritisePlaceholder ? this.answerText() : this.placeholder;
return this.answerText() && !this.params().prioritisePlaceholder
? this.answerText()
: this.params().placeholder;
});

constructor(
Expand All @@ -79,25 +86,25 @@ export class TmplComboBoxComponent
},
{ allowSignalWrites: true }
);
effect(() => {
this.parameterList();
this.getParams();
});
}

getParams() {
this.placeholder = getStringParamFromTemplateRow(this._row, "placeholder", "");
this.prioritisePlaceholder = getBooleanParamFromTemplateRow(
this._row,
"prioritise_placeholder",
false
);
this.disabledText = getStringParamFromTemplateRow(this._row, "disabled_text", "");
this.style = getStringParamFromTemplateRow(this._row, "style", "");
this.variant = getStringParamFromTemplateRow(this._row, "variant", "modal") as
| "modal"
| "dropdown";
this.authorDisabled = getBooleanParamFromTemplateRow(this._row, "disabled", false);
private getParams(authorParams?: FlowTypes.TemplateRow["parameter_list"]): IComboBoxParams {
return {
disabled: getBooleanParamFromTemplateRow(this._row, "disabled", false),
disabledText: getStringParamFromTemplateRow(this._row, "disabled_text", ""),
placeholder: getStringParamFromTemplateRow(this._row, "placeholder", ""),
prioritisePlaceholder: getBooleanParamFromTemplateRow(
this._row,
"prioritise_placeholder",
false
),
style: getStringParamFromTemplateRow(this._row, "style", ""),
variant: getStringParamFromTemplateRow(
this._row,
"variant",
"modal"
) as IComboBoxParams["variant"],
};
}

public async handleDropdownChange(value) {
Expand All @@ -114,12 +121,12 @@ export class TmplComboBoxComponent
row: this._row,
selectedValue: this.customAnswerSelected() ? this.answerText() : this._row.value,
customAnswerSelected: this.customAnswerSelected(),
style: this.style,
style: this.params().style,
},
});

modal.onDidDismiss().then(async (data) => {
this.prioritisePlaceholder = false;
this.params().prioritisePlaceholder = false;
this.answerText.set(data?.data?.answer?.text);
this.customAnswerSelected.set(data?.data?.customAnswerSelected);
this.customAnswerText = this.customAnswerSelected() ? data?.data?.answer?.text : "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,10 @@ describe("TemplateActionService", () => {
expect(service.container.templateRowService.templateRowMapValues.mock_row_1).toEqual("updated");
});

it("Uses latest value for `this.value` arg", async () => {
const _triggeredBy = { _nested_name: "mock_row_1", name: "mock_row_1", type: "" };
it("Uses latest value for `this.value` arg from trigger row", async () => {
const _triggeredBy = { _nested_name: "", name: "", type: "", value: "updated" };
await service.handleActions(
[
{ trigger: "click", action_id: "set_self", args: ["mock_row_1", "updated"] },
{
trigger: "click",
action_id: "set_local",
Expand Down Expand Up @@ -123,7 +122,7 @@ describe("TemplateActionService", () => {
});

it("Uses latest value for `this.value` param", async () => {
const _triggeredBy = { _nested_name: "mock_row_1", name: "mock_row_1", type: "" };
const _triggeredBy = { _nested_name: "", name: "", type: "", value: "updated" };
await service.handleActions(
[
{ trigger: "click", action_id: "set_self", args: ["mock_row_1", "updated"] },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ export class TemplateActionService extends SyncServiceBase {
action: FlowTypes.TemplateRowAction
): FlowTypes.TemplateRowAction {
// Update action.args and action.params
const currentValue = this.container?.templateRowMap?.[action._triggeredBy?._nested_name]?.value;
const currentValue = action._triggeredBy?.value;
// define a replacer that preserves type if `this.value` specified, replacing as string for
// other expressions `@local.some_field_{this.value}`
function replaceReference(v: any) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export default async (service: DynamicDataService, params: IActionSetDataParams)
params._updates = await generateUpdateList(service, params);
}
const { _list_id, _updates } = params;
console.log("[Set Data]", _list_id, _updates);
// Hack, no current method for bulk update so make successive (changes debounced in component)
for (const { id, ...writeableProps } of _updates) {
await service.update("data_list", _list_id, id, writeableProps);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ export class DynamicDataService extends AsyncServiceBase {
}

if (itemDataIDs.includes(targetRowId)) {
console.log("[Set Item]", flow_name, targetRowId, writeableProps);
await this.update("data_list", flow_name, targetRowId, writeableProps);
} else {
console.warn(`[SET ITEM] - No item ${_id ? "with ID " + _id : "at index " + _index}`);
Expand Down

0 comments on commit 9584d64

Please sign in to comment.