Skip to content
Snippets Groups Projects
Commit d7e0838c authored by Anton Kulyk's avatar Anton Kulyk Committed by Reza Lotun
Browse files

Add ability to make all children collections official or regular (#17168)

* Add `update_collection_tree_authority_level` field

* Add authority level tree update

* Test authority level children bulk update
parent 32a88aa4
No related merge requests found
import React from "react";
import PropTypes from "prop-types";
import { t } from "ttag";
import CheckBox from "metabase/components/CheckBox";
import {
SegmentedControl,
optionShape,
} from "metabase/components/SegmentedControl";
import { AUTHORITY_LEVELS } from "../constants";
import { FormFieldRoot, Label } from "./FormCollectionAuthorityLevel.styled";
const propTypes = {
field: PropTypes.shape({
value: PropTypes.any,
initialValue: PropTypes.any,
onChange: PropTypes.func.isRequired,
}).isRequired,
options: PropTypes.arrayOf(optionShape).isRequired,
values: PropTypes.shape({
id: PropTypes.number,
authority_level: PropTypes.oneOf(["official"]),
update_collection_tree_authority_level: PropTypes.bool,
}),
onChangeField: PropTypes.func.isRequired,
};
export function FormCollectionAuthorityLevel({ field, options }) {
export function FormCollectionAuthorityLevel({
field,
options,
values,
onChangeField,
}) {
const isNewCollection = !values.id;
const selectedAuthorityLevel =
AUTHORITY_LEVELS[field.value] || AUTHORITY_LEVELS.regular;
const shouldSuggestToUpdateChildren =
!isNewCollection && field.initialValue !== field.value;
return (
<SegmentedControl
value={field.value}
onChange={field.onChange}
options={options}
/>
<FormFieldRoot>
<SegmentedControl
value={field.value}
onChange={field.onChange}
options={options}
/>
{shouldSuggestToUpdateChildren && (
<CheckBox
label={
<Label>{t`Make all sub-collections ${selectedAuthorityLevel.name}, too.`}</Label>
}
checked={values.update_collection_tree_authority_level}
onChange={e =>
onChangeField(
"update_collection_tree_authority_level",
e.target.checked,
)
}
/>
)}
</FormFieldRoot>
);
}
......
import styled from "styled-components";
import CheckBox from "metabase/components/CheckBox";
import { color } from "metabase/lib/colors";
export const FormFieldRoot = styled.div`
display: flex;
align-items: center;
justify-content: space-between;
`;
export const Label = styled(CheckBox.Label)`
color: ${color("text-dark")};
font-size: 1em;
font-weight: bold;
margin-bottom: 1px;
`;
......@@ -44,6 +44,10 @@ PLUGIN_COLLECTIONS.formFields = [
},
],
},
{
name: "update_collection_tree_authority_level",
type: "hidden",
},
];
PLUGIN_FORM_WIDGETS.collectionAuthorityLevel = FormCollectionAuthorityLevel;
......
......@@ -23,6 +23,10 @@ describeWithToken("collections types", () => {
cy.signInAsAdmin();
});
const TREE_UPDATE_REGULAR_MESSAGE = "Make all sub-collections Regular, too.";
const TREE_UPDATE_OFFICIAL_MESSAGE =
"Make all sub-collections Official, too.";
it("should be able to manage collection authority level", () => {
cy.visit("/collection/root");
......@@ -42,6 +46,56 @@ describeWithToken("collections types", () => {
it("displays official badge throughout the application", () => {
testOfficialBadgePresence();
});
it("should be able to update authority level for collection children", () => {
cy.visit("/collection/root");
cy.findByText("First collection").click();
// Test not visible when creating a new collection
cy.icon("new_folder").click();
modal().within(() => {
cy.findByText(TREE_UPDATE_REGULAR_MESSAGE).should("not.exist");
cy.findByText(TREE_UPDATE_OFFICIAL_MESSAGE).should("not.exist");
setOfficial();
cy.findByText(TREE_UPDATE_REGULAR_MESSAGE).should("not.exist");
cy.findByText(TREE_UPDATE_OFFICIAL_MESSAGE).should("not.exist");
cy.icon("close").click();
});
// Test can make all children official
editCollection();
modal().within(() => {
cy.findByText(TREE_UPDATE_REGULAR_MESSAGE).should("not.exist");
cy.findByText(TREE_UPDATE_OFFICIAL_MESSAGE).should("not.exist");
setOfficial();
cy.findByText(TREE_UPDATE_REGULAR_MESSAGE).should("not.exist");
cy.findByText(TREE_UPDATE_OFFICIAL_MESSAGE).click();
cy.button("Update").click();
});
getSidebarCollectionChildrenFor("First collection").within(() => {
expandCollectionChildren("Second collection");
cy.icon("badge").should("have.length", 3);
cy.icon("folder").should("not.exist");
});
// Test can make all children regular
editCollection();
modal().within(() => {
cy.findByText(TREE_UPDATE_REGULAR_MESSAGE).should("not.exist");
cy.findByText(TREE_UPDATE_OFFICIAL_MESSAGE).should("not.exist");
setOfficial(false);
cy.findByText(TREE_UPDATE_REGULAR_MESSAGE).click();
cy.findByText(TREE_UPDATE_OFFICIAL_MESSAGE).should("not.exist");
cy.button("Update").click();
});
getSidebarCollectionChildrenFor("First collection").within(() => {
expandCollectionChildren("Second collection");
cy.icon("folder").should("have.length", 3);
cy.icon("badge").should("not.exist");
});
});
});
describeWithoutToken("collection types", () => {
......@@ -134,6 +188,22 @@ function editCollection() {
cy.findByText("Edit this collection").click();
}
function expandCollectionChildren(collectionName) {
cy.findByText(collectionName)
.parent()
.find(".Icon-chevronright")
.eq(0) // there may be more nested icons, but we need the top level one
.click();
}
function getSidebarCollectionChildrenFor(collectionName) {
return sidebar()
.findByText(collectionName)
.closest("a")
.parent()
.parent();
}
function setOfficial(official = true) {
const isOfficialNow = !official;
cy.findByLabelText("Regular").should(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment