Skip to content

Commit bdd076a

Browse files
authored
feature: [Models, Applications] Roles Tab Redesign (Issue #147) (#443)
1 parent 2a79e24 commit bdd076a

File tree

15 files changed

+542
-179
lines changed

15 files changed

+542
-179
lines changed

apps/ai-dial-admin/src/components/AddEntitiesTab/AddEntitiesView.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ const AddEntitiesView: FC<Props> = ({
4848
keys,
4949
viewTitle,
5050
customColumns,
51-
modalTitle: modalTitle,
51+
modalTitle,
5252
onAdd,
5353
onRemove,
5454
emptyDataTitle,

apps/ai-dial-admin/src/components/AddEntitiesTab/AddEntitiesView.utils.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { ENTITY_BASE_COLUMNS } from '@/src/constants/grid-columns/grid-columns';
44
import { LIMIT_COLUMNS } from '@/src/components/EntityView/Roles/utils';
55
import { NO_LIMITS_KEY } from '@/src/constants/role';
66
import { DialApplication, DialApplicationScheme } from '@/src/models/dial/application';
7-
import { DialBaseEntity } from '@/src/models/dial/base-entity';
7+
import { DialBaseEntity, DialRoleShare } from '@/src/models/dial/base-entity';
88
import { DialInterceptor } from '@/src/models/dial/interceptor';
99
import { DialKey } from '@/src/models/dial/key';
1010
import { DialModel } from '@/src/models/dial/model';
@@ -28,6 +28,10 @@ export const ENTITY_COLUMNS = (t: (v: string) => string): ColDef[] => [
2828
},
2929
];
3030

31+
export const isDialRoleShareKey = (key: string): key is keyof DialRoleShare => {
32+
return key === 'invitationTtl' || key === 'maxAcceptedUsers';
33+
};
34+
3135
export const ROLES_ENTITIES_COLUMNS = (
3236
t: (v: string) => string,
3337
onChangeLimits: ((value: number, data: DialRole, token: string) => void) | undefined,
@@ -121,14 +125,16 @@ export const getEntitiesForRole = (role: DialRole, allEntities: EntitiesGridData
121125

122126
Object.keys(role?.limits).forEach((entityName) => {
123127
const limit = role?.limits?.[entityName];
124-
128+
const share = role?.share?.[entityName];
125129
const entity = allEntities.find((m) => m.name === entityName);
126130
data.push({
127131
...(entity as EntitiesGridData),
128132
day: limit?.day == null ? NO_LIMITS_KEY : limit?.day,
129133
minute: limit?.minute == null ? NO_LIMITS_KEY : limit?.minute,
130134
month: limit?.month == null ? NO_LIMITS_KEY : limit?.month,
131135
week: limit?.week == null ? NO_LIMITS_KEY : limit?.week,
136+
invitationTtl: share?.invitationTtl == null ? NO_LIMITS_KEY : share?.invitationTtl,
137+
maxAcceptedUsers: share?.maxAcceptedUsers == null ? NO_LIMITS_KEY : share?.maxAcceptedUsers,
132138
});
133139
});
134140

apps/ai-dial-admin/src/components/AddEntitiesTab/tests/AddEntitiesView.utils.spec.ts

Lines changed: 131 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,27 @@ const keys = [{ name: 'key', type: MenuI18nKey.Keys, route: ApplicationRoute.Key
2525
describe('Add Entities tab :: getEntitiesGridData', () => {
2626
test('Should return all items', () => {
2727
expect(
28-
getEntitiesGridData(
29-
[{ name: 'model' }],
30-
[{ name: 'application' }],
31-
[{ name: 'role' }],
32-
[{ name: 'key' }],
33-
),
28+
getEntitiesGridData([{ name: 'model' }], [{ name: 'application' }], [{ name: 'role' }], [{ name: 'key' }]),
3429
).toEqual(data);
3530
});
3631
});
3732

3833
describe('Add Entities tab :: getEntitiesForRole ', () => {
39-
test('Should return empty array', () => {
34+
test('Should return empty array when no limits are defined', () => {
4035
expect(getEntitiesForRole({}, data)).toEqual([]);
4136
});
4237

43-
test('Should return array with model', () => {
44-
expect(getEntitiesForRole({ limits: { model: { day: 1 } }, model1: { day: 1 } }, data)).toEqual([
38+
test('Should return array with model and share properties when share is defined', () => {
39+
expect(
40+
getEntitiesForRole(
41+
{
42+
limits: { model: { day: 1 } },
43+
share: { model: { invitationTtl: 3600, maxAcceptedUsers: 10 } },
44+
model1: { day: 1 },
45+
},
46+
data,
47+
),
48+
).toEqual([
4549
{
4650
day: 1,
4751
minute: 'No Limits',
@@ -50,14 +54,44 @@ describe('Add Entities tab :: getEntitiesForRole ', () => {
5054
name: 'model',
5155
route: ApplicationRoute.Models,
5256
type: MenuI18nKey.Models,
57+
invitationTtl: 3600,
58+
maxAcceptedUsers: 10,
5359
},
5460
]);
5561
});
5662

57-
test('Should return array with model', () => {
63+
test('Should return array with model and updated limits and share properties', () => {
64+
expect(
65+
getEntitiesForRole(
66+
{
67+
limits: { model: { minute: 1, week: 2, month: 3 } },
68+
share: { model: { invitationTtl: 1800, maxAcceptedUsers: 5 } },
69+
model1: { minute: 1, week: 2, month: 3 },
70+
},
71+
data,
72+
),
73+
).toEqual([
74+
{
75+
day: 'No Limits',
76+
minute: 1,
77+
week: 2,
78+
month: 3,
79+
name: 'model',
80+
route: ApplicationRoute.Models,
81+
type: MenuI18nKey.Models,
82+
invitationTtl: 1800,
83+
maxAcceptedUsers: 5,
84+
},
85+
]);
86+
});
87+
88+
test('Should handle missing share properties and return "No Limits"', () => {
5889
expect(
5990
getEntitiesForRole(
60-
{ limits: { model: { minute: 1, week: 2, month: 3 } }, model1: { minute: 1, week: 2, month: 3 } },
91+
{
92+
limits: { model: { minute: 1, week: 2, month: 3 } },
93+
model1: { minute: 1, week: 2, month: 3 },
94+
},
6195
data,
6296
),
6397
).toEqual([
@@ -69,6 +103,92 @@ describe('Add Entities tab :: getEntitiesForRole ', () => {
69103
name: 'model',
70104
route: ApplicationRoute.Models,
71105
type: MenuI18nKey.Models,
106+
invitationTtl: 'No Limits',
107+
maxAcceptedUsers: 'No Limits',
108+
},
109+
]);
110+
});
111+
112+
test('Should handle multiple entities with some missing share properties', () => {
113+
expect(
114+
getEntitiesForRole(
115+
{
116+
limits: {
117+
model: { day: 1 },
118+
model2: { minute: 1, week: 2, month: 3 },
119+
},
120+
share: {
121+
model: { invitationTtl: 3600, maxAcceptedUsers: 10 },
122+
},
123+
model1: { day: 1 },
124+
},
125+
data,
126+
),
127+
).toEqual([
128+
{
129+
day: 1,
130+
minute: 'No Limits',
131+
week: 'No Limits',
132+
month: 'No Limits',
133+
name: 'model',
134+
route: ApplicationRoute.Models,
135+
type: MenuI18nKey.Models,
136+
invitationTtl: 3600,
137+
maxAcceptedUsers: 10,
138+
},
139+
{
140+
day: 'No Limits',
141+
minute: 1,
142+
week: 2,
143+
month: 3,
144+
invitationTtl: 'No Limits',
145+
maxAcceptedUsers: 'No Limits',
146+
},
147+
]);
148+
});
149+
150+
test('Should return empty array if role.limits is null or not an object', () => {
151+
expect(getEntitiesForRole({ limits: null }, data)).toEqual([]);
152+
expect(getEntitiesForRole({ limits: undefined }, data)).toEqual([]);
153+
});
154+
155+
test('Should return empty array when no limits or share properties exist', () => {
156+
expect(getEntitiesForRole({}, data)).toEqual([]);
157+
});
158+
159+
test('Should return data for entities that have limits and default "No Limits" for others', () => {
160+
expect(
161+
getEntitiesForRole(
162+
{
163+
limits: {
164+
model: { minute: 10 },
165+
model2: { month: 5 },
166+
},
167+
share: {
168+
model: { invitationTtl: 3600 },
169+
},
170+
},
171+
data,
172+
),
173+
).toEqual([
174+
{
175+
day: 'No Limits',
176+
minute: 10,
177+
week: 'No Limits',
178+
month: 'No Limits',
179+
name: 'model',
180+
route: ApplicationRoute.Models,
181+
type: MenuI18nKey.Models,
182+
invitationTtl: 3600,
183+
maxAcceptedUsers: 'No Limits',
184+
},
185+
{
186+
day: 'No Limits',
187+
minute: 'No Limits',
188+
week: 'No Limits',
189+
month: 5,
190+
invitationTtl: 'No Limits',
191+
maxAcceptedUsers: 'No Limits',
72192
},
73193
]);
74194
});

0 commit comments

Comments
 (0)