Skip to content

Commit 0370fff

Browse files
committed
Adress comments
1 parent b27ede8 commit 0370fff

File tree

12 files changed

+126
-172
lines changed

12 files changed

+126
-172
lines changed

FeatureFlags.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@ module.exports = {
4545
// Whether the Chatbot UserInterface and its functionality should be enabled
4646
enableChatbot: false,
4747

48-
// Whether the competence matching feature should be enabled
49-
enableCompetenceMatching: true,
50-
5148
//feature to switch to prisma from fs
5249
enableUseDB: true,
5350
//feature to use GCP_bucket / fs depending on deployment env to store blobs

src/management-system-v2/app/(dashboard)/[environmentId]/layout.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ import { customLinkIcons } from '@/lib/custom-links/icons';
4343
import { CustomNavigationLink } from '@/lib/custom-links/custom-link';
4444
import { env } from '@/lib/ms-config/env-vars';
4545
import { getUserPassword } from '@/lib/data/db/iam/users';
46-
import { enableCompetenceMatching } from 'FeatureFlags';
4746

4847
const DashboardLayout = async ({
4948
children,
@@ -309,10 +308,7 @@ const DashboardLayout = async ({
309308
}
310309

311310
// TODO: Add proper authorization check for competences
312-
if (
313-
can('manage', 'User') &&
314-
(enableCompetenceMatching || msConfig.PROCEED_PUBLIC_COMPETENCE_MATCHING_ACTIVE)
315-
) {
311+
if (can('manage', 'User') && msConfig.PROCEED_PUBLIC_COMPETENCE_MATCHING_ACTIVE) {
316312
children.push({
317313
key: 'competences',
318314
label: <Link href={spaceURL(activeEnvironment, `/iam/competences`)}>Competences</Link>,
@@ -351,7 +347,7 @@ const DashboardLayout = async ({
351347
icon: <TbUserEdit />,
352348
selectedRegex: profileRegex,
353349
},
354-
...(enableCompetenceMatching || msConfig.PROCEED_PUBLIC_COMPETENCE_MATCHING_ACTIVE
350+
...(msConfig.PROCEED_PUBLIC_COMPETENCE_MATCHING_ACTIVE
355351
? [
356352
{
357353
key: 'personal-competence',

src/management-system-v2/app/(dashboard)/[environmentId]/processes/[mode]/[processId]/properties-panel.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ import { usePathname } from 'next/navigation';
4949
import { BPMNCanvasRef } from '@/components/bpmn-canvas';
5050
import VariableDefinition from './variable-definition';
5151
import SuggestPotentialOwner from '@/components/competence/potential-owner/suggest-potential-owner';
52-
import { enableCompetenceMatching } from 'FeatureFlags';
5352
import IsExecutableSection from './is-executable';
5453

5554
// Elements that should not display the planned duration field
@@ -508,7 +507,7 @@ const PropertiesPanelContent: React.FC<PropertiesPanelContentProperties> = ({
508507
modeler={modeler}
509508
readOnly={readOnly || !isExecutable}
510509
/>
511-
{(enableCompetenceMatching || env.PROCEED_PUBLIC_COMPETENCE_MATCHING_ACTIVE) && (
510+
{env.PROCEED_PUBLIC_COMPETENCE_MATCHING_ACTIVE && (
512511
<SuggestPotentialOwner selectedElement={selectedElement} modeler={modeler} />
513512
)}
514513
<Divider />

src/management-system-v2/components/competence/organization/space-competences-management.tsx

Lines changed: 13 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
'use client';
22

3-
import { useState, useEffect } from 'react';
4-
import { debugLog } from '../utils/debug';
3+
import { useState } from 'react';
4+
import { useQueryClient } from '@tanstack/react-query';
5+
import { useOrganizationSpaceCompetences } from '@/lib/competence/useOrganizationSpaceCompetences';
56
import {
67
Table,
78
Button,
@@ -19,7 +20,6 @@ import {
1920
createOrganizationSpaceCompetence,
2021
updateOrganizationSpaceCompetence,
2122
deleteOrganizationSpaceCompetence,
22-
getOrganizationSpaceCompetences,
2323
} from '../actions/organization-competence-actions';
2424
import SpaceCompetenceFormModal from './space-competence-form-modal';
2525
import { SpaceCompetence } from '@/lib/data/competence-schema';
@@ -36,27 +36,13 @@ const SpaceCompetencesManagement: React.FC<SpaceCompetencesManagementProps> = ({
3636
initialCompetences,
3737
currentUserId,
3838
}) => {
39-
const [competences, setCompetences] = useState<SpaceCompetence[]>(initialCompetences);
39+
const queryClient = useQueryClient();
40+
const { data: competences = initialCompetences, isLoading: isPolling } =
41+
useOrganizationSpaceCompetences(spaceId);
4042
const [isModalOpen, setIsModalOpen] = useState(false);
4143
const [editingCompetence, setEditingCompetence] = useState<SpaceCompetence | null>(null);
4244
const [loading, setLoading] = useState(false);
4345

44-
useEffect(() => {
45-
// Poll for updates every 5 seconds
46-
const interval = setInterval(async () => {
47-
try {
48-
const result = await getOrganizationSpaceCompetences(spaceId);
49-
if (result.success && result.data) {
50-
setCompetences(result.data);
51-
}
52-
} catch (error) {
53-
debugLog('Error polling space competences:', error);
54-
}
55-
}, 5000);
56-
57-
return () => clearInterval(interval);
58-
}, [spaceId]);
59-
6046
const showModal = (competence?: SpaceCompetence) => {
6147
setEditingCompetence(competence || null);
6248
setIsModalOpen(true);
@@ -89,21 +75,8 @@ const SpaceCompetencesManagement: React.FC<SpaceCompetencesManagementProps> = ({
8975
});
9076

9177
if (result.success) {
92-
// Update local state
93-
setCompetences((prev) =>
94-
prev.map((comp) =>
95-
comp.id === editingCompetence.id
96-
? {
97-
...comp,
98-
name: values.name,
99-
description: values.description,
100-
externalQualificationNeeded: values.externalQualificationNeeded,
101-
renewalTimeInterval: values.renewalTimeInterval,
102-
claimedBy: values.unclaimForAllUsers ? [] : comp.claimedBy,
103-
}
104-
: comp,
105-
),
106-
);
78+
// Invalidate the cache to trigger a refetch
79+
queryClient.invalidateQueries({ queryKey: ['organizationSpaceCompetences', spaceId] });
10780
message.success('Space competence updated successfully');
10881
handleCancel();
10982
} else {
@@ -121,8 +94,8 @@ const SpaceCompetencesManagement: React.FC<SpaceCompetencesManagementProps> = ({
12194
});
12295

12396
if (result.success && result.data) {
124-
// Add the newly created competence to local state
125-
setCompetences((prev) => [...prev, result.data!]);
97+
// Invalidate the cache to trigger a refetch
98+
queryClient.invalidateQueries({ queryKey: ['organizationSpaceCompetences', spaceId] });
12699
message.success('Space competence created successfully');
127100
handleCancel();
128101
} else if (!result.success) {
@@ -145,7 +118,8 @@ const SpaceCompetencesManagement: React.FC<SpaceCompetencesManagementProps> = ({
145118
});
146119

147120
if (result.success) {
148-
setCompetences((prev) => prev.filter((comp) => comp.id !== competenceId));
121+
// Invalidate the cache to trigger a refetch
122+
queryClient.invalidateQueries({ queryKey: ['organizationSpaceCompetences', spaceId] });
149123
message.success('Space competence deleted successfully');
150124
} else {
151125
message.error(result.message);
@@ -300,6 +274,7 @@ const SpaceCompetencesManagement: React.FC<SpaceCompetencesManagementProps> = ({
300274
dataSource={competences}
301275
rowKey="id"
302276
pagination={{ pageSize: 10, position: ['bottomCenter'] }}
277+
loading={isPolling}
303278
/>
304279

305280
<SpaceCompetenceFormModal

src/management-system-v2/components/competence/organization/user-competences-overview.tsx

Lines changed: 7 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
'use client';
22

3-
import { useState, useEffect } from 'react';
4-
import { debugLog } from '../utils/debug';
3+
import { useState } from 'react';
4+
import { useQueryClient } from '@tanstack/react-query';
5+
import { useUserCompetences } from '@/lib/competence/useUserCompetences';
56
import { Row, Col, Card, Typography, Empty, Space } from 'antd';
67
import UserListSelector from './user-list-selector';
78
import { User } from '@/lib/data/user-schema';
@@ -26,45 +27,10 @@ const UserCompetencesOverview: React.FC<UserCompetencesOverviewProps> = ({
2627
organizationMembers,
2728
}) => {
2829
const [selectedUser, setSelectedUser] = useState<User | null>(null);
29-
const [userCompetences, setUserCompetences] = useState<any[]>([]);
3030
const [loading, setLoading] = useState(false);
31-
32-
useEffect(() => {
33-
if (selectedUser) {
34-
loadUserCompetences(selectedUser.id, true); // Initial load with loading indicator
35-
36-
// Poll for updates every 5 seconds while a user is selected (without loading indicator)
37-
const interval = setInterval(() => {
38-
loadUserCompetences(selectedUser.id, false);
39-
}, 5000);
40-
41-
return () => clearInterval(interval);
42-
} else {
43-
setUserCompetences([]);
44-
}
45-
}, [selectedUser]);
46-
47-
const loadUserCompetences = async (userId: string, showLoading: boolean = false) => {
48-
if (showLoading) {
49-
setLoading(true);
50-
}
51-
try {
52-
const result = await getUserCompetences(userId);
53-
if (result.success && result.data) {
54-
setUserCompetences(result.data);
55-
} else if (!result.success) {
56-
debugLog('Error loading user competences:', result.message);
57-
setUserCompetences([]);
58-
}
59-
} catch (error) {
60-
debugLog('Error loading user competences:', error);
61-
setUserCompetences([]);
62-
} finally {
63-
if (showLoading) {
64-
setLoading(false);
65-
}
66-
}
67-
};
31+
const { data: userCompetences = [], isLoading: isPolling } = useUserCompetences(
32+
selectedUser?.id || '',
33+
);
6834

6935
return (
7036
<>
@@ -100,7 +66,7 @@ const UserCompetencesOverview: React.FC<UserCompetencesOverviewProps> = ({
10066
description="Select a user from the list to view their competences"
10167
style={{ marginTop: 60 }}
10268
/>
103-
) : loading ? (
69+
) : loading || isPolling ? (
10470
<div
10571
style={{
10672
display: 'flex',

src/management-system-v2/components/competence/potential-owner/suggest-potential-owner.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22
import { FC, useState, useEffect } from 'react';
33
import type { ElementLike } from 'diagram-js/lib/core/Types';
44
import { Button, Descriptions, DescriptionsProps, Modal, Alert, Typography, Steps } from 'antd';
5-
import { PlusOutlined, ReloadOutlined } from '@ant-design/icons';
5+
import { ReloadOutlined } from '@ant-design/icons';
66
import { LuInfo } from 'react-icons/lu';
77
import { BPMNCanvasRef } from '@/components/bpmn-canvas';
88
import ProceedLoadingIndicator from '@/components/loading-proceed';
99
import {
10-
getCompetenceMatches,
1110
createCompetenceList,
1211
createMatching,
1312
transformMatchResults,
@@ -21,8 +20,6 @@ import { useBPMNResources } from './potential-owner';
2120
import { Shape } from 'bpmn-js/lib/model/Types';
2221
import { debugLog } from '../utils/debug';
2322

24-
const { Text } = Typography;
25-
2623
type SuggestPotentialOwnerProps = {
2724
selectedElement: ElementLike;
2825
modeler: BPMNCanvasRef | null;

src/management-system-v2/components/competence/user-competences/space-competences-claim.tsx

Lines changed: 11 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
'use client';
22

3-
import { useState, useEffect } from 'react';
3+
import { useState } from 'react';
4+
import { useQueryClient } from '@tanstack/react-query';
5+
import { useSpaceCompetences } from '@/lib/competence/useSpaceCompetences';
46
import {
57
Table,
68
Button,
@@ -13,7 +15,6 @@ import {
1315
Tag,
1416
Card,
1517
Typography,
16-
Spin,
1718
Popconfirm,
1819
} from 'antd';
1920
import { CheckCircleOutlined, TrophyOutlined, DeleteOutlined } from '@ant-design/icons';
@@ -42,45 +43,13 @@ type SpaceCompetencesClaimProps = {
4243

4344
const SpaceCompetencesClaim: React.FC<SpaceCompetencesClaimProps> = ({ userId }) => {
4445
const environment = useEnvironment();
45-
const [spaceCompetences, setSpaceCompetences] = useState<SpaceCompetence[]>([]);
46-
const [loading, setLoading] = useState(true);
46+
const queryClient = useQueryClient();
47+
const { data: spaceCompetences = [], isLoading } = useSpaceCompetences(environment.spaceId);
4748
const [isModalOpen, setIsModalOpen] = useState(false);
4849
const [selectedCompetence, setSelectedCompetence] = useState<SpaceCompetence | null>(null);
4950
const [claiming, setClaiming] = useState(false);
5051
const [form] = Form.useForm();
5152

52-
useEffect(() => {
53-
loadSpaceCompetences(true); // Initial load with loading indicator
54-
55-
// Poll for updates every 5 seconds (without loading indicator)
56-
const interval = setInterval(() => {
57-
loadSpaceCompetences(false);
58-
}, 5000);
59-
60-
return () => clearInterval(interval);
61-
}, [environment.spaceId]);
62-
63-
const loadSpaceCompetences = async (showLoading: boolean = false) => {
64-
if (showLoading) {
65-
setLoading(true);
66-
}
67-
try {
68-
const response = await fetch(`/api/spaces/${environment.spaceId}/competences`);
69-
if (response.ok) {
70-
const data = await response.json();
71-
setSpaceCompetences(data);
72-
} else {
73-
message.error('Failed to load space competences');
74-
}
75-
} catch (error) {
76-
message.error('Error loading space competences');
77-
} finally {
78-
if (showLoading) {
79-
setLoading(false);
80-
}
81-
}
82-
};
83-
8453
const showClaimModal = (competence: SpaceCompetence) => {
8554
setSelectedCompetence(competence);
8655
form.resetFields();
@@ -110,11 +79,8 @@ const SpaceCompetencesClaim: React.FC<SpaceCompetencesClaimProps> = ({ userId })
11079
});
11180

11281
if (result.success) {
113-
setSpaceCompetences((prev) =>
114-
prev.map((comp) =>
115-
comp.id === selectedCompetence.id ? { ...comp, isClaimed: true } : comp,
116-
),
117-
);
82+
// Invalidate the cache to trigger a refetch
83+
queryClient.invalidateQueries({ queryKey: ['spaceCompetences', environment.spaceId] });
11884
message.success('Competence claimed successfully');
11985
handleCancel();
12086
} else {
@@ -133,9 +99,8 @@ const SpaceCompetencesClaim: React.FC<SpaceCompetencesClaimProps> = ({ userId })
13399
const result = await unclaimSpaceCompetence({ userId, competenceId });
134100

135101
if (result.success) {
136-
setSpaceCompetences((prev) =>
137-
prev.map((comp) => (comp.id === competenceId ? { ...comp, isClaimed: false } : comp)),
138-
);
102+
// Invalidate the cache to trigger a refetch
103+
queryClient.invalidateQueries({ queryKey: ['spaceCompetences', environment.spaceId] });
139104
message.success('Competence unclaimed successfully');
140105
} else {
141106
message.error(result.message);
@@ -240,7 +205,7 @@ const SpaceCompetencesClaim: React.FC<SpaceCompetencesClaimProps> = ({ userId })
240205
</Paragraph>
241206
</div>
242207

243-
{loading ? (
208+
{isLoading ? (
244209
<div
245210
style={{
246211
display: 'flex',
@@ -252,7 +217,7 @@ const SpaceCompetencesClaim: React.FC<SpaceCompetencesClaimProps> = ({ userId })
252217
gap: '16px',
253218
}}
254219
>
255-
<ProceedLoadingIndicator loading={true} small={true} /* scale="140" */ />
220+
<ProceedLoadingIndicator loading={true} small={true} />
256221
</div>
257222
) : (
258223
<Table

src/management-system-v2/components/competence/user-competences/user-competence-manager.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { useState } from 'react';
44
import { Card, Tabs, Typography, Space } from 'antd';
5-
import { TrophyOutlined, AppstoreOutlined, CheckSquareOutlined } from '@ant-design/icons';
5+
import { TrophyOutlined, CheckSquareOutlined } from '@ant-design/icons';
66
import UserCompetencesList from './user-competences-list';
77
import SpaceCompetencesClaim from './space-competences-claim';
88

0 commit comments

Comments
 (0)