Skip to content

Commit

Permalink
[frontend] improve confidence overrides edition + bugfixes (#6837)
Browse files Browse the repository at this point in the history
  • Loading branch information
labo-flg committed Apr 30, 2024
1 parent 0a56d02 commit 8e3cb8c
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 61 deletions.
1 change: 1 addition & 0 deletions opencti-platform/opencti-front/lang/front/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -1463,6 +1463,7 @@
"Matches all indicator main observable types if none is listed.": "Entspricht allen Indikator-Hauptbeobachtungstypen, wenn keiner aufgeführt ist.",
"Matrix view": "Matrixansicht",
"Max Confidence": "Maximalvertrauen",
"Max Confidence is overridden for some entity types:": "Max Confidence wird für einige Entitätstypen außer Kraft gesetzt:",
"Max Confidence Level": "Max. Konfidenzniveau",
"Max Confidence Level:": "Max. Konfidenzniveau:",
"Max file size (in MB)": "Maximale Dateigröße (in MB)",
Expand Down
1 change: 1 addition & 0 deletions opencti-platform/opencti-front/lang/front/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1463,6 +1463,7 @@
"Matches all indicator main observable types if none is listed.": "Matches all indicator main observable types if none is listed.",
"Matrix view": "Matrix view",
"Max Confidence": "Max Confidence",
"Max Confidence is overridden for some entity types:": "Max Confidence is overridden for some entity types:",
"Max Confidence Level": "Max Confidence Level",
"Max Confidence Level:": "Max Confidence Level:",
"Max file size (in MB)": "Max file size (in MB)",
Expand Down
1 change: 1 addition & 0 deletions opencti-platform/opencti-front/lang/front/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -1463,6 +1463,7 @@
"Matches all indicator main observable types if none is listed.": "Coincide con todos los tipos observables principales del indicador si no se enumera ninguno.",
"Matrix view": "Vista en matriz",
"Max Confidence": "Max Confianza",
"Max Confidence is overridden for some entity types:": "La confianza máxima se anula para algunos tipos de entidad:",
"Max Confidence Level": "Nivel de confianza máximo",
"Max Confidence Level:": "Nivel Máximo de Confianza:",
"Max file size (in MB)": "Tamaño máximo del archivo (en MB)",
Expand Down
1 change: 1 addition & 0 deletions opencti-platform/opencti-front/lang/front/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -1463,6 +1463,7 @@
"Matches all indicator main observable types if none is listed.": "Correspond à tous les types d'observables principaux des indicateurs si aucun n'est listé.",
"Matrix view": "Vue matricielle",
"Max Confidence": "Confiance max",
"Max Confidence is overridden for some entity types:": "La confiance max est surchargée pour certains types d'entités :",
"Max Confidence Level": "Niveau de confiance maximal",
"Max Confidence Level:": "Niveau de confiance maximum :",
"Max file size (in MB)": "Taille maximale du fichier (en Mo)",
Expand Down
1 change: 1 addition & 0 deletions opencti-platform/opencti-front/lang/front/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -1463,6 +1463,7 @@
"Matches all indicator main observable types if none is listed.": "もし何もリストされていなければ、全ての指標となる主要な観測可能な型にマッチします。",
"Matrix view": "マトリックス表示",
"Max Confidence": "マックス・コンフィデンス",
"Max Confidence is overridden for some entity types:": "エンティティの種類によっては、最大信頼度がオーバーライドされます:",
"Max Confidence Level": "最大信頼度",
"Max Confidence Level:": "最大信頼度:",
"Max file size (in MB)": "最大ファイルサイズ(単位:MB)",
Expand Down
1 change: 1 addition & 0 deletions opencti-platform/opencti-front/lang/front/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -1463,6 +1463,7 @@
"Matches all indicator main observable types if none is listed.": "如果没有列出主要观测指标类型,则匹配所有指标类型。",
"Matrix view": "矩阵视图",
"Max Confidence": "最大置信度",
"Max Confidence is overridden for some entity types:": "对于某些实体类型,最大置信度会被覆盖:",
"Max Confidence Level": "最大置信度",
"Max Confidence Level:": "最大置信度:",
"Max file size (in MB)": "最大文件大小(兆字节)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@ type OverridesProps = {
};

const Overrides: React.FC<OverridesProps> = ({ overrides }) => {
return (
<>
{overrides?.map((override, index) => (
<div key={index} style={{ marginTop: '5px' }}>
{`${override.entity_type}: ${override.max_confidence}`}
const { t_i18n } = useFormatter();
return overrides?.length ? (
<div style={{ marginTop: '5px' }}>
<div>{t_i18n('Max Confidence is overridden for some entity types:')}</div>
{overrides.map((override, index) => (
<div key={index}>
{`- ${t_i18n(`entity_${override.entity_type}`)}: ${override.max_confidence}`}
</div>
))}
</>
);
</div>
) : null;
};

const ConfidenceSource: React.FC<UserConfidenceLevelProps> = ({ user }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ const UserConfidenceOverrideField: FunctionComponent<UserConfidenceOverridesFiel
if (isEmptyField(override.entity_type)) {
return `${number} ${t_i18n('New override of an entity')}`;
}
const label = `${t_i18n(`entity_${override.entity_type}`)}`;
const label = `${t_i18n(`entity_${override.entity_type}`)}: ${override.max_confidence}`;
return `${number} ${label[0].toUpperCase()}${label.slice(1)}`;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { userMutationFieldPatch } from '@components/settings/users/edition/UserE
import UserConfidenceOverrideField from '@components/settings/users/edition/UserConfidenceOverrideField';
import { fieldSpacingContainerStyle } from '../../../../../utils/field';
import { useFormatter } from '../../../../../components/i18n';
import { isNotEmptyField } from '../../../../../utils/utils';
import { isEmptyField, isNotEmptyField } from '../../../../../utils/utils';
import useApiMutation from '../../../../../utils/hooks/useApiMutation';

export interface OverrideFormData {
Expand Down Expand Up @@ -73,61 +73,63 @@ const UserEditionConfidence: FunctionComponent<UserEditionConfidenceProps> = ({
userConfidenceValidation(t_i18n)
.validateAt(name, { [name]: value })
.then(() => {
if (name === 'user_confidence_level') {
let finalValue;
if (user.user_confidence_level && isNotEmptyField(value)) {
// We edit an existing value inside the object: use object_path
finalValue = parseInt(value, 10);
} else if (!user.user_confidence_level && value) {
// We have no user_confidence_level, and we add one: push a complete object
finalValue = {
max_confidence: parseInt(value, 10),
overrides: [],
};
} else if (user.user_confidence_level && !value) {
// we have an existing value, but we want to remove it: push [null] (and not null!)
finalValue = [null];
}
if (finalValue) {
commitFieldPatch({
variables: {
id: user.id,
input: {
key: 'user_confidence_level',
object_path: '/user_confidence_level/max_confidence',
value: finalValue,
},
let finalValue;
let object_path;
if (user.user_confidence_level && isNotEmptyField(value)) {
// we are updating the value
object_path = '/user_confidence_level/max_confidence';
finalValue = parseInt(value, 10);
} else if (!user.user_confidence_level && value) {
// We have no user_confidence_level, and we add one: push a complete object
object_path = '/user_confidence_level';
finalValue = {
max_confidence: parseInt(value, 10),
overrides: [],
};
} else if (user.user_confidence_level && !value) {
// we have an existing value, but we want to remove it: push [null] (and not null!)
object_path = '/user_confidence_level/max_confidence';
finalValue = [null];
}
if (finalValue) {
commitFieldPatch({
variables: {
id: user.id,
input: {
key: 'user_confidence_level',
object_path,
value: finalValue,
},
});
}
},
});
}
})
.catch(() => false);
};

const handleSubmitOverride = (index: number, value: OverrideFormData | null) => {
const name = `overrides[${index}]`;
if (!user.user_confidence_level) {
if (isNotEmptyField(value?.entity_type) && isNotEmptyField(value?.max_confidence)) {
let object_path = '';
let finalValue;
// If there is no user_confidence_level defined and value is provided, initialize it with an override
if (isNotEmptyField(value) && value.entity_type && isNotEmptyField(value.max_confidence)) {
commitFieldPatch({
variables: {
id: user.id,
input: {
key: 'user_confidence_level',
value: {
max_confidence: null, // Initialize max_confidence as null
overrides: [{
entity_type: value.entity_type,
max_confidence: parseInt(value.max_confidence ?? '0', 10),
}],
},
},
},
});
if (!user.user_confidence_level) {
object_path = 'user_confidence_level';
finalValue = {
max_confidence: null, // Initialize global max_confidence as null
overrides: [{
entity_type: value.entity_type,
max_confidence: parseInt(value.max_confidence ?? '0', 10),
}],
};
} else {
// If user_confidence_level already exists, just update or add the override
object_path = `/user_confidence_level/overrides/${index}`;
finalValue = [{
entity_type: value.entity_type,
max_confidence: parseInt(value.max_confidence ?? '0', 10),
}];
}
} else if (isNotEmptyField(value) && value.entity_type && isNotEmptyField(value.max_confidence)) {
// If user_confidence_level already exists, just update or add the override
const name = `overrides[${index}]`;
userConfidenceValidation(t_i18n)
.validateAt(name, { [name]: value })
.then(() => {
Expand All @@ -136,17 +138,14 @@ const UserEditionConfidence: FunctionComponent<UserEditionConfidenceProps> = ({
id: user.id,
input: {
key: 'user_confidence_level',
object_path: `/user_confidence_level/overrides/${index}`,
value: [{
entity_type: value.entity_type,
max_confidence: parseInt(value.max_confidence ?? '0', 10),
}],
object_path,
value: finalValue,
},
},
});
})
.catch(() => false);
} else if (!isNotEmptyField(value)) {
} else if (isEmptyField(value)) {
commitFieldPatch({
variables: {
id: user.id,
Expand Down

0 comments on commit 8e3cb8c

Please sign in to comment.