Skip to content

Commit

Permalink
refactor(wizards/reportcontrol): minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakob Vogelsang committed Dec 16, 2021
1 parent 9dd92ff commit d30df48
Showing 1 changed file with 49 additions and 52 deletions.
101 changes: 49 additions & 52 deletions src/wizards/reportcontrol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,45 +47,38 @@ function getRptEnabledAction(

function updateReportControlAction(element: Element): WizardActor {
return (inputs: WizardInput[]): EditorAction[] => {
const name = inputs.find(i => i.label === 'name')!.value!;
const desc = getValue(inputs.find(i => i.label === 'desc')!);
const buffered = getValue(inputs.find(i => i.label === 'buffered')!);
const rptID = getValue(inputs.find(i => i.label === 'rptID')!)!;
const indexed = getValue(inputs.find(i => i.label === 'indexed')!);
const max = getValue(inputs.find(i => i.label === 'max Clients')!);
const bufTime = getValue(inputs.find(i => i.label === 'bufTime')!);
const intgPd = getValue(inputs.find(i => i.label === 'intgPd')!);
const attributes: Record<string, string | null> = {};
const attributeKeys = [
'name',
'desc',
'buffered',
'rptID',
'indexed',
'bufTime',
'intgPd',
];

attributeKeys.forEach(key => {
attributes[key] = getValue(inputs.find(i => i.label === key)!);
});

let reportControlAction: EditorAction | null;
let rptEnabledAction: EditorAction | null;
let reportControlAction: EditorAction | null = null;
if (
name === element.getAttribute('name') &&
desc === element.getAttribute('desc') &&
buffered === element.getAttribute('buffered') &&
rptID === element.getAttribute('rptID') &&
indexed === element.getAttribute('indexed') &&
bufTime === element.getAttribute('bufTime') &&
intgPd === element.getAttribute('intgPd')
attributeKeys.some(key => attributes[key] !== element.getAttribute(key))
) {
reportControlAction = null;
} else {
const newElement = cloneElement(element, {
name,
desc,
buffered,
rptID,
indexed,
bufTime,
intgPd,
});
reportControlAction = { old: { element }, new: { element: newElement } };
const newElement = cloneElement(element, attributes);
reportControlAction = {
old: { element },
new: { element: newElement },
};
}

const max = getValue(inputs.find(i => i.label === 'max Clients')!);

let rptEnabledAction: EditorAction | null = null;
if (
max === (element.querySelector('RptEnabled')?.getAttribute('max') ?? null)
max !== (element.querySelector('RptEnabled')?.getAttribute('max') ?? null)
)
rptEnabledAction = null;
else
rptEnabledAction = getRptEnabledAction(
element.querySelector('RptEnabled')!,
max,
Expand All @@ -99,20 +92,24 @@ function updateReportControlAction(element: Element): WizardActor {
};
}

function renderReportControlAttributes(
name: string | null,
desc: string | null,
buffered: string | null,
rptID: string | null,
indexed: string | null,
max: string | null,
bufTime: string | null,
intgPd: string | null
interface RenderOptions {
name: string | null;
desc: string | null;
buffered: string | null;
rptID: string | null;
indexed: string | null;
max: string | null;
bufTime: string | null;
intgPd: string | null;
}

function renderReportControlWizardInputs(
options: RenderOptions
): TemplateResult[] {
return [
html`<wizard-textfield
label="name"
.maybeValue=${name}
.maybeValue=${options.name}
helper="${translate('scl.name')}"
required
validationMessage="${translate('textfield.required')}"
Expand All @@ -122,13 +119,13 @@ function renderReportControlAttributes(
></wizard-textfield>`,
html`<wizard-textfield
label="desc"
.maybeValue=${desc}
.maybeValue=${options.desc}
nullable
helper="${translate('scl.desc')}"
></wizard-textfield>`,
html`<wizard-select
label="buffered"
.maybeValue=${buffered}
.maybeValue=${options.buffered}
helper="${translate('scl.buffered')}"
disabled
>${['true', 'false'].map(
Expand All @@ -138,14 +135,14 @@ function renderReportControlAttributes(
>`,
html`<wizard-textfield
label="rptID"
.maybeValue=${rptID}
.maybeValue=${options.rptID}
helper="${translate('scl.id')}"
required
validationMessage="${translate('textfield.nonempty')}"
></wizard-textfield>`,
html`<wizard-select
label="indexed"
.maybeValue=${indexed}
.maybeValue=${options.indexed}
nullable
required
helper="${translate('scl.indexed')}"
Expand All @@ -155,15 +152,15 @@ function renderReportControlAttributes(
>`,
html`<wizard-textfield
label="max Clients"
.maybeValue=${max}
.maybeValue=${options.max}
helper="${translate('scl.maxReport')}"
nullable
type="number"
suffix="ms"
></wizard-textfield>`,
html`<wizard-textfield
label="bufTime"
.maybeValue=${bufTime}
.maybeValue=${options.bufTime}
helper="${translate('scl.bufTime')}"
nullable
required
Expand All @@ -173,7 +170,7 @@ function renderReportControlAttributes(
></wizard-textfield>`,
html`<wizard-textfield
label="intgPd"
.maybeValue=${intgPd}
.maybeValue=${options.intgPd}
helper="${translate('scl.intgPd')}"
nullable
required
Expand Down Expand Up @@ -206,16 +203,16 @@ export function editReportControlWizard(element: Element): Wizard {
action: updateReportControlAction(element),
},
content: [
...renderReportControlAttributes(
...renderReportControlWizardInputs({
name,
desc,
buffered,
rptID,
indexed,
max,
bufTime,
intgPd
),
intgPd,
}),
],
},
];
Expand Down

0 comments on commit d30df48

Please sign in to comment.