Skip to content

Commit 754c7ce

Browse files
committed
Refactor ComponentsPacksWebviewMain to improve project handling and enhance dispose logic; update ComponentPackManager layout for better responsiveness; adjust ComponentsView variant column for improved display.
1 parent 3877ead commit 754c7ce

3 files changed

Lines changed: 109 additions & 60 deletions

File tree

src/views/manage-components-packs/components-packs-webview-main.ts

Lines changed: 61 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ export class ComponentsPacksWebviewMain {
5757

5858
public static readonly WEBVIEW_COMMAND_ID = `${manifest.PACKAGE_NAME}.manageComponentsPacks`;
5959

60-
private currentProject: CurrentProject;
61-
60+
private project: CurrentProject;
6261
private componentTree!: CtRoot;
6362
private validations!: Results;
6463
private selectedContext: TargetSetData | undefined;
@@ -88,7 +87,6 @@ export class ComponentsPacksWebviewMain {
8887
new WebviewManager(context, MANAGE_COMPONENTS_WEBVIEW_OPTIONS, commandsProvider);
8988
this.manageComponentsActions.setCsolutionService(this.csolutionService);
9089
this.manageComponentsActions.setMessageProvider(this.messageProvider);
91-
this.manageComponentsActions.setCurrentProject(this.currentProject);
9290
this.projectFileUpdater = new ProjectFileUpdaterImpl(this.solutionManager);
9391
}
9492

@@ -103,11 +101,58 @@ export class ComponentsPacksWebviewMain {
103101
await this.webviewManager.activate(context);
104102
}
105103

106-
private dispose(): void {
107-
this.currentProject = undefined;
108-
this.componentTree = { success: false, classes: [] };
109-
this.validations = { success: false, result: 'UNDEFINED', validation: [] };
110-
this.manageComponentsActions.setCurrentProject(this.currentProject);
104+
private async dispose(): Promise<void> {
105+
const discardView = () => {
106+
this.currentProject = undefined;
107+
this.componentTree = { success: false, classes: [] };
108+
this.validations = { success: false, result: 'UNDEFINED', validation: [] };
109+
this.usedItems = { components: [], packs: [], success: false };
110+
this.cachedTargetSetData = undefined;
111+
this.availablePacksCache = {};
112+
this.unlinkRequests.clear();
113+
this.isLoading = false;
114+
this.scope = ComponentScope.Solution;
115+
};
116+
117+
if (await this.isDirty()) {
118+
const buttonOptions = [
119+
{ title: 'Save' },
120+
{ title: 'Discard', isCloseAffordance: true },
121+
{ title: 'Reopen' },
122+
];
123+
const messageOptions: vscode.MessageOptions = { modal: true, detail: 'Do you want to save changes before closing?' };
124+
125+
const pick = (await vscode.window.showWarningMessage(
126+
'Unsaved changes will be lost.',
127+
messageOptions,
128+
...buttonOptions,
129+
)) || { title: 'Cancel' };
130+
131+
switch (pick.title) {
132+
case 'Save':
133+
await this.handleApplyComponentSet();
134+
discardView();
135+
break;
136+
case 'Reopen':
137+
this.webviewManager.createOrShowPanel();
138+
break;
139+
case 'Discard':
140+
default:
141+
discardView();
142+
break;
143+
}
144+
} else {
145+
discardView();
146+
}
147+
}
148+
149+
get currentProject(): CurrentProject | undefined {
150+
return this.project;
151+
}
152+
153+
set currentProject(project: CurrentProject | undefined) {
154+
this.project = project;
155+
this.manageComponentsActions.setCurrentProject(project);
111156
}
112157

113158
private async handleWebviewCommand(treeNode: COutlineItem | undefined) {
@@ -265,7 +310,6 @@ export class ComponentsPacksWebviewMain {
265310
if (csolution) {
266311
this.clearTargetSetCache();
267312
this.currentProject = { solutionPath: csolution.solutionPath, project: createProject(projectId) };
268-
this.manageComponentsActions.setCurrentProject(this.currentProject);
269313
const actx = this.getActiveContext();
270314

271315
const activeTs = csolution.getActiveTargetSetName() ?? '';
@@ -294,11 +338,12 @@ export class ComponentsPacksWebviewMain {
294338
throw new Error(`Failed loading solution: ${solutionPath} due to previous errors`);
295339
}
296340

297-
await this.webviewManager.sendMessage({ type: 'SET_SOLUTION_STATE', stateMessage: 'Fetching Packs Info...' });
341+
await this.webviewManager.sendMessage({ type: 'SET_SOLUTION_STATE', stateMessage: 'Retrieving assigned items...' });
342+
this.usedItems = await this.csolutionService.getUsedItems({ context: activeContext });
298343
}
299-
this.usedItems = await this.csolutionService.getUsedItems({ context: activeContext });
300344
await this.webviewManager.sendMessage({ type: 'SET_UNLINKREQUESTS_STACK', unlinkRequests: Array.from(this.unlinkRequests) });
301345
await this.sendSolutionData();
346+
await this.sendDirtyState();
302347
} catch (error) {
303348
const messages = await this.csolutionService.getLogMessages();
304349

@@ -394,10 +439,12 @@ export class ComponentsPacksWebviewMain {
394439
};
395440

396441
private async handleRequestInitialData(): Promise<void> {
397-
const projectId = this.getValidProjectId();
442+
const cprojectPath = this.getValidProjectId();
398443
this.scope = ComponentScope.Solution;
399-
if (projectId) {
400-
await this.debounce_load(projectId, true);
444+
if (cprojectPath) {
445+
const reload = this.projectFromPath(this.currentProject?.project.projectId) !== this.projectFromPath(cprojectPath);
446+
447+
await this.debounce_load(cprojectPath, reload);
401448
}
402449
}
403450

src/views/manage-components-packs/view/components/component-pack-manager.tsx

Lines changed: 47 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -110,51 +110,53 @@ export const ComponentPackManager = (props: ComponentProps) => {
110110
},
111111
token: { fontSize: 13, sizeStep: 4, borderRadius: 3 }
112112
}}>
113-
<Row className='components-view-actions'>
114-
<Col>
115-
<Button onClick={onApplyComponentSet} disabled={!state.isDirty} style={{ minWidth: '100px' }} type='primary'>Save</Button>
116-
</Col>
117-
<Col flex={'350px'}>
118-
<Segmented
119-
options={[{ label: 'Components', value: 'components' }, { label: 'Software packs', value: 'packs' }]}
120-
value={activeView}
121-
onChange={onChangeActiveView} />
122-
</Col>
123-
<Col flex={'auto'}>
124-
<Segmented
125-
options={[{ label: 'Packs in solution', value: ComponentScope.Solution }, { label: 'All installed packs', value: ComponentScope.All }]}
126-
value={state.componentScope}
127-
onChange={onChangeComponentRange} />
128-
</Col>
129-
</Row>
130-
131-
{activeView === 'components' &&
132-
<ComponentsView
133-
treeNodes={treeNodes}
134-
state={state}
135-
expandedRowKeys={expandedRowKeys}
136-
setExpandedRowKeys={setExpandedRowKeys}
137-
dropdownKey={dropdownKey}
138-
setDropdownKey={setDropdownKey}
139-
componentRefs={componentRefs}
140-
messageHandler={messageHandler}
141-
validationErrorComponents={validationErrorComponents}
142-
onChangeComponentValue={onChangeComponentValue}
143-
onChangeComponentVariant={onChangeComponentVariant}
144-
onChangeBundle={onChangeBundle}
145-
openFile={openFile}
146-
openDocFile={openDocFile}
147-
onSearch={onSearch}
148-
/>
149-
}
150-
{activeView === 'packs' &&
151-
<PacksView
152-
state={state}
153-
openFile={openFile}
154-
messageHandler={messageHandler}
155-
availablePacks={state.availablePacks}
156-
/>
157-
}
113+
<div style={{ minWidth: '790px', overflowX: 'auto' }}>
114+
<Row className='components-view-actions'>
115+
<Col>
116+
<Button onClick={onApplyComponentSet} disabled={!state.isDirty} style={{ minWidth: '100px' }} type='primary'>Save</Button>
117+
</Col>
118+
<Col flex={'350px'}>
119+
<Segmented
120+
options={[{ label: 'Components', value: 'components' }, { label: 'Software packs', value: 'packs' }]}
121+
value={activeView}
122+
onChange={onChangeActiveView} />
123+
</Col>
124+
<Col flex={'auto'}>
125+
<Segmented
126+
options={[{ label: 'Packs in solution', value: ComponentScope.Solution }, { label: 'All installed packs', value: ComponentScope.All }]}
127+
value={state.componentScope}
128+
onChange={onChangeComponentRange} />
129+
</Col>
130+
</Row>
131+
132+
{activeView === 'components' &&
133+
<ComponentsView
134+
treeNodes={treeNodes}
135+
state={state}
136+
expandedRowKeys={expandedRowKeys}
137+
setExpandedRowKeys={setExpandedRowKeys}
138+
dropdownKey={dropdownKey}
139+
setDropdownKey={setDropdownKey}
140+
componentRefs={componentRefs}
141+
messageHandler={messageHandler}
142+
validationErrorComponents={validationErrorComponents}
143+
onChangeComponentValue={onChangeComponentValue}
144+
onChangeComponentVariant={onChangeComponentVariant}
145+
onChangeBundle={onChangeBundle}
146+
openFile={openFile}
147+
openDocFile={openDocFile}
148+
onSearch={onSearch}
149+
/>
150+
}
151+
{activeView === 'packs' &&
152+
<PacksView
153+
state={state}
154+
openFile={openFile}
155+
messageHandler={messageHandler}
156+
availablePacks={state.availablePacks}
157+
/>
158+
}
159+
</div>
158160
</ConfigProvider>
159161
</div>
160162
</React.StrictMode>

src/views/manage-components-packs/view/components/components-view.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export const ComponentsView: React.FC<ComponentsViewProps> = ({
113113
{ title: '', width: 40, render: (record: ComponentRowDataType) => renderWarningCell(record, state) },
114114
Table.SELECTION_COLUMN,
115115
{ title: '', width: 40, render: (record: ComponentRowDataType) => renderEditField(record, setSelectedComponent, state) },
116-
{ title: 'Variant', dataIndex: ['parsed', 'variant'], key: 'variant', minWidth: 60, render: (value: string, record: ComponentRowDataType, index: number) => renderVariantCell(value, record, index, onChangeBundle, onChangeComponentVariant), ellipsis: false },
116+
{ title: 'Variant', dataIndex: ['parsed', 'variant'], key: 'variant', minWidth: 60, maxWidth: 90, ellipsis: true, render: (value: string, record: ComponentRowDataType, index: number) => renderVariantCell(value, record, index, onChangeBundle, onChangeComponentVariant) },
117117
{ title: 'Version', dataIndex: ['parsed', 'version'], key: 'version', minWidth: 60, ellipsis: false },
118118
{ title: 'Vendor', dataIndex: ['parsed', 'vendor'], key: 'vendor', minWidth: 60, ellipsis: false },
119119
{ title: 'Description', dataIndex: ['data', 'description'], key: 'data.description', width: 'calc(fit-content - 50px)', ellipsis: true, render: (value: string, record: ComponentRowDataType) => renderDescriptionCell(value, record, state, openDocFile) },

0 commit comments

Comments
 (0)