Sha256: e58f8b3f1023b8fe1da50b59312183eda6163236f2fd8d88badd5a2a520b4af1
Contents?: true
Size: 1.42 KB
Versions: 1
Compression:
Stored size: 1.42 KB
Contents
import * as PageEditor from "../../types/PageEditor"; import * as Pages from "../../types/Pages"; import * as Template from "../../types/Template"; import { LocalizedValue, MaybeLocalizedValue } from "../../types"; export function blockValue( state: PageEditor.State, block: Template.Block ): string { if (block.localized) { const value: LocalizedValue = (state.page.blocks[block.name] as LocalizedValue) || {}; return value[state.locale] || ""; } else { return (state.page.blocks[block.name] as string) || ""; } } export function errorsOn(page: Pages.Resource, attribute: string): string[] { return page.errors .filter((e) => e.attribute === attribute) .map((e) => e.message); } export function unconfiguredBlocks(state: PageEditor.State): Template.Block[] { const allBlocks: Record<string, Template.Block> = state.templates .flatMap((t) => t.blocks) .reduce((bs, b) => ({ [b.name]: b, ...bs }), {}); const anyValue = (v: MaybeLocalizedValue) => { if (typeof v === "string") { return v ? true : false; } else { return Object.values(v).filter((v) => v).length > 0; } }; const hasValue = Object.keys(allBlocks).filter((k) => { const value = state.page.blocks[k] || ""; return anyValue(value); }); const enabled = state.templateConfig.blocks.map((b) => b.name); return hasValue .filter((b) => enabled.indexOf(b) === -1) .map((n) => allBlocks[n]); }
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
pages_core-3.15.5 | app/javascript/components/PageForm/utils.ts |