Untitled

mail@pastecode.io avatar
unknown
plain_text
15 days ago
1.7 kB
1
Indexable
Never
const filterAuthOfferings = () => {
    let refTable = rfiUtil.getRefTableDataByCacheName(
        ConstantKeys.REF_TABLE.CREATE_RFI_REF_TABLES,
    );
    let filteredOfferingData = [];
    const privilegeData = AppContext.security.getProfile().profile;
    console.log('privilegeData:', privilegeData);

    // Extract all unique offering values from the privilegeData
    const uniqueOfferings = [...new Set(privilegeData.flatMap(detail => detail.offering))];
    console.log('uniqueOfferings:', uniqueOfferings);

    // Filter offerings based on the unique offerings
    filteredOfferingData = refTable.OFFERING.filter((offering) =>
        uniqueOfferings.includes(offering.CODE)
    );

    // Update the offering list if filtered data is available
    if (filteredOfferingData.length > 0) {
        setFilteredOfferings(filteredOfferingData);
    }

    // Reset the value of offering and program to default value when state changes
    setFilteredPrograms([]);
    setFilteredCategory([]);
    updateRFIRequest({
        ...rfiRequest,
        offering: '',
        category: [...ConstantKeys.DEFAULT_OPTION.CATEGORY],
        programs: [...ConstantKeys.DEFAULT_OPTION.PROGRAM],
    });
};

const filterProgramAndCategory = (value) => {
    const selectedOffering = value;

    // Get the programs and categories for the selected offering
    const filteredProg = rfiUtil.getTableDataForOffering(
        ConstantKeys.REF_TABLE_NAMES.PROGRAM,
        selectedOffering,
    );
    setFilteredPrograms(filteredProg);

    const filteredCategories = rfiUtil.getTableDataForOffering(
        ConstantKeys.REF_TABLE_NAMES.CATEGORY,
        selectedOffering,
    );
    setFilteredCategory(filteredCategories);
};
Leave a Comment