Skip to content

Commit 2df3f31

Browse files
Ni-2alsakhaev
andauthored
feat: Picker and Highlighter use data-mweb-context-level parameter (DAP-4731) (#11)
* feat: Picker and Highlighter use `data-mweb-context-level` parameter (DAP-4731) * fix: callouts can be at different layers * style: format code --------- Co-authored-by: Alexander Sakhaev <alsakhaev@gmail.com>
1 parent 78d22ed commit 2df3f31

File tree

14 files changed

+89
-22
lines changed

14 files changed

+89
-22
lines changed

apps/extension/src/contentscript/multitable-panel/components/dropdown.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ export const Dropdown: FC<DropdownProps> = ({
163163
data-testid="mutate-button"
164164
data-mweb-context-type="notch"
165165
data-mweb-context-parsed={JSON.stringify({ id: 'mutate-button' })}
166+
data-mweb-context-level="system"
166167
>
167168
Mutate {<Mutate />}
168169
<div data-mweb-insertion-point="hidden" style={{ display: 'none' }}></div>
@@ -175,6 +176,7 @@ export const Dropdown: FC<DropdownProps> = ({
175176
data-testid="recently-used-mutations"
176177
data-mweb-context-type="notch"
177178
data-mweb-context-parsed={JSON.stringify({ id: 'recently-used-mutations' })}
179+
data-mweb-context-level="system"
178180
>
179181
{recentlyUsedMutations.map((mut) => (
180182
<InputBlock key={mut.id} isActive={mut.id === selectedMutation?.id}>
@@ -229,6 +231,7 @@ export const Dropdown: FC<DropdownProps> = ({
229231
onClick={handleAccordeonClick}
230232
data-mweb-context-type="notch"
231233
data-mweb-context-parsed={JSON.stringify({ id: 'unused-mutations-title' })}
234+
data-mweb-context-level="system"
232235
>
233236
<AvalibleLable>available</AvalibleLable>
234237
{/* todo: mock */}

apps/extension/src/contentscript/multitable-panel/multitable-panel.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ export const MultitablePanel: FC<MultitablePanelProps> = ({ eventEmitter }) => {
215215
data-testid="notch"
216216
data-mweb-context-type="notch"
217217
data-mweb-context-parsed={JSON.stringify({ id: 'notch' })}
218+
data-mweb-context-level="system"
218219
className={
219220
isPin
220221
? 'visible-pin'

apps/gateway/src/components/navigation/desktop/MutationDropdown.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ export function MutationDropdown({ imageSrc, listPosition = 'right' }) {
302302
<MutationWrapper
303303
data-mweb-context-type="mweb-gateway"
304304
data-mweb-context-parsed={JSON.stringify({ id: 'mutation-wrapper' })}
305+
data-mweb-context-level="system"
305306
>
306307
<div data-mweb-insertion-point="mutation-wrapper" style={{ display: 'none' }}></div>
307308
<ActiveMutation>
@@ -315,6 +316,7 @@ export function MutationDropdown({ imageSrc, listPosition = 'right' }) {
315316
<MutationWrapper
316317
data-mweb-context-type="mweb-gateway"
317318
data-mweb-context-parsed={JSON.stringify({ id: 'mutation-wrapper' })}
319+
data-mweb-context-level="system"
318320
>
319321
<div data-mweb-insertion-point="mutation-wrapper" style={{ display: 'none' }}></div>
320322
{selectedMutation ? (
@@ -349,6 +351,7 @@ export function MutationDropdown({ imageSrc, listPosition = 'right' }) {
349351
}}
350352
data-mweb-context-type="mweb-gateway"
351353
data-mweb-context-parsed={JSON.stringify({ id: 'mutations-list' })}
354+
data-mweb-context-level="system"
352355
>
353356
<div data-mweb-insertion-point="mutations-list" style={{ display: 'none' }}></div>
354357
{selectedMutation ? (

libs/core/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export { JsonParser, JsonParserConfig } from './parsers/json-parser'
55
export { BosParser, BosParserConfig } from './parsers/bos-parser'
66
export { MutableWebParser } from './parsers/mweb-parser'
77
export { PureContextNode } from './tree/pure-tree/pure-context-node'
8-
export { IContextNode, ITreeBuilder } from './tree/types'
8+
export { IContextNode, ITreeBuilder, ContextLevel } from './tree/types'
99
export { AdapterType, ParserConfig } from './types'
1010
export { Subscription } from './event-emitter'
1111
export { InsertionPointWithElement } from './tree/types'

libs/core/src/tree/pure-tree/pure-context-node.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { EventEmitter, Subscription } from '../../event-emitter'
2-
import { IContextNode, InsertionPointWithElement, TreeNodeEvents } from '../types'
2+
import { ContextLevel, IContextNode, InsertionPointWithElement, TreeNodeEvents } from '../types'
33

44
export class PureContextNode implements IContextNode {
55
public id: string | null = null
66
public contextType: string
7+
public contextLevel: ContextLevel
78
public namespace: string
89
public parentNode: IContextNode | null = null
910
public children: IContextNode[] = []
@@ -37,13 +38,15 @@ export class PureContextNode implements IContextNode {
3738
contextType: string,
3839
parsedContext: any = {},
3940
insPoints: InsertionPointWithElement[] = [],
40-
element: HTMLElement | null = null
41+
element: HTMLElement | null = null,
42+
contextLevel: ContextLevel
4143
) {
4244
this.namespace = namespace
4345
this.contextType = contextType
4446
this.parsedContext = parsedContext
4547
this.insPoints = insPoints
4648
this.element = element
49+
this.contextLevel = contextLevel
4750

4851
// ToDo: the similar logic is in tree builder
4952
this.id = parsedContext.id ?? null

libs/core/src/tree/pure-tree/pure-tree-builder.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import { DappletsEngineNs } from '../../constants'
22
import { isDeepEqual } from '../../utils'
3-
import { IContextNode, ITreeBuilder, InsertionPointWithElement, ParsedContext } from '../types'
3+
import {
4+
ContextLevel,
5+
IContextNode,
6+
ITreeBuilder,
7+
InsertionPointWithElement,
8+
ParsedContext,
9+
} from '../types'
410
import { PureContextNode } from './pure-context-node'
511

612
export type TreeBuilderEvents = {
@@ -36,7 +42,14 @@ export class PureTreeBuilder implements ITreeBuilder {
3642
insPoints: InsertionPointWithElement[] = [],
3743
element: HTMLElement | null = null
3844
): IContextNode {
39-
return new PureContextNode(namespace, contextType, parsedContext, insPoints, element)
45+
return new PureContextNode(
46+
namespace,
47+
contextType,
48+
parsedContext,
49+
insPoints,
50+
element,
51+
(element?.getAttribute('data-mweb-context-level') || 'default') as ContextLevel // ToDo: hardcoded
52+
)
4053
}
4154

4255
updateParsedContext(context: IContextNode, newParsedContext: any): void {

libs/core/src/tree/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@ export type ParsedContext = {
1818
[key: string]: any
1919
}
2020

21+
export type ContextLevel = 'default' | 'system' | 'callout'
22+
2123
export interface IContextNode {
2224
id: string | null
2325
contextType: string // ToDo: rename to type
26+
contextLevel: ContextLevel
2427
namespace: string
2528
parentNode: IContextNode | null // ToDo: rename to parent
2629
element: HTMLElement | null

libs/core/src/utils.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { IContextNode } from './tree/types'
2-
31
export function isDeepEqual(obj1: any, obj2: any): boolean {
42
if (obj1 === obj2) return true
53

libs/engine/src/app/common/transferable-context.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { IContextNode } from '@mweb/core'
1+
import { IContextNode, ContextLevel } from '@mweb/core'
22

33
export interface TransferableContext {
44
namespace: string
55
type: string
6+
level: ContextLevel
67
id: string | null
78
parsed: any
89
parent: TransferableContext | null
@@ -13,6 +14,7 @@ export interface TransferableContext {
1314
export const buildTransferableContext = (context: IContextNode): TransferableContext => ({
1415
namespace: context.namespace,
1516
type: context.contextType,
17+
level: context.contextLevel,
1618
id: context.id,
1719
parsed: context.parsedContext,
1820
parent: context.parentNode ? buildTransferableContext(context.parentNode) : null,

libs/engine/src/app/components/context-highlighter.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,29 @@ export const ContextHighlighter = () => {
2020
: TargetService.isTargetMet(highlighterTask.target, context)
2121
: true
2222

23+
const calloutLevel =
24+
context.contextLevel === 'callout' &&
25+
context.element?.attributes?.getNamedItem('data-context-level')?.value
26+
2327
return isSuitable && context.element ? (
2428
<Highlighter
2529
el={context.element}
2630
styles={{
2731
...highlighterTask.styles,
2832
opacity: 1,
33+
zIndex:
34+
1000 *
35+
(context.contextLevel === 'system'
36+
? 6
37+
: calloutLevel === 'default'
38+
? 3
39+
: calloutLevel === 'system'
40+
? 8
41+
: 1),
42+
position:
43+
context.contextLevel === 'default' || calloutLevel === 'default'
44+
? 'absolute'
45+
: 'fixed',
2946
}}
3047
isFilled={highlighterTask.isFilled}
3148
children={highlighterTask.icon}

0 commit comments

Comments
 (0)