Refactor expiry indicator configuration and update command set logic

This commit is contained in:
Torsten Brendgen
2026-07-16 22:51:21 +02:00
parent c1f1d02d9c
commit 5446fa871a
5 changed files with 30 additions and 20 deletions

View File

@@ -3,7 +3,7 @@
"port": 4321, "port": 4321,
"https": true, "https": true,
"serveConfigurations": { "serveConfigurations": {
"fieldCustomizer": { "default": {
"pageUrl": "https://sharepoint/sites/demo/Lists/Test/AllItems.aspx", "pageUrl": "https://sharepoint/sites/demo/Lists/Test/AllItems.aspx",
"fieldCustomizers": { "fieldCustomizers": {
"ExpiryDate": { "ExpiryDate": {
@@ -23,4 +23,3 @@
} }
} }
} }

View File

@@ -17,6 +17,7 @@
"@microsoft/sp-dialog": "1.4.1", "@microsoft/sp-dialog": "1.4.1",
"@microsoft/sp-http": "1.4.1", "@microsoft/sp-http": "1.4.1",
"@microsoft/sp-listview-extensibility": "1.4.1", "@microsoft/sp-listview-extensibility": "1.4.1",
"@microsoft/sp-page-context": "1.4.1",
"@types/es6-promise": "0.0.33", "@types/es6-promise": "0.0.33",
"@types/webpack-env": "1.13.1" "@types/webpack-env": "1.13.1"
}, },
@@ -30,4 +31,3 @@
"gulp": "~3.9.1" "gulp": "~3.9.1"
} }
} }

View File

@@ -0,0 +1,12 @@
/* tslint:disable */
require('./ExpiryIndicatorFieldCustomizer.module.css');
const styles = {
cell: 'cell_012cf8b1',
date: 'date_012cf8b1',
label: 'label_012cf8b1',
calculated: 'calculated_012cf8b1',
neutral: 'neutral_012cf8b1',
};
export default styles;
/* tslint:enable */

View File

@@ -1,6 +1,6 @@
import { override } from '@microsoft/decorators'; import { override } from '@microsoft/decorators';
import { SPPermission } from '@microsoft/sp-core-library';
import { Dialog } from '@microsoft/sp-dialog'; import { Dialog } from '@microsoft/sp-dialog';
import { SPPermission } from '@microsoft/sp-page-context';
import { import {
BaseListViewCommandSet, BaseListViewCommandSet,
Command, Command,
@@ -107,8 +107,9 @@ export default class ExpiryIndicatorCommandSet
}; };
if (this._config.confirmExtension) { if (this._config.confirmExtension) {
Dialog.confirm(strings.ConfirmMessage.replace('{0}', String(ids.length))) if (window.confirm(strings.ConfirmMessage.replace('{0}', String(ids.length)))) {
.then((confirmed: boolean): Promise<void> => confirmed ? execute() : Promise.resolve()); execute();
}
} else { } else {
execute(); execute();
} }
@@ -125,14 +126,12 @@ export default class ExpiryIndicatorCommandSet
}); });
} }
); );
dialog.show().then((): void => { this.raiseOnChange(); }); dialog.show();
} }
private _refreshFieldState(): Promise<void> { private _refreshFieldState(): Promise<void> {
return this._itemService.fieldExists(this._config.expiryField).then((exists: boolean): void => { return this._itemService.fieldExists(this._config.expiryField).then((exists: boolean): void => {
this._expiryFieldExists = exists; this._expiryFieldExists = exists;
this.raiseOnChange();
}); });
} }
} }

View File

@@ -8,12 +8,12 @@ import {
import * as strings from 'ExpiryIndicatorCommandSetStrings'; import * as strings from 'ExpiryIndicatorCommandSetStrings';
export class ExpirySettingsDialog extends BaseDialog { export class ExpirySettingsDialog extends BaseDialog {
private _config: IExpiryConfig; private _expiryConfig: IExpiryConfig;
private _save: (config: IExpiryConfig) => Promise<void>; private _save: (config: IExpiryConfig) => Promise<void>;
public constructor(config: IExpiryConfig, save: (config: IExpiryConfig) => Promise<void>) { public constructor(config: IExpiryConfig, save: (config: IExpiryConfig) => Promise<void>) {
super(); super();
this._config = config; this._expiryConfig = config;
this._save = save; this._save = save;
} }
@@ -49,14 +49,14 @@ export class ExpirySettingsDialog extends BaseDialog {
'</div>' + '</div>' +
'</div>'; '</div>';
this._setValue('baseField', this._config.baseField); this._setValue('baseField', this._expiryConfig.baseField);
this._setValue('expiryField', this._config.expiryField); this._setValue('expiryField', this._expiryConfig.expiryField);
this._setValue('lifetimeValue', String(this._config.default.lifeTime.value)); this._setValue('lifetimeValue', String(this._expiryConfig.default.lifeTime.value));
this._setValue('lifetimeUnit', this._config.default.lifeTime.unit); this._setValue('lifetimeUnit', this._expiryConfig.default.lifeTime.unit);
this._setValue('defaultColumnRule', JSON.stringify(this._config.default.columnRule, undefined, 2)); this._setValue('defaultColumnRule', JSON.stringify(this._expiryConfig.default.columnRule, undefined, 2));
this._setValue('rules', JSON.stringify(this._config.rules, undefined, 2)); this._setValue('rules', JSON.stringify(this._expiryConfig.rules, undefined, 2));
this._setValue('nullText', this._config.nullText); this._setValue('nullText', this._expiryConfig.nullText);
(this._field('confirmExtension') as HTMLInputElement).checked = this._config.confirmExtension; (this._field('confirmExtension') as HTMLInputElement).checked = this._expiryConfig.confirmExtension;
(this.domElement.querySelector('[data-action="cancel"]') as HTMLButtonElement).onclick = (): void => { (this.domElement.querySelector('[data-action="cancel"]') as HTMLButtonElement).onclick = (): void => {
this.close(); this.close();
@@ -95,7 +95,7 @@ export class ExpirySettingsDialog extends BaseDialog {
saveButton.disabled = true; saveButton.disabled = true;
this._save(config).then((): void => { this._save(config).then((): void => {
this._config = config; this._expiryConfig = config;
this.close(); this.close();
}).catch((error: Error): void => { }).catch((error: Error): void => {
saveButton.disabled = false; saveButton.disabled = false;