Skip to content

Commit

Permalink
dynamic pagination support
Browse files Browse the repository at this point in the history
  • Loading branch information
harshtech123 committed Jan 13, 2025
1 parent 189727e commit 31e3680
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 44 deletions.
28 changes: 14 additions & 14 deletions source/components/generateGraphData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ type ResourceInstance = {

type Relationship = {
label: string;
value: string;
ObjectId: string;
id: string;
subjectvalue: string;
value1: string;
subjectId: string;
Object: string;
};

type RoleAssignment = {
Expand Down Expand Up @@ -39,39 +39,39 @@ export const generateGraphData = (

relationships.forEach((relations, resourceId) => {
relations.forEach(relation => {
if (!existingNodeIds.has(relation.value1)) {
if (!existingNodeIds.has(relation.Object)) {
nodes.push({
data: { id: relation.value1, label: `${relation.value1}` },
data: { id: relation.Object, label: `${relation.Object}` },
});
existingNodeIds.add(relation.value1);
existingNodeIds.add(relation.Object);
}

if (resourceId !== relation.value1) {
if (resourceId !== relation.Object) {
edges.push({
data: {
source: resourceId,
target: relation.value1,
target: relation.Object,
label: `IS ${relation.label} OF`,
},
classes: 'relationship-connection', // Class for orange lines
});
}
});
});
relationships.forEach((relations, subjectvalue) => {
relationships.forEach((relations, subjectId) => {
relations.forEach(relation => {
if (!existingNodeIds.has(relation.id)) {
nodes.push({
data: { id: relation.value, label: `${relation.value}` },
data: { id: relation.ObjectId, label: `${relation.ObjectId}` },
});
existingNodeIds.add(relation.value);
existingNodeIds.add(relation.ObjectId);
}

if (subjectvalue !== relation.value) {
if (subjectId !== relation.ObjectId) {
edges.push({
data: {
source: subjectvalue,
target: relation.value,
source: subjectId,
target: relation.ObjectId,
label: relation.label,
},
classes: 'relationship-connection', // Class for orange lines
Expand Down
66 changes: 36 additions & 30 deletions source/components/graphCommand.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ import { generateGraphData } from '../components/generateGraphData.js';
import zod from 'zod';
import { option } from 'pastel';
import { useAuth } from '../components/AuthProvider.js'; // Import useAuth
import { object } from 'joi';

// Define types
type Relationship = {
label: string;
value: string;
id: string;
subjectvalue: string;
value1: string;
subjectId: string;
ObjectId: string;
Object: string;
};

type RoleAssignment = {
Expand Down Expand Up @@ -142,8 +143,10 @@ export default function Graph({ options }: Props) {
id: string;
id2: string;
key: string;
relationships?: any[];
}[] = [];
let allRoleAssignmentsData: RoleAssignment[] = [];
const relationsMap = new Map<string, Relationship[]>();

while (hasMoreData) {
const resourceResponse = await apiCall(
Expand All @@ -157,6 +160,7 @@ export default function Graph({ options }: Props) {
id: res.id,
id2: `${res.resource}:${res.key}`,
key: res.key,
relationships: res.relationships || [],
}));

allResourcesData = [...allResourcesData, ...resourcesData];
Expand All @@ -166,39 +170,41 @@ export default function Graph({ options }: Props) {
Page++;
}

allResourcesData.forEach((resource: any) => {
console.log(resource.label);
})

// Create a lookup map for id2 to resource labels
const id2ToLabelMap = new Map<string, string>();
allResourcesData.forEach((resource: { id2: string; id: string }) => {
id2ToLabelMap.set(resource.id2, resource.id);
});

const relationsMap = new Map<string, Relationship[]>();

allResourcesData.forEach((resource: any) => {
const relationsData = resource.relationships || [];
relationsMap.set(
resource.id,
relationsData.map((relation: any) => {
// Check if relation.object matches any id2
const matchedLabel = id2ToLabelMap.get(relation.object);
const matchedsubjectid = id2ToLabelMap.get(relation.subject);

// Convert relation.relation to uppercase
const relationLabel = relation.relation
? relation.relation.toUpperCase()
: 'UNKNOWN RELATION';

return {
label: relationLabel,
value: matchedLabel || relation.object,
value1: relation.object,
subjectvalue: matchedsubjectid || resource.id,
id: resource.id,
};
}),
);
});

allResourcesData.forEach((resource: any) => {
const relationsData = resource.relationships || [];
relationsMap.set(
resource.id,
relationsData.map((relation: any) => {
// Check if relation.object matches any id2
const matchedLabel = id2ToLabelMap.get(relation.object);
const matchedsubjectid = id2ToLabelMap.get(relation.subject);

// Convert relation.relation to uppercase
const relationLabel = relation.relation
? relation.relation.toUpperCase()
: 'UNKNOWN RELATION';

return {
label: relationLabel,
objectId: matchedLabel || relation.object,
Object: relation.object,
subjectId: matchedsubjectid || resource.id,
id: resource.id,
};
}),
);
});

Page = 1;
hasMoreData = true;

Expand Down

0 comments on commit 31e3680

Please sign in to comment.