Skip to content

Commit

Permalink
define the connection type config map typescript types
Browse files Browse the repository at this point in the history
  • Loading branch information
christianvogt committed Jul 30, 2024
1 parent 8e17ae3 commit afb75ec
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 1 deletion.
101 changes: 101 additions & 0 deletions frontend/src/concepts/connectionTypes/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import { K8sResourceCommon } from '@openshift/dynamic-plugin-sdk-utils';
import { DashboardLabels, DisplayNameAnnotations } from '~/k8sTypes';

export enum ConnectionTypeFieldType {
Boolean = 'boolean',
Dropdown = 'dropdown',
File = 'file',
Hidden = 'hidden',
Numeric = 'numeric',
Paragraph = 'paragraph',
Section = 'section',
ShortText = 'short-text',
URI = 'uri',
}

// exclude 'section'
export const connectionTypeDataFields = [
ConnectionTypeFieldType.Boolean,
ConnectionTypeFieldType.Dropdown,
ConnectionTypeFieldType.File,
ConnectionTypeFieldType.Hidden,
ConnectionTypeFieldType.Numeric,
ConnectionTypeFieldType.Paragraph,
ConnectionTypeFieldType.ShortText,
ConnectionTypeFieldType.URI,
];

type Field<T extends ConnectionTypeFieldType | string> = {
type: T;
name: string;
description: string;
};

type DataField<T extends ConnectionTypeFieldType | string, P> = Field<T> & {
envVar: string;
required?: boolean;
properties: P;
};

type TextProps = {
defaultValue?: string;
defaultReadOnly?: boolean;
};

export type SectionField = Field<ConnectionTypeFieldType.Section | 'section'>;

export type HiddenField = DataField<ConnectionTypeFieldType.Hidden | 'hidden', TextProps>;
export type ParagraphField = DataField<ConnectionTypeFieldType.Paragraph | 'paragraph', TextProps>;
export type FileField = DataField<ConnectionTypeFieldType.File | 'file', TextProps>;
export type ShortTextField = DataField<ConnectionTypeFieldType.ShortText | 'short-text', TextProps>;
export type UriField = DataField<ConnectionTypeFieldType.URI | 'uri', TextProps>;
export type BooleanField = DataField<
ConnectionTypeFieldType.Boolean | 'boolean',
{
label?: string;
defaultValue?: boolean;
defaultReadOnly?: boolean;
}
>;
export type DropdownField = DataField<
ConnectionTypeFieldType.Dropdown | 'dropdown',
{
variant: 'single' | 'multi';
items: { key: string; value: string }[];
defaultItem?: string[];
}
>;
export type NumericField = DataField<
ConnectionTypeFieldType.Numeric | 'numeric',
{
defaultValue?: number;
defaultReadOnly?: boolean;
}
>;

export type ConnectionTypeField =
| BooleanField
| DropdownField
| FileField
| HiddenField
| NumericField
| ParagraphField
| SectionField
| ShortTextField
| UriField;

export type ConnectionTypeConfigMap = K8sResourceCommon & {
metadata: {
name: string;
annotations: DisplayNameAnnotations & {
'opendatahub.io/enabled'?: 'true' | 'false';
'opendatahub.io/username'?: string;
};
labels: DashboardLabels & {
'opendatahub.io/connection-type': 'true';
};
};
data: {
fields?: ConnectionTypeField[];
};
};
2 changes: 1 addition & 1 deletion frontend/src/k8sTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export type K8sVerb =
* Annotations that we will use to allow the user flexibility in describing items outside of the
* k8s structure.
*/
type DisplayNameAnnotations = Partial<{
export type DisplayNameAnnotations = Partial<{
'openshift.io/description': string; // the description provided by the user
'openshift.io/display-name': string; // the name provided by the user
}>;
Expand Down

0 comments on commit afb75ec

Please sign in to comment.