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 7b49ab6
Showing
11 changed files
with
154 additions
and
8 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
23 changes: 23 additions & 0 deletions
23
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,23 @@ | ||
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 { IRegisteredInteraction } from './interactions/node-interaction.model'; | ||
|
||
export const RegisterNodeInteractions: FunctionComponent<PropsWithChildren> = ({ children }) => { | ||
const metadataApi = useContext(MetadataContext)!; | ||
const { registerInteraction } = useContext(NodeInteractionContext); | ||
const interactionsToRegister = useRef<IRegisteredInteraction[]>([ | ||
{ | ||
activationFn: datamapperActivationFn, | ||
onDelete: (vizNode) => onDeleteDataMapper(metadataApi, vizNode), | ||
}, | ||
]); | ||
|
||
interactionsToRegister.current.forEach((regComponent) => { | ||
registerInteraction(regComponent); | ||
}); | ||
|
||
return <>{children}</>; | ||
}; |
40 changes: 40 additions & 0 deletions
40
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,40 @@ | ||
import { IVisualizationNode } from '../../../models'; | ||
|
||
export interface IRegisteredInteraction { | ||
activationFn: (vizNode: IVisualizationNode) => boolean; | ||
onDelete: (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 interaction which pass the validation function | ||
* | ||
* @example | ||
* ```tsx | ||
* const nodeInteractionContext = useContext(NodeInteractionContext); | ||
* | ||
* const interaction = nodeInteractionContext.getRegisteredInteraction(vizNode); | ||
* interaction?.onDelete(vizNode); | ||
* ``` | ||
* @param vizNode The visualization node to pass to the component | ||
* @returns `IRegisteredInteraction` A registered interaction | ||
*/ | ||
getRegisteredInteraction: (vizNode: IVisualizationNode) => IRegisteredInteraction | undefined; | ||
} |
27 changes: 27 additions & 0 deletions
27
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,27 @@ | ||
import { createContext, FunctionComponent, PropsWithChildren, useCallback, useMemo, useRef } from 'react'; | ||
import { IVisualizationNode } from '../../../models'; | ||
import { INodeInteractionContext, IRegisteredInteraction } from './node-interaction.model'; | ||
|
||
export const NodeInteractionContext = createContext<INodeInteractionContext>({ | ||
registerInteraction: () => {}, | ||
getRegisteredInteraction: () => undefined, | ||
}); | ||
|
||
export const NodeInteractionProvider: FunctionComponent<PropsWithChildren> = ({ children }) => { | ||
const registeredInteractions = useRef<IRegisteredInteraction[]>([]); | ||
|
||
const registerInteraction = useCallback((interaction: IRegisteredInteraction) => { | ||
registeredInteractions.current.push(interaction); | ||
}, []); | ||
|
||
const getRegisteredInteraction = useCallback((vizNode: IVisualizationNode) => { | ||
return registeredInteractions.current.find((registeredInteraction) => registeredInteraction.activationFn(vizNode)); | ||
}, []); | ||
|
||
const value = useMemo( | ||
() => ({ registerInteraction, getRegisteredInteraction }), | ||
[getRegisteredInteraction, 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