mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2026-04-16 22:24:49 +00:00
ACS-11155: update conditional checks to use optional chaining (#11658)
- Modified several components to use optional chaining for safer property access, enhancing code robustness. - Updated ESLint configuration to enforce stricter rules on the use of optional chaining. - Adjusted tests to reflect changes in property access patterns.
This commit is contained in:
@@ -77,7 +77,7 @@ module.exports = {
|
||||
}
|
||||
],
|
||||
'@typescript-eslint/await-thenable': 'error',
|
||||
'@typescript-eslint/prefer-optional-chain': 'warn',
|
||||
'@typescript-eslint/prefer-optional-chain': 'error',
|
||||
'@typescript-eslint/no-inferrable-types': 'off',
|
||||
'@typescript-eslint/no-require-imports': 'off',
|
||||
'@typescript-eslint/no-var-requires': 'error',
|
||||
|
||||
@@ -160,7 +160,7 @@ export class SearchDatetimeRangeComponent implements SearchWidget, OnInit {
|
||||
}
|
||||
|
||||
apply(model: Partial<{ from: Date; to: Date }>, isValidValue: boolean, updateContext = true) {
|
||||
if (isValidValue && this.id && this.context && this.settings && this.settings.field) {
|
||||
if (isValidValue && this.id && this.context?.queryFragments && this.settings?.field) {
|
||||
this.isActive = true;
|
||||
|
||||
const start = DateFnsUtils.utcToLocal(startOfMinute(model.from)).toISOString();
|
||||
|
||||
@@ -82,7 +82,7 @@ export class SearchLogicalFilterComponent implements SearchWidget, OnInit {
|
||||
}
|
||||
|
||||
submitValues(updateContext = true) {
|
||||
if (this.hasValidValue() && this.id && this.context && this.settings && this.settings.field) {
|
||||
if (this.hasValidValue() && this.id && this.context?.queryFragments && this.settings?.field) {
|
||||
this.updateDisplayValue();
|
||||
const fields = this.settings.field.split(',').map((field) => (field += ':'));
|
||||
let query = '';
|
||||
|
||||
@@ -128,7 +128,7 @@ export class SearchSliderComponent implements SearchWidget, OnInit {
|
||||
private updateQuery(value: number | null, updateContext = true) {
|
||||
this.context.filterRawParams[this.id] = value;
|
||||
this.displayValue$.next(this.value ? `${this.value} ${this.settings.unit ?? ''}` : '');
|
||||
if (this.id && this.context && this.settings && this.settings.field) {
|
||||
if (this.id && this.context?.queryFragments && this.settings?.field) {
|
||||
if (value === null) {
|
||||
this.context.queryFragments[this.id] = '';
|
||||
} else {
|
||||
|
||||
@@ -118,7 +118,7 @@ export class SearchTextComponent implements SearchWidget, OnInit {
|
||||
}
|
||||
|
||||
this.displayValue$.next(value);
|
||||
if (this.context && this.settings && this.settings.field) {
|
||||
if (this.context?.queryFragments && this.settings?.field) {
|
||||
this.context.queryFragments[this.id] = value ? `${this.settings.field}:'${this.getSearchPrefix()}${value}${this.getSearchSuffix()}'` : '';
|
||||
if (updateContext) {
|
||||
this.context.update();
|
||||
|
||||
@@ -963,7 +963,7 @@ export class DataTableComponent implements OnInit, AfterContentInit, OnChanges,
|
||||
}
|
||||
|
||||
getCellTooltip(row: DataRow, col: DataColumn): string {
|
||||
if (row && col && col.formatTooltip) {
|
||||
if (row && col?.formatTooltip) {
|
||||
const result: string = col.formatTooltip(row, col);
|
||||
if (result) {
|
||||
return result;
|
||||
|
||||
@@ -357,7 +357,7 @@ const render = (args: DataColumnComponent & { rows: DataRow[] }) => ({
|
||||
|
||||
// Text Column
|
||||
export const TextColumn: Story = {
|
||||
render: render,
|
||||
render,
|
||||
args: {
|
||||
rows: mockData.textColumnRows,
|
||||
key: 'firstname',
|
||||
@@ -368,7 +368,7 @@ export const TextColumn: Story = {
|
||||
|
||||
// Text Column With Custom Tooltip
|
||||
export const TextColumnWithCustomTooltip: Story = {
|
||||
render: render,
|
||||
render,
|
||||
argTypes: {
|
||||
formatTooltip: { control: { disable: false } }
|
||||
},
|
||||
@@ -383,7 +383,7 @@ export const TextColumnWithCustomTooltip: Story = {
|
||||
|
||||
// Icon Column
|
||||
export const IconColumn: Story = {
|
||||
render: render,
|
||||
render,
|
||||
argTypes: {
|
||||
copyContent: { control: { disable: true } }
|
||||
},
|
||||
@@ -397,7 +397,7 @@ export const IconColumn: Story = {
|
||||
|
||||
// Image Column
|
||||
export const ImageColumn: Story = {
|
||||
render: render,
|
||||
render,
|
||||
argTypes: {
|
||||
copyContent: { control: { disable: true } }
|
||||
},
|
||||
@@ -411,7 +411,7 @@ export const ImageColumn: Story = {
|
||||
|
||||
// Date Column
|
||||
export const DateColumn: Story = {
|
||||
render: render,
|
||||
render,
|
||||
argTypes: {
|
||||
copyContent: { control: { disable: true } },
|
||||
dateConfig: { control: { disable: false } }
|
||||
@@ -426,7 +426,7 @@ export const DateColumn: Story = {
|
||||
|
||||
// Date Column Time Ago
|
||||
export const DateColumnTimeAgo: Story = {
|
||||
render: render,
|
||||
render,
|
||||
argTypes: {
|
||||
copyContent: { control: { disable: true } },
|
||||
dateConfig: { control: { disable: false } }
|
||||
@@ -442,7 +442,7 @@ export const DateColumnTimeAgo: Story = {
|
||||
|
||||
// File Size Column
|
||||
export const FileSizeColumn: Story = {
|
||||
render: render,
|
||||
render,
|
||||
argTypes: {
|
||||
copyContent: { control: { disable: true } }
|
||||
},
|
||||
@@ -456,7 +456,7 @@ export const FileSizeColumn: Story = {
|
||||
|
||||
// Location Column
|
||||
export const LocationColumn: Story = {
|
||||
render: render,
|
||||
render,
|
||||
argTypes: {
|
||||
copyContent: { control: { disable: true } },
|
||||
format: { control: { disable: false } },
|
||||
@@ -473,7 +473,7 @@ export const LocationColumn: Story = {
|
||||
|
||||
// Boolean Column
|
||||
export const BooleanColumn: Story = {
|
||||
render: render,
|
||||
render,
|
||||
argTypes: {
|
||||
copyContent: { control: { disable: true } }
|
||||
},
|
||||
@@ -487,7 +487,7 @@ export const BooleanColumn: Story = {
|
||||
|
||||
// Json Column
|
||||
export const JsonColumn: Story = {
|
||||
render: render,
|
||||
render,
|
||||
argTypes: {
|
||||
editable: { control: { disable: false } },
|
||||
copyContent: { control: { disable: true } }
|
||||
@@ -502,7 +502,7 @@ export const JsonColumn: Story = {
|
||||
|
||||
// Amount Column
|
||||
export const AmountColumn: Story = {
|
||||
render: render,
|
||||
render,
|
||||
argTypes: {
|
||||
copyContent: { control: { disable: true } },
|
||||
currencyConfig: { control: { disable: false } }
|
||||
@@ -517,7 +517,7 @@ export const AmountColumn: Story = {
|
||||
|
||||
// Number Column
|
||||
export const NumberColumn: Story = {
|
||||
render: render,
|
||||
render,
|
||||
argTypes: {
|
||||
decimalConfig: { control: { disable: false } },
|
||||
copyContent: { control: { disable: true } }
|
||||
|
||||
@@ -337,7 +337,7 @@ export class SuperagentHttpClient implements HttpClient {
|
||||
const newParams: { [key: string]: any } = {};
|
||||
|
||||
for (const key in params) {
|
||||
if (Object.prototype.hasOwnProperty.call(params, key) && params[key] !== undefined && params[key] !== null) {
|
||||
if (Object.prototype.hasOwnProperty.call(params, key) && params[key] != null) {
|
||||
const value = params[key];
|
||||
if (SuperagentHttpClient.isFileParam(value) || Array.isArray(value)) {
|
||||
newParams[key] = value;
|
||||
|
||||
@@ -1905,7 +1905,7 @@ describe('retrieve metadata on submit', () => {
|
||||
});
|
||||
|
||||
it('should handle outcomeId correctly when completing form with confirmation dialog', () => {
|
||||
let matDialog = TestBed.inject(MatDialog);
|
||||
const matDialog = TestBed.inject(MatDialog);
|
||||
spyOn(matDialog, 'open').and.returnValue({ afterClosed: () => of(true) } as any);
|
||||
spyOn(formComponent['formCloudService'], 'completeTaskForm').and.returnValue(of({} as any));
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ export interface OutputData {
|
||||
export class RichTextParserService {
|
||||
private static readonly CUSTOM_PARSER = {
|
||||
header: (block: any): string => {
|
||||
if (!block.data || !block.data.text || !block.data.level) {
|
||||
if (!block.data?.text || !block.data.level) {
|
||||
return '';
|
||||
}
|
||||
const paragraphAlign = block.data.alignment || block.data.align || block.tunes?.anyTuneName?.alignment;
|
||||
@@ -40,7 +40,7 @@ export class RichTextParserService {
|
||||
}
|
||||
},
|
||||
paragraph: (block: any): string => {
|
||||
if (!block.data || !block.data.text) {
|
||||
if (!block.data?.text) {
|
||||
return '';
|
||||
}
|
||||
const paragraphAlign = block.data.alignment || block.data.align || block.tunes?.anyTuneName?.alignment;
|
||||
|
||||
Reference in New Issue
Block a user