Skip to content

Commit

Permalink
🐛 Add parser for custom rule file label title in manual upload flow (k…
Browse files Browse the repository at this point in the history
…onveyor#1702)

Resolves https://issues.redhat.com/browse/MTA-2004

<img width="1197" alt="Screenshot 2024-02-27 at 9 59 25 AM"
src="https://github.com/konveyor/tackle2-ui/assets/11218376/720d137a-098b-4736-ba1c-b0905073c144">

---------

Signed-off-by: Ian Bolton <[email protected]>
  • Loading branch information
ibolton336 committed Feb 28, 2024
1 parent d07b30d commit 0c79947
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
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

0 comments on commit 0c79947

Please sign in to comment.