Move away from logical && operator returns in job getters
In our Vuex store for our jobs UI we are using the logical && operator a few times to return a non-boolean value. This can cause some confusion if you are looking at the code and don't know if the type is a non-boolean value. We aren't very explicit in the value being returned here.
An example can be found here https://gitlab.com/gitlab-org/gitlab/-/blob/master/app/assets/javascripts/jobs/store/getters.js#L34
export const emptyStateAction = (state) =>
(state.job && state.job.status && state.job.status.action) || null;
In this situation we determine: Is there a job? Does the job have a status? If so let's return state.job.status.action
(Object). If not let's return null
We can simplify the few times we do this in our getters
file by using the optional chain operator ?.
Note: We also may be able to get rid of the null
return if we aren't using it downstream in some capacity. The optional chain operator will return undefined
if the action is not present, that may be enough.