Skip to content

Commit

Permalink
support for editing boolean endpoint address resolver metadata proper…
Browse files Browse the repository at this point in the history
…ties (#1759)

* add support for editing boolean endpoint address resolver metadata properties

* improve metadata hints
  • Loading branch information
moscicky authored Oct 25, 2023
1 parent f1125c8 commit 880ea3c
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 5 deletions.
2 changes: 1 addition & 1 deletion hermes-console-vue/json-server/db.json
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@
}
],
"endpointAddressResolverMetadata": {
"additionalMetadata": false,
"additionalMetadata": true,
"nonSupportedProperty": 2
},
"http2Enabled": false,
Expand Down
2 changes: 1 addition & 1 deletion hermes-console-vue/json-server/subscriptions.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
}
],
"endpointAddressResolverMetadata": {
"additionalMetadata": false,
"additionalMetadata": true,
"nonSupportedProperty": 2
},
"http2Enabled": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,5 +148,6 @@ function initializeForm(
deleteSubscriptionAutomatically: false,
pathFilters: [],
headerFilters: [],
endpointAddressResolverMetadata: form.value.endpointAddressResolverMetadata,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export function parseFormToRequestBody(
},
subscriptionPolicy: mapSubscriptionPolicy(form),
trackingMode: form.messageDeliveryTrackingMode,
endpointAddressResolverMetadata: {},
endpointAddressResolverMetadata: form.endpointAddressResolverMetadata,
subscriptionIdentityHeadersEnabled: form.attachSubscriptionIdentityHeaders,
autoDeleteWithTopicEnabled: form.deleteSubscriptionAutomatically,
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { ComputedRef } from 'vue';
import type { EndpointAddressResolverMetadata } from '@/api/subscription';
import type { FieldValidator } from '@/utils/validators';
import type { HeaderFilter } from '@/views/subscription/subscription-form/subscription-header-filters/types';
import type { OwnerSource } from '@/api/owner';
Expand Down Expand Up @@ -31,6 +32,7 @@ export interface SubscriptionForm {
deleteSubscriptionAutomatically: boolean;
pathFilters: PathFilter[];
headerFilters: HeaderFilter[];
endpointAddressResolverMetadata: EndpointAddressResolverMetadata;
}

export interface FormSubscriptionPolicy {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type {
SubscriptionForm,
UseFormSubscription,
} from '@/composables/subscription/use-form-subscription/types';
import type { EndpointAddressResolverMetadata } from '@/api/subscription';
import type { HeaderFilter } from '@/views/subscription/subscription-form/subscription-header-filters/types';
import type {
MessageFilterSpecification,
Expand Down Expand Up @@ -133,6 +134,35 @@ function getRawDataSources(): RawDataSources {
};
}

function getEndpointAddressResolverDefaultValues(): Record<string, any> {
const configStore = useAppConfigStore();
const defaults: Record<string, any> = {};
for (const [propertyName, value] of Object.entries(
configStore.appConfig!.subscription.endpointAddressResolverMetadata,
)) {
if (value.type == 'boolean') {
defaults[propertyName] = false;
}
}
return defaults;
}

function getEndpointAddressResolverValues(
metadata: EndpointAddressResolverMetadata,
): Record<string, any> {
const mergedMetadata: Record<string, any> = {};
for (const [propertyName, defaultValue] of Object.entries(
getEndpointAddressResolverDefaultValues(),
)) {
if (metadata[propertyName] !== undefined) {
mergedMetadata[propertyName] = metadata[propertyName];
} else {
mergedMetadata[propertyName] = defaultValue;
}
}
return mergedMetadata;
}

function createEmptyForm(): Ref<SubscriptionForm> {
return ref({
name: '',
Expand Down Expand Up @@ -166,6 +196,7 @@ function createEmptyForm(): Ref<SubscriptionForm> {
deleteSubscriptionAutomatically: false,
pathFilters: [],
headerFilters: [],
endpointAddressResolverMetadata: getEndpointAddressResolverDefaultValues(),
});
}

Expand Down Expand Up @@ -224,6 +255,9 @@ export function initializeFullyFilledForm(
deleteSubscriptionAutomatically: subscription.autoDeleteWithTopicEnabled,
pathFilters: mapToPathFilter(subscription.filters),
headerFilters: mapToHeaderFilter(subscription.filters),
endpointAddressResolverMetadata: getEndpointAddressResolverValues(
subscription.endpointAddressResolverMetadata,
),
};
}

Expand Down
9 changes: 9 additions & 0 deletions hermes-console-vue/src/dummy/subscription-form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ export const dummySubscriptionForm = {
deleteSubscriptionAutomatically: false,
pathFilters: [],
headerFilters: [],
endpointAddressResolverMetadata: {
supportedMetadata: false,
},
};

export const dummySubscriptionFormValidator = {
Expand Down Expand Up @@ -159,6 +162,9 @@ export const dummyInitializedSubscriptionForm = {
deleteSubscriptionAutomatically: false,
pathFilters: [],
headerFilters: [],
endpointAddressResolverMetadata: {
supportedMetadata: false,
},
};

export const dummyInitializedEditSubscriptionForm = {
Expand Down Expand Up @@ -192,4 +198,7 @@ export const dummyInitializedEditSubscriptionForm = {
deleteSubscriptionAutomatically: dummySubscription.autoDeleteWithTopicEnabled,
pathFilters: [],
headerFilters: [],
endpointAddressResolverMetadata: {
supportedMetadata: true,
},
};
2 changes: 1 addition & 1 deletion hermes-console-vue/src/dummy/subscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const dummySubscription: Subscription = {
{ name: 'X-Another-Header', value: 'foobar' },
],
endpointAddressResolverMetadata: {
supportedMetadata: false,
supportedMetadata: true,
unsupportedMetadata: 2,
},
http2Enabled: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ describe('PropertiesCard', () => {
// then
const row = getByText('Supported metadata').closest('tr')!;
expect(row).toBeVisible();
expect(within(row).getByText('false')).toBeVisible();
expect(within(row).getByText('true')).toBeVisible();
});

it('should render additional unsupported properties', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@
:key="property.key"
:name="property.title"
:value="property.value"
:tooltip="property.hint"
/>

<key-value-card-item
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import SubscriptionPathFilters from '@/views/subscription/subscription-form/subscription-basic-filters/SubscriptionPathFilters.vue';
import SubscriptionPathFiltersDebug from '@/views/subscription/subscription-form/subscription-basic-filters/SubscriptionPathFiltersDebug.vue';
import TextField from '@/components/text-field/TextField.vue';
import TooltipIcon from '@/components/tooltip-icon/TooltipIcon.vue';
import type { Subscription } from '@/api/subscription';
const props = defineProps<{
Expand Down Expand Up @@ -372,6 +373,23 @@
hide-details
/>
<div
v-for="([propertyName, propertyValue]) in Object.entries(configStore.appConfig!.subscription.endpointAddressResolverMetadata)"
:key="propertyName"
class="d-flex flex-row"
>
<v-switch
v-model="form.endpointAddressResolverMetadata[propertyName]"
inset
:label="propertyValue.title"
v-if="propertyValue.type == 'boolean'"
color="success"
density="comfortable"
hide-details
/>
<tooltip-icon :content="propertyValue.hint" class="align-self-center" />
</div>
<div class="d-flex justify-end column-gap-2 mt-4">
<v-btn
variant="outlined"
Expand Down

0 comments on commit 880ea3c

Please sign in to comment.