Skip to content

Commit

Permalink
wait for upload status before initializing jobExecutions data
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnC-80 committed Sep 20, 2023
1 parent f194a5b commit 4623b56
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/components/DataFetcher/DataFetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,10 @@ export class DataFetcher extends Component {
splitStatus: {
type: 'okapi',
path: requestConfiguration,
shouldRefreshRemote: () => false,
throwErrors: false,
}
},
splitConfiguration: {}
});

static propTypes = {
Expand All @@ -113,21 +115,38 @@ export class DataFetcher extends Component {
PropTypes.shape({ jobExecutions: PropTypes.arrayOf(jobExecutionPropTypes).isRequired }),
).isRequired,
}),
splitStatus: PropTypes.shape({
hasLoaded: PropTypes.bool,
records: PropTypes.arrayOf(
PropTypes.shape({ splitStatus: PropTypes.bool.isRequired }),
).isRequired,
}),
}).isRequired,
updateInterval: PropTypes.number, // milliseconds
};

static defaultProps = { updateInterval: DEFAULT_FETCHER_UPDATE_INTERVAL };

state = {
statusLoaded: false,
contextData: { // eslint-disable-line object-curly-newline
hasLoaded: false,
},
};

componentDidMount() {
this.mounted = true;
this.initialize();
this.initialFetchPending = false;
}

componentDidUpdate(props, state) {
const { resources:{ splitStatus } } = props;
const { statusLoaded } = state;
if (!statusLoaded && splitStatus?.hasLoaded) {
this.setState({ statusLoaded: true }, () => {
if (!this.initialFetchPending) this.initialize();
});
}
}

componentWillUnmount() {
Expand Down Expand Up @@ -164,6 +183,7 @@ export class DataFetcher extends Component {
.reduce((res, resourceMutator) => res.concat(this.fetchResourceData(resourceMutator)), []);

try {
this.initialFetchPending = true;
await Promise.all(fetchResourcesPromises);
this.mapResourcesToState();
} catch (error) {
Expand Down

0 comments on commit 4623b56

Please sign in to comment.