bookbrainz/bookbrainz-site

View on GitHub
src/client/unified-form/validators/detail-tab.ts

Summary

Maintainability
A
0 mins
Test Coverage
import {get} from 'lodash';
import {validateEditionSection} from '../../entity-editor/validators/edition';


export const initialEditionSection = {
    authorCreditEditorVisible: false,
    format: null,
    languages: [],
    matchingNameEditionGroups: [],
    physicalEnable: true,
    publisher: {},
    releaseDate: '',
    status: null
};
const stringifiedInitialState = JSON.stringify(initialEditionSection);

/**
 *     Validates the Detail Tab state.
 *
 * @param {object} data - the form state object
 * @returns {boolean} - true if detail tab state is valid
 */
export function validateDetailTab(data: any): boolean {
    return validateEditionSection(get(data, 'editionSection'), true);
}

/**
 * Check whether Detail Tab is modified or not.
 *
 * @param {object} data - the form state object
 * @returns {boolean} - true if detail tab state is empty
 */
export function isDetailTabEmpty(data:any): boolean {
    const editionSection = get(data, 'editionSection', {});
    const annotationContent = get(data, ['annotationSection', 'content'], '');
    return JSON.stringify(editionSection) === stringifiedInitialState && annotationContent.length === 0;
}