Skip to content

Commit 35445ed

Browse files
committed
fist draft
1 parent 83dae1d commit 35445ed

File tree

3 files changed

+34
-21
lines changed

3 files changed

+34
-21
lines changed

packages/fe-fpm-writer/src/building-block/index.ts

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import {
1414
type TemplateConfig,
1515
type CustomFilterField
1616
} from './types';
17+
import type { InternalCustomFilter } from '../filter/types';
18+
1719
import { DOMParser, XMLSerializer } from '@xmldom/xmldom';
1820
import * as xpath from 'xpath';
1921
import format from 'xml-formatter';
@@ -55,7 +57,7 @@ export async function generateBuildingBlock<T extends BuildingBlock>(
5557
fs?: Editor
5658
): Promise<Editor> {
5759
debugger;
58-
console.log('last attempt');
60+
console.log('last kitty');
5961

6062
const { viewOrFragmentPath, aggregationPath, buildingBlockData, allowAutoAddDependencyLib = true } = config;
6163
// Validate the base and view paths
@@ -256,33 +258,39 @@ function processBuildingBlock<T extends BuildingBlock>(
256258

257259
if (isCustomFilterField(buildingBlockData) && buildingBlockData.embededFragment) {
258260
const embededFragment = setCommonDefaults(buildingBlockData.embededFragment, manifestPath, manifest);
261+
262+
const config: InternalCustomFilter = {} as InternalCustomFilter;
263+
if (buildingBlockData.embededFragment) {
264+
config.controlID = buildingBlockData.filterFieldKey!;
265+
config.label = buildingBlockData.label!;
266+
config.property = buildingBlockData.property!;
267+
config.required = buildingBlockData.required ?? false;
268+
config.position = buildingBlockData.position!;
269+
270+
config.eventHandler = buildingBlockData.embededFragment.eventHandler;
271+
config.ns = embededFragment.ns;
272+
config.name = embededFragment.name;
273+
config.path = embededFragment.path;
274+
}
275+
259276
const viewPath = join(
260277
embededFragment.path,
261278
`${embededFragment.fragmentFile ?? embededFragment.name}.fragment.xml`
262279
);
263280

264281
// Apply event handler
265-
if (buildingBlockData.embededFragment.eventHandler) {
266-
buildingBlockData.embededFragment.eventHandler = applyEventHandlerConfiguration(
267-
fs,
268-
buildingBlockData.embededFragment,
269-
buildingBlockData.embededFragment.eventHandler,
270-
{
271-
controllerSuffix: false,
272-
typescript: buildingBlockData.embededFragment.typescript
273-
}
274-
);
282+
if (config.eventHandler) {
283+
config.eventHandler = applyEventHandlerConfiguration(fs, config, config.eventHandler, {
284+
controllerSuffix: false,
285+
typescript: buildingBlockData.embededFragment.typescript,
286+
templatePath: 'filter/Controller'
287+
});
275288
}
276289

277-
buildingBlockData.embededFragment.content = getDefaultFragmentContent(
278-
'Sample Text',
279-
buildingBlockData.embededFragment.eventHandler
280-
);
281290
if (!fs.exists(viewPath)) {
282-
fs.copyTpl(getTemplatePath('common/Fragment.xml'), viewPath, buildingBlockData.embededFragment);
291+
fs.copyTpl(getTemplatePath('filter/Fragment.xml'), viewPath, config);
283292
}
284293

285-
// check xmlDocument for macrosFilterBar element
286294
const filterBarResult = updateAggregationPathForFilterBar(xmlDocument, aggregationPath, buildingBlockData);
287295
updatedAggregationPath = filterBarResult.updatedAggregationPath;
288296
hasAggregation = filterBarResult.hasFilterFields;

packages/fe-fpm-writer/src/building-block/types.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -413,10 +413,9 @@ export interface CustomFilterField extends BuildingBlock {
413413
*/
414414
label: string;
415415
/**
416-
* Defines where this filter should be placed relative to the defined anchor.
417-
* Allowed values are `Before` and `After`.
416+
* Position of a custom filter relative to an anchor element.
418417
*/
419-
placement: 'Before' | 'After';
418+
position?: Position;
420419
/**
421420
* The property used to filter by.
422421
*/
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
<% if (!config?.hasAggregation) { %><<%- macrosNamespace %>:filterFields><% } %>
2-
<<%- config?.aggregationNamespace %>:FilterField key="<%- data.filterFieldKey %>" label="<%- data.label %>">
2+
<<%- config?.aggregationNamespace %>:FilterField
3+
key="<%- data.filterFieldKey %>"
4+
label="<%- data.label %>"
5+
<% if (data.position.anchor) { %> anchor="<%- data.position.anchor %>"<% } %>
6+
<% if (data.position.placement) { %> placement="<%- data.position.placement %>"<% } %>
7+
<% if (data.required) { %> required="<%- data.required %>"<% } %>
8+
<% if (data.property) { %> property="<%- data.property %>"<% } %>>
39
<core:Fragment fragmentName="<%- data.embededFragment.ns %>.<%- data.embededFragment.name %>" type="XML" />
410
</<%- config?.aggregationNamespace %>:FilterField>
511
<% if (!config?.hasAggregation) { %></<%- macrosNamespace %>:filterFields><% } %>

0 commit comments

Comments
 (0)