-
Notifications
You must be signed in to change notification settings - Fork 560
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
Color Customization V1 #2824
Color Customization V1 #2824
Conversation
a7fab9d
to
048f882
Compare
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## develop #2824 +/- ##
===========================================
- Coverage 62.00% 62.00% -0.01%
===========================================
Files 260 264 +4
Lines 44185 44867 +682
Branches 354 356 +2
===========================================
+ Hits 27399 27821 +422
- Misses 16786 17046 +260
Flags with carried forward coverage won't be shown. Click here to find out more.
☔ View full report in Codecov by Sentry. |
d5aee66
to
f98d0e8
Compare
32dec3c
to
677f5a1
Compare
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.
nice work Lanny! leaving some thoughts - still reviewing / testing
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.
Looks really good! Still playing with functionality. We can sync up today to talk backend details
885adfd
to
d9ce018
Compare
f6fdb45
to
973876b
Compare
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.
nice work @lanzhenw ! 🍨
The code is looking good! nice work separating the logic between different options in color settings 💯
it looks reasonably safe and isolated. Let's merge this if
- basic app features are working as expected - for example, you can open sample modal, tag, navigate between them, filtering, visualization, etc.
for followup: One trend I noticed was filtering or mapping over collections and not caching them. This can cause performance issues if heavy calculations run for every field every re-render. We can avoid some these maybe by adding useMemos, useCallbacks, etc. to avoid re-defining these values/functions on re-renders
@@ -51,6 +58,11 @@ const ColorFooter: React.FC<Prop> = ({ eligibleFields }) => { | |||
onCancel(); | |||
}; | |||
|
|||
const onClearSave = () => { |
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.
nit: useCallback cache the result on re-render
import useSendEvent from "./useSendEvent"; | ||
import { DEFAULT_APP_COLOR_SCHEME } from "../utils"; | ||
|
||
const useClearSessionColorScheme = () => { |
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.
nit: could combine this class with useClearSavedColorScheme - There are similarities
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.
Implemented.
const videoFields = useRecoilValue( | ||
fos.fields({ | ||
space: fos.State.SPACE.FRAME, | ||
ftype: EMBEDDED_DOCUMENT_FIELD, | ||
}) | ||
)?.filter((f) => | ||
VALID_LABEL_TYPES.includes( | ||
f?.embeddedDocType?.split(".")?.slice(-1)[0] ?? "" | ||
) | ||
); | ||
const sampleFields = useRecoilValue( | ||
fos.fields({ | ||
space: fos.State.SPACE.SAMPLE, | ||
ftype: EMBEDDED_DOCUMENT_FIELD, | ||
}) | ||
)?.filter((f) => | ||
VALID_LABEL_TYPES.includes( | ||
f?.embeddedDocType?.split(".")?.slice(-1)[0] ?? "" | ||
) | ||
); | ||
const customizeColorFields = [...videoFields, ...sampleFields]; |
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.
nit: for performance, we could cache these results by using useMemo or similar way
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.
I made a eligibleFieldsToCustomizeColor
recoil selector.
const defaultColor = | ||
coloring.pool[Math.floor(Math.random() * coloring.pool.length)]; | ||
const expandedPath = useRecoilValue(fos.expandPath(path!)); | ||
const VALID_COLOR_ATTRIBUTE_TYPES = [BOOLEAN_FIELD, INT_FIELD, STRING_FIELD]; |
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.
nit: move this to a constant outside
@@ -273,6 +293,13 @@ function FieldInfoExpanded({ | |||
onClick={(e) => e.stopPropagation()} | |||
> | |||
<FieldInfoExpandedContainer color={color}> | |||
{field.embeddedDocType && !isModal && canEdit && ( |
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.
this is basically one of the few places we are adding our feature 👍
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.
yes, this is the place in the sidebar. I am moving canEdit
flag to the saving part.
@@ -426,3 +423,58 @@ const getFieldAndValue = ( | |||
|
|||
return [field, value, list]; | |||
}; | |||
|
|||
const compareObjectArrays = (arr1, arr2) => { |
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.
nit: can you use loadash for these?
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.
the lodash isEqual
function is strict with the order of the array. These two helper functions only check if elements are the same, regardless of order.
}; | ||
|
||
// Helper function to sort arrays of objects based on their key-value pairs | ||
function sortObjectArrays(a, b) { |
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.
nit: same here
const fieldColor = customizeColorSetting.find( | ||
(s) => s.field === this.field | ||
)?.fieldColor; |
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.
nit: I am unfamiliar with this code. hopefully the computation here is small enough not to impact rendering performance
view._dataset.save() | ||
state.view = view | ||
|
||
await dispatch_event(subscription, StateUpdate(state=state)) |
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.
you might have to dispatch if save_to_app if you are following save view approach
166160f
to
d6f139e
Compare
Added color scheme set up feature:
session.color_scheme
dataset.app_config
In loading, session color scheme >> dataset.app_config >> default app setting
Setting colors in the UI:
https://user-images.githubusercontent.com/17770824/234972360-44ea9c70-6a5e-4552-b7f3-5f231329c8f5.mp4
Setting the colors in the SDK:
https://user-images.githubusercontent.com/17770824/234973226-6a65fbc2-46db-428d-91f6-995b543c0069.mp4
Save to dataset:
https://user-images.githubusercontent.com/17770824/234973275-374a1c14-4977-4dbf-8814-f098f6121cca.mp4
How to test it?
What changes are proposed in this pull request?
How is this patch tested? If it is not, please explain why.
(Details)
Release Notes
Is this a user-facing change that should be mentioned in the release notes?
notes for FiftyOne users.
(Details in 1-2 sentences. You can just refer to another PR with a description
if this PR is part of a larger change.)
What areas of FiftyOne does this PR affect?
fiftyone
Python library changes