Skip to content
Snippets Groups Projects
Unverified Commit cbbc9c64 authored by adam-james's avatar adam-james Committed by GitHub
Browse files

Disallow Filter labels to be any variation of the word 'tab'. (#37905)

To prevent ambiguous dashboard URLs, labels should not be called 'tab'.
parent 63725479
Branches
Tags
No related merge requests found
......@@ -141,7 +141,10 @@ function getLabelError({
return t`Required`;
}
if (isParameterSlugUsed(labelValue)) {
return t`This label is already in use`;
return t`This label is already in use.`;
}
if (labelValue.toLowerCase() === "tab") {
return t`This label is reserved for dashboard tabs.`;
}
return null;
}
......
......@@ -56,6 +56,33 @@ describe("ParameterSidebar", () => {
expect(labelInput).toHaveValue("bar");
});
it("should not update the label if the input is any variation of the word 'tab'", () => {
const { onChangeName } = setup({
parameter: createMockUiParameter({
name: "foo",
type: "string/=",
sectionId: "string",
}),
});
const labelInput = screen.getByLabelText("Label");
expect(labelInput).toHaveValue("foo");
fillValue(labelInput, "tAb");
// expect there to be an error message with the text "reserved"
expect(screen.getByText(/reserved/i)).toBeInTheDocument();
labelInput.blur();
// when the input blurs, the value should have reverted to the original
expect(onChangeName).not.toHaveBeenCalled();
expect(labelInput).toHaveValue("foo");
// the error message should disappear
expect(screen.queryByText(/reserved/i)).not.toBeInTheDocument();
// sanity check with a non-blank value
fillValue(labelInput, "bar");
labelInput.blur();
expect(onChangeName).toHaveBeenCalledWith("bar");
expect(labelInput).toHaveValue("bar");
});
it("should allow to change source settings for location parameters", () => {
const { onChangeQueryType } = setup({
parameter: createMockUiParameter({
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment