This repository has been archived by the owner on Dec 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(DataMapper): Delete DataMapper metadata entry when the step is de…
…leted Fixes: #80
- Loading branch information
1 parent
b1c353e
commit 65e738d
Showing
11 changed files
with
198 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
packages/ui/src/components/DataMapper/on-delete-datamapper.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { DataMapperMetadataService } from '../../services/datamapper-metadata.service'; | ||
import { IMetadataApi } from '../../providers'; | ||
import { IVisualizationNode } from '../../models'; | ||
|
||
export const onDeleteDataMapper = (api: IMetadataApi, vizNode: IVisualizationNode) => { | ||
const metadataId = DataMapperMetadataService.getDataMapperMetadataId(vizNode); | ||
DataMapperMetadataService.deleteMetadata(api, metadataId); | ||
// TODO DataMapperMetadataService.deleteXsltFile(api, metadataId); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
packages/ui/src/components/registers/RegisterNodeInteractions.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { FunctionComponent, PropsWithChildren, useContext, useRef } from 'react'; | ||
import { datamapperActivationFn } from './datamapper.activationfn'; | ||
import { MetadataContext } from '../../providers'; | ||
import { onDeleteDataMapper } from '../DataMapper/on-delete-datamapper'; | ||
import { NodeInteractionContext } from './interactions/node-interaction.provider'; | ||
import { IInteractionType, IRegisteredInteraction } from './interactions/node-interaction.model'; | ||
|
||
export const RegisterNodeInteractions: FunctionComponent<PropsWithChildren> = ({ children }) => { | ||
const metadataApi = useContext(MetadataContext)!; | ||
const { registerInteraction } = useContext(NodeInteractionContext); | ||
const interactionsToRegister = useRef<IRegisteredInteraction[]>([ | ||
{ | ||
interaction: IInteractionType.ON_DELETE, | ||
activationFn: datamapperActivationFn, | ||
callback: (vizNode) => { | ||
metadataApi && onDeleteDataMapper(metadataApi, vizNode); | ||
}, | ||
}, | ||
]); | ||
|
||
interactionsToRegister.current.forEach((interaction) => { | ||
registerInteraction(interaction); | ||
}); | ||
|
||
return <>{children}</>; | ||
}; |
48 changes: 48 additions & 0 deletions
48
packages/ui/src/components/registers/interactions/node-interaction.model.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { IVisualizationNode } from '../../../models'; | ||
|
||
export enum IInteractionType { | ||
ON_DELETE = 'onDelete', | ||
} | ||
|
||
export interface IRegisteredInteraction { | ||
interaction: IInteractionType; | ||
activationFn: (vizNode: IVisualizationNode) => boolean; | ||
callback: (vizNode: IVisualizationNode) => void; | ||
} | ||
|
||
export interface INodeInteractionContext { | ||
/** | ||
* Register a component to be rendered in the given anchor | ||
* | ||
* @example | ||
* ```tsx | ||
* const nodeInteractionContext = useContext(NodeInteractionContext); | ||
* | ||
* renderingAnchorContext.registerInteraction({ | ||
* activationFn: () => true, | ||
* onDelete: () => { doSomething() } | ||
* }); | ||
* ``` | ||
* @param interaction Registered node interaction | ||
* @returns void | ||
*/ | ||
registerInteraction: (interaction: IRegisteredInteraction) => void; | ||
|
||
/** | ||
* Get registered interactions | ||
* | ||
* @example | ||
* ```tsx | ||
* const nodeInteractionContext = useContext(NodeInteractionContext); | ||
* | ||
* const interactions = nodeInteractionContext.getRegisteredInteractions(vizNode); | ||
* interactions.forEach((i) => { | ||
* i.onDelete(vizNode); | ||
* }); | ||
* ``` | ||
* @param interaction The interaction type enum value | ||
* @param vizNode The visualization node to pass to the interaction | ||
* @returns `IRegisteredInteraction` An array of registered interactions | ||
*/ | ||
getRegisteredInteractions: (interaction: IInteractionType, vizNode: IVisualizationNode) => IRegisteredInteraction[]; | ||
} |
30 changes: 30 additions & 0 deletions
30
packages/ui/src/components/registers/interactions/node-interaction.provider.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { createContext, FunctionComponent, PropsWithChildren, useCallback, useMemo, useRef } from 'react'; | ||
import { IVisualizationNode } from '../../../models'; | ||
import { IInteractionType, INodeInteractionContext, IRegisteredInteraction } from './node-interaction.model'; | ||
|
||
export const NodeInteractionContext = createContext<INodeInteractionContext>({ | ||
registerInteraction: () => {}, | ||
getRegisteredInteractions: () => [], | ||
}); | ||
|
||
export const NodeInteractionProvider: FunctionComponent<PropsWithChildren> = ({ children }) => { | ||
const registeredInteractions = useRef<IRegisteredInteraction[]>([]); | ||
|
||
const registerInteraction = useCallback((interaction: IRegisteredInteraction) => { | ||
registeredInteractions.current.push(interaction); | ||
}, []); | ||
|
||
const getRegisteredInteractions = useCallback((interaction: IInteractionType, vizNode: IVisualizationNode) => { | ||
return registeredInteractions.current.filter( | ||
(registeredInteraction) => | ||
registeredInteraction.interaction === interaction && registeredInteraction.activationFn(vizNode), | ||
); | ||
}, []); | ||
|
||
const value = useMemo( | ||
() => ({ registerInteraction, getRegisteredInteractions }), | ||
[getRegisteredInteractions, registerInteraction], | ||
); | ||
|
||
return <NodeInteractionContext.Provider value={value}>{children}</NodeInteractionContext.Provider>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters