Skip to content

Commit

Permalink
[UX] Fix SchemaAddFieldModal stuttering on first new schema field add
Browse files Browse the repository at this point in the history
- With the new template, transitioning from the empty state to the filled schema state causes the modal to stutter due to the component rerender

- Changing the page to not instantly react/update `hasSchema` when local schema state changes but instead to wait for the server call to finish and for cachedSchema to update fixes the UX problem
  • Loading branch information
cee-chen committed Jun 22, 2021
1 parent 2bed412 commit ae6335e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,13 @@ describe('SchemaLogic', () => {

describe('selectors', () => {
describe('hasSchema', () => {
it('returns true when the schema obj has items', () => {
mountAndSetSchema({ schema: { test: SchemaType.Text } });
it('returns true when the cached server schema obj has items', () => {
mount({ cachedSchema: { test: SchemaType.Text } });
expect(SchemaLogic.values.hasSchema).toEqual(true);
});

it('returns false when the schema obj is empty', () => {
mountAndSetSchema({ schema: {} });
it('returns false when the cached server schema obj is empty', () => {
mount({ schema: {} });
expect(SchemaLogic.values.hasSchema).toEqual(false);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ export const SchemaLogic = kea<MakeLogicType<SchemaValues, SchemaActions>>({
],
},
selectors: {
hasSchema: [(selectors) => [selectors.schema], (schema) => Object.keys(schema).length > 0],
hasSchema: [
(selectors) => [selectors.cachedSchema],
(cachedSchema) => Object.keys(cachedSchema).length > 0,
],
hasSchemaChanged: [
(selectors) => [selectors.schema, selectors.cachedSchema],
(schema, cachedSchema) => !isEqual(schema, cachedSchema),
Expand Down

0 comments on commit ae6335e

Please sign in to comment.