Skip to content

Commit

Permalink
Added check for real changes
Browse files Browse the repository at this point in the history
  • Loading branch information
rmathis committed Jun 11, 2021
1 parent f9137b6 commit 84ef2c9
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 21 deletions.
5 changes: 3 additions & 2 deletions backend/src/main/resources/i18n/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -551,8 +551,9 @@ tooltip.want-assertions-signed=Want Assertions Signed
tooltip.certificate-name=Certificate Name
tooltip.certificate-type=Certificate Type
tooltip.certificate=Certificate
tooltip.logout-endpoints-url=Logout Endpoints Url
tooltip.logout-endpoints-binding-type=Logout Endpoints Binding Type
tooltip.logout-endpoints=Logout Endpoints
tooltip.url=Logout Endpoints Url
tooltip.binding-type=Logout Endpoints Binding Type
tooltip.mdui-display-name=Typically, the IdP Display Name field will be presented on IdP discovery service interfaces.
tooltip.mdui-information-url=The IdP Information URL is a link to a comprehensive information page about the IdP. This page should expand on the content of the IdP Description field.
tooltip.mdui-description=The IdP Description is a brief description of the IdP service. On a well-designed discovery interface, the IdP Description will be presented to the user in addition to the IdP Display Name, and so the IdP Description helps disambiguate duplicate or similar IdP Display Names.
Expand Down
6 changes: 2 additions & 4 deletions backend/src/main/resources/metadata-sources-ui-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
"serviceEnabled": {
"title": "label.enable-this-service",
"description": "tooltip.enable-this-service-upon-saving",
"type": "boolean",
"default": false
"type": "boolean"
},
"organization": {
"$ref": "#/definitions/Organization"
Expand Down Expand Up @@ -72,8 +71,7 @@
},
"properties": {
"x509CertificateAvailable": {
"type": "boolean",
"default": true
"type": "boolean"
},
"authenticationRequestsSigned": {
"title": "label.authentication-requests-signed",
Expand Down
9 changes: 9 additions & 0 deletions ui/src/app/metadata/domain/source/SourceDefinition.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ export const SourceBase = {
}
}
}

if (formData?.securityInfo?.x509Certificates) {
if (formData.securityInfo.x509Certificates?.length > 0) {
d.securityInfo.x509CertificateAvailable = true;
} else {
d.securityInfo.x509CertificateAvailable = false;
}
}

return d;
},

Expand Down
11 changes: 10 additions & 1 deletion ui/src/app/metadata/editor/MetadataEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ import API_BASE_PATH from '../../App.constant';
import { MetadataObjectContext } from '../hoc/MetadataSelector';
import { FilterableProviders } from '../domain/provider';

import { detailedDiff } from 'deep-object-diff';
import { removeNull } from '../../core/utility/remove_null';

export function MetadataEditor ({ current }) {

const translator = useTranslator();
Expand All @@ -35,10 +38,16 @@ export function MetadataEditor ({ current }) {
const { state, dispatch } = React.useContext(MetadataFormContext);
const { metadata, errors } = state;

const checkChanges = (original, updates) => {
const diff = detailedDiff(original, removeNull(updates, true));
const hasChanges = Object.keys(diff).some(d => Object.keys(diff[d]).length > 0);
return hasChanges;
};

const onChange = (changes) => {
dispatch(setFormDataAction(changes.formData));
dispatch(setFormErrorAction(changes.errors));
setBlocking(true);
setBlocking(checkChanges(metadata, changes.formData));
};

function save(metadata) {
Expand Down
4 changes: 1 addition & 3 deletions ui/src/app/metadata/editor/MetadataEditorForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ export function MetadataEditorForm({ metadata, definition, schema, current, onCh
onChange(definition.bindings ? { ...form, formData: definition.bindings(data, form.formData) }: form);
};

console.log(uiSchema);

return (
<>
{step.locked && <div className="">
Expand Down Expand Up @@ -72,8 +70,8 @@ export function MetadataEditorForm({ metadata, definition, schema, current, onCh
validate={validator}>
<></>
</Form>

</div>

</>
);
}
3 changes: 2 additions & 1 deletion ui/src/app/metadata/editor/MetadataFilterEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { MetadataEditorForm } from './MetadataEditorForm';
import { MetadataEditorNav } from './MetadataEditorNav';
import { useMetadataFilters } from '../hooks/api';
import { MetadataFilterContext } from '../hoc/MetadataFilterSelector';
import { checkChanges } from '../hooks/utility';

export function MetadataFilterEditor({children, onNavigate, block}) {

Expand All @@ -28,7 +29,7 @@ export function MetadataFilterEditor({children, onNavigate, block}) {
const onChange = (changes) => {
dispatch(setFormDataAction(changes.formData));
dispatch(setFormErrorAction(changes.errors));
block();
block(checkChanges(metadata, changes.formData));
};

const validator = definition.validator(data, current);
Expand Down
9 changes: 9 additions & 0 deletions ui/src/app/metadata/hooks/utility.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
import { detailedDiff } from "deep-object-diff";
import { removeNull } from "../../core/utility/remove_null";

export const checkChanges = (original, updates) => {
const diff = detailedDiff(original, removeNull(updates, true));
const hasChanges = Object.keys(diff).some(d => Object.keys(diff[d]).length > 0);
return hasChanges;
}

export function getDefinition(path, definitions) {
let def = path.split('/').pop();
return definitions[def];
Expand Down
2 changes: 1 addition & 1 deletion ui/src/app/metadata/new/NewFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export function NewFilter() {
{(type, base) =>
<MetadataSchema type={type}>
<MetadataForm initial={base}>
<MetadataFilterEditor onNavigate={onNavigate} block={() => setBlocking(true)}>
<MetadataFilterEditor onNavigate={onNavigate} block={(b) => setBlocking(b)}>
{(filter, isInvalid) =>
<div className="d-flex justify-content-end">
<Button variant="info" className="mr-2"
Expand Down
2 changes: 1 addition & 1 deletion ui/src/app/metadata/view/EditFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export function EditFilter() {
</div>
</div>
<hr />
<MetadataFilterEditor onNavigate={onNavigate } block={ () => setBlocking(true) }>
<MetadataFilterEditor onNavigate={onNavigate } block={ (b) => setBlocking(b) }>
{(filter, isInvalid) =>
<div className="d-flex justify-content-end">
<Button variant="info" className="mr-2"
Expand Down
4 changes: 2 additions & 2 deletions ui/src/app/metadata/wizard/MetadataProviderWizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { WizardNav } from './WizardNav';
import { MetadataWizardForm } from './MetadataWizardForm';
import { setWizardIndexAction, useCurrentIndex, useIsLastPage, useWizardDispatcher } from './Wizard';
import { useMetadataDefinitionContext, useMetadataSchemaContext } from '../hoc/MetadataSchema';
import { useMetadataSchema } from '../hooks/schema';
import { checkChanges, useMetadataSchema } from '../hooks/schema';
import { useMetadataFormDispatcher, setFormDataAction, setFormErrorAction, useMetadataFormData, useMetadataFormErrors } from '../hoc/MetadataFormContext';
import { MetadataConfiguration } from '../component/MetadataConfiguration';
import { Configuration } from '../hoc/Configuration';
Expand Down Expand Up @@ -40,7 +40,7 @@ export function MetadataProviderWizard({onRestart}) {
const onChange = (changes) => {
formDispatch(setFormDataAction(changes.formData));
formDispatch(setFormErrorAction(changes.errors));
setBlocking(true);
setBlocking(checkChanges(metadata, changes.formData));
};

const onEditFromSummary = (idx) => {
Expand Down
16 changes: 10 additions & 6 deletions ui/src/app/metadata/wizard/MetadataSourceWizard.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import React from 'react';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faExclamationTriangle } from '@fortawesome/free-solid-svg-icons';
import Alert from 'react-bootstrap/Alert';
import Row from 'react-bootstrap/Row';
import Col from 'react-bootstrap/Col';

import { WizardNav } from './WizardNav';
import { MetadataWizardForm } from './MetadataWizardForm';
import { setWizardIndexAction, useCurrentIndex, useIsFirstPage, useIsLastPage, useWizardDispatcher } from './Wizard';
Expand All @@ -9,12 +15,10 @@ import { Configuration } from '../hoc/Configuration';
import { useMetadataEntity, useMetadataSources } from '../hooks/api';
import { Prompt, useHistory } from 'react-router';
import { removeNull } from '../../core/utility/remove_null';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faExclamationTriangle } from '@fortawesome/free-solid-svg-icons';

import Translate from '../../i18n/components/translate';
import Alert from 'react-bootstrap/Alert';
import Row from 'react-bootstrap/Row';
import Col from 'react-bootstrap/Col';
import { checkChanges } from '../hooks/utility';


export function MetadataSourceWizard ({ onShowNav }) {

Expand Down Expand Up @@ -46,7 +50,7 @@ export function MetadataSourceWizard ({ onShowNav }) {
const onChange = (changes) => {
formDispatch(setFormDataAction(changes.formData));
formDispatch(setFormErrorAction(changes.errors));
setBlocking(true);
setBlocking(checkChanges(metadata, changes.formData));
};

const onEditFromSummary = (idx) => {
Expand Down

0 comments on commit 84ef2c9

Please sign in to comment.