Skip to content
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

[UI v2] Adds Create or edit dialog for concurrency limit #16248

Merged
merged 1 commit into from
Dec 6, 2024

Conversation

devinvillarosa
Copy link
Contributor

@devinvillarosa devinvillarosa commented Dec 6, 2024

image

  1. Adds Switch component using cli
  2. Adds Creating or Editing a global concurrent limit using hook logic. (Only manually tested creation)
  3. Adds UI for creating a new global concurrent limit

Will add tests when testing for the entire page functionality. Similar to variables.test.tsx. I think our hook tests in hooks/global-concurrent-limits.test.tsx is suffice for now for confidence

Checklist

  • This pull request references any related issue by including "closes <link to issue>"
    • If no issue exists and your change is not a small fix, please create an issue first.
  • If this pull request adds new functionality, it includes unit tests that cover the changes
  • If this pull request removes docs files, it includes redirect settings in mint.json.
  • If this pull request adds functions or classes, it includes helpful docstrings.

Related to #15512

@devinvillarosa devinvillarosa force-pushed the create-or-edit-limit-dialog branch 2 times, most recently from e9d76c9 to 16eeace Compare December 6, 2024 18:14
@devinvillarosa devinvillarosa marked this pull request as ready for review December 6, 2024 18:31
Comment on lines 13 to 17
const [openAddOrEditDialog, setOpenAddOrEditDialog] =
useState<AddOrEditDialogState>({
open: false,
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had some trouble wrapping my head around this on the first couple of reads. This suggestion I think it a little more clear, but I'm open to alternatives.

Suggested change
const [openAddOrEditDialog, setOpenAddOrEditDialog] =
useState<AddOrEditDialogState>({
open: false,
});
const [addOrEditDialogState, addOrEditDialogState] =
useState<AddOrEditDialogState>({
open: false,
limitIdToEdit: undefined
});

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on your comment below here: https://github.com/PrefectHQ/prefect/pull/16248/files#r1873864935, this makes sense.

I was trying to represent the dialog state to:

  1. is it open?
  2. Should it open with a limit to be edited?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in latest push.

Simplified it to it just keeps track of it being open.
I removed the selected row logic and will handle it when doing the table

Comment on lines 20 to 26
const selectedlimitToUpdate = useMemo(() => {
if (!openAddOrEditDialog.limitIdToEdit) {
return undefined;
}
return data.find((limit) => limit.id === openAddOrEditDialog.limitIdToEdit);
}, [data, openAddOrEditDialog.limitIdToEdit]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to revisit this once the table is created. We should be able to have the table put the full data in a callback, which would negate the need to have a .find call.

Copy link
Contributor Author

@devinvillarosa devinvillarosa Dec 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll keep an eye out for it, because this approach is to help eliminate duplicate state - which can lead to UX bugs.

eg problem case for duplicating state:

  1. UI gets list of data from useSuspenseQuery.
  2. UI duplicates selected data into a useState.
  3. useSuspenseQuery refetches, and updates its state of that selected data. (from some async event). The UI is now working with stale data.

When using this memoize approach.

  1. UI gets list of data from useSuspenseQuery.
  2. UI keeps track of the selected data by id via useState.
  3. Selected data is found by .find().
  4. useSuspenseQuery refetches, and updates its state of that selected data. (from some async event).
  5. the selected data that calls .find() is ran because the useMemo dependency has changed from the async event. The UI is now working with the updated data source

Here's a good blog that goes in detail about it: https://blog.webdevsimplified.com/2019-11/never-store-derived-state/

Copy link
Member

@desertaxle desertaxle Dec 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense. I don't think we'll need to worry about stale data from the table because we can directly pass in the data from our query to useTable and retrieve the original data for the row to avoid working with duplicated data.

Plus, since we're using this data in a form, I don't think we want it to change if a new update comes in since that means the form values could change while the user is editing a concurrency limit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh nice, that makes sense

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll update that when I implement the table next

@devinvillarosa devinvillarosa force-pushed the create-or-edit-limit-dialog branch 2 times, most recently from 065a21a to 1033e3d Compare December 6, 2024 19:34
@devinvillarosa devinvillarosa force-pushed the create-or-edit-limit-dialog branch from 1033e3d to ad1cf8e Compare December 6, 2024 21:17
Copy link
Member

@desertaxle desertaxle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@devinvillarosa devinvillarosa merged commit 3b5bbea into main Dec 6, 2024
9 checks passed
@devinvillarosa devinvillarosa deleted the create-or-edit-limit-dialog branch December 6, 2024 22:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants