Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Add parser for custom rule file label title in manual upload flow #1702

Merged
merged 2 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ export const CustomRules: React.FC = () => {
filteredItems?.forEach((item) => {
const { source, target, total } = parseRules(item);

const sourceLabelName = getParsedLabel(source)?.labelValue ?? "";
const targetLabelName = getParsedLabel(target)?.labelValue ?? "";
const sourceTargetLabel = `${sourceLabelName} / ${targetLabelName}`;

rows.push({
entity: item,
cells: [
Expand All @@ -171,9 +175,7 @@ export const CustomRules: React.FC = () => {
},
{
title: (
<TableText wrapModifier="truncate">
{source} / {target}
</TableText>
<TableText wrapModifier="truncate">{sourceTargetLabel}</TableText>
),
},
{
Expand Down
11 changes: 10 additions & 1 deletion client/src/app/utils/rules-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,25 @@ interface ParsedLabel {
labelValue: string;
}

export const getParsedLabel = (label: string): ParsedLabel => {
export const getParsedLabel = (label: string | null): ParsedLabel => {
if (label === null) {
return {
labelType: "",
labelValue: "",
};
}

const char1 = label.indexOf("/") + 1;
const char2 = label.lastIndexOf("=");
const type = label.substring(char1, char2);
const value = label.split("=").pop();

return {
labelType: type || "",
labelValue: value || "",
};
};

export const getLabels = (labels: string[]) =>
labels.reduce(
(map: ILabelMap, label) => {
Expand Down
Loading