Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(createScanDialog): issues/1 scan creation options
 #25

Merged
merged 3 commits into from
Mar 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@
"patternfly": "3.55.0",
"patternfly-react": "^2.24.3",
"prop-types": "^15.6.2",
"react": "^16.5.1",
"react": "^16.8.4",
"react-bootstrap": "^0.32.4",
"react-dom": "^16.5.1",
"react-dom": "^16.8.4",
"react-infinite-scroller": "^1.2.1",
"react-redux": "^5.0.7",
"react-router": "^4.3.1",
Expand Down
6 changes: 3 additions & 3 deletions src/common/__tests__/__snapshots__/helpers.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ exports[`Helpers should handle http status 400 level error messages from respons

exports[`Helpers should handle http status 400 level error messages from response: 400 fallback again error message 1`] = `"Request failed with status code XXX"`;

exports[`Helpers should handle http status 400 level error messages from response: 400 fallback error message 1`] = `""`;
exports[`Helpers should handle http status 400 level error messages from response: 400 fallback error message 1`] = `"{\\"ipsum\\":{\\"sed\\":\\"nulla sed consequat urna\\",\\"dolor\\":{\\"sit\\":\\"sit dolor\\\\nconsequat urna\\",\\"placerat\\":\\"\\"}}}"`;

exports[`Helpers should handle http status 400 level error messages from response: 400 fallback yet again error message 1`] = `"XXX Request failed"`;

exports[`Helpers should handle http status 400 level error messages from response: 400 filtered blank message 1`] = `""`;

exports[`Helpers should handle http status 400 level error messages from response: 400 filtered message 1`] = `"Lorem ipsum dolor sit"`;

exports[`Helpers should handle http status 400 level error messages from response: 400 filtered object message 1`] = `"{\\"sit\\":[\\"sit dolor\\",\\"consequat urna\\"],\\"placerat\\":[{\\"ante\\":\\"sed placerat ante\\"}]"`;

exports[`Helpers should handle http status 500 level error messages from response: 500 level error message 1`] = `"500 Lorem ipsum dolor sit"`;

exports[`Helpers should handle http status 500 level error messages from response: 500 level fallback again error message 1`] = `"500 Request failed with status code XXX"`;
Expand Down
11 changes: 9 additions & 2 deletions src/common/__tests__/helpers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,14 @@ describe('Helpers', () => {
const payload = {
response: {
data: {
lorem: ['Lorem ipsum dolor sit']
lorem: ['Lorem ipsum dolor sit'],
ipsum: {
sed: 'nulla sed consequat urna',
dolor: {
sit: ['sit dolor', 'consequat urna'],
placerat: [{ ante: 'sed placerat ante' }]
}
}
},
status: 400,
statusText: 'Bad Request',
Expand All @@ -143,7 +150,7 @@ describe('Helpers', () => {

expect(helpers.getMessageFromResults(payload, 'lorem').message).toMatchSnapshot('400 filtered message');

expect(helpers.getMessageFromResults(payload, 'dolor').message).toMatchSnapshot('400 filtered blank message');
expect(helpers.getMessageFromResults(payload, 'dolor').message).toMatchSnapshot('400 filtered object message');

delete payload.response.data.lorem;
expect(helpers.getMessageFromResults(payload).message).toMatchSnapshot('400 fallback error message');
Expand Down
49 changes: 38 additions & 11 deletions src/common/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,35 +199,62 @@ const getMessageFromResults = (results, filter = null) => {
return messages;
}

const getMessages = (messageObjectArrayString, filterField) => {
const getMessages = messageObjectArrayString => {
const parsed = {};
const parsedFiltered = {};
const filterFields = (Array.isArray(filterField) && filterField) || (filterField && [filterField]) || [];

if (messageObjectArrayString && typeof messageObjectArrayString === 'string') {
return messageObjectArrayString.replace(/\[object\sObject\]/g, '');
return messageObjectArrayString.replace(/\[object\sObject]/g, '');
}

if (Array.isArray(messageObjectArrayString)) {
return getMessages(messageObjectArrayString.join('\n'));
}

Object.keys(messageObjectArrayString).forEach(key => {
const message = getMessages(messageObjectArrayString[key]);
parsed[key] = getMessages(messageObjectArrayString[key]);
});

if (filterFields.length && filterFields.includes(key)) {
parsedFiltered[key] = message;
}
return parsed;
};

const filtered = (messageObjectArrayString, filterField) => {
const parsed = {};
const str = JSON.stringify(messageObjectArrayString);
const filterFields = (Array.isArray(filterField) && filterField) || (filterField && [filterField]) || [];

filterFields.forEach(val => {
const match = str.match(new RegExp(`"${val}":(\\[(.*?)]]?|{(.*?)}]?|"(.*?)"),?`));

parsed[key] = message;
if (match && match[1]) {
parsed[val] = match[1]; // eslint-disable-line

if (match && match[2]) {
parsed[val] = JSON.parse(match[1]);

if (Array.isArray(parsed[val])) {
parsed[val] = parsed[val].join(', ');
} else if (typeof parsed[val] !== 'string') {
parsed[val] = Object.values(parsed[val]).join(', ');
}

parsed[val] = parsed[val].replace(/,?\s?\[object\sObject]/, '');
}
}
});

return filterFields.length ? parsedFiltered : parsed;
return parsed;
};

messages.messages = getMessages(messageResponse || detailResponse, filter);
messages.messages =
(filter && filtered(messageResponse || detailResponse, filter)) || getMessages(messageResponse || detailResponse);
messages.message = `${displayStatus}${Object.values(messages.messages).join('\n')}`;

if (messages.message === '[object Object]') {
messages.message = JSON.stringify(messages.messages);
} else {
messages.message = messages.message.replace(/\n?\[object\sObject]/g, '');
}

return messages;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ exports[`AddSourceWizard Component should display update steps: connected update
title="Edit Source"
/>
<WizardBody
aria-live="polite"
className=""
>
<WizardSteps
Expand Down Expand Up @@ -130,6 +131,7 @@ exports[`AddSourceWizard Component should render a connected component: connecte
title="Add Source"
/>
<WizardBody
aria-live="polite"
className=""
>
<WizardSteps
Expand Down
2 changes: 1 addition & 1 deletion src/components/addSourceWizard/addSourceWizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class AddSourceWizard extends React.Component {
return (
<Wizard show={show}>
<Wizard.Header onClose={this.onCancel} title={edit ? 'Edit Source' : 'Add Source'} />
<Wizard.Body>
<Wizard.Body aria-live="polite">
<Wizard.Steps steps={this.renderWizardSteps()} />
<Wizard.Row>
<Wizard.Main>
Expand Down
2 changes: 2 additions & 0 deletions src/components/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import helpers from '../common/helpers';
import AboutModal from './aboutModal/aboutModal';
import AddSourceWizard from './addSourceWizard/addSourceWizard';
import CreateCredentialDialog from './createCredentialDialog/createCredentialDialog';
import CreateScanDialog from './createScanDialog/createScanDialog';
import Content from './content/content';
import ToastNotificationsList from './toastNotificationsList/toastNotificationsList';
import ConfirmationModal from './confirmationModal/confirmationModal';
Expand Down Expand Up @@ -127,6 +128,7 @@ class App extends React.Component {
<AboutModal />
<AddSourceWizard />
<CreateCredentialDialog />
<CreateScanDialog />
</div>
</div>
);
Expand Down
Loading