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

Product filters backend response filters. #769

Merged
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
2 changes: 1 addition & 1 deletion maas-schemas/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "maas-schemas",
"version": "20.9.0",
"version": "20.10.0",
"description": "Schemas for MaaS infrastructure",
"main": "index.js",
"engine": {
Expand Down
81 changes: 81 additions & 0 deletions maas-schemas/schemas/maas-backend/products/provider.json
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,12 @@
},
"created": {
"$ref": "https://schemas.maas.global/core/components/units.json#/definitions/time"
},
"filters": {
"type": "array",
"items": {
"$ref": "#/definitions/providerFilter"
}
}
},
"required": [
Expand All @@ -213,6 +219,55 @@
],
"additionalProperties": false,
"definitions": {
"providerFilter": {
"description": "Product provider filter",
"type": "object",
"required": ["name", "label"],
"properties": {
"name": {
"type": "string"
},
"label": {
"type": "string"
},
"default": {
"anyOf": [
{
"$ref": "#/definitions/providerFilterOption"
},
{
"type": "null"
}
]
},
"selectionOptions": {
"type": "array",
"items": {
"$ref": "#/definitions/providerFilterOption"
}
}
}
},
"providerFilterOption": {
"description": "Product provider filter option",
"type": "object",
"required": ["value", "label"],
"properties": {
"value": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
]
},
"label": {
"type": "string"
}
}
},
"selection": {
"description": "Optional parameter for selections",
"type": "object",
Expand Down Expand Up @@ -313,6 +368,32 @@
"stationsList": true,
"stationsRetrieve": true
},
"filters": [
{
"name": "ticketType",
"label": "ticketTypeLabel",
"selectionOptions": [
{
"value": null,
"label": "PLEASE_CHOOSE"
},
{
"value": "ordinary",
"label": "TYPE_ORDINARY"
}
],
"default": {
"value": null,
"label": "PLEASE_CHOOSE"
}
},
{
"name": "ticketZone",
"label": "ticketZoneLabel",
"selectionOptions": [],
"default": null
}
],
"personalDataOptionsAllow": [],
"personalDataCreateAllow": [],
"optionalParameters": [
Expand Down
8 changes: 8 additions & 0 deletions maas-schemas/src/io-ts/_translation.log
Original file line number Diff line number Diff line change
Expand Up @@ -1950,6 +1950,14 @@ INFO: primitive type "string" used outside top-level definitions
in schemas/maas-backend/products/provider.json
INFO: primitive type "string" used outside top-level definitions
in schemas/maas-backend/products/provider.json
INFO: primitive type "string" used outside top-level definitions
in schemas/maas-backend/products/provider.json
INFO: primitive type "string" used outside top-level definitions
in schemas/maas-backend/products/provider.json
INFO: primitive type "string" used outside top-level definitions
in schemas/maas-backend/products/provider.json
INFO: primitive type "string" used outside top-level definitions
in schemas/maas-backend/products/provider.json
WARNING: minItems field not supported outside top-level definitions
in schemas/maas-backend/products/provider.json
INFO: primitive type "string" used outside top-level definitions
Expand Down
168 changes: 168 additions & 0 deletions maas-schemas/src/io-ts/_types/maas-backend/products/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ import * as PersonalDataValidation_1572_ from '../../core/components/personalDat
import * as PersonalDocumentRequiredItem_b279_ from '../../core/components/personalDocumentRequiredItem';
import * as Units_c404_ from '../../core/components/units';

export type NullBrand = {
readonly Null: unique symbol;
};
export type NullC = t.BrandC<t.UnknownC, NullBrand>;
export const Null: NullC = t.brand(
t.unknown,
(n): n is t.Branded<unknown, NullBrand> => n === null,
'Null',
);
export type Null = t.TypeOf<typeof Null>;

export type Defined = {} | null;
export class DefinedType extends t.Type<Defined> {
readonly _tag: 'DefinedType' = 'DefinedType';
Expand All @@ -36,6 +47,142 @@ export const Defined: DefinedC = new DefinedType();

export const schemaId = 'https://schemas.maas.global/maas-backend/products/provider.json';

// ProviderFilterOption
// Product provider filter option
export type ProviderFilterOption = t.Branded<
({
value?: string | Null;
label?: string;
} & Record<string, unknown>) & {
value: Defined;
label: Defined;
},
ProviderFilterOptionBrand
>;
export type ProviderFilterOptionC = t.BrandC<
t.IntersectionC<
[
t.IntersectionC<
[
t.PartialC<{
value: t.UnionC<[t.StringC, typeof Null]>;
label: t.StringC;
}>,
t.RecordC<t.StringC, t.UnknownC>,
]
>,
t.TypeC<{
value: typeof Defined;
label: typeof Defined;
}>,
]
>,
ProviderFilterOptionBrand
>;
export const ProviderFilterOption: ProviderFilterOptionC = t.brand(
t.intersection([
t.intersection([
t.partial({
value: t.union([t.string, Null]),
label: t.string,
}),
t.record(t.string, t.unknown),
]),
t.type({
value: Defined,
label: Defined,
}),
]),
(
x,
): x is t.Branded<
({
value?: string | Null;
label?: string;
} & Record<string, unknown>) & {
value: Defined;
label: Defined;
},
ProviderFilterOptionBrand
> => true,
'ProviderFilterOption',
);
export type ProviderFilterOptionBrand = {
readonly ProviderFilterOption: unique symbol;
};

// ProviderFilter
// Product provider filter
export type ProviderFilter = t.Branded<
({
name?: string;
label?: string;
default?: ProviderFilterOption | Null;
selectionOptions?: Array<ProviderFilterOption>;
} & Record<string, unknown>) & {
name: Defined;
label: Defined;
},
ProviderFilterBrand
>;
export type ProviderFilterC = t.BrandC<
t.IntersectionC<
[
t.IntersectionC<
[
t.PartialC<{
name: t.StringC;
label: t.StringC;
default: t.UnionC<[typeof ProviderFilterOption, typeof Null]>;
selectionOptions: t.ArrayC<typeof ProviderFilterOption>;
}>,
t.RecordC<t.StringC, t.UnknownC>,
]
>,
t.TypeC<{
name: typeof Defined;
label: typeof Defined;
}>,
]
>,
ProviderFilterBrand
>;
export const ProviderFilter: ProviderFilterC = t.brand(
t.intersection([
t.intersection([
t.partial({
name: t.string,
label: t.string,
default: t.union([ProviderFilterOption, Null]),
selectionOptions: t.array(ProviderFilterOption),
}),
t.record(t.string, t.unknown),
]),
t.type({
name: Defined,
label: Defined,
}),
]),
(
x,
): x is t.Branded<
({
name?: string;
label?: string;
default?: ProviderFilterOption | Null;
selectionOptions?: Array<ProviderFilterOption>;
} & Record<string, unknown>) & {
name: Defined;
label: Defined;
},
ProviderFilterBrand
> => true,
'ProviderFilter',
);
export type ProviderFilterBrand = {
readonly ProviderFilter: unique symbol;
};

// Selection
// Optional parameter for selections
export type Selection = t.Branded<
Expand Down Expand Up @@ -470,6 +617,7 @@ export type Provider = t.Branded<
>;
disruption?: Record<string, unknown> & Record<string, unknown>;
created?: Units_c404_.Time;
filters?: Array<ProviderFilter>;
} & {
name: Defined;
agencyId: Defined;
Expand Down Expand Up @@ -586,6 +734,7 @@ export type ProviderC = t.BrandC<
>;
disruption: t.IntersectionC<[t.UnknownRecordC, t.RecordC<t.StringC, t.UnknownC>]>;
created: typeof Units_c404_.Time;
filters: t.ArrayC<typeof ProviderFilter>;
}>,
t.TypeC<{
name: typeof Defined;
Expand Down Expand Up @@ -683,6 +832,7 @@ export const Provider: ProviderC = t.brand(
),
disruption: t.intersection([t.UnknownRecord, t.record(t.string, t.unknown)]),
created: Units_c404_.Time,
filters: t.array(ProviderFilter),
}),
t.type({
name: Defined,
Expand Down Expand Up @@ -756,6 +906,7 @@ export const Provider: ProviderC = t.brand(
>;
disruption?: Record<string, unknown> & Record<string, unknown>;
created?: Units_c404_.Time;
filters?: Array<ProviderFilter>;
} & {
name: Defined;
agencyId: Defined;
Expand Down Expand Up @@ -783,6 +934,23 @@ export const examplesProvider: NonEmptyArray<Provider> = [
hidden: false,
branding: {},
features: { ticket: true, stationsList: true, stationsRetrieve: true },
filters: [
{
name: 'ticketType',
label: 'ticketTypeLabel',
selectionOptions: [
{ value: null, label: 'PLEASE_CHOOSE' },
{ value: 'ordinary', label: 'TYPE_ORDINARY' },
],
default: { value: null, label: 'PLEASE_CHOOSE' },
},
{
name: 'ticketZone',
label: 'ticketZoneLabel',
selectionOptions: [],
default: null,
},
],
personalDataOptionsAllow: [],
personalDataCreateAllow: [],
optionalParameters: [
Expand Down