Skip to content

Commit c845470

Browse files
committed
Web components updates
1 parent 33987e6 commit c845470

File tree

9 files changed

+107
-78
lines changed

9 files changed

+107
-78
lines changed

src/Umbraco.Cms.Integrations.Crm.Dynamics/Client/generated/services.gen.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,7 @@ export class DynamicsService {
7171
public static checkOauthConfiguration(): CancelablePromise<CheckOauthConfigurationResponse> {
7272
return __request(OpenAPI, {
7373
method: 'GET',
74-
url: '/dynamics/management/api/v1/forms/oauth-configuration',
75-
errors: {
76-
401: 'Unauthorized'
77-
}
74+
url: '/dynamics/management/api/v1/forms/oauth-configuration'
7875
});
7976
}
8077

src/Umbraco.Cms.Integrations.Crm.Dynamics/Client/generated/types.gen.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -826,10 +826,6 @@ export type $OpenApiTs = {
826826
* OK
827827
*/
828828
200: OAuthConfigurationDtoModel;
829-
/**
830-
* Unauthorized
831-
*/
832-
401: unknown;
833829
};
834830
};
835831
};

src/Umbraco.Cms.Integrations.Crm.Dynamics/Client/src/config/authorization/authorization-property-editor.element.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ export class DynamicsAuthorizationElement extends UmbElementMixin(LitElement){
8888
}, false);
8989
}
9090

91-
async getAccessToken(oauthRequestDtoModel: OAuthRequestDtoModel){
91+
async getAccessToken(oauthRequestDtoModel: OAuthRequestDtoModel) {
92+
this._loading = false;
9293
const { data } = await this.#dynamicsContext.getAccessToken(oauthRequestDtoModel);
9394
if (!data) return;
9495

@@ -162,7 +163,7 @@ export class DynamicsAuthorizationElement extends UmbElementMixin(LitElement){
162163
@click=${this.#connectButtonClick}></uui-button>
163164
<uui-button
164165
color="danger"
165-
look="secondary"
166+
look="primary"
166167
label="Revoke"
167168
?disabled=${!this._oauthSetup?.isConnected}
168169
@click=${this.#revokeButtonClick}></uui-button>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { DynamicsModuleModel } from "@umbraco-integrations/dynamics/generated";
2+
3+
export function parseModule(module: string) {
4+
switch (module) {
5+
case "1": return DynamicsModuleModel.OUTBOUND;
6+
case "2": return DynamicsModuleModel.REAL_TIME;
7+
}
8+
}
Lines changed: 81 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
import { customElement, html, repeat, state } from "@umbraco-cms/backoffice/external/lit";
1+
import { css, customElement, html, nothing, property, repeat, state } from "@umbraco-cms/backoffice/external/lit";
22
import { UmbModalBaseElement } from "@umbraco-cms/backoffice/modal";
33
import { DynamicsFormPickerModalData, DynamicsFormPickerModalValue } from "./dynamics.modal-token";
44
import { DYNAMICS_CONTEXT_TOKEN } from "../context/dynamics.context";
5-
import { FormDtoModel, OAuthConfigurationDtoModel } from "@umbraco-integrations/dynamics/generated";
5+
import { DynamicsModuleModel, FormDtoModel, OAuthConfigurationDtoModel } from "@umbraco-integrations/dynamics/generated";
66
import { UMB_NOTIFICATION_CONTEXT, UmbNotificationColor } from "@umbraco-cms/backoffice/notification";
77
import { UUIInputEvent } from "@umbraco-cms/backoffice/external/uui";
8-
import { UmbPropertyValueChangeEvent } from "@umbraco-cms/backoffice/property-editor";
8+
import {
9+
type UmbPropertyEditorConfigCollection,
10+
UmbPropertyValueChangeEvent
11+
} from "@umbraco-cms/backoffice/property-editor";
12+
import * as dynamicsModuleHelper from "../helpers/dynamic-module.helper";
913

1014
const elementName = "dynamics-forms-modal";
11-
enum testEnum {
12-
OUTBOUND = "1",
13-
REAL_TIME = "2"
14-
}
1515

1616
@customElement(elementName)
1717
export default class DynamicsFormModalElement extends UmbModalBaseElement<DynamicsFormPickerModalData, DynamicsFormPickerModalValue>{
@@ -23,12 +23,19 @@ export default class DynamicsFormModalElement extends UmbModalBaseElement<Dynami
2323
@state()
2424
private _forms: Array<FormDtoModel> = [];
2525
@state()
26-
private _filterForms: Array<FormDtoModel> = [];
26+
private _filteredForms: Array<FormDtoModel> = [];
27+
@state()
28+
private _selectedForm: FormDtoModel = {
29+
id: "",
30+
module: DynamicsModuleModel.BOTH,
31+
name: "",
32+
rawHtml: "",
33+
standaloneHtml: ""
34+
};
2735
@state()
2836
private renderWithIFrame: boolean = false;
2937
@state()
3038
private toggleLabel: string = "Render with Script";
31-
3239

3340
constructor() {
3441
super();
@@ -47,7 +54,7 @@ export default class DynamicsFormModalElement extends UmbModalBaseElement<Dynami
4754
await this.#checkOAuthConfiguration();
4855
}
4956

50-
async #checkOAuthConfiguration(){
57+
async #checkOAuthConfiguration() {
5158
if (!this.#settingsModel) return;
5259

5360
if (!this.#settingsModel.isAuthorized) {
@@ -57,34 +64,31 @@ export default class DynamicsFormModalElement extends UmbModalBaseElement<Dynami
5764
}
5865
}
5966

60-
async #getForms(){
67+
async #getForms() {
6168
this._loading = true;
62-
const { data } = await this.#dynamicsContext.getForms("Both");
63-
if(!data) return;
69+
const { data } = await this.#dynamicsContext.getForms(this.data?.module!);
70+
if (!data) return;
6471

6572
this._forms = data;
66-
this._filterForms = data;
73+
this._filteredForms = data;
6774
this._loading = false;
6875
}
6976

70-
async _onSelect(form: FormDtoModel){
71-
var result = await this.checkEmbed(form);
72-
if (result){
73-
this.value = { selectedForm: form };
74-
this._submitModal();
75-
}
77+
async _onSelect(form: FormDtoModel) {
78+
this._selectedForm = form;
7679
}
7780

78-
async checkEmbed(form: FormDtoModel){
79-
if(this.renderWithIFrame && form.module.toString() === testEnum.REAL_TIME){
80-
var { data } = await this.#dynamicsContext.getEmbedCode(form.id);
81-
if (!data || data.result.length == 0){
81+
async _onSubmit() {
82+
if (this.renderWithIFrame && dynamicsModuleHelper.parseModule(this._selectedForm.module.toString()) == DynamicsModuleModel.OUTBOUND) {
83+
var { data } = await this.#dynamicsContext.getEmbedCode(this._selectedForm.id);
84+
if (!data || data.result.length == 0) {
8285
this._showError("Unable to embed selected form. Please check if it is live.");
8386
return false;
8487
}
8588
}
8689

87-
return true;
90+
this.value = { selectedForm: this._selectedForm, iframeEmbedded: this.renderWithIFrame };
91+
this._submitModal();
8892
}
8993

9094
private async _showError(message: string) {
@@ -98,63 +102,82 @@ export default class DynamicsFormModalElement extends UmbModalBaseElement<Dynami
98102
});
99103
}
100104

101-
onMessageOnSubmitIsHtmlChange(){
105+
onMessageOnSubmitIsHtmlChange() {
102106
this.renderWithIFrame = !this.renderWithIFrame;
103107
this.toggleLabel = !this.renderWithIFrame ? "Render with Script" : "Render with iFrame";
104108
}
105109

106-
onSearchChange(e: UUIInputEvent){
107-
var searchText = e.target?.value as string;
108-
this._filterForms = this._forms.filter(f => f.name.toLowerCase().includes(searchText.toLowerCase()));
109-
this.dispatchEvent(new UmbPropertyValueChangeEvent());
110+
#handleFilterInput(event: UUIInputEvent) {
111+
let query = (event.target.value as string) || '';
112+
query = query.toLowerCase();
113+
114+
const result = !query
115+
? this._forms
116+
: this._forms.filter((form) => form.name?.toLowerCase().includes(query));
117+
118+
this._filteredForms = result;
119+
}
120+
private _renderFilter() {
121+
return html` <uui-input
122+
type="search"
123+
id="filter"
124+
@input="${this.#handleFilterInput}"
125+
placeholder="Type to filter..."
126+
label="Type to filter forms">
127+
<uui-icon name="search" slot="prepend" id="filter-icon"></uui-icon>
128+
</uui-input>`;
110129
}
111130

112-
render(){
131+
render() {
113132
return html`
114133
<umb-body-layout>
115-
${this._loading ?
116-
html`<div class="center loader"><uui-loader></uui-loader></div>` :
134+
${this._loading ?
135+
html`<div class="center loader"><uui-loader></uui-loader></div>` :
117136
html`
118137
<uui-box headline=${this.data!.headline}>
119-
<div slot="header">Select a form</div>
120-
121-
<uui-input placeholder="Type to search..." @change=${(e: UUIInputEvent) => this.onSearchChange(e)}>
122-
<div slot="append" style="background:#f3f3f3; padding-left:var(--uui-size-2, 6px)">
123-
<uui-icon-registry-essential>
124-
<uui-icon name="search"></uui-icon>
125-
</uui-icon-registry-essential>
126-
</div>
127-
</uui-input>
128-
129-
${this._filterForms.length > 0 ?
138+
${this._renderFilter()}
139+
${this._filteredForms.length > 0 ?
130140
html`
131-
${repeat(this._filterForms, (form) => html`
132-
<uui-ref-node-form
133-
selectable
134-
name=${form.name ?? ""}
135-
@selected=${() => this._onSelect(form)}>
136-
</uui-ref-node-form>
137-
`)}
138-
139-
<uui-toggle
140-
?checked=${this.renderWithIFrame}
141-
.label=${this.toggleLabel}
142-
@change=${this.onMessageOnSubmitIsHtmlChange}></uui-toggle>
143-
` :
141+
${repeat(this._filteredForms, (form) => html`
142+
<uui-ref-node-form
143+
selectable
144+
?selected=${this._selectedForm.id == form.id}
145+
name=${form.name ?? ""}
146+
@selected=${() => this._onSelect(form)}>
147+
</uui-ref-node-form>
148+
`)}
149+
<uui-toggle
150+
?checked=${this.renderWithIFrame}
151+
.label=${this.toggleLabel}
152+
@change=${this.onMessageOnSubmitIsHtmlChange}></uui-toggle>
153+
` :
144154
html``}
145155
</uui-box>
146156
147157
<br />
148158
149159
<uui-box headline="Dynamics - OAuth Status">
150-
<div slot="header">Please connect with your Microsoft account.</div>
151160
<dynamics-authorization></dynamics-authorization>
152161
</uui-box>
153162
`}
154163
164+
<uui-button look="primary" slot="actions" label="Submit" @click=${this._onSubmit}></uui-button>
155165
<uui-button slot="actions" label=${this.localize.term("general_close")} @click=${this._rejectModal}></uui-button>
156166
</umb-body-layout>
157167
`;
158168
}
169+
170+
static styles = [
171+
css`
172+
#filter {
173+
width: 100%;
174+
margin-bottom: var(--uui-size-3);
175+
}
176+
177+
uui-icon {
178+
margin: auto;
179+
margin-left: var(--uui-size-2);
180+
}
181+
`];
159182
}
160183

src/Umbraco.Cms.Integrations.Crm.Dynamics/Client/src/modal/dynamics.modal-token.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ import { DynamicsFormPickerConfiguration } from "../types/types";
44

55
export type DynamicsFormPickerModalData = {
66
headline: string;
7+
module: string;
78
}
89

910
export type DynamicsFormPickerModalValue = {
10-
selectedForm : FormDtoModel;
11+
selectedForm: FormDtoModel;
12+
iframeEmbedded: boolean;
1113
}
1214

1315
export const DYNAMICS_MODAL_TOKEN = new UmbModalToken<DynamicsFormPickerModalData, DynamicsFormPickerModalValue>("Dynamics.Modal", {

src/Umbraco.Cms.Integrations.Crm.Dynamics/Client/src/property-editor/dynamics-form-picker-property-editor.element.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element';
33
import { UmbPropertyEditorUiElement } from '@umbraco-cms/backoffice/extension-registry';
44
import { DYNAMICS_CONTEXT_TOKEN } from "../context/dynamics.context";
55
import { UMB_MODAL_MANAGER_CONTEXT } from "@umbraco-cms/backoffice/modal";
6-
import { FormDtoModel, OAuthConfigurationDtoModel } from "@umbraco-integrations/dynamics/generated";
6+
import { DynamicsModuleModel, FormDtoModel, OAuthConfigurationDtoModel } from "@umbraco-integrations/dynamics/generated";
77
import { DynamicsFormPickerConfiguration } from "../types/types";
88
import { UmbPropertyEditorConfigCollection } from "@umbraco-cms/backoffice/property-editor";
99
import { DYNAMICS_MODAL_TOKEN } from "../modal/dynamics.modal-token";
@@ -60,7 +60,7 @@ export class DynamicsFormPickerPropertyEditor extends UmbLitElement implements U
6060
}, 3000);
6161
}
6262

63-
#checkConfiguration(){
63+
#checkConfiguration() {
6464
if (this.value == null || this.value.length == 0) return;
6565

6666
if(!this.#settingsModel) return;
@@ -76,10 +76,12 @@ export class DynamicsFormPickerPropertyEditor extends UmbLitElement implements U
7676

7777
private async _openModal() {
7878
const module = this._config?.module == "Both" ? "Outbound | Real-Time" : this._config?.module;
79+
7980
const pickerContext = this.#modalManagerContext?.open(this, DYNAMICS_MODAL_TOKEN, {
8081
data: {
81-
headline: `Dynamics Forms - ${module} Marketing Forms`
82-
},
82+
headline: `Dynamics Forms - ${module} Marketing Forms`,
83+
module: this._config?.module!
84+
}
8385
});
8486

8587
const data = await pickerContext?.onSubmit();

src/Umbraco.Cms.Integrations.Crm.Dynamics/Client/src/property-editor/manifests.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export const propertyEditorUiManifest : ManifestPropertyEditorUi = {
88
js: () => import("./dynamics-form-picker-property-editor.element"),
99
meta: {
1010
label: "Dynamics Form Picker",
11-
icon: "icon-book",
11+
icon: "icon-handshake",
1212
group: "pickers",
1313
propertyEditorSchemaAlias: 'Umbraco.Cms.Integrations.Crm.Dynamics.FormPicker',
1414
settings: {

src/Umbraco.Cms.Integrations.Crm.Dynamics/Umbraco.Cms.Integrations.Crm.Dynamics.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@
3030
<PackageReference Include="Umbraco.Cms.Web.Common" Version="[14.0.0, 15)" />
3131
</ItemGroup>
3232

33-
<ItemGroup>
34-
<Folder Include="Client\" />
35-
</ItemGroup>
36-
3733
<ItemGroup>
3834
<FrameworkReference Include="Microsoft.AspNetCore.App" />
3935
<SupportedPlatform Include="browser" />
@@ -50,6 +46,10 @@
5046
<None Include="docs\readme.md" Pack="true" PackagePath="\" />
5147
</ItemGroup>
5248

49+
<ItemGroup>
50+
<Content Include="Views\**" />
51+
</ItemGroup>
52+
5353
<!-- Build client assets using NPM -->
5454
<Import Project="build\Microsoft.AspNetCore.ClientAssets.targets" />
5555
<PropertyGroup>

0 commit comments

Comments
 (0)