Skip to content

Commit ab59fd6

Browse files
Merge branch 'cognition-integration-provider' of github.com:code-kern-ai/refinery-ui into cognition-integration-provider
2 parents 43bebe3 + 332cd08 commit ab59fd6

File tree

14 files changed

+36
-69
lines changed

14 files changed

+36
-69
lines changed

src/components/projects/projectId/attributes/attributeId/AttributeCalculations.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Statuses from "@/src/components/shared/statuses/Statuses";
22
import { selectAllLookupLists, setAllLookupLists } from "@/src/reduxStore/states/pages/lookup-lists";
3-
import { selectAttributes, selectVisibleAttributeAC, setAllAttributes, setLabelingTasksAll, updateAttributeById } from "@/src/reduxStore/states/pages/settings";
3+
import { selectAttributes, selectVisibleAttributeAC, selectVisibleAttributesWithoutPermissions, setAllAttributes, setLabelingTasksAll, updateAttributeById } from "@/src/reduxStore/states/pages/settings";
44
import { selectProjectId } from "@/src/reduxStore/states/project"
55
import { Attribute, AttributeState, AttributeVisibility, AttributeWithOnClick, LLMConfig } from "@/src/types/components/projects/projectId/settings/data-schema";
66
import { DataTypeEnum } from "@/src/types/shared/general";
@@ -52,7 +52,7 @@ export default function AttributeCalculation() {
5252

5353
const projectId = useSelector(selectProjectId);
5454
const attributes = useSelector(selectAttributes);
55-
const usableAttributes = useSelector(selectVisibleAttributeAC)
55+
const usableAttributes = useSelector(selectVisibleAttributesWithoutPermissions);
5656
const lookupLists = useSelector(selectAllLookupLists);
5757
const allUsers = useSelector(selectAllUsers);
5858

src/components/projects/projectId/attributes/attributeId/ExecutionContainer.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,12 @@ export default function ExecutionContainer(props: ExecutionContainerProps) {
7474

7575
const sampleRecordsFinal = useMemo(() => {
7676
if (sampleRecords && sampleRecords.calculatedAttributesDisplay) {
77-
return sampleRecords.calculatedAttributesDisplay.map((record: any) => {
77+
return sampleRecords.calculatedAttributesDisplay.map((record: any, index) => {
78+
const calculatedValue = currentAttributesRef.current.dataType != DataTypeEnum.EMBEDDING_LIST ? record : { id: record.id, value: JSON.parse(record.value) }
7879
return {
7980
...record,
80-
onClick: viewRecordDetails(record.id)
81+
onClick: viewRecordDetails(index),
82+
calculatedValue: calculatedValue
8183
}
8284
}
8385
);
@@ -130,7 +132,7 @@ export default function ExecutionContainer(props: ExecutionContainerProps) {
130132
<div className="inline-block min-w-full align-middle">
131133
<div className="overflow-hidden shadow ring-1 ring-black ring-opacity-5 md:rounded-lg">
132134
<div className="min-w-full border divide-y divide-gray-300">
133-
{sampleRecordsFinal.map((record: any, index: number) => (
135+
{sampleRecordsFinal.map((record: any) => (
134136
<div key={record.id} className="divide-y divide-gray-200 bg-white">
135137
<div className="flex-shrink-0 border-b border-gray-200 shadow-sm flex justify-between items-center">
136138
<div className="flex items-center text-xs leading-5 text-gray-500 font-normal mx-4 my-3 text-justify">
@@ -151,7 +153,7 @@ export default function ExecutionContainer(props: ExecutionContainerProps) {
151153
</div>
152154
</div >}
153155

154-
<ViewRecordDetailsModal currentAttribute={props.currentAttribute} sampleRecords={sampleRecords} />
156+
<ViewRecordDetailsModal currentAttribute={props.currentAttribute} sampleRecords={sampleRecordsFinal} />
155157
<ConfirmExecutionModal currentAttributeId={props.currentAttribute.id} />
156158
</div >)
157159
}

src/components/projects/projectId/attributes/attributeId/ViewRecordDetailsModal.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ export default function ViewRecordDetailsModal(props: ViewRecordDetailsModalProp
2424
<div className="text-sm leading-5 text-left text-gray-900 font-medium">Calculated value</div>
2525
<div className="text-sm leading-5 text-left text-gray-500 font-normal whitespace-pre-line">
2626
{props.currentAttribute.dataType != DataTypeEnum.EMBEDDING_LIST ? <span>
27-
{props.sampleRecords.calculatedAttributes[modalViewRecordDetails.recordIdx]}
27+
{props.sampleRecords[modalViewRecordDetails.recordIdx].calculatedValue.value}
2828
</span> : <div className="flex flex-col gap-y-2 divide-y">
29-
{props.sampleRecords.calculatedAttributesListDisplay[modalViewRecordDetails.recordIdx].map((item: any) => <span key={item.id} className="mt-1">
30-
{props.sampleRecords.calculatedAttributesList[modalViewRecordDetails.recordIdx]}
29+
{props.sampleRecords[modalViewRecordDetails.recordIdx].calculatedValue.value.map((item: any) => <span key={item} className="mt-1">
30+
{item}
3131
</span>)}
3232
</div>}
3333
</div>

src/components/projects/projectId/data-browser/SearchGroups.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ export default function SearchGroups() {
8585
});
8686
colors.push('gray');
8787
visibleAttributes.forEach((att) => {
88+
if (att.dataType == DataTypeEnum.PERMISSION) return;
8889
attributesSort.push({
8990
name: att.name,
9091
key: att.id,

src/components/projects/projectId/heuristics/heuristicId/labeling-function/LabelingFunction.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { postProcessCurrentHeuristic, postProcessLastTaskLogs } from "@/src/util
88
import { Tooltip } from "@nextui-org/react";
99
import { TOOLTIPS_DICT } from "@/src/util/tooltip-constants";
1010
import { postProcessLabelingTasksSchema } from "@/src/util/components/projects/projectId/settings/labeling-tasks-helper";
11-
import { selectVisibleAttributesHeuristics, selectLabelingTasksAll, setLabelingTasksAll } from "@/src/reduxStore/states/pages/settings";
11+
import { selectVisibleAttributesHeuristics, selectLabelingTasksAll, setLabelingTasksAll, selectVisibleAttributesWithoutPermissions } from "@/src/reduxStore/states/pages/settings";
1212
import HeuristicsEditor from "../shared/HeuristicsEditor";
1313
import DangerZone from "@/src/components/shared/danger-zone/DangerZone";
1414
import HeuristicRunButtons from "../shared/HeuristicRunButtons";
@@ -46,7 +46,7 @@ export default function LabelingFunction() {
4646
const projectId = useSelector(selectProjectId);
4747
const currentHeuristic = useSelector(selectHeuristic);
4848
const labelingTasks = useSelector(selectLabelingTasksAll);
49-
const attributes = useSelector(selectVisibleAttributesHeuristics);
49+
const attributes = useSelector(selectVisibleAttributesWithoutPermissions);
5050
const allUsers = useSelector(selectAllUsers);
5151

5252
const [lastTaskLogs, setLastTaskLogs] = useState<string[]>([]);

src/components/projects/projectId/heuristics/heuristicId/shared/HeuristicsLayout.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Statuses from "@/src/components/shared/statuses/Statuses";
22
import { selectHeuristic, setActiveHeuristics, updateHeuristicsState } from "@/src/reduxStore/states/pages/heuristics";
33
import { selectAllLookupLists, setAllLookupLists } from "@/src/reduxStore/states/pages/lookup-lists";
4-
import { selectVisibleAttributesHeuristics, setAllAttributes } from "@/src/reduxStore/states/pages/settings";
4+
import { selectVisibleAttributesHeuristics, selectVisibleAttributesWithoutPermissions, setAllAttributes } from "@/src/reduxStore/states/pages/settings";
55
import { selectProjectId } from "@/src/reduxStore/states/project"
66
import { HeuristicsProperty } from "@/src/types/components/projects/projectId/heuristics/heuristicId/heuristics-details";
77
import { Attribute } from "@/src/types/components/projects/projectId/settings/data-schema";
@@ -26,7 +26,7 @@ export default function HeuristicsLayout(props: any) {
2626

2727
const projectId = useSelector(selectProjectId);
2828
const currentHeuristic = useSelector(selectHeuristic);
29-
const usableAttributes = useSelector(selectVisibleAttributesHeuristics);
29+
const usableAttributes = useSelector(selectVisibleAttributesWithoutPermissions);
3030
const lookupLists = useSelector(selectAllLookupLists);
3131

3232
const [isHeaderNormal, setIsHeaderNormal] = useState(true);

src/components/projects/projectId/playground/CreateEvaluationSetModal.tsx

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { useCallback, useEffect, useState } from "react";
1515
import { useDispatch, useSelector } from "react-redux";
1616
import QuestionHistory from "./QuestionHistory";
1717
import { MemoIconPlus, MemoIconWand } from "@/submodules/react-components/components/kern-icons/icons";
18+
import { postProcessUpdateAndSortRecords } from "@/submodules/javascript-functions/post-process-functions";
1819

1920
const ACCEPT_BUTTON = { buttonCaption: 'Create', useButton: true };
2021
const SEARCH_REQUEST = { offset: 0, limit: 20 };
@@ -129,16 +130,7 @@ export default function CreateEvaluationSetModal(props: CreateEvaluationSetsModa
129130
}
130131

131132
function updateAndSortRecordList(newRecords = []) {
132-
setRecordList((prev) => {
133-
const merged = [...prev, ...newRecords];
134-
const uniqueRecords = Array.from(
135-
new Map(merged.map((item) => [item.data?.running_id, item])).values()
136-
);
137-
uniqueRecords.sort(
138-
(a, b) => (a.data?.running_id || 0) - (b.data?.running_id || 0)
139-
);
140-
return uniqueRecords;
141-
});
133+
setRecordList((prev) => postProcessUpdateAndSortRecords(prev, newRecords));
142134
}
143135

144136
function resetState() {

src/components/shared/record-display/RecordDisplay.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import { selectAttributesDict } from "@/src/reduxStore/states/pages/settings";
33
import { LineBreaksType } from "@/src/types/components/projects/projectId/data-browser/data-browser";
44
import { Attribute } from "@/src/types/components/projects/projectId/settings/data-schema";
55
import { DataTypeEnum } from "@/src/types/shared/general";
6-
import { postProcessAttributes, postProcessRecord } from "@/src/util/shared/record-display-helper";
76
import { useEffect, useState } from "react";
87
import { useSelector } from "react-redux";
98
import Highlight from "../highlight/Highlight";
109
import { MemoIconAlertCircle } from "@/submodules/react-components/components/kern-icons/icons";
10+
import { postProcessAttributes, postProcessRecord } from "@/submodules/javascript-functions/post-process-functions";
1111

1212
export function RecordDisplay(props: any) {
1313
const attributesDict = useSelector(selectAttributesDict);
@@ -33,16 +33,16 @@ export function RecordDisplay(props: any) {
3333
</div>
3434
</div>
3535
{attributesDict[attribute.id] && <div className="text-gray-800 text-sm mb-4 overflow-anywhere flex text-left">
36-
{attribute.dataType == DataTypeEnum.EMBEDDING_LIST ? (<div className="flex flex-col gap-y-1 divide-y">
37-
{preparedRecord.data[attributesDict[attribute.key].name] && preparedRecord.data[attributesDict[attribute.key].name].map((item, indexJ) => (<div key={indexJ} className="pt-1">
36+
{attribute.dataType === DataTypeEnum.EMBEDDING_LIST || attribute.dataType === DataTypeEnum.PERMISSION ? (<div className="flex flex-col gap-y-1 divide-y">
37+
{preparedRecord.data[attributesDict[attribute.key].name] ? preparedRecord.data[attributesDict[attribute.key].name].map((item, indexJ) => (<div key={indexJ} className="pt-1">
3838
{(configuration.highlightText && isTextHighlightNeeded[attribute.key]) ? (<Highlight text={item.toString()}
3939
additionalClasses={[configuration.lineBreaks == LineBreaksType.NORMAL ? '' : (configuration.lineBreaks == LineBreaksType.IS_PRE_WRAP ? 'whitespace-pre-wrap' : 'whitespace-pre-line')]}
4040
searchForExtended={textHighlight[attribute.id]} />) : (
4141
<span className={configuration && configuration.lineBreaks != LineBreaksType.NORMAL ? (configuration.lineBreaks == LineBreaksType.IS_PRE_WRAP ? 'whitespace-pre-wrap' : 'whitespace-pre-line') : ''}>
4242
{item != null && item !== '' ? item : <NotPresentInRecord />}
4343
</span>
4444
)}
45-
</div>))}
45+
</div>)) : <NotPresentInRecord />}
4646
</div>) : (<>
4747
{(configuration.highlightText && isTextHighlightNeeded[attribute.key]) ? (<Highlight text={preparedRecord.data[attributesDict[attribute.key].name]?.toString()}
4848
additionalClasses={[configuration.lineBreaks == LineBreaksType.NORMAL ? '' : (configuration.lineBreaks == LineBreaksType.IS_PRE_WRAP ? 'whitespace-pre-wrap' : 'whitespace-pre-line')]}

src/reduxStore/StoreManagerComponent.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useEffect, useState } from "react";
22
import { useRouter } from "next/router";
33
import { useDispatch, useSelector } from "react-redux";
4-
import { selectIsAdmin, selectOrganization, setAllUsers, setIsAdmin, setOrganization, setRouteColor, setUser } from "./states/general";
4+
import { selectIsAdmin, selectOrganization, selectUser, setAllUsers, setIsAdmin, setOrganization, setRouteColor, setUser } from "./states/general";
55
import { getUserAvatarUri } from "@/submodules/javascript-functions/general";
66
import { setActiveProject } from "./states/project";
77
import { WebSocketsService } from "../../submodules/react-components/hooks/web-socket/WebSocketsService";
@@ -18,12 +18,14 @@ import { getProjectByProjectId } from "../services/base/project";
1818
import { getIsAdmin, getVersionOverview } from "../services/base/misc";
1919
import { getUserInfo, getOrganization, getOrganizationUsers } from "../services/base/organization";
2020
import { getAllTokenizerOptions, getEmbeddingPlatforms, getRecommendedEncoders } from "../services/base/embedding";
21+
import { UserRole } from "../types/shared/sidebar";
2122

2223
export function GlobalStoreDataComponent(props: React.PropsWithChildren) {
2324
const router = useRouter();
2425
const dispatch = useDispatch();
2526
const isAdmin = useSelector(selectIsAdmin);
2627
const organization = useSelector(selectOrganization);
28+
const userRole = useSelector(selectUser)?.role;
2729

2830
const [dataLoaded, setDataLoaded] = useState(false);
2931

@@ -33,6 +35,10 @@ export function GlobalStoreDataComponent(props: React.PropsWithChildren) {
3335
});
3436

3537
getUserInfo((res) => {
38+
if (res.role == UserRole.ANNOTATOR || res.role == UserRole.EXPERT) {
39+
window.location.href = '/cognition';
40+
return;
41+
}
3642
const userInfo = { ...res };
3743
userInfo.avatarUri = getUserAvatarUri(res);
3844
dispatch(setUser(userInfo));
@@ -106,6 +112,6 @@ export function GlobalStoreDataComponent(props: React.PropsWithChildren) {
106112
})
107113
}, [ConfigManager.isInit()]);
108114

109-
if (!dataLoaded) return <></>;
115+
if (!dataLoaded || userRole !== UserRole.ENGINEER) return <></>;
110116
return <div>{props.children}</div>;
111117
}

src/reduxStore/states/pages/settings.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ export const selectVisibleAttributesDataBrowser = createSelector([selectUsableAt
148148
export const selectVisibleAttributeAC = createSelector([selectUsableAttributesFiltered], (a): any => a ? a.filter((a) => a.visibility != AttributeVisibility.HIDE) : null);
149149
export const selectVisibleAttributesHeuristics = createSelector([selectUsableAttributesFiltered], (a): any => a ? a.filter((a) => a.visibility != AttributeVisibility.HIDE) : null);
150150
export const selectOnAttributeEmbeddings = createSelector([selectEmbeddings], (a): any => a ? a.filter((embedding) => embedding.type == EmbeddingType.ON_ATTRIBUTE && embedding.state == Status.FINISHED) : null);
151+
export const selectVisibleAttributesWithoutPermissions = createSelector([selectUsableAttributesFiltered], (a): any => a ? a.filter((a) => a.dataType != DataTypeEnum.PERMISSION) : null);
151152

152153
export const { setAllAttributes, extendAllAttributes, removeFromAllAttributesById, updateAttributeById, setAllEmbeddings, setFilteredEmbeddings, removeFromAllEmbeddingsById, setAllRecommendedEncodersDict, setRecommendedEncodersAll, setLabelingTasksAll, removeFromAllLabelingTasksById, removeLabelFromLabelingTask } = settingsSlice.actions;
153154
export const settingsReducer = settingsSlice.reducer;

0 commit comments

Comments
 (0)