Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
144 changes: 70 additions & 74 deletions shell/models/chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,91 +136,87 @@ export default class Chart extends SteveModel {
* @returns {Object} Card content object with `subHeaderItems`, `footerItems`, and `statuses` arrays.
*/
get cardContent() {
if (!this._cardContent) {
const latestVersion = this.latestCompatibleVersion;
const subHeaderItems = [];

if (latestVersion) {
const hasZeroTime = latestVersion.created === ZERO_TIME;

subHeaderItems.push({
icon: 'icon-version-alt',
iconTooltip: { key: 'tableHeaders.version' },
label: latestVersion.version
});

const lastUpdatedItem = {
icon: 'icon-refresh-alt',
iconTooltip: { key: 'tableHeaders.lastUpdated' },
label: hasZeroTime ? this.t('generic.na') : day(latestVersion.created).format('MMM D, YYYY')
};

if (hasZeroTime) {
lastUpdatedItem.labelTooltip = this.t('catalog.charts.appChartCard.subHeaderItem.missingVersionDate');
}

subHeaderItems.push(lastUpdatedItem);
}
const latestVersion = this.latestCompatibleVersion;
const subHeaderItems = [];

if (latestVersion) {
const hasZeroTime = latestVersion.created === ZERO_TIME;

subHeaderItems.push({
icon: 'icon-version-alt',
iconTooltip: { key: 'tableHeaders.version' },
label: latestVersion.version
});

const lastUpdatedItem = {
icon: 'icon-refresh-alt',
iconTooltip: { key: 'tableHeaders.lastUpdated' },
label: hasZeroTime ? this.t('generic.na') : day(latestVersion.created).format('MMM D, YYYY')
};

const footerItems = [
{
type: REPO,
icon: 'icon-repository-alt',
iconTooltip: { key: 'tableHeaders.repoName' },
labels: [this.repoNameDisplay],
labelTooltip: this.t('catalog.charts.findSimilar.message', { type: this.t('catalog.charts.findSimilar.types.repo') }, true)
}
];

if (this.categories.length) {
footerItems.push( {
type: CATEGORY,
icon: 'icon-category-alt',
iconTooltip: { key: 'generic.category' },
labels: this.categories,
labelTooltip: this.t('catalog.charts.findSimilar.message', { type: this.t('catalog.charts.findSimilar.types.category') }, true)
});
if (hasZeroTime) {
lastUpdatedItem.labelTooltip = this.t('catalog.charts.appChartCard.subHeaderItem.missingVersionDate');
}

if (this.tags.length) {
footerItems.push({
type: TAG,
icon: 'icon-tag-alt',
iconTooltip: { key: 'generic.tags' },
labels: this.tags,
labelTooltip: this.t('catalog.charts.findSimilar.message', { type: this.t('catalog.charts.findSimilar.types.tag') }, true)
});
subHeaderItems.push(lastUpdatedItem);
}

const footerItems = [
{
type: REPO,
icon: 'icon-repository-alt',
iconTooltip: { key: 'tableHeaders.repoName' },
labels: [this.repoNameDisplay],
labelTooltip: this.t('catalog.charts.findSimilar.message', { type: this.t('catalog.charts.findSimilar.types.repo') }, true)
}
];

if (this.categories.length) {
footerItems.push( {
type: CATEGORY,
icon: 'icon-category-alt',
iconTooltip: { key: 'generic.category' },
labels: this.categories,
labelTooltip: this.t('catalog.charts.findSimilar.message', { type: this.t('catalog.charts.findSimilar.types.category') }, true)
});
}

const statuses = [];
if (this.tags.length) {
footerItems.push({
type: TAG,
icon: 'icon-tag-alt',
iconTooltip: { key: 'generic.tags' },
labels: this.tags,
labelTooltip: this.t('catalog.charts.findSimilar.message', { type: this.t('catalog.charts.findSimilar.types.tag') }, true)
});
}

if (this.deprecated) {
statuses.push({
icon: 'icon-alert-alt', color: 'error', tooltip: { key: 'generic.deprecated' }
});
}
const statuses = [];

if (this.upgradeable) {
statuses.push({
icon: 'icon-upgrade-alt', color: 'info', tooltip: { key: 'generic.upgradeable' }
});
}
if (this.deprecated) {
statuses.push({
icon: 'icon-alert-alt', color: 'error', tooltip: { key: 'generic.deprecated' }
});
}

if (this.isInstalled) {
const installedVersion = this.matchingInstalledApps[0]?.spec?.chart?.metadata?.version;
if (this.upgradeable) {
statuses.push({
icon: 'icon-upgrade-alt', color: 'info', tooltip: { key: 'generic.upgradeable' }
});
}

statuses.push({
icon: 'icon-confirmation-alt', color: 'success', tooltip: { text: `${ this.t('generic.installed') } (${ installedVersion })` }
});
}
if (this.isInstalled) {
const installedVersion = this.matchingInstalledApps[0]?.spec?.chart?.metadata?.version;

this._cardContent = {
subHeaderItems,
footerItems,
statuses
};
statuses.push({
icon: 'icon-confirmation-alt', color: 'success', tooltip: { text: `${ this.t('generic.installed') } (${ installedVersion })` }
});
}

return this._cardContent;
return {
subHeaderItems,
footerItems,
statuses
};
}
}
34 changes: 13 additions & 21 deletions shell/pages/c/_cluster/apps/charts/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ export default {
}
}
],
appCardsCache: {},
selectedSortOption: CATALOG_SORT_OPTIONS.RECOMMENDED,
sortOptions: [
{ kind: 'group', label: this.t('catalog.charts.sort.prefix') },
Expand Down Expand Up @@ -280,26 +279,19 @@ export default {
appChartCards() {
const charts = this.filteredCharts.slice(0, this.visibleChartsCount);

return charts.map((chart) => {
if (!this.appCardsCache[chart.id]) {
// Cache the converted value. We're caching chart.cardContent anyway, so no need to worry about showing updates to state
this.appCardsCache[chart.id] = {
id: chart.id,
pill: chart.featured ? { label: { key: 'generic.shortFeatured' }, tooltip: { key: 'generic.featured' } } : undefined,
header: {
title: { text: chart.chartNameDisplay },
statuses: chart.cardContent.statuses
},
subHeaderItems: chart.cardContent.subHeaderItems,
image: { src: chart.latestCompatibleVersion.icon, alt: { text: this.t('catalog.charts.iconAlt', { app: get(chart, 'chartNameDisplay') }) } },
content: { text: chart.chartDescription },
footerItems: chart.cardContent.footerItems,
rawChart: chart
};
}

return this.appCardsCache[chart.id];
});
return charts.map((chart) => ({
id: chart.id,
pill: chart.featured ? { label: { key: 'generic.shortFeatured' }, tooltip: { key: 'generic.featured' } } : undefined,
header: {
title: { text: chart.chartNameDisplay },
statuses: chart.cardContent.statuses
},
subHeaderItems: chart.cardContent.subHeaderItems,
image: { src: chart.latestCompatibleVersion.icon, alt: { text: this.t('catalog.charts.iconAlt', { app: get(chart, 'chartNameDisplay') }) } },
content: { text: chart.chartDescription },
footerItems: chart.cardContent.footerItems,
rawChart: chart
}));
},

clusterId() {
Expand Down
Loading