Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/linode/manager into M3-8…
Browse files Browse the repository at this point in the history
…912-fix-support-ticket-creation-for-obj-storage
  • Loading branch information
harsh-akamai committed Dec 5, 2024
2 parents 35af917 + 7609507 commit 9068774
Show file tree
Hide file tree
Showing 959 changed files with 7,763 additions and 4,257 deletions.
33 changes: 19 additions & 14 deletions docs/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,23 @@ Please specify a release date (and environment, if applicable) to guarantee time
- [ ] ...
- [ ] ...

## As an Author, I have considered 🤔

- 👀 Doing a self review
- ❔ Our [contribution guidelines](https://github.com/linode/manager/blob/develop/docs/CONTRIBUTING.md)
- 🤏 Splitting feature into small PRs
- ➕ Adding a [changeset](https://github.com/linode/manager/blob/develop/docs/CONTRIBUTING.md#writing-a-changeset)
- 🧪 Providing/improving test coverage
- 🔐 Removing all sensitive information from the code and PR description
- 🚩 Using a feature flag to protect the release
- 👣 Providing comprehensive reproduction steps
- 📑 Providing or updating our documentation
- 🕛 Scheduling a pair reviewing session
- 📱 Providing mobile support
- ♿ Providing accessibility support
<details>
<summary> Author Checklists </summary>

## As an Author, to speed up the review process, I considered 🤔

👀 Doing a self review
❔ Our [contribution guidelines](https://github.com/linode/manager/blob/develop/docs/CONTRIBUTING.md)
🤏 Splitting feature into small PRs
➕ Adding a [changeset](https://github.com/linode/manager/blob/develop/docs/CONTRIBUTING.md#writing-a-changeset)
🧪 Providing/improving test coverage
🔐 Removing all sensitive information from the code and PR description
🚩 Using a feature flag to protect the release
👣 Providing comprehensive reproduction steps
📑 Providing or updating our documentation
🕛 Scheduling a pair reviewing session
📱 Providing mobile support
♿ Providing accessibility support

<br/>

Expand All @@ -73,6 +76,8 @@ Please specify a release date (and environment, if applicable) to guarantee time
- [ ] TypeScript compilation succeeded without errors
- [ ] Code passes all linting rules

</details>

---

## Commit message and pull request title format standards
Expand Down
2 changes: 1 addition & 1 deletion docs/development-guide/04-component-library.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ We use [Material-UI](https://mui.com/material-ui/getting-started/overview/) as t
All MUI components have abstractions in the Cloud Manager codebase, meaning you will use relative imports to use them instead of importing from MUI directly:

```ts
import { Typography } from "src/components/Typography"; // NOT from '@mui/material/Typography'
import { Typography } from "@linode/ui"; // NOT from '@mui/material/Typography'
```

We do this because it gives us the ability to customize the component and still keep imports consistent. It also gives us flexibility if we ever wanted to change out the underlying component library.
Expand Down
71 changes: 71 additions & 0 deletions docs/development-guide/15-composition.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,74 @@ The Linode Create Page is a good example of a complex form that is built using r
### Uncontrolled Forms
Uncontrolled forms are a type of form that does not have a state for its values. It is often used for simple forms that do not need to be controlled, such as forms with a single input field or call to action.

## Form Validation (React Hook Form)
### Best Practices
1. Keep API validation in `@linode/validation` package
2. Create extended schemas in `@linode/manager` package when you need validation beyond the API contract
3. Use yup.concat() to extend existing schemas
4. Add custom validation logic within the resolver function
5. Include type definitions for form values and context

### Simple Schema Extension
For basic form validation, extend the API schema directly:

```typescript
import { CreateWidgetSchema } from '@linode/validation';
import { object, string } from 'yup';
import { yupResolver } from '@hookform/resolvers/yup';

const extendedSchema = CreateWidgetSchema.concat(
object({
customField: string().required('Required field'),
})
);

const form = useForm({
resolver: yupResolver(extendedSchema)
});
```

### Complex Schema Extensions
You may create a `resolver` function that handles the validation (see: [ManageImageRegionsForm.tsx](https://github.com/linode/manager/blob/develop/packages/manager/src/features/Images/ImagesLanding/ImageRegions/ManageImageRegionsForm.tsx#L189-L213)):

```typescript
// Step 1: Create a Resolver Function
// This function validates your form data against specific requirements

type Resolver<FormData, Context> = (values: FormData, context: Context) => {
errors: Record<string, any>;
values: FormData;
};

// Example resolver that checks if at least one item from a list is selected
const resolver: Resolver<YourFormData, YourContext> = (values, context) => {
// Check if at least one valid option is selected
const hasValidSelection = values.selectedItems.some(
item => context.availableItems.includes(item)
);

if (!hasValidSelection) {
return {
errors: {
selectedItems: {
message: 'Please select at least one valid option',
type: 'validate'
}
},
values
};
}

return { errors: {}, values };
};

// Step 2: Use the Resolver in Your Form
const form = useForm({
resolver,
defaultValues: { selectedItems: [] },
context: { availableItems: ['item1', 'item2'] }
});
```

### Additional Complexity
When working with multiple sequential schemas that require validation, you can create a resolver map and function (see: [LinodeCreate/resolvers.ts](https://github.com/linode/manager/blob/develop/packages/manager/src/features/Linodes/LinodeCreate/resolvers.ts])).
5 changes: 5 additions & 0 deletions packages/api-v4/.changeset/pr-11257-removed-1731594995947.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/api-v4": Removed
---

`deleted` from the `ImageStatus` type ([#11257](https://github.com/linode/manager/pull/11257))
5 changes: 5 additions & 0 deletions packages/api-v4/.changeset/pr-11258-added-1731996671316.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/api-v4": Added
---

Linter rules for common pr feedback points ([#11258](https://github.com/linode/manager/pull/11258))
5 changes: 5 additions & 0 deletions packages/api-v4/.changeset/pr-11261-added-1732225555236.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/api-v4": Added
---

Placement Groups migrations Types ([#11261](https://github.com/linode/manager/pull/11261))
5 changes: 5 additions & 0 deletions packages/api-v4/.changeset/pr-11286-changed-1732032917339.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/api-v4": Added
---

service_type as parameter for the Create Alert POST request ([#11286](https://github.com/linode/manager/pull/11286))
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/api-v4": Upcoming Features
---

Add new types and v4beta endpoints for LKE-E ([#11302](https://github.com/linode/manager/pull/11302))
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/api-v4": Tech Stories
---

Update yup from `0.32.9` to `1.4.0` ([#11324](https://github.com/linode/manager/pull/11324))
5 changes: 5 additions & 0 deletions packages/api-v4/.changeset/pr-11330-removed-1732610877556.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/api-v4": Removed
---

Recently added camelCase rule ([#11330](https://github.com/linode/manager/pull/11330))
5 changes: 5 additions & 0 deletions packages/api-v4/.changeset/pr-11337-added-1732714186488.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/api-v4": Added
---

Linter rules for naming convention ([#11337](https://github.com/linode/manager/pull/11337))
70 changes: 41 additions & 29 deletions packages/api-v4/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,54 @@
{
"ignorePatterns": [
"node_modules",
"lib",
"index.js",
"!.eslintrc.js"
],
"ignorePatterns": ["node_modules", "lib", "index.js", "!.eslintrc.js"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2020,
"warnOnUnsupportedTypeScriptVersion": true
},
"plugins": [
"@typescript-eslint",
"sonarjs",
"prettier"
],
"plugins": ["@typescript-eslint", "sonarjs", "prettier"],
"extends": [
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"plugin:sonarjs/recommended",
"plugin:prettier/recommended"
],
"rules": {
"@typescript-eslint/naming-convention": [
"warn",
{
"format": ["camelCase", "UPPER_CASE", "PascalCase"],
"leadingUnderscore": "allow",
"selector": "variable",
"trailingUnderscore": "allow"
},
{
"format": null,
"modifiers": ["destructured"],
"selector": "variable"
},
{
"format": ["camelCase", "PascalCase"],
"selector": "function"
},
{
"format": ["camelCase"],
"leadingUnderscore": "allow",
"selector": "parameter"
},
{
"format": ["PascalCase"],
"selector": "typeLike"
}
],
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/no-inferrable-types": "off",
"@typescript-eslint/no-namespace": "warn",
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/no-empty-interface": "warn",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-explicit-any": "warn",
"@typescript-eslint/no-use-before-define": "off",
"@typescript-eslint/interface-name-prefix": "off",
"no-unused-vars": [
"warn",
{
Expand All @@ -38,23 +65,10 @@
"array-callback-return": "error",
"no-invalid-this": "off",
"no-new-wrappers": "error",
"no-restricted-imports": [
"error",
"rxjs"
],
"no-restricted-imports": ["error", "rxjs"],
"no-console": "error",
"no-undef-init": "off",
"radix": "error",
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/no-inferrable-types": "off",
"@typescript-eslint/no-namespace": "warn",
"@typescript-eslint/camelcase": "off",
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/no-empty-interface": "warn",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-use-before-define": "off",
"@typescript-eslint/interface-name-prefix": "off",
"sonarjs/cognitive-complexity": "warn",
"sonarjs/no-duplicate-string": "warn",
"sonarjs/prefer-immediate-return": "warn",
Expand All @@ -74,9 +88,7 @@
},
"overrides": [
{
"files": [
"*ts"
],
"files": ["*ts"],
"rules": {
"@typescript-eslint/ban-types": [
"warn",
Expand All @@ -97,4 +109,4 @@
}
}
]
}
}
3 changes: 1 addition & 2 deletions packages/api-v4/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"@linode/validation": "*",
"axios": "~1.7.4",
"ipaddr.js": "^2.0.0",
"yup": "^0.32.9"
"yup": "^1.4.0"
},
"scripts": {
"start": "concurrently --raw \"tsc -w --preserveWatchOutput\" \"tsup --watch\"",
Expand All @@ -57,7 +57,6 @@
"lib"
],
"devDependencies": {
"@types/yup": "^0.29.13",
"axios-mock-adapter": "^1.22.0",
"concurrently": "^9.0.1",
"eslint": "^6.8.0",
Expand Down
13 changes: 10 additions & 3 deletions packages/api-v4/src/cloudpulse/alerts.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import { createAlertDefinitionSchema } from '@linode/validation';
import Request, { setURL, setMethod, setData } from '../request';
import { Alert, CreateAlertDefinitionPayload } from './types';
import { Alert, AlertServiceType, CreateAlertDefinitionPayload } from './types';
import { BETA_API_ROOT as API_ROOT } from 'src/constants';

export const createAlertDefinition = (data: CreateAlertDefinitionPayload) =>
export const createAlertDefinition = (
data: CreateAlertDefinitionPayload,
serviceType: AlertServiceType
) =>
Request<Alert>(
setURL(`${API_ROOT}/monitor/alert-definitions`),
setURL(
`${API_ROOT}/monitor/services/${encodeURIComponent(
serviceType!
)}/alert-definitions`
),
setMethod('POST'),
setData(data, createAlertDefinitionSchema)
);
31 changes: 11 additions & 20 deletions packages/api-v4/src/cloudpulse/types.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
export type AlertSeverityType = 0 | 1 | 2 | 3 | null;
type MetricAggregationType = 'avg' | 'sum' | 'min' | 'max' | 'count' | null;
type MetricOperatorType = 'eq' | 'gt' | 'lt' | 'gte' | 'lte' | null;
type DimensionFilterOperatorType =
| 'eq'
| 'neq'
| 'startswith'
| 'endswith'
| null;
type AlertDefinitionType = 'default' | 'custom';
type AlertStatusType = 'enabled' | 'disabled';
export type AlertSeverityType = 0 | 1 | 2 | 3;
export type MetricAggregationType = 'avg' | 'sum' | 'min' | 'max' | 'count';
export type MetricOperatorType = 'eq' | 'gt' | 'lt' | 'gte' | 'lte';
export type AlertServiceType = 'linode' | 'dbaas';
type DimensionFilterOperatorType = 'eq' | 'neq' | 'startswith' | 'endswith';
export type AlertDefinitionType = 'default' | 'custom';
export type AlertStatusType = 'enabled' | 'disabled';
export interface Dashboard {
id: number;
label: string;
Expand Down Expand Up @@ -147,20 +143,14 @@ export interface ServiceTypesList {
export interface CreateAlertDefinitionPayload {
label: string;
description?: string;
resource_ids?: string[];
entity_ids?: string[];
severity: AlertSeverityType;
rule_criteria: {
rules: MetricCriteria[];
};
triggerCondition: TriggerCondition;
channel_ids: number[];
}
export interface CreateAlertDefinitionForm
extends CreateAlertDefinitionPayload {
region: string;
service_type: string;
engine_type: string;
}
export interface MetricCriteria {
metric: string;
aggregation_type: MetricAggregationType;
Expand All @@ -184,11 +174,12 @@ export interface Alert {
id: number;
label: string;
description: string;
has_more_resources: boolean;
status: AlertStatusType;
type: AlertDefinitionType;
severity: AlertSeverityType;
service_type: string;
resource_ids: string[];
service_type: AlertServiceType;
entity_ids: string[];
rule_criteria: {
rules: MetricCriteria[];
};
Expand Down
6 changes: 1 addition & 5 deletions packages/api-v4/src/images/types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
export type ImageStatus =
| 'available'
| 'creating'
| 'deleted'
| 'pending_upload';
export type ImageStatus = 'available' | 'creating' | 'pending_upload';

export type ImageCapabilities = 'cloud-init' | 'distributed-sites';

Expand Down
Loading

0 comments on commit 9068774

Please sign in to comment.