Removes pathological queries; Creates linting rule to prevent raw useFirestoreConnect import#801
Conversation
|
@thecadams Created this branch/draft PR to get visibility back on the board for this issue + link up it's context, but absolutely happy for you to run with it and make the fixes/etc from your original PR. |
|
@0xdevalias picking this up now |
…s-doc-or-collection-queries
|
After conducting extensive research, I couldn't find a way to distinguish I have found a way to solve this issue by replacing all |
This comment has been minimized.
This comment has been minimized.
I think I conveyed my thoughts in an unclear way. I'm didn't mean that we don't need linting. I meant that replacing |
|
@0xdevalias I think the problem we have been experiencing recently is a lot of unrelated changes happening in one PR. To avoid that, I would rather implement https://github.com/sparkletown/internal-sparkle-issues/issues/2 issues in another PR |
228abeb to
97e96ce
Compare
I think using
Can you please expand on this, and your reasoning for it? In what cases are you seeing 'explicit The original PR that introduced this was #784 (which was reverted in #797 as it broke things in production, and then this current PR was bringing it back + fixes) Unfortunately #784 (like many of our PR's, which is something we need to change) doesn't have a useful description to outline the intended changes within it, so we have to rely on memory/inferring from the code. Pulling from the review comments on that PR:
The relevant type-related code is at https://github.com/sparkletown/sparkle/pull/784/files#diff-254a400761084e5ebd89145b80d201db7f0fd1e2dff8684213ee5d1804ee886aR11-R45 export interface SparkleRFQuery extends ReduxFirestoreQuerySetting {
doc?: never;
where: WhereOptions | WhereOptions[];
storeAs?: ValidFirestoreKeys;
}
export interface SparkleRFDocQuery extends ReduxFirestoreQuerySetting {
doc: string;
where?: never;
storeAs?: ValidFirestoreKeys;
}Inferring from this code (without actually reading deeply/playing with it), I believe the intent is that:
You can also see that |
Even though I support this intent, it didn't seem to work right. The current implementation of this( |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
RE: #801 (comment)
That makes sense. I agree that they are lower priority. 👍🏻 RE: #801 (comment)
I'm happy for that to be how we approach it. 👍🏻 |
0xdevalias
left a comment
There was a problem hiding this comment.
Includes requested changes (I can't use the official 'request changes' review mode as I opened the original PR)
| const chatQuery = useMemo(() => { | ||
| if (!hasElements(chatUserIds)) return undefined; | ||
| const chatQuery = useMemo<SparkleRFQConfig>(() => { | ||
| if (!hasElements(chatUserIds)) return; |
There was a problem hiding this comment.
I believe this will have the same code effect (that undefined) will be returned, yet this change makes that less explicitly obvious. What was the intent behind this change?
| const { venueId } = useParams(); | ||
| const venueId = useVenueId(); | ||
| const { user } = useUser(); | ||
| const [currentTimestamp] = useState(Date.now() / 1000); |
There was a problem hiding this comment.
[OOS] This is going to set currentTimestamp the first time this hook is called, and then never updated it again I believe, which seems (from it's usage) like it probably isn't the desired intent.
I think in other places where we have wanted this sort of 'only change every x timeframe' pattern we have used an interval or similar to update the useState. That might be a useful solution here as well.
| const siblingVenuesQuery: SparkleRFQConfig | undefined = !!parentId | ||
| const siblingVenuesQuery: SparkleRFQConfig = !!parentId |
There was a problem hiding this comment.
Why was undefined removed here?
| const subvenuesQuery: SparkleRFQConfig | undefined = !!venueId | ||
| const subvenuesQuery: SparkleRFQConfig = !!venueId |
There was a problem hiding this comment.
Why was undefined removed here?
|
|
||
| // Parent Events | ||
| const parentVenueEventsQuery: SparkleRFQConfig | undefined = | ||
| const parentVenueEventsQuery = |
There was a problem hiding this comment.
Why was undefined removed here?
There was a problem hiding this comment.
@mike-lvov can you add the explicit typing back here please
| import { | ||
| SparkleRFQConfig, | ||
| useFirestoreConnect, | ||
| } from "hooks/useFirestoreConnect"; | ||
| import { useVenueId } from "hooks/useVenueId"; |
There was a problem hiding this comment.
Sort with other hooks/ imports
| import { useSelector } from "hooks/useSelector"; | ||
| import VenueEventDetails from "./VenueEventDetails"; | ||
| import { useFirestoreConnect } from "react-redux-firebase"; | ||
| import { useFirestoreConnect } from "hooks/useFirestoreConnect"; |
There was a problem hiding this comment.
Sort with other hooks/ imports
| if (!venueId) return history.replace("/admin"); | ||
|
|
There was a problem hiding this comment.
Why are we redirecting within this function? I assume the intent of this addition was to ensure venueId isn't undefined/similar by the time it gets passed to .doc(). Why wouldn't we just return early like we do with all of our other guard patterns like this?
| if (!venueId) return history.replace("/admin"); | |
| if (!venueId) return |
There was a problem hiding this comment.
I see that later on this same history.replace code is used, so that makes sense.
Though it seems we could move this guard outside of the async fetchVenueFromAPI function and just have it in the root of the useEffect?
There was a problem hiding this comment.
I think so, but it still would be the same
There was a problem hiding this comment.
Thats fine. I think it just more confused me being inside the inner function, rather than the root of the useEffect
| const allValidQueries: SparkleRFQConfig[] = [ | ||
| const allValidQueries: SparkleRFQConfig = [ |
There was a problem hiding this comment.
This feels more confusing than how it used to be.. probably would have named your 'fusion' type as AnySparkleRFQConfig or something specific about the props the function accepts.
Alternatively, given the change has already been done, this would probably be more correct/easy to understand as SparkleRFQConfigObject[]. 'Hiding' the array'ness of it makes it confusing, and I need to go any look up the original 'fusion type' to understand whats going on.
|
|
||
| import { ValidFirestoreKeys } from "types/Firestore"; | ||
|
|
||
| /** |
There was a problem hiding this comment.
Defined<T> is already defined in src/types/utility.ts so doesn't need to exist here
|
RE: #801 (comment)
@mike-lvov See sub-PR #1076 for an implementation that fixes this properly, without needing to result to |
…ery patterns + update related usages (#1076)
0xdevalias
left a comment
There was a problem hiding this comment.
Skimming over the changed files I only had 1 small request, then i'm happy for this PR to be merged.
Since I was the one who originally opened it, I can't actually approve it. But once you make the change mentioned here, feel free to approve and merge it.
(When squash-merging, make sure to keep the 'co-authored by' text it adds)
|
|
||
| // Parent Events | ||
| const parentVenueEventsQuery: SparkleRFQConfig | undefined = | ||
| const parentVenueEventsQuery = |
There was a problem hiding this comment.
@mike-lvov can you add the explicit typing back here please
| // @debt I think we could just use useParams() here instead of needing to loop through all of the venuePath, so long as the use :venueId in their path | ||
| // https://reactrouter.com/web/api/Hooks/useparams | ||
| // useParams returns an object of key/value pairs of URL parameters. Use it to access match.params of the current <Route>. |
There was a problem hiding this comment.
|
Code Climate has analyzed commit ab6d832 and detected 6 issues on this pull request. Here's the issue category breakdown:
View more on Code Climate. |
Background Context: The original PR (#784) was deployed in #795, which broke things in production, and was reverted in #797
Thoughts: @denisdimitrov originally had #780 up to solve the core of our
priority-prod-fixconcerns for an upcoming event. If that solves the immediate need, then maybe we should resurrect that and get it out sooner, which will triage that need, and then we can work on these fixes over a less risky timeframe.This PR will fix the issues that were breaking the admin page/anything else it broke in production.