Skip to content

Commit

Permalink
Adjust filter criteria popup error text
Browse files Browse the repository at this point in the history
Signed-off-by: Tomás Castillo <[email protected]>
  • Loading branch information
tomrndom committed Jul 19, 2024
1 parent 1405202 commit 1d59ddf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
32 changes: 20 additions & 12 deletions src/actions/filter-criteria-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
* */

import T from "i18n-react/dist/i18n-react";

Check warning on line 14 in src/actions/filter-criteria-actions.js

View workflow job for this annotation

GitHub Actions / build

'T' is defined but never used

Check warning on line 14 in src/actions/filter-criteria-actions.js

View workflow job for this annotation

GitHub Actions / build

'T' is defined but never used
import {
VALIDATE,
getRequest,

Check warning on line 17 in src/actions/filter-criteria-actions.js

View workflow job for this annotation

GitHub Actions / build

'getRequest' is defined but never used

Check warning on line 17 in src/actions/filter-criteria-actions.js

View workflow job for this annotation

GitHub Actions / build

'getRequest' is defined but never used
putRequest,

Check warning on line 18 in src/actions/filter-criteria-actions.js

View workflow job for this annotation

GitHub Actions / build

'putRequest' is defined but never used

Check warning on line 18 in src/actions/filter-criteria-actions.js

View workflow job for this annotation

GitHub Actions / build

'putRequest' is defined but never used
postRequest,
Expand All @@ -25,9 +26,16 @@ import {
fetchResponseHandler,
fetchErrorHandler
} from "openstack-uicore-foundation/lib/utils/actions";
import { getAccessTokenSafely } from "../utils/methods";
import URI from "urijs";
import Swal from "sweetalert2";
import _ from "lodash";

import { getAccessTokenSafely } from "../utils/methods";
import {
DEBOUNCE_WAIT,
DEFAULT_PER_PAGE,
ERROR_CODE_412
} from "../utils/constants";

export const FILTER_CRITERIA_ADDED = "FILTER_CRITERIA_ADDED";
export const FILTER_CRITERIA_DELETED = "FILTER_CRITERIA_DELETED";
Expand Down Expand Up @@ -78,13 +86,13 @@ export const queryFilterCriterias = _.debounce(
async (summitId, context, input, callback) => {
const accessToken = await getAccessTokenSafely();

let apiUrl = URI(
const apiUrl = URI(
`${window.PERSIST_FILTER_CRITERIA_API}/api/v1/filter-criterias`
);
apiUrl.addQuery("access_token", accessToken);
apiUrl.addQuery("order", "+name");
apiUrl.addQuery("order", "+id");
apiUrl.addQuery("per_page", 10);
apiUrl.addQuery("per_page", DEFAULT_PER_PAGE);
apiUrl.addQuery("show_id", `${summitId}`);
apiUrl.addQuery("context", `${context}`);

Expand All @@ -99,7 +107,7 @@ export const queryFilterCriterias = _.debounce(
})
.catch(fetchErrorHandler);
},
500
DEBOUNCE_WAIT
);

export const customErrorHandler = (err, res) => (dispatch, state) => {

Check warning on line 113 in src/actions/filter-criteria-actions.js

View workflow job for this annotation

GitHub Actions / build

'state' is defined but never used

Check warning on line 113 in src/actions/filter-criteria-actions.js

View workflow job for this annotation

GitHub Actions / build

'state' is defined but never used
Expand All @@ -109,19 +117,19 @@ export const customErrorHandler = (err, res) => (dispatch, state) => {
dispatch(stopLoading());

switch (code) {
case 412:
case ERROR_CODE_412:
if (Array.isArray(err.response.body)) {
err.response.body.forEach((er) => {
msg += er + "<br>";
msg += `${er}<br>`;
});
} else {
for (var [key, value] of Object.entries(err.response.body)) {
if (isNaN(key)) {
msg += key + ": ";
Object.keys(err.response.body).forEach((key) => {
if (Number.isNaN(key)) {
msg += `${key}: "`;
}

msg += value + "<br>";
}
msg += `${err.response.body[key]}<br>`;
});
}

Swal.fire("Validation error", msg, "warning");
Expand Down
4 changes: 4 additions & 0 deletions src/utils/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,7 @@ export const DEFAULT_CURRENT_PAGE = 1;
export const DEFAULT_PER_PAGE = 10;

export const DEFAULT_ORDER_DIR = 1;

export const ERROR_CODE_412 = 412;

export const DEBOUNCE_WAIT = 500;

0 comments on commit 1d59ddf

Please sign in to comment.