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

Issue 1534: disabling element if no collapsing locators #1689

Closed
wants to merge 3 commits into from
Closed
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
102 changes: 3 additions & 99 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 20 additions & 6 deletions src/features/locators/components/LocatorListHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ export const LocatorListHeader = ({
const [expandAll, setExpandAll] = useState(ExpandState.Expanded);
const [searchString, setSearchString] = useState('');
const [isAllLocatorsSelected, setIsAllLocatorsSelected] = useState<boolean>(false);
const [isDisabled, setIsDisabled] = useState(false);
const [hasSubLocators, setHasSubLocators] = useState(false);

const locators = useSelector(selectFilteredLocators);
const generatedLocators = useSelector(selectGenerateByPageObject);
Expand All @@ -54,6 +56,12 @@ export const LocatorListHeader = ({
const isCreatingForm = useSelector(selectIsCreatingFormOpen);

useEffect(() => {
setIsDisabled(locators.length === emptyLength);
const locatorHasSubLocators = locators.some(
(locator) => Array.isArray(locator.children) && locator.children.length > 0,
);
setHasSubLocators(locatorHasSubLocators);

if (
checkedLocators.length > emptyLength &&
checkedLocators.length === locators.length &&
Expand All @@ -63,7 +71,7 @@ export const LocatorListHeader = ({
} else {
setIsAllLocatorsSelected(false);
}
}, [checkedLocators.length]);
}, [locators, checkedLocators.length, generatedLocators.length]);

const partiallySelected =
checkedLocators.length > emptyLength &&
Expand Down Expand Up @@ -115,14 +123,20 @@ export const LocatorListHeader = ({
<span className="jdn__items-list_header-title">
<CaretDown
style={{
transform: expandAll === ExpandState.Expanded ? 'rotate(180deg)' : 'rotate(0deg)',
transform: hasSubLocators
? `rotate(${expandAll === ExpandState.Expanded ? '180' : '0'}deg)`
: 'rotate(0deg)',

pointerEvents: isDisabled || !hasSubLocators ? 'none' : 'auto',
}}
className="jdn__items-list_header-collapse"
color="#878A9C"
color={`${isDisabled || !hasSubLocators ? 'rgba(0, 0, 0, 0.25)' : '#878A9C'}`}
size={14}
onClick={() =>
setExpandAll(expandAll === ExpandState.Collapsed ? ExpandState.Expanded : ExpandState.Collapsed)
}
onClick={() => {
if (hasSubLocators) {
setExpandAll(expandAll === ExpandState.Collapsed ? ExpandState.Expanded : ExpandState.Collapsed);
}
}}
/>
<Checkbox
checked={isAllLocatorsSelected}
Expand Down
Loading