-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(web): sort the order of tags when saving an item #1330
Conversation
WalkthroughThe changes in this pull request primarily focus on enhancing the Changes
Possibly related PRs
Suggested labels
Suggested reviewers
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
✅ Deploy Preview for reearth-cms ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Outside diff range and nitpick comments (5)
web/src/components/organisms/Project/Content/ContentList/hooks.ts (1)
205-208
: Consider destructuringmetaFieldsMap
entries for clarityIn the mapping over
metaFieldsMap
, you're usingfield[1]
to access the field object, which can be unclear. Destructure the entries for better readability.Apply this diff to improve clarity:
-const fields = [...metaFieldsMap].map(field => ({ - value: field[1].id === key ? value : "", - type: field[1].type as SchemaFieldType, +const fields = [...metaFieldsMap].map(([fieldId, fieldObj]) => ({ + value: fieldId === key ? value : "", + type: fieldObj.type as SchemaFieldType,web/src/components/molecules/Schema/FieldModal/FieldDefaultInputs/TagField/index.tsx (1)
69-72
: Reusability ofTagWrapper
componentSince
TagWrapper
is used in multiple files, consider extracting it into a shared component to promote reusability.web/src/components/molecules/Content/Form/fields/FieldComponents/TagField.tsx (1)
84-88
: ExtractTagWrapper
to a shared componentSimilar to the previous file, consider making
TagWrapper
a shared component to maintain consistency and reduce code duplication.web/src/components/molecules/Content/Form/index.tsx (1)
Line range hint
403-416
: Consider extracting group field handling logic.The group field handling logic in the submit handler is becoming complex. Consider extracting it into a separate function for better maintainability.
+const handleGroupField = ( + value: unknown, + key: string, + groupFields: Map<string, Field>, +): ItemField[] => { + const fields: ItemField[] = []; + if (typeof value === "object" && value !== null) { + for (const [groupFieldKey, groupFieldValue] of Object.entries(value)) { + const groupField = groupFields.get(key); + if (groupField) { + fields.push({ + value: inputValueGet(groupFieldValue, groupField), + schemaFieldId: key, + itemGroupId: groupFieldKey, + type: groupField.type, + }); + } + } + } + return fields; +};web/src/components/molecules/Schema/FieldModal/hooks.ts (1)
200-213
: Optimize tag filtering performanceThe current implementation uses separate filter and map operations, which creates unnecessary iterations over the tags array.
Consider combining the operations into a single reduce:
case "Tag": { const defaultValue = Array.isArray(values.defaultValue) && values.defaultValue.length - ? values.tags - ?.filter(tag => values.defaultValue.includes(tag.name)) - .map(({ name }) => name) + ? values.tags?.reduce((acc, { name }) => { + if (values.defaultValue.includes(name)) { + acc.push(name); + } + return acc; + }, [] as string[]) : (values.tags?.some(tag => tag.name === values.defaultValue) ? values.defaultValue : undefined); return { tag: { defaultValue, tags: values.tags ?? [], }, }; }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (7)
web/src/components/molecules/Content/Form/fields/FieldComponents/TagField.tsx
(3 hunks)web/src/components/molecules/Content/Form/index.tsx
(5 hunks)web/src/components/molecules/Content/utils.ts
(2 hunks)web/src/components/molecules/Schema/FieldModal/FieldDefaultInputs/TagField/index.tsx
(3 hunks)web/src/components/molecules/Schema/FieldModal/hooks.ts
(1 hunks)web/src/components/molecules/Schema/types.ts
(1 hunks)web/src/components/organisms/Project/Content/ContentList/hooks.ts
(5 hunks)
🔇 Additional comments (7)
web/src/components/organisms/Project/Content/ContentList/hooks.ts (2)
254-256
: Potential mismatch in value
assignment
In the fields
array, you're checking field[1].id === key
but assigning value
to value: field[1].id === key ? value : ""
. If multiple fields share the same key
, this may cause issues.
Run the following script to verify that field.id
is unique across all fields:
229-230
: Ensure tags
is defined before calling selectedTagIdsGet
There is a possibility that tags
may be undefined
if metaFieldsMap.get(key)
returns undefined
. This could lead to unexpected behavior.
Run the following script to check if tags
can be undefined
:
web/src/components/molecules/Content/utils.ts (1)
12-13
: Clarify the purpose and parameters of selectedTagIdsGet
The function selectedTagIdsGet
may cause confusion regarding whether value
contains tag IDs or tag names. Ensure that value
consistently contains tag IDs.
Run the following script to check where selectedTagIdsGet
is called and what type of data value
holds:
Consider renaming the function or adding JSDoc comments to clarify its usage.
web/src/components/molecules/Schema/FieldModal/FieldDefaultInputs/TagField/index.tsx (1)
46-49
: Ensure consistent overflow styling for tag display
The added overflow styles improve tag display, but make sure that it doesn't negatively affect other components or create horizontal scroll issues.
Test the component with a large number of tags to ensure the UI remains user-friendly.
web/src/components/molecules/Content/Form/fields/FieldComponents/TagField.tsx (1)
62-65
: Review the impact of overflow styles on accessibility
While the overflow settings improve the layout, ensure that they don't hinder keyboard navigation or screen reader accessibility.
Test the component using keyboard navigation and screen readers.
web/src/components/molecules/Schema/types.ts (1)
112-112
:
Update documentation and usage for defaultValue
type change
The defaultValue
in FieldTypePropertyInput
now accepts string | string[]
. Ensure that all usages and documentation reflect this change to prevent type errors.
Apply this diff to update the type definition:
typeProperty: FieldTypePropertyInput;
};
export type FieldTypePropertyInput = {
text?: { defaultValue?: string; maxLength?: number };
textArea?: { defaultValue?: string; maxLength?: number };
markdownText?: { defaultValue?: string; maxLength?: number };
asset?: { defaultValue?: string };
date?: { defaultValue: string };
bool?: { defaultValue?: boolean };
select?: { defaultValue: string; values: string[] };
tag?: {
- defaultValue?: string;
+ defaultValue?: string | string[];
tags: Tag[];
};
Check all components that use defaultValue
for tag
fields to ensure they handle both string
and string[]
types.
web/src/components/molecules/Content/Form/index.tsx (1)
337-347
: LGTM! Improved tag handling with proper type checking.
The refactored inputValueGet
function now properly handles tag fields by:
- Using the new
selectedTagIdsGet
utility for tag type fields - Maintaining proper type safety with explicit checks
- Handling both multiple and single selection cases
Overview
This PR fixes to sort the order of tags when saving an item and styling of the tag field.
Memo
I'm going to refactor
web/src/components/molecules/Schema/FieldModal/hooks.ts
in the future.Summary by CodeRabbit
Release Notes
New Features
TagWrapper
, for improved tag display in selection modes.Bug Fixes
Documentation
Refactor