Skip to content

Commit

Permalink
Merge pull request #4763 from specify/issue-4741-fixup
Browse files Browse the repository at this point in the history
refactor(FormEditor): use .getRelationship() in viewSpec
  • Loading branch information
maxpatiiuk authored Aug 7, 2024
2 parents e1f53d0 + 1197d91 commit 196fe71
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
21 changes: 10 additions & 11 deletions specifyweb/frontend/js_src/lib/components/FormEditor/viewSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,12 +413,14 @@ const subViewSpec = (
syncer(
(raw: string) => {
const cellName = cell.rest.node.attributes.name;
const cellRelationship = table?.fields
.filter((field) => field.isRelationship)
.find((table) => table.name === cellName) as
| Relationship
| undefined;
const cellRelatedTableName = cellRelationship?.relatedTable.name;
const cellRelationship =
typeof cellName === 'string'
? syncers.field(table?.name).serializer(cellName)?.at(-1)
: undefined;
const cellRelatedTableName =
cellRelationship?.isRelationship === true
? cellRelationship.relatedTable.name
: undefined;
const parsed = toLargeSortConfig(raw);
const fieldNames = syncers
.field(cellRelatedTableName)
Expand Down Expand Up @@ -781,11 +783,8 @@ const textSpec = f.store(() =>
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
const textAreaSpec = (
_field: SpecToJson<ReturnType<typeof rawFieldSpec>>,
{
rawType,
}: {
readonly rawType: string;
}
_: unknown,
rawType: string
) =>
createXmlSpec({
rows: pipe(
Expand Down
7 changes: 4 additions & 3 deletions specifyweb/frontend/js_src/lib/components/Syncer/syncers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,8 @@ export const syncers = {
MAPPER extends {
readonly [KEY in TYPE_MAPPER[keyof TYPE_MAPPER] | 'Unknown']: (
input: IN,
extra: EXTRA & { readonly rawType: keyof TYPE_MAPPER }
extra: EXTRA,
rawType: keyof TYPE_MAPPER
) => BaseSpec<SimpleXmlNode>;
},
MAPPED extends {
Expand Down Expand Up @@ -658,7 +659,7 @@ export const syncers = {
]) as TYPE_MAPPER[keyof TYPE_MAPPER]) ?? ('Unknown' as const);
const spec = mapper[type] ?? mapper.Unknown;
const { serializer } = syncers.object(
spec(cell, { ...extraPayload, rawType })
spec(cell, extraPayload, rawType)
);

return {
Expand Down Expand Up @@ -692,7 +693,7 @@ export const syncers = {
)?.[0] ?? rawType;
const spec = mapper[definition.type] ?? mapper.Unknown;
const { deserializer } = syncers.object(
spec(cell as unknown as IN, { ...extraPayload, rawType })
spec(cell as unknown as IN, extraPayload, rawType)
);
const node = deserializer(definition);
const rawNode: NodeWithContext<SimpleXmlNode> = {
Expand Down

0 comments on commit 196fe71

Please sign in to comment.