Skip to content

Commit 4857d22

Browse files
author
Marvin Zhang
committed
feat: add activeNavItem prop and enhance page element filtering in AutoProbe components
1 parent 50c4bc3 commit 4857d22

File tree

5 files changed

+39
-2
lines changed

5 files changed

+39
-2
lines changed

frontend/crawlab-ui/src/components/core/autoprobe/AutoProbeResultsContainer.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const props = defineProps<{
1212
data?: PageData | PageData[];
1313
fields?: AutoProbeNavItem[];
1414
activeFieldName?: string;
15+
activeNavItem?: AutoProbeNavItem;
1516
url?: string;
1617
viewport?: PageViewPort;
1718
activeId?: string;
@@ -162,6 +163,7 @@ defineOptions({ name: 'ClAutoProbeResultsContainer' });
162163
v-if="activeId"
163164
ref="previewRef"
164165
:active-id="activeId"
166+
:active-nav-item="activeNavItem"
165167
:viewport="viewport"
166168
/>
167169
</template>

frontend/crawlab-ui/src/components/core/autoprobe/AutoProbeResultsPreview.vue

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
type CSSProperties,
44
onMounted,
55
ref,
6+
computed,
67
watch,
78
onBeforeUnmount,
89
} from 'vue';
@@ -12,6 +13,7 @@ import { debounce } from 'lodash';
1213
1314
const props = defineProps<{
1415
activeId: string;
16+
activeNavItem?: AutoProbeNavItem;
1517
viewport?: PageViewPort;
1618
}>();
1719
@@ -108,6 +110,37 @@ const getElementMaskStyle = (el: PageElement): CSSProperties => {
108110
};
109111
};
110112
113+
const pageElements = computed<PageElement[]>(() => {
114+
const { activeNavItem } = props;
115+
if (!activeNavItem) {
116+
return previewResult.value?.page_elements ?? [];
117+
}
118+
if (!previewResult.value?.page_elements) {
119+
return [];
120+
}
121+
if (activeNavItem.type === 'page_pattern') {
122+
return previewResult.value.page_elements;
123+
} else if (activeNavItem.type === 'list') {
124+
const listElement = previewResult.value.page_elements.find(
125+
el => el.name === activeNavItem.name
126+
);
127+
if (!listElement) {
128+
return [];
129+
}
130+
const itemElements = listElement.children ?? [];
131+
const fieldElements = itemElements.flatMap(el => el.children ?? []);
132+
return [...itemElements, ...fieldElements];
133+
} else if (activeNavItem.type === 'field') {
134+
return (
135+
previewResult.value.page_elements.filter(
136+
el => el.name === activeNavItem.name
137+
) ?? []
138+
);
139+
} else {
140+
return [];
141+
}
142+
});
143+
111144
defineExpose({
112145
updateOverlayScale,
113146
});
@@ -121,7 +154,7 @@ defineOptions({ name: 'ClAutoProbeResultsPreview' });
121154
<div v-if="previewResult" ref="overlayRef" class="preview-overlay">
122155
<img class="screenshot" :src="previewResult.screenshot_base64" />
123156
<div
124-
v-for="(el, index) in previewResult.page_elements"
157+
v-for="(el, index) in pageElements"
125158
:key="index"
126159
class="element-mask"
127160
:style="getElementMaskStyle(el)"

frontend/crawlab-ui/src/interfaces/models/autoprobe.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ export declare global {
117117
name: string;
118118
type: PageElementType;
119119
coordinates: ElementCoordinates;
120+
children?: PageElement[];
120121
}
121122

122123
interface PagePreviewResult {

frontend/crawlab-ui/src/utils/autoprobe.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export const getIconByPageElementType = (itemType?: PageElementType): Icon => {
4848
case 'list':
4949
return ['fa', 'list'];
5050
case 'list-item':
51-
return ['fa', 'list-alt'];
51+
return ['fa', 'bars'];
5252
case 'pagination':
5353
return ['fa', 'ellipsis-h'];
5454
default:

frontend/crawlab-ui/src/views/autoprobe/detail/tabs/AutoProbeDetailTabPatterns.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ defineOptions({ name: 'ClAutoProbeDetailTabPatterns' });
263263
:data="resultsData"
264264
:fields="resultsFields"
265265
:active-field-name="resultsActiveField?.name"
266+
:active-nav-item="activeNavItem"
266267
:url="form.url"
267268
:viewport="form.viewport"
268269
:active-id="activeId"

0 commit comments

Comments
 (0)