Skip to content

Commit

Permalink
fix: remove graphql api from GroupItem
Browse files Browse the repository at this point in the history
  • Loading branch information
caichi-t committed Mar 19, 2024
1 parent 3592302 commit 06bf7b1
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 26 deletions.
20 changes: 0 additions & 20 deletions web/src/components/molecules/Common/Form/GroupItem/hooks.ts

This file was deleted.

21 changes: 15 additions & 6 deletions web/src/components/molecules/Common/Form/GroupItem/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import styled from "@emotion/styled";
import { useCallback, useMemo, MouseEvent } from "react";
import { useCallback, useMemo, MouseEvent, useState, useEffect } from "react";

import Collapse from "@reearth-cms/components/atoms/Collapse";
import Icon from "@reearth-cms/components/atoms/Icon";
Expand All @@ -13,14 +13,12 @@ import {
import { DefaultField } from "@reearth-cms/components/molecules/Content/Form/fields/FieldComponents";
import { FIELD_TYPE_COMPONENT_MAP } from "@reearth-cms/components/molecules/Content/Form/fields/FieldTypesMap";
import { FormItem, ItemAsset } from "@reearth-cms/components/molecules/Content/types";
import { Field } from "@reearth-cms/components/molecules/Schema/types";
import { Field, Group } from "@reearth-cms/components/molecules/Schema/types";
import {
AssetSortType,
SortDirection,
} from "@reearth-cms/components/organisms/Project/Asset/AssetList/hooks";

import useHooks from "./hooks";

type Props = {
value?: string;
onChange?: (value: string) => void;
Expand Down Expand Up @@ -68,6 +66,7 @@ type Props = {
disableMoveUp?: boolean;
disableMoveDown?: boolean;
onGetAsset: (assetId: string) => Promise<string | undefined>;
onGroupGet: (id: string) => Promise<Group | undefined>;
};

const GroupItem: React.FC<Props> = ({
Expand Down Expand Up @@ -112,11 +111,21 @@ const GroupItem: React.FC<Props> = ({
disableMoveUp,
disableMoveDown,
onGetAsset,
onGroupGet,
}) => {
const { Panel } = Collapse;
const { group } = useHooks(parentField?.typeProperty?.groupId);

const fields = useMemo(() => group?.schema.fields, [group?.schema.fields]);
const [fields, setFields] = useState<Field[]>();

useEffect(() => {
const handleFieldsSet = async (id: string) => {
const group = await onGroupGet(id);
setFields(group?.schema.fields);
};

if (parentField?.typeProperty?.groupId) handleFieldsSet(parentField.typeProperty.groupId);
}, [onGroupGet, parentField?.typeProperty?.groupId]);

const itemGroupId = useMemo(() => value ?? "", [value]);

const handleMoveUp = useCallback(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ const MultiValueGroup: React.FC<Props> = ({
disableMoveUp={key === 0}
disableMoveDown={key === value.length - 1}
onGetAsset={onGetAsset}
onGroupGet={onGroupGet}
/>
</FieldWrapper>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ const GroupField: React.FC<GroupFieldProps> = ({
setFileList={setFileList}
setUploadModalVisibility={setUploadModalVisibility}
onGetAsset={onGetAsset}
onGroupGet={onGroupGet}
/>
)}
</Form.Item>
Expand Down

0 comments on commit 06bf7b1

Please sign in to comment.