-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Disponibilizando funções de legenda para inputFilter.
- Loading branch information
Showing
7 changed files
with
168 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,7 @@ | |
.input-filter-select { | ||
width: 40%; | ||
max-width: 200px; | ||
min-width: 130px; | ||
} | ||
|
||
.input-filter-field { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from "./legend"; | ||
export * from "./inputfilter"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { MES } from "../utils"; | ||
import { optionsLabel } from "./const"; | ||
|
||
/** | ||
* Retorna a legenda de acordo com operador na string | ||
* @param value - Valor a ser tratado | ||
*/ | ||
export function filterLegend(value: string | undefined): string | null { | ||
if (!value) { | ||
return null; | ||
} | ||
let optsRegex = /(=|!=|<|>|<=|>=|%|!%|\{\})/; | ||
let optsMatch = value?.match(optsRegex); | ||
let opts = value.charAt(value.length - 1); | ||
let option = optsMatch?.[0]; | ||
|
||
if (optsMatch?.[0] !== opts && isNaN(parseInt(opts)) && option?.slice(-1) !== opts) { | ||
option = optsMatch?.[0] + opts; | ||
} | ||
return optionsLabel.filter(item => item.options === option)[0]?.label ?? null; | ||
} | ||
|
||
/** | ||
* Realiza o tratamento das informações para retorna a legenda do tipo `Date` | ||
* @param value - Valor a ser tratado | ||
*/ | ||
export function filterLegendData(value: string | undefined): string { | ||
let legend = filterLegend(value); | ||
if (legend === null) { | ||
return "Não encontramos legenda definida."; | ||
} | ||
|
||
let interval = value?.split("{}"); | ||
let date = value?.split("/"); | ||
|
||
const handleLegend = (date: any): string => { | ||
let dia = parseInt(date[0]); | ||
let mes = parseInt(date[1], 10); | ||
let ano = parseInt(date[2]); | ||
|
||
return ` | ||
${(dia > 0 ? `${mes == 0 ? "dia" : ""} ${dia}` : "")} | ||
${mes > 0 ? `${dia > 0 ? "de" : ""} ${MES[mes - 1]?.name}` : ""} | ||
${ano > 0 ? `${dia > 0 || mes > 0 ? "de" : ""} ${ano}` : ""} | ||
`.replace(/\s+/g, " ").trim(); | ||
}; | ||
let result = interval?.[1] === undefined | ||
? handleLegend(date) | ||
: handleLegend(interval[0].split("/")) + " à " + handleLegend(interval[1].split("/")); | ||
return legend + ": " + result; | ||
} | ||
|
||
/** | ||
* Realiza o tratamento das informações para retorna a legenda do tipo `Text` | ||
* @param value - Valor a ser tratado | ||
*/ | ||
export function filterLegendText(value: string | undefined): string { | ||
let legend = filterLegend(value); | ||
if (legend === null) { | ||
return "Não encontramos legenda definida."; | ||
} | ||
return legend + ": " + (value?.replace(/(=|!=|<|>|<=|>=|%|!%|\{\})/g, "") ?? ""); | ||
} | ||
|
||
/** | ||
* Realiza o tratamento das informações para retorna a legando do tipo `autocomplete` | ||
* @param value - Valor a ser tratado | ||
* @param dto - Array de objeto para ser pesquisado a legenda | ||
* @param word - Limite de palavras para a legenda | ||
*/ | ||
export function filterLegendAutocomplete(value: string | undefined, dto: any[] = [], word: number = 30): string { | ||
let legend = filterLegend(value); | ||
if (legend === null || dto.length === 0) { | ||
return "Não encontramos legenda definida."; | ||
} | ||
let ids: any[] = value?.split(";").map(item => parseInt(item)) ?? []; | ||
let values = dto | ||
.filter(obj => ids.includes(obj.id)) | ||
.map(item => item.label).join(", "); | ||
let text = values.substring(0, word); | ||
return legend + ": " + text + (text.length !== values.length ? "..." : ""); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { expect, describe, test } from "@jest/globals"; | ||
import { filterLegend, filterLegendData, filterLegendText, filterLegendAutocomplete } from "../dist/inputfilter"; | ||
|
||
describe("InputFilter", () => { | ||
|
||
describe("Arquivo -> legend.ts", () => { | ||
test("filterLegend - Undefined", () => expect(filterLegend(undefined)).toBeNull()); | ||
test("filterLegend - Valor diferente", () => expect(filterLegend("9/11/2024>!@#")).toBeNull()); | ||
test("filterLegend - Igual a", () => expect(filterLegend("9/11/2024=")).toEqual("Igual a")); | ||
test("filterLegend - Maior ou igual a", () => expect(filterLegend("9/11/2024>=")).toEqual("Maior ou igual a")); | ||
test("filterLegend - Intervalo", () => expect(filterLegend("9/11/2024{}0/0/0")).toEqual("Intervalo")); | ||
|
||
test("filterLegendData", () => expect(typeof filterLegendData(undefined)).toBe("string")); | ||
test("filterLegendData", () => expect(typeof filterLegendData("9/11/2024=")).toBe("string")); | ||
|
||
test("filterLegendText", () => expect(typeof filterLegendText(undefined)).toBe("string")); | ||
test("filterLegendText", () => expect(typeof filterLegendText("luizfernando!%")).toBe("string")); | ||
|
||
test("filterLegendAutocomplete", () => expect(typeof filterLegendAutocomplete(undefined)).toBe("string")); | ||
test("filterLegendAutocomplete", () => expect(filterLegendAutocomplete("1!=", [{ | ||
id: 1, | ||
label: "TESTE" | ||
}])).toBe("Diferente de: TESTE")); | ||
}); | ||
}); |