Skip to content

Commit

Permalink
fix(tagsModal): skeleton flash
Browse files Browse the repository at this point in the history
  • Loading branch information
Hyperkid123 committed Mar 3, 2021
1 parent ceca81f commit f79e696
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
2 changes: 2 additions & 0 deletions packages/inventory/src/redux/entities.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ export function showTags(state, { payload, meta }) {
const { tags, ...activeSystemTag } = state.rows ? state.rows.find(({ id }) => meta.systemId === id) : state.entity || {};
return {
...state,
tagModalLoaded: true,
activeSystemTag: {
...activeSystemTag,
tags: Object.values(payload.results)[0],
Expand All @@ -183,6 +184,7 @@ export function showTagsPending(state, { meta }) {
const { tags, ...activeSystemTag } = state.rows ? state.rows.find(({ id }) => meta.systemId === id) : state.entity || {};
return {
...state,
tagModalLoaded: false,
activeSystemTag: {
...activeSystemTag,
tagsCount: meta.tagsCount,
Expand Down
9 changes: 9 additions & 0 deletions packages/inventory/src/redux/entityDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,21 @@ function toggleDrawer(state, { payload }) {
};
}

function showTagsPending(state) {
return {
...state,
tagModalLoaded: false
};
}

export default {
[ACTION_TYPES.LOAD_ENTITIES_PENDING]: () => defaultState,
[ACTION_TYPES.LOAD_ENTITY_PENDING]: entityDetailPending,
[ACTION_TYPES.LOAD_ENTITY_FULFILLED]: entityDetailLoaded,
[APPLICATION_SELECTED]: onApplicationSelected,
[ACTION_TYPES.LOAD_TAGS]: showTags,
[ACTION_TYPES.LOAD_TAGS_PENDING]: showTagsPending,
[ACTION_TYPES.LOAD_TAGS_FULFILLED]: showTags,
[TOGGLE_TAG_MODAL]: toggleTagModal,
[TOGGLE_DRAWER]: toggleDrawer,
...systemIssuesReducer
Expand Down
7 changes: 1 addition & 6 deletions packages/inventory/src/shared/TagsModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,8 @@ const TagsModal = ({
return entities?.allTagsPagination || statePagination;
}, shallowEqual);

const loaded = useSelector(({ entities, entityDetails }) => {
if (entityDetails?.entity) {
return entityDetails?.loaded;
}
const loaded = useSelector(({ entities, entityDetails }) => entities?.tagModalLoaded || entityDetails?.tagModalLoaded);

return entities?.activeSystemTag?.tagsLoaded || (entities || entityDetails)?.allTagsLoaded;
});
const activeSystemTag = useSelector(({ entities, entityDetails }) => entities?.activeSystemTag || entityDetails?.entity);
const tags = useSelector(({ entities, entityDetails }) => {
const activeTags = entities?.activeSystemTag?.tags || entityDetails?.entity?.tags;
Expand Down
5 changes: 3 additions & 2 deletions packages/inventory/src/shared/TagsModal.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { shallow, mount } from 'enzyme';
import { mount } from 'enzyme';
import configureStore from 'redux-mock-store';
import promiseMiddleware from 'redux-promise-middleware';
import { Provider } from 'react-redux';
Expand All @@ -18,7 +18,8 @@ describe('TagsModal', () => {
mockStore = configureStore([ promiseMiddleware() ]);
initialState = {
entities: {
showTagDialog: true
showTagDialog: true,
tagModalLoaded: true
}
};
});
Expand Down

0 comments on commit f79e696

Please sign in to comment.