{"size": 1035, "ext": "js", "max_stars_repo_path": "src/modules/relativeItems/index.js", "max_stars_repo_name": "dhis2/d2-ui-analytics", "max_stars_repo_stars_event_min_datetime": "2019-03-01T14:31:35.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-17T20:01:07.000Z", "max_issues_repo_path": "src/modules/relativeItems/index.js", "max_issues_repo_name": "dhis2/analytics", "max_issues_repo_issues_event_min_datetime": "2019-03-01T00:06:50.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T08:07:40.000Z", "max_forks_repo_path": "src/modules/relativeItems/index.js", "max_forks_repo_name": "dhis2/d2-ui-analytics", "max_forks_repo_forks_event_min_datetime": "2020-09-17T01:40:29.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-13T08:14:37.000Z"}
{"max_stars_count": 9, "max_issues_count": 1060, "max_forks_count": 4, "avg_line_length": 33.3870967742, "max_line_length": 96, "alphanum_fraction": 0.6164251208}
import { getRelativePeriodIds } from '../../components/PeriodDimension/utils/relativePeriods.js'
import {
    ouIdHelper,
    USER_ORG_UNIT,
    USER_ORG_UNIT_CHILDREN,
    USER_ORG_UNIT_GRANDCHILDREN,
} from '../ouIdHelper/index.js'
import {
    DIMENSION_ID_ASSIGNED_CATEGORIES,
    DIMENSION_ID_ORGUNIT,
    DIMENSION_ID_PERIOD,
} from '../predefinedDimensions.js'

export const hasRelativeItems = (dimension, itemIds = []) =>
    dimension === DIMENSION_ID_ASSIGNED_CATEGORIES ||
    (dimension === DIMENSION_ID_ORGUNIT &&
        Array.isArray(itemIds) &&
        itemIds.some(
            (id) =>
                ouIdHelper.hasLevelPrefix(id) ||
                ouIdHelper.hasGroupPrefix(id) ||
                [
                    USER_ORG_UNIT,
                    USER_ORG_UNIT_CHILDREN,
                    USER_ORG_UNIT_GRANDCHILDREN,
                ].includes(id)
        )) ||
    (dimension === DIMENSION_ID_PERIOD &&
        Array.isArray(itemIds) &&
        itemIds.some((id) => getRelativePeriodIds().includes(id)))
