mirror of
https://github.com/chartdb/chartdb.git
synced 2025-11-14 10:57:22 +00:00
relationships except for Cardinality edit
This commit is contained in:
@@ -233,13 +233,16 @@ export const ChartDBProvider: React.FC<React.PropsWithChildren> = ({
|
||||
sourceFieldId: string;
|
||||
targetFieldId: string;
|
||||
}) => {
|
||||
const sourceTableName = getTable(sourceTableId)?.name ?? '';
|
||||
const targetTableName = getTable(targetTableId)?.name ?? '';
|
||||
const relationship: DBRelationship = {
|
||||
id: generateId(),
|
||||
name: `${sourceTableName}_${targetTableName}_fk`,
|
||||
sourceTableId,
|
||||
targetTableId,
|
||||
sourceFieldId,
|
||||
targetFieldId,
|
||||
type: 'one-to-one',
|
||||
type: 'one_to_one',
|
||||
createdAt: Date.now(),
|
||||
};
|
||||
|
||||
@@ -257,6 +260,14 @@ export const ChartDBProvider: React.FC<React.PropsWithChildren> = ({
|
||||
);
|
||||
};
|
||||
|
||||
const removeRelationships = (...ids: string[]) => {
|
||||
setRelationships((relationships) =>
|
||||
relationships.filter(
|
||||
(relationship) => !ids.includes(relationship.id)
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
const updateRelationship = (
|
||||
id: string,
|
||||
relationship: Partial<DBRelationship>
|
||||
@@ -296,6 +307,7 @@ export const ChartDBProvider: React.FC<React.PropsWithChildren> = ({
|
||||
createRelationship,
|
||||
getRelationship,
|
||||
removeRelationship,
|
||||
removeRelationships,
|
||||
updateRelationship,
|
||||
}}
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user